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 +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/vcloud-rest/vcloud/vm.rb +135 -0
- data/lib/vcloud-rest/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2eb998fce7438cab0aceb5308024a7c660b487
|
4
|
+
data.tar.gz: b7d09d0d744be363ef4dbe172c0d9d31474625eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccab7973655779b11498d5df9da2c50626f6aa199ac0d97ca1417f0285e30b9d486a0a7f1aff43b84a132d76bd0d1bc9b80b3b2a8c6776fc86343f0c512014ac
|
7
|
+
data.tar.gz: 64a015a7b3803fdedfc30efe46c31ecced6f797a2036227eefe3cedb0811f17ae671433d87e13754104f723ad49faa91ea5b034d5eb146c9dc5db775b90975b7
|
data/CHANGELOG.md
CHANGED
@@ -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",
|
data/lib/vcloud-rest/version.rb
CHANGED
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.
|
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
|
+
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:
|