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

Merge pull request #1551 from chirag-jog/vcloud_enhancements

vCloud Director 1.5 enhancements
This commit is contained in:
Wesley Beary 2013-02-08 08:05:46 -08:00
commit 83e8d790f4
5 changed files with 73 additions and 7 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

@ -37,6 +37,17 @@ module Fog
:href => href :href => href
) )
end 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 end
end end

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

View file

@ -49,8 +49,13 @@ module Fog
if options[:network_uri] if options[:network_uri]
# TODO - implement properly # TODO - implement properly
xml.NetworkConfigSection { xml.NetworkConfigSection {
xml.NetworkConfig { xml.tag!("ovf:Info"){ "Configuration parameters for logical networks" }
xml.NetworkAssociation( :href => options[:network_uri] ) 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 end
@ -66,8 +71,7 @@ module Fog
include Shared include Shared
def instantiate_vapp_template options = {} def instantiate_vapp_template options = {}
validate_instantiate_vapp_template_options options validate_instantiate_vapp_template_options optionsgi
request( request(
:body => generate_instantiate_vapp_template_request(options), :body => generate_instantiate_vapp_template_request(options),
:expects => 201, :expects => 201,