vcloud-rest 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 633b84969bc2687f204a6393a60c826791e057c1
4
- data.tar.gz: 6588a7985b975089fd0ba629caaa719dd262c6a2
3
+ metadata.gz: 7c2eb998fce7438cab0aceb5308024a7c660b487
4
+ data.tar.gz: b7d09d0d744be363ef4dbe172c0d9d31474625eb
5
5
  SHA512:
6
- metadata.gz: 1fbb7b9ce96cb65c796813ee31c7d1a266a15e791f8f51e507945c234b97860c1848827324e2d90df53723ac07fad7359a6eed5418620789df5a8fb3321982f5
7
- data.tar.gz: 80d5e7180bd05dc72f208cd741e3b54e4204aa5387c5c11bc15ca86d9ab611871cf61b3cc0f4efa73b6192e8e85de021f64ca1913ea5f70d222cc686b50d3fd5
6
+ metadata.gz: ccab7973655779b11498d5df9da2c50626f6aa199ac0d97ca1417f0285e30b9d486a0a7f1aff43b84a132d76bd0d1bc9b80b3b2a8c6776fc86343f0c512014ac
7
+ data.tar.gz: 64a015a7b3803fdedfc30efe46c31ecced6f797a2036227eefe3cedb0811f17ae671433d87e13754104f723ad49faa91ea5b034d5eb146c9dc5db775b90975b7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  Changes
2
2
  ==
3
+ 2013-12-13 (1.1.0)
4
+ --
5
+
6
+ FEATURES:
7
+
8
+ * Add commands `[add|edit|delete]_vm_network` to manage multiple networks
9
+
10
+ DEPRECATIONS:
11
+
12
+ * `set_vm_network_config` is now deprecated
13
+
3
14
  2013-11-29 (1.0.0)
4
15
  --
5
16
 
@@ -116,9 +116,144 @@ module VCloudClient
116
116
  task_id
117
117
  end
118
118
 
119
+ ##
120
+ # Edit VM Network Config
121
+ #
122
+ # Retrieve the existing network config section and edit it
123
+ # to ensure settings are not lost
124
+ def edit_vm_network(vmId, network, config={})
125
+ params = {
126
+ 'method' => :get,
127
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
128
+ }
129
+
130
+ netconfig_response, headers = send_request(params)
131
+
132
+ picked_network = netconfig_response.css("NetworkConnection").select do |net|
133
+ net.attribute('network').text == network[:name]
134
+ end.first
135
+
136
+ raise WrongItemIDError, "Network named #{network[:name]} not found." unless picked_network
137
+
138
+ if config[:ip_allocation_mode]
139
+ node = picked_network.css('IpAddressAllocationMode').first
140
+ node.content = config[:ip_allocation_mode]
141
+ end
142
+
143
+ if config[:network_index]
144
+ node = picked_network.css('NetworkConnectionIndex').first
145
+ node.content = config[:network_index]
146
+ end
147
+
148
+ if config[:is_connected]
149
+ node = picked_network.css('IsConnected').first
150
+ node.content = config[:is_connected]
151
+ end
152
+
153
+ if config[:ip]
154
+ node = picked_network.css('IpAddress').first
155
+ node.content = config[:ip]
156
+ end
157
+
158
+ params = {
159
+ 'method' => :put,
160
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
161
+ }
162
+
163
+ response, headers = send_request(params, netconfig_response.to_xml, "application/vnd.vmware.vcloud.networkConnectionSection+xml")
164
+
165
+ task_id = headers[:location].gsub(/.*\/task\//, "")
166
+ task_id
167
+ end
168
+
169
+ ##
170
+ # Add a new network to a VM
171
+ def add_vm_network(vmId, network, config={})
172
+ params = {
173
+ 'method' => :get,
174
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
175
+ }
176
+
177
+ netconfig_response, headers = send_request(params)
178
+
179
+ parent_section = netconfig_response.css('NetworkConnectionSection').first
180
+
181
+ # For some reasons these elements must be removed
182
+ netconfig_response.css("Link").each {|n| n.remove}
183
+
184
+ networks_count = netconfig_response.css('NetworkConnection').count
185
+
186
+ new_network = Nokogiri::XML::Node.new "NetworkConnection", parent_section
187
+ new_network["network"] = network[:name]
188
+ new_network["needsCustomization"] = true
189
+
190
+ idx_node = Nokogiri::XML::Node.new "NetworkConnectionIndex", new_network
191
+ idx_node.content = config[:network_index] || networks_count
192
+ new_network.add_child(idx_node)
193
+
194
+ is_connected_node = Nokogiri::XML::Node.new "IsConnected", new_network
195
+ is_connected_node.content = config[:is_connected] || true
196
+ new_network.add_child(is_connected_node)
197
+
198
+ allocation_node = Nokogiri::XML::Node.new "IpAddressAllocationMode", new_network
199
+ allocation_node.content = config[:ip_allocation_mode] || "POOL"
200
+ new_network.add_child(allocation_node)
201
+
202
+ if config[:ip]
203
+ ip_node = Nokogiri::XML::Node.new "IpAddress", new_network
204
+ ip_node.content = config[:ip]
205
+ new_network.add_child(ip_node)
206
+ end
207
+
208
+ parent_section.add_child(new_network)
209
+
210
+ params = {
211
+ 'method' => :put,
212
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
213
+ }
214
+
215
+ put_response, headers = send_request(params, netconfig_response.to_xml, "application/vnd.vmware.vcloud.networkConnectionSection+xml")
216
+
217
+ task_id = headers[:location].gsub(/.*\/task\//, "")
218
+ task_id
219
+ end
220
+
221
+ ##
222
+ # Remove an existing network
223
+ def delete_vm_network(vmId, network)
224
+ params = {
225
+ 'method' => :get,
226
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
227
+ }
228
+
229
+ netconfig_response, headers = send_request(params)
230
+
231
+ picked_network = netconfig_response.css("NetworkConnection").select do |net|
232
+ net.attribute('network').text == network[:name]
233
+ end.first
234
+
235
+ raise WrongItemIDError, "Network #{network[:name]} not found on this VM." unless picked_network
236
+
237
+ picked_network.remove
238
+
239
+ params = {
240
+ 'method' => :put,
241
+ 'command' => "/vApp/vm-#{vmId}/networkConnectionSection"
242
+ }
243
+
244
+ put_response, headers = send_request(params, netconfig_response.to_xml, "application/vnd.vmware.vcloud.networkConnectionSection+xml")
245
+
246
+ task_id = headers[:location].gsub(/.*\/task\//, "")
247
+ task_id
248
+ end
249
+
119
250
  ##
120
251
  # Set VM Network Config
252
+ #
253
+ # DEPRECATED: use set_vm_network
121
254
  def set_vm_network_config(vmid, network_name, config={})
255
+ @logger.warn 'DEPRECATION WARNING: use [add,delete,edit]_vm_network instead.'
256
+
122
257
  builder = Nokogiri::XML::Builder.new do |xml|
123
258
  xml.NetworkConnectionSection(
124
259
  "xmlns" => "http://www.vmware.com/vcloud/v1.5",
@@ -1,3 +1,3 @@
1
1
  module VCloudClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcloud-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Tortarolo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-29 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -111,3 +111,4 @@ signing_key:
111
111
  specification_version: 4
112
112
  summary: Unofficial ruby bindings for VMWare vCloud's API
113
113
  test_files: []
114
+ has_rdoc: