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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/delphix/environment.rb', line 92

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



133
134
135
136
137
138
139
140
# File 'lib/delphix/environment.rb', line 133

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



86
87
88
# File 'lib/delphix/environment.rb', line 86

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

#delete(delete_all_sources = true) ⇒ Object

basic operations



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/delphix/environment.rb', line 14

def delete(delete_all_sources=true)

  if delete_all_sources
    # stop and delete all sources on this environment
    sources = lookup_sources
    if sources != nil
      containers = {}

      # build a list of unique container references
      sources.each do |src|
        container_ref = src.details['container']
        containers[container_ref] = container_ref
      end

      # get a list of all databases
      databases = Delphix::Database.list

      # now delete all containers(databases)
      containers.keys.each do |ref|
        db = databases.lookup_by_ref ref
        db.delete.wait_for_completion
      end
    end
  end

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

#disable(disable_all_sources = true) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/delphix/environment.rb', line 61

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/delphix/environment.rb', line 44

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



80
81
82
# File 'lib/delphix/environment.rb', line 80

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