Permalink
Browse files

Support to Configure the VM network

  • Loading branch information...
1 parent e27b2ee commit 6b7ae788cda11450970a9fcc9b45ccf629f621a9 @chirag-jog chirag-jog committed Feb 2, 2013
@@ -117,6 +117,7 @@ class Compute < Fog::Service
request :configure_vm_name_description
request :configure_vm_disks
request :configure_vm_password
+ request :configure_vm_network
request :delete_vapp
request :get_catalog_item
request :get_customization_options
@@ -18,7 +18,7 @@ class Server < Fog::Vcloud::Model
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 :guest_customization, :aliases => :GuestCustomizationSection
@@ -123,7 +123,14 @@ def memory=(amount)
@update_memory_value = amount
amount
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
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 }
@@ -203,6 +210,12 @@ def save
wait_for { ready? }
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
data = disk_mess.delete_if do |vh|
vh[:'rasd:ResourceType'] == '17' &&
@@ -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

0 comments on commit 6b7ae78

Please sign in to comment.