Class: LabManager

Inherits:
Object
  • Object
show all
Defined in:
lib/lab_manager.rb

Overview

Lab Manager API

Configure using configure method:

LabManager.url = "YOUR URL"

Constant Summary collapse

@@DEBUG =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organization, username = nil, password = nil, url = nil) ⇒ LabManager

Returns a new instance of LabManager.



61
62
63
64
65
66
67
68
# File 'lib/lab_manager.rb', line 61

def initialize(organization, username = nil, password = nil, url = nil)
  load_config(url, username, password)
  raise "Missing url" if @@url.nil?
  raise "Missing username" if @@username.nil?
  raise "Missing password" if @@password.nil?

  @organization = organization
end

Instance Attribute Details

#workspaceObject

Returns the value of attribute workspace.



59
60
61
# File 'lib/lab_manager.rb', line 59

def workspace
  @workspace
end

Class Method Details

.configPathObject



30
31
32
# File 'lib/lab_manager.rb', line 30

def self.configPath
  @@configPath
end

.configPath=(value) ⇒ Object



33
34
35
# File 'lib/lab_manager.rb', line 33

def self.configPath=(value)
  @@configPath = value
end

.DEBUG=(value) ⇒ Object



26
27
28
# File 'lib/lab_manager.rb', line 26

def self.DEBUG=(value)
  @@DEBUG = value
end

.passwordObject



46
47
48
# File 'lib/lab_manager.rb', line 46

def self.password
  @@password
end

.resetObject



50
51
52
53
54
55
56
# File 'lib/lab_manager.rb', line 50

def self.reset
  @@configPath = File.expand_path("~/.lab_manager")

  @@url = nil
  @@username = nil
  @@password = nil
end

.urlObject



37
38
39
# File 'lib/lab_manager.rb', line 37

def self.url
  @@url
end

.url=(value) ⇒ Object



40
41
42
# File 'lib/lab_manager.rb', line 40

def self.url=(value)
  @@url = value
end

.usernameObject



43
44
45
# File 'lib/lab_manager.rb', line 43

def self.username
  @@username
end

Instance Method Details

#checkout(configuration_name, new_configuration_name) ⇒ Object

Clones a configuration from a library.

XML Samples

<ConfigurationCheckout xmlns:n1="http://vmware.com/labmanager">
  <configurationId>1138</configurationId>
  <workspaceName>NEW TEST CONFIG</workspaceName>
</ConfigurationCheckout>
  • configuration_name to clone from the library

  • new_configuration_name to clone to

return the new configuration id



183
184
185
186
187
188
189
190
# File 'lib/lab_manager.rb', line 183

def checkout(configuration_name, new_configuration_name)
  config = configuration(configuration_name)

  data = proxy.ConfigurationCheckout(
            :configurationId => config.id,
            :workspaceName => new_configuration_name)
  data["ConfigurationCheckoutResult"]
end

#clone(configuration_name, new_configuration_name) ⇒ Object

Clone a configuration to a new name

XML Sample

<ConfigurationClone xmlns="http://vmware.com/labmanager">
   <configurationId>int</configurationId>
   <newWorkspaceName>string</newWorkspaceName>
</ConfigurationClone>

<ConfigurationCloneResponse xmlns="http://vmware.com/labmanager">
    <ConfigurationCloneResult>1150</ConfigurationCloneResult>
</ConfigurationCloneResponse>
  • configuration_name to clone

  • new_configuration_name to clone to

returns the id of the cloned configuration.



210
211
212
213
214
215
216
217
# File 'lib/lab_manager.rb', line 210

def clone(configuration_name, new_configuration_name)
  config = configuration(configuration_name)

  data = proxy.ConfigurationClone(
            :configurationId => config.id, 
            :newWorkspaceName => new_configuration_name)
  data["ConfigurationCloneResult"]
end

#configuration(name_or_id) ⇒ Object

Retrieve configuration information

XML Sample

<GetConfigurationByName xmlns=“vmware.com/labmanager”>

<name>string</name>

</GetConfigurationByName>

<GetConfigurationByNameResponse xmlns=“vmware.com/labmanager”>

