lab-manager 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # ##########################################################################################
3
+ # lab_checkout.rb
4
+ #
5
+ # bin/lab_checkout.rb "ORG" "WORKSPACE" "CONFIGURATION" "NEW CONFIGURATION"
6
+ # ##########################################################################################
7
+
8
+ require 'rubygems'
9
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
10
+ require "lab_manager"
11
+
12
+ if (ARGV.size < 4)
13
+ puts "usage: #{File.basename __FILE__} <organization> <workspace> <configuration> <new configuration>"
14
+ Process.exit(1)
15
+ end
16
+
17
+ organization = ARGV[0]
18
+ workspace = ARGV[1]
19
+ configuration = ARGV[2]
20
+ new_configuration = ARGV[3]
21
+
22
+ lab = LabManager.new(organization)
23
+ lab.workspace = workspace
24
+ lab.checkout(configuration, new_configuration)
25
+
26
+ puts "Clone of library complete"
27
+
data/bin/lab_clone.sh ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # ##########################################################################################
3
+ # lab_clone.rb
4
+ #
5
+ # bin/lab_clone.rb "ORG" "WORKSPACE" "CONFIGURATION" "NEW CONFIGURATION"
6
+ # ##########################################################################################
7
+
8
+ require 'rubygems'
9
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
10
+ require "lab_manager"
11
+
12
+ if (ARGV.size < 4)
13
+ puts "usage: #{File.basename __FILE__} <organization> <workspace> <configuration> <new configuration>"
14
+ Process.exit(1)
15
+ end
16
+
17
+ organization = ARGV[0]
18
+ workspace = ARGV[1]
19
+ configuration = ARGV[2]
20
+ new_configuration = ARGV[3]
21
+
22
+ lab = LabManager.new(organization)
23
+ lab.workspace = workspace
24
+ lab.clone(configuration, new_configuration)
25
+
26
+ puts "Clone complete"
27
+
data/bin/lab_delete.sh ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # ##########################################################################################
3
+ # lab_delete.rb
4
+ #
5
+ # bin/lab_delete.rb "ORG" "WORKSPACE" "CONFIGURATION"
6
+ # ##########################################################################################
7
+
8
+ require 'rubygems'
9
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
10
+ require "lab_manager"
11
+
12
+ if (ARGV.size < 3)
13
+ puts "usage: #{File.basename __FILE__} <organization> <workspace> <configuration>"
14
+ Process.exit(1)
15
+ end
16
+
17
+ organization = ARGV[0]
18
+ workspace = ARGV[1]
19
+ configuration = ARGV[2]
20
+
21
+ lab = LabManager.new(organization)
22
+ lab.workspace = workspace
23
+ lab.delete(configuration)
24
+
25
+ puts "Delete complete"
26
+
data/lib/lab_manager.rb CHANGED
@@ -5,8 +5,10 @@ require 'soap/element'
5
5
  require 'soap/netHttpClient'
6
6
  require 'xsd/datatypes'
7
7
  require 'yaml'
8
+ require 'ostruct'
8
9
 
9
10
  require 'lab_manager/machine'
11
+ require 'lab_manager/configuration'
10
12
 
11
13
  require 'lab_manager/httpclient_patch'
12
14
 
@@ -65,32 +67,53 @@ class LabManager
65
67
  @organization = organization
66
68
  end
67
69
 
68
- #<GetConfigurationByName xmlns="http://vmware.com/labmanager">
69
- # <name>string</name>
70
- #</GetConfigurationByName>
71
- #
72
- #<GetConfigurationByNameResponse xmlns="http://vmware.com/labmanager">
73
- # <GetConfigurationByNameResult>
74
- # <Configuration>
75
- # <id>int</id>
76
- # <name>string</name>
77
- # <description>string</description>
78
- # <isPublic>boolean</isPublic>
79
- # <isDeployed>boolean</isDeployed>
80
- # <fenceMode>int</fenceMode>
81
- # <type>int</type>
82
- # <owner>string</owner>
83
- # <dateCreated>dateTime</dateCreated>
84
- # <autoDeleteInMilliSeconds>double</autoDeleteInMilliSeconds>
85
- # <bucketName>string</bucketName>
86
- # <mustBeFenced>NotSpecified or True or False</mustBeFenced>
87
- # <autoDeleteDateTime>dateTime</autoDeleteDateTime>
88
- # </Configuration>
89
- #
90
- def configuration(name)
91
- proxy.GetConfigurationByName(:name => name)
70
+ # Retrieve configuration information
71
+ #
72
+ # ==== XML Sample
73
+ #
74
+ # <GetConfigurationByName xmlns="http://vmware.com/labmanager">
75
+ # <name>string</name>
76
+ # </GetConfigurationByName>
77
+ #
78
+ # <GetConfigurationByNameResponse xmlns="http://vmware.com/labmanager">
79
+ # <GetConfigurationByNameResult>
80
+ # <Configuration>
81
+ # <id>int</id>
82
+ # <name>string</name>
83
+ # <description>string</description>
84
+ # <isPublic>boolean</isPublic>
85
+ # <isDeployed>boolean</isDeployed>
86
+ # <fenceMode>int</fenceMode>
87
+ # <type>int</type>
88
+ # <owner>string</owner>
89
+ # <dateCreated>dateTime</dateCreated>
90
+ # <autoDeleteInMilliSeconds>double</autoDeleteInMilliSeconds>
91
+ # <bucketName>string</bucketName>
92
+ # <mustBeFenced>NotSpecified or True or False</mustBeFenced>
93
+ # <autoDeleteDateTime>dateTime</autoDeleteDateTime>
94
+ # </Configuration>
95
+ #
96
+ # * name_or_id can be a configuration name or a configuration id returned
97
+ # by another method. An id is identified as only digits.
98
+ #
99
+ def configuration(name_or_id)
100
+ if name_or_id =~ /^\d+$/
101
+ config_data = proxy.GetConfiguration(:configurationId => name_or_id)
102
+ else
103
+ config_data = proxy.GetConfigurationByName(:name => name_or_id)
104
+ end
105
+ Configuration.parse(config_data)
106
+ end
107
+
108
+ # Retrieve a list of configuration information
109
+ def configurations()
110
+ proxy.ListConfigurations(:configurationType => 2)
92
111
  end
93
112
 
113
+ # Retrieve a list of machines in a configuration
114
+ #
115
+ # ==== XML Sample
116
+ #
94
117
  # <ListMachines xmlns="http://vmware.com/labmanager">
95
118
  # <configurationId>int</configurationId>
96
119
  # </ListMachines>
@@ -112,15 +135,18 @@ class LabManager
112
135
  # <HostNameDeployedOn>string</HostNameDeployedOn>
113
136
  # <OwnerFullName>string</OwnerFullName>
114
137
  # </Machine>
138
+ #
139
+ # * configuration_name
140
+ #
141
+ # ==== Examples
115
142
  #
116
143
  # lab_manager.machines("CONFIG NAME")
117
144
  # lab_manager.machines("CONFIG NAME", :exclude => ["machine name"])
118
145
  #
119
- def machines(configurationName, options = {})
120
- configuration = proxy.GetConfigurationByName(:name => configurationName)
121
- configurationId = configuration["GetConfigurationByNameResult"]["Configuration"]["id"]
146
+ def machines(configuration_name, options = {})
147
+ config = configuration(configuration_name)
122
148
 
123
- data = proxy.ListMachines(:configurationId => configurationId)
149
+ data = proxy.ListMachines(:configurationId => config.id)
124
150
 
125
151
  machines = Machine.from_list(data)
126
152
 
@@ -133,13 +159,109 @@ class LabManager
133
159
  machines
134
160
  end
135
161
 
136
- def machine(configurationName, machineName)
137
- machines(configurationName).find { |machine|
162
+ # Retrieve the informaiton for a single machine in a configuration
163
+ def machine(configuration_name, machineName)
164
+ machines(configuration_name).find { |machine|
138
165
  machine.name == machineName
139
166
  }
140
167
  end
141
168
 
169
+ # Clones a configuration from a library.
170
+ #
171
+ # ==== XML Samples
172
+ #
173
+ # <ConfigurationCheckout xmlns:n1="http://vmware.com/labmanager">
174
+ # <configurationId>1138</configurationId>
175
+ # <workspaceName>NEW TEST CONFIG</workspaceName>
176
+ # </ConfigurationCheckout>
177
+ #
178
+ # * configuration_name to clone from the library
179
+ # * new_configuration_name to clone to
180
+ #
181
+ # return the new configuration id
182
+ #
183
+ def checkout(configuration_name, new_configuration_name)
184
+ config = configuration(configuration_name)
185
+
186
+ data = proxy.ConfigurationCheckout(
187
+ :configurationId => config.id,
188
+ :workspaceName => new_configuration_name)
189
+ data["ConfigurationCheckoutResult"]
190
+ end
191
+
192
+ # Clone a configuration to a new name
193
+ #
194
+ # ==== XML Sample
195
+ #
196
+ # <ConfigurationClone xmlns="http://vmware.com/labmanager">
197
+ # <configurationId>int</configurationId>
198
+ # <newWorkspaceName>string</newWorkspaceName>
199
+ # </ConfigurationClone>
200
+ #
201
+ # <ConfigurationCloneResponse xmlns="http://vmware.com/labmanager">
202
+ # <ConfigurationCloneResult>1150</ConfigurationCloneResult>
203
+ # </ConfigurationCloneResponse>
204
+ #
205
+ # * configuration_name to clone
206
+ # * new_configuration_name to clone to
207
+ #
208
+ # returns the id of the cloned configuration.
209
+ #
210
+ def clone(configuration_name, new_configuration_name)
211
+ config = configuration(configuration_name)
212
+
213
+ data = proxy.ConfigurationClone(
214
+ :configurationId => config.id,
215
+ :newWorkspaceName => new_configuration_name)
216
+ data["ConfigurationCloneResult"]
217
+ end
218
+
219
+ # Undeploys a configuration
220
+ #
221
+ # ==== XML Sample
222
+ #
223
+ # * configuration_name to undeploy
224
+ #
225
+ def undeploy(configuration_name)
226
+ config = configuration(configuration_name)
227
+
228
+ proxy.ConfigurationUndeploy(:configurationId => config.id)
229
+ end
230
+
231
+ # Delete a configuration
232
+ #
233
+ # ==== XML Sample
234
+ #
235
+ # <ConfigurationDelete xmlns="http://vmware.com/labmanager">
236
+ # <configurationId>int</configurationId>
237
+ # </ConfigurationDelete>
238
+ #
239
+ # <ConfigurationDeleteResponse xmlns="http://vmware.com/labmanager" />
240
+ #
241
+ # * configuration_name to be deleted
242
+ #
243
+ # raises SOAP:FaultError. See e.faultstring or e.detail
244
+ #
245
+ def delete(configuration_name, options = {})
246
+ config = configuration(configuration_name)
247
+
248
+ if (config.deployed)
249
+ fault = OpenStruct.new(
250
+ :faultstring => "Can not delete configuration that is deployed",
251
+ :detail => "Must use force flag to auto-undeploy.")
252
+ raise SOAP::FaultError.new(fault) unless options[:force]
253
+
254
+ proxy.ConfigurationUndeploy(:configurationId => config.id)
255
+ end
256
+
257
+ proxy.ConfigurationDelete(:configurationId => config.id)
258
+ end
259
+
142
260
  private
261
+ def self.config
262
+ YAML::load_file(@@configPath)
263
+ end
264
+
143
265
  def proxy
144
266
  factory = SOAP::WSDLDriverFactory.new("#{@@url}?WSDL")
145
267
  proxy = factory.create_rpc_driver
@@ -147,6 +269,9 @@ class LabManager
147
269
  proxy.generate_explicit_type = false # No datatype with request
148
270
  proxy.headerhandler << LabManagerHeader.new(@organization, @workspace, @@username, @@password)
149
271
 
272
+ # The lab manager clone and checkout requests can take a long time.
273
+ proxy.streamhandler.client.receive_timeout = 15 * 60 # seconds
274
+
150
275
  #proxy.streamhandler.client.ssl_config.verify_mode = false
151
276
 
152
277
  proxy
@@ -154,10 +279,10 @@ class LabManager
154
279
 
155
280
  def load_config(url, username, password)
156
281
  if File.exists? @@configPath
157
- config = YAML::load_file(@@configPath)
158
- @@url = config["url"]
159
- @@username = config["username"]
160
- @@password = config["password"]
282
+ configData = LabManager.config
283
+ @@url = configData["url"]
284
+ @@username = configData["username"]
285
+ @@password = configData["password"]
161
286
  end
162
287
 
163
288
  @@url = url if !url.nil?
@@ -0,0 +1,23 @@
1
+ class Configuration
2
+
3
+ def self.parse(data)
4
+
5
+ if !data.keys.empty? && data.keys.first != "Configuration"
6
+ data = data.values[0]
7
+ end
8
+
9
+ configuration = Configuration.new
10
+ data_config = data["Configuration"]
11
+ if data_config
12
+ configuration.id = data_config["id"]
13
+ configuration.name = data_config["name"]
14
+ configuration.deployed = data_config["isDeployed"] == "true" ? true : false
15
+ end
16
+
17
+ configuration
18
+ end
19
+
20
+ attr_accessor :id
21
+ attr_accessor :name
22
+ attr_accessor :deployed
23
+ end
metadata CHANGED
@@ -1,97 +1,84 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lab-manager
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 7
10
- version: 1.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ed Sumerfield
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-11-05 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: mumboe-soap4r
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
47
38
  type: :development
48
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
49
46
  description: Access information about your Lab Manager configurations.
50
47
  email: esumerfield@ipcoop.com
51
48
  executables: []
52
-
53
49
  extensions: []
54
-
55
50
  extra_rdoc_files: []
56
-
57
- files:
51
+ files:
52
+ - lib/lab_manager/configuration.rb
58
53
  - lib/lab_manager/httpclient_patch.rb
59
54
  - lib/lab_manager/machine.rb
60
55
  - lib/lab_manager.rb
56
+ - bin/lab_checkout.sh
57
+ - bin/lab_clone.sh
58
+ - bin/lab_delete.sh
61
59
  - bin/lab_machines.sh
62
- has_rdoc: true
63
60
  homepage:
64
61
  licenses: []
65
-
66
62
  post_install_message:
67
63
  rdoc_options: []
68
-
69
- require_paths:
64
+ require_paths:
70
65
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
66
+ required_ruby_version: !ruby/object:Gem::Requirement
72
67
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
80
- required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
73
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
89
78
  requirements: []
90
-
91
79
  rubyforge_project:
92
- rubygems_version: 1.6.2
80
+ rubygems_version: 1.8.23
93
81
  signing_key:
94
82
  specification_version: 3
95
83
  summary: Client for VMWare Lab Manager
96
84
  test_files: []
97
-