lab-manager 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ class Machine
2
+
3
+ def self.fromList(data)
4
+ return [] if data.nil?
5
+ return [] if data["ListMachinesResult"].nil?
6
+ return [] if data["ListMachinesResult"]["Machine"].nil?
7
+
8
+ data["ListMachinesResult"]["Machine"].collect { |machine|
9
+ Machine.new(machine)
10
+ }
11
+ end
12
+
13
+ def self.to_csv(machines)
14
+ machines.each do |machine|
15
+ puts machine.to_csv
16
+ end
17
+ end
18
+
19
+ attr_reader :name, :internal_ip, :external_ip
20
+
21
+ def initialize(machine)
22
+ @name = machine["name"]
23
+ @internal_ip = machine["internalIP"]
24
+ @external_ip = machine["externalIP"]
25
+ end
26
+
27
+ def to_csv
28
+ "#{name},#{internal_ip},#{external_ip}"
29
+ end
30
+ end
31
+
@@ -0,0 +1,181 @@
1
+ require 'net/https'
2
+ require 'soap/wsdlDriver'
3
+ require 'soap/header/simplehandler'
4
+ require 'soap/element'
5
+ require 'xsd/datatypes'
6
+
7
+ require 'soap/netHttpClient'
8
+
9
+ require 'lab_manager/machine'
10
+
11
+ #
12
+ # Monkey Patch HTTP Client
13
+ # Sets SSL verify mode to NONE so that we can connect to an SSL server
14
+ # that does not have a trusted certificate.
15
+ #
16
+ # The 1.8.7 patch adds a new constructor.
17
+ # The 1.9.3 patch intercepts the existing constructor now that the class
18
+ # name has changed.
19
+ if RUBY_VERSION == "1.8.7"
20
+ class HTTPAccess2::Client
21
+ def initialize(*args)
22
+ super(args[0], args[1])
23
+ @session_manager.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
24
+ #@session_manager.debug_dev = STDOUT
25
+ end
26
+ end
27
+ else # > 1.8.7
28
+ class HTTPClient
29
+ alias_method :original_initialize, :initialize
30
+ def initialize(*args)
31
+ original_initialize(args[0], args[1])
32
+ @session_manager.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
33
+ #@session_manager.debug_dev = STDOUT
34
+ end
35
+ end
36
+ end
37
+
38
+ #
39
+ # Lab Manager API
40
+ #
41
+ # Configure using configure method:
42
+ #
43
+ # LabManager.url = "YOUR URL"
44
+ #
45
+ class LabManager
46
+
47
+ @@url = nil
48
+ def self.url
49
+ @@url
50
+ end
51
+ def self.url=(value)
52
+ @@url = value
53
+ end
54
+
55
+ attr_accessor :workspace
56
+
57
+ def initialize(organization, username, password, url = nil)
58
+ raise "Missing url" if @@url.nil?
59
+
60
+ @organization = organization
61
+ @username = username
62
+ @password = password
63
+ @@url = url
64
+ end
65
+
66
+ #<GetConfigurationByName xmlns="http://vmware.com/labmanager">
67
+ # <name>string</name>
68
+ #</GetConfigurationByName>
69
+ #
70
+ #<GetConfigurationByNameResponse xmlns="http://vmware.com/labmanager">
71
+ # <GetConfigurationByNameResult>
72
+ # <Configuration>
73
+ # <id>int</id>
74
+ # <name>string</name>
75
+ # <description>string</description>
76
+ # <isPublic>boolean</isPublic>
77
+ # <isDeployed>boolean</isDeployed>
78
+ # <fenceMode>int</fenceMode>
79
+ # <type>int</type>
80
+ # <owner>string</owner>
81
+ # <dateCreated>dateTime</dateCreated>
82
+ # <autoDeleteInMilliSeconds>double</autoDeleteInMilliSeconds>
83
+ # <bucketName>string</bucketName>
84
+ # <mustBeFenced>NotSpecified or True or False</mustBeFenced>
85
+ # <autoDeleteDateTime>dateTime</autoDeleteDateTime>
86
+ # </Configuration>
87
+ #
88
+ def configuration(name)
89
+ proxy.GetConfigurationByName(:name => name)
90
+ end
91
+
92
+ # <ListMachines xmlns="http://vmware.com/labmanager">
93
+ # <configurationId>int</configurationId>
94
+ # </ListMachines>
95
+ #
96
+ # <ListMachinesResponse xmlns="http://vmware.com/labmanager">
97
+ # <ListMachinesResult>
98
+ # <Machine>
99
+ # <id>int</id>
100
+ # <name>string</name>
101
+ # <description>string</description>
102
+ # <internalIP>string</internalIP>
103
+ # <externalIP>string</externalIP>
104
+ # <macAddress>string</macAddress>
105
+ # <memory>int</memory>
106
+ # <status>int</status>
107
+ # <isDeployed>boolean</isDeployed>
108
+ # <configID>int</configID>
109
+ # <DatastoreNameResidesOn>string</DatastoreNameResidesOn>
110
+ # <HostNameDeployedOn>string</HostNameDeployedOn>
111
+ # <OwnerFullName>string</OwnerFullName>
112
+ # </Machine>
113
+ #
114
+ # lab_manager.machines("CONFIG NAME")
115
+ # lab_manager.machines("CONFIG NAME", :exclude => ["machine name"])
116
+ #
117
+ def machines(configurationName, options = {})
118
+ configuration = proxy.GetConfigurationByName(:name => configurationName)
119
+ configurationId = configuration["GetConfigurationByNameResult"]["Configuration"]["id"]
120
+
121
+ data = proxy.ListMachines(:configurationId => configurationId)
122
+
123
+ machines = Machine.fromList(data)
124
+
125
+ if (!options[:exclude].nil?)
126
+ machines = machines.find_all { |machine|
127
+ !options[:exclude].include?(machine.name)
128
+ }
129
+ end
130
+
131
+ machines
132
+ end
133
+
134
+ def machine(configurationName, machineName)
135
+ machines(configurationName).find { |machine|
136
+ machine.name == machineName
137
+ }
138
+ end
139
+
140
+ private
141
+ def proxy
142
+ factory = SOAP::WSDLDriverFactory.new("#{@@url}?WSDL")
143
+ proxy = factory.create_rpc_driver
144
+ #proxy.wiredump_dev = STDOUT
145
+ proxy.generate_explicit_type = false # No datatype with request
146
+ proxy.headerhandler << LabManagerHeader.new(@organization, @workspace, @username, @password)
147
+
148
+ proxy
149
+ end
150
+ end
151
+
152
+ # <soap:Header>
153
+ # <AuthenticationHeader xmlns="http://vmware.com/labmanager">
154
+ # <username>string</username>
155
+ # <password>string</password>
156
+ # <organizationname>string</organizationname>
157
+ # <workspacename>string</workspacename>
158
+ # </AuthenticationHeader>
159
+ # </soap:Header>
160
+ class LabManagerHeader < SOAP::Header::Handler
161
+
162
+ def initialize(organization, workspace, username, password)
163
+ super(XSD::QName.new("http://vmware.com/labmanager", ""))
164
+ @organization = organization
165
+ @workspace = workspace
166
+ @username = username
167
+ @password = password
168
+ end
169
+
170
+ def on_outbound
171
+ authentication = SOAP::SOAPElement.new('AuthenticationHeader')
172
+ authentication.extraattr['xmlns'] = 'http://vmware.com/labmanager'
173
+
174
+ authentication.add(SOAP::SOAPElement.new('username', @username))
175
+ authentication.add(SOAP::SOAPElement.new('password', @password))
176
+ authentication.add(SOAP::SOAPElement.new('organizationname', @organization))
177
+ authentication.add(SOAP::SOAPElement.new('workspacename', @workspace)) if @workspace
178
+
179
+ SOAP::SOAPHeaderItem.new(authentication, true)
180
+ end
181
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lab-manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ed Sumerfield
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mumboe-soap4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
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
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Access information about your Lab Manager configurations.
47
+ email: esumerfield@ipcoop.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - lib/lab_manager/machine.rb
53
+ - lib/lab_manager.rb
54
+ homepage:
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.23
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Client for VMWare Lab Manager
78
+ test_files: []