<GetConfigurationByNameResult>
  <Configuration>
    <id>int</id>
    <name>string</name>
    <description>string</description>
    <isPublic>boolean</isPublic>
    <isDeployed>boolean</isDeployed>
    <fenceMode>int</fenceMode>
    <type>int</type>
    <owner>string</owner>
    <dateCreated>dateTime</dateCreated>
    <autoDeleteInMilliSeconds>double</autoDeleteInMilliSeconds>
    <bucketName>string</bucketName>
    <mustBeFenced>NotSpecified or True or False</mustBeFenced>
    <autoDeleteDateTime>dateTime</autoDeleteDateTime>
  </Configuration>
  • name_or_id can be a configuration name or a configuration id returned

by another method. An id is identified as only digits.



99
100
101
102
103
104
105
106
# File 'lib/lab_manager.rb', line 99

def configuration(name_or_id)
  if name_or_id =~ /^\d+$/
    config_data = proxy.GetConfiguration(:configurationId => name_or_id)
  else
    config_data = proxy.GetConfigurationByName(:name => name_or_id)
  end
  Configuration.parse(config_data)
end

#configurationsObject

Retrieve a list of configuration information



109
110
111
# File 'lib/lab_manager.rb', line 109

def configurations()
  proxy.ListConfigurations(:configurationType => 2)
end

#delete(configuration_name, options = {}) ⇒ Object

Delete a configuration

XML Sample

<ConfigurationDelete xmlns="http://vmware.com/labmanager">
   <configurationId>int</configurationId>
</ConfigurationDelete>

<ConfigurationDeleteResponse xmlns="http://vmware.com/labmanager" />
  • configuration_name to be deleted

raises SOAP:FaultError. See e.faultstring or e.detail



245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/lab_manager.rb', line 245

def delete(configuration_name, options = {})
  config = configuration(configuration_name)

  if (config.deployed)
    fault = OpenStruct.new(
        :faultstring => "Can not delete configuration that is deployed",
        :detail => "Must use force flag to auto-undeploy.")
    raise SOAP::FaultError.new(fault) unless options[:force]

    proxy.ConfigurationUndeploy(:configurationId => config.id)
  end

  proxy.ConfigurationDelete(:configurationId => config.id)
end

#machine(configuration_name, machineName) ⇒ Object

Retrieve the informaiton for a single machine in a configuration



163
164
165
166
167
# File 'lib/lab_manager.rb', line 163

def machine(configuration_name, machineName)
  machines(configuration_name).find { |machine|
    machine.name == machineName
  }
end

#machines(configuration_name, options = {}) ⇒ Object

Retrieve a list of machines in a configuration

XML Sample

<ListMachines xmlns="http://vmware.com/labmanager">
  <configurationId>int</configurationId>
</ListMachines>

<ListMachinesResponse xmlns="http://vmware.com/labmanager">
  <ListMachinesResult>
    <Machine>
      <id>int</id>
      <name>string</name>
      <description>string</description>
      <internalIP>string</internalIP>
      <externalIP>string</externalIP>
      <macAddress>string</macAddress>
      <memory>int</memory>
      <status>int</status>
      <isDeployed>boolean</isDeployed>
      <configID>int</configID>
      <DatastoreNameResidesOn>string</DatastoreNameResidesOn>
      <HostNameDeployedOn>string</HostNameDeployedOn>
      <OwnerFullName>string</OwnerFullName>
    </Machine>
  • configuration_name

Examples

lab_manager.machines("CONFIG NAME")
lab_manager.machines("CONFIG NAME", :exclude => ["machine name"])


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/lab_manager.rb', line 146

def machines(configuration_name, options = {})
  config = configuration(configuration_name)

  data = proxy.ListMachines(:configurationId => config.id)

  machines = Machine.from_list(data)

  if (!options[:exclude].nil?)
    machines = machines.find_all { |machine| 
      !options[:exclude].include?(machine.name)
    } 
  end

  machines
end

#undeploy(configuration_name) ⇒ Object

Undeploys a configuration

XML Sample

  • configuration_name to undeploy



225
226
227
228
229
# File 'lib/lab_manager.rb', line 225

def undeploy(configuration_name)
  config = configuration(configuration_name)
  
  proxy.ConfigurationUndeploy(:configurationId => config.id)
end