Class: Delphix::Environment

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/delphix/environment.rb

Instance Attribute Summary

Attributes included from Base

#details

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#name, #reference, #refresh_details, #to_s, #type

Constructor Details

#initialize(reference, details = nil) ⇒ Environment

Returns a new instance of Environment.



8
9
10
# File 'lib/delphix/environment.rb', line 8

def initialize(reference, details=nil)
  super(reference, details)
end

Class Method Details

.create(name, address, port, toolkit_path, username, password) ⇒ Object

class methods



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/delphix/environment.rb', line 68

def self.create(name, address, port, toolkit_path, username, password)
  body = {
    :type => 'HostEnvironmentCreateParameters',
    :primaryUser => {
      :type => 'EnvironmentUser',
      :name => username,
      :credential => {
        :type => 'PasswordCredential',
        :password => password
      }
    },
    :hostEnvironment => {
      :type => 'UnixHostEnvironment',
      :name => name
    },
    :hostParameters => {
      :type => 'UnixHostCreateParameters',
      :host => {
        :type => 'UnixHost',
        :address => address,
        :sshPort => port,
        :toolkitPath => toolkit_path
      }
    }
  }

  # create the environment
  resp = Delphix::Response.new( Delphix.post('/resources/json/delphix/environment', body.to_json))
  return nil if resp.is_error?

  # wait until the environment has been created
  resp.job.wait_for_completion

  # create a new skeleton environment object
  env = Delphix::Environment.new resp.details
  # and refresh the object from the engine
  env.refresh_details

  env
end

.listObject



109
110
111
112
113
114
115
116
# File 'lib/delphix/environment.rb', line 109

def self.list
  envs = Delphix::BaseArray.new
  result = Delphix.get('/resources/json/delphix/environment')['result']
  result.each do |env|
    envs << Delphix::Environment.new(env['reference'],env)
  end
  envs
end

Instance Method Details

#base_endpointObject

inherited operations



62
63
64
# File 'lib/delphix/environment.rb', line 62

def base_endpoint
  '/resources/json/delphix/environment'
end

#deleteObject

basic operations



14
15
16
# File 'lib/delphix/environment.rb', line 14

def delete
  Delphix::Response.new( Delphix.delete("#{base_endpoint}/#{reference}"))
end

#disable(disable_all_sources = true) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/delphix/environment.rb', line 37

def disable(disable_all_sources=true)

  if disable_all_sources
    # stop and disable all sources on this environment
    sources = lookup_sources
    if sources != nil
      sources.each do |src|
        if src.virtual?
          src.stop.wait_for_completion
        end
        src.disable.wait_for_completion
      end
    end
  end

  # now disable the environment itself
  Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/disable"))
end

#enable(enable_all_sources = false) ⇒ Object

specific operations



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/delphix/environment.rb', line 20

def enable(enable_all_sources=false)
  resp = Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/enable"))
  return resp if !enable_all_sources

  resp.wait_for_completion

  # enable all sources on this environment
  sources = lookup_sources
  if sources != nil
    sources.each do |src|
      src.enable.wait_for_completion
    end
  end

  resp
end

#refreshObject



56
57
58
# File 'lib/delphix/environment.rb', line 56

def refresh
  Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/refresh"))
end