diff --git a/lib/fog/vcloud/compute.rb b/lib/fog/vcloud/compute.rb index 168c60eec..d65b24a87 100644 --- a/lib/fog/vcloud/compute.rb +++ b/lib/fog/vcloud/compute.rb @@ -117,6 +117,7 @@ module Fog 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 diff --git a/lib/fog/vcloud/models/compute/server.rb b/lib/fog/vcloud/models/compute/server.rb index 0944eeb23..d2ea9f30c 100644 --- a/lib/fog/vcloud/models/compute/server.rb +++ b/lib/fog/vcloud/models/compute/server.rb @@ -18,7 +18,7 @@ module Fog 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 @@ module Fog @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 @@ module Fog 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' && diff --git a/lib/fog/vcloud/models/compute/vapp.rb b/lib/fog/vcloud/models/compute/vapp.rb index 5e39ecfdc..30d40cc84 100644 --- a/lib/fog/vcloud/models/compute/vapp.rb +++ b/lib/fog/vcloud/models/compute/vapp.rb @@ -37,6 +37,17 @@ module Fog :href => href ) end + + def ready? + reload_status # always ensure we have the correct status + status != '0' + end + + private + def reload_status + vapp = service.get_vapp(href) + self.status = vapp.status + end end end end diff --git a/lib/fog/vcloud/requests/compute/configure_vm_network.rb b/lib/fog/vcloud/requests/compute/configure_vm_network.rb new file mode 100644 index 000000000..e51e5b2c2 --- /dev/null +++ b/lib/fog/vcloud/requests/compute/configure_vm_network.rb @@ -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 = < + Specifies the available VM network connections + 0 + + 0 + true + #{network_info[:NetworkConnection][:IpAddressAllocationMode]} + + +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 diff --git a/lib/fog/vcloud/requests/compute/instantiate_vapp_template.rb b/lib/fog/vcloud/requests/compute/instantiate_vapp_template.rb index 7683f98a4..5023deabd 100644 --- a/lib/fog/vcloud/requests/compute/instantiate_vapp_template.rb +++ b/lib/fog/vcloud/requests/compute/instantiate_vapp_template.rb @@ -10,7 +10,7 @@ module Fog unless valid_opts.all? { |opt| options.has_key?(opt) } raise ArgumentError.new("Required data missing: #{(valid_opts - options.keys).map(&:inspect).join(", ")}") end - + catalog_item_uri = options[:catalog_item_uri] # Figure out the template_uri @@ -49,8 +49,13 @@ module Fog if options[:network_uri] # TODO - implement properly xml.NetworkConfigSection { - xml.NetworkConfig { - xml.NetworkAssociation( :href => options[:network_uri] ) + xml.tag!("ovf:Info"){ "Configuration parameters for logical networks" } + xml.NetworkConfig("networkName" => options[:network_name]) { + # xml.NetworkAssociation( :href => options[:network_uri] ) + xml.Configuration { + xml.ParentNetwork("name" => options[:network_name], "href" => options[:network_uri]) + xml.FenceMode("bridged") + } } } end @@ -66,8 +71,7 @@ module Fog include Shared def instantiate_vapp_template options = {} - validate_instantiate_vapp_template_options options - + validate_instantiate_vapp_template_options optionsgi request( :body => generate_instantiate_vapp_template_request(options), :expects => 201,