1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Support to Configure the VM network

This commit is contained in:
Chirag Jog 2013-02-02 12:09:43 +05:30
parent e8bcf413e1
commit a4508c27de
3 changed files with 53 additions and 2 deletions

View file

@ -117,6 +117,7 @@ module Fog
request :configure_vm_name_description request :configure_vm_name_description
request :configure_vm_disks request :configure_vm_disks
request :configure_vm_password request :configure_vm_password
request :configure_vm_network
request :delete_vapp request :delete_vapp
request :get_catalog_item request :get_catalog_item
request :get_customization_options request :get_customization_options

View file

@ -18,7 +18,7 @@ module Fog
attribute :vapp_scoped_local_id, :aliases => :VAppScopedLocalId attribute :vapp_scoped_local_id, :aliases => :VAppScopedLocalId
attribute :network_connections, :aliases => :NetworkConnectionSection, :squash => :NetworkConnection attribute :network_connections, :aliases => :NetworkConnectionSection#, :squash => :NetworkConnection
attribute :virtual_hardware, :aliases => :'ovf:VirtualHardwareSection', :squash => :'ovf:Item' attribute :virtual_hardware, :aliases => :'ovf:VirtualHardwareSection', :squash => :'ovf:Item'
attribute :guest_customization, :aliases => :GuestCustomizationSection attribute :guest_customization, :aliases => :GuestCustomizationSection
@ -123,7 +123,14 @@ module Fog
@update_memory_value = amount @update_memory_value = amount
amount amount
end end
def network
network_connections[:NetworkConnection] if network_connections
end
def network=(network_info)
@changed = true
@update_network = network_info
network_info
end
def disks def disks
disk_mess.map do |dm| disk_mess.map do |dm|
{ :number => dm[:"rasd:AddressOnParent"].to_i, :size => dm[:"rasd:HostResource"][:vcloud_capacity].to_i, :resource => dm[:"rasd:HostResource"], :disk_data => dm } { :number => dm[:"rasd:AddressOnParent"].to_i, :size => dm[:"rasd:HostResource"][:vcloud_capacity].to_i, :resource => dm[:"rasd:HostResource"], :disk_data => dm }
@ -203,6 +210,12 @@ module Fog
wait_for { ready? } wait_for { ready? }
end end
if @update_network
network_connections[:NetworkConnection][:network] = @update_network[:network_name]
network_connections[:NetworkConnection][:IpAddressAllocationMode] = @update_network[:network_mode]
service.configure_vm_network(network_connections)
wait_for { ready? }
end
if @disk_change == :deleted if @disk_change == :deleted
data = disk_mess.delete_if do |vh| data = disk_mess.delete_if do |vh|
vh[:'rasd:ResourceType'] == '17' && vh[:'rasd:ResourceType'] == '17' &&

View file

@ -0,0 +1,37 @@
# -*- encoding: utf-8 -*-
module Fog
module Vcloud
class Compute
class Real
def configure_vm_network(network_info)
edit_uri = network_info.select {|k,v| k == :Link && v[:rel] == 'edit'}
edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[1][:href] : edit_uri[:Link][:href]
body = <<EOF
<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="#{edit_uri}">
<ovf:Info>Specifies the available VM network connections</ovf:Info>
<PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex>
<NetworkConnection network="#{network_info[:NetworkConnection][:network]}" needsCustomization="true">
<NetworkConnectionIndex>0</NetworkConnectionIndex>
<IsConnected>true</IsConnected>
<IpAddressAllocationMode>#{network_info[:NetworkConnection][:IpAddressAllocationMode]}</IpAddressAllocationMode>
</NetworkConnection>
</NetworkConnectionSection>
EOF
print "Request: #{body}"
request(
:body => body,
:expects => 202,
:headers => {'Content-Type' => network_info[:"vcloud_type"] },
:method => 'PUT',
:uri => "#{edit_uri}",
:parse => true
)
end
end
end
end
end