# File lib/fog/vcloud/compute.rb, line 151 def basic_request(*args) self.class_eval def #{args[0]}(uri) request( { :expects => #{args[1] || 200}, :method => '#{args[2] || 'GET'}', :headers => #{args[3] ? args[3].inspect : '{}'}, :body => '#{args[4] ? args[4] : ''}', :parse => true, :uri => uri } ) end, __FILE__,__LINE__ end
# File lib/fog/vcloud/compute.rb, line 184 def initialize(options = {}) require 'builder' require 'fog/core/parser' @connections = {} @connection_options = options[:connection_options] || {} @persistent = options[:persistent] @username = options[:vcloud_username] @password = options[:vcloud_password] @host = options[:vcloud_host] @base_path = options[:vcloud_base_path] || Fog::Vcloud::Compute::BASE_PATH @version = options[:vcloud_version] || Fog::Vcloud::Compute::DEFAULT_VERSION @path = options[:vcloud_path] || "#{@base_path}/v#{@version}" @port = options[:vcloud_port] || Fog::Vcloud::Compute::PORT @scheme = options[:vcloud_scheme] || Fog::Vcloud::Compute::SCHEME @vdc_href = options[:vcloud_default_vdc] end
# File lib/fog/vcloud/compute.rb, line 168 def unauthenticated_basic_request(*args) self.class_eval def #{args[0]}(uri) unauthenticated_request({ :expects => #{args[1] || 200}, :method => '#{args[2] || 'GET'}', :headers => #{args[3] ? args[3].inspect : '{}'}, :parse => true, :uri => uri }) end, __FILE__,__LINE__ end
# File lib/fog/vcloud/compute.rb, line 280 def base_path_url "#{@scheme}://#{@host}:#{@port}#{@base_path}" end
# File lib/fog/vcloud/compute.rb, line 269 def basic_request_params(uri,*args) { :expects => args[0] || 200, :method => args[1] || 'GET', :headers => args[2] ? args[2].inspect : {}, :body => args[3] ? args[3] : '', :parse => true, :uri => uri } end
# File lib/fog/vcloud/requests/compute/clone_vapp.rb, line 21 def clone_vapp(vdc_uri, vapp_uri, options = {}) unless options.has_key?(:poweron) options[:poweron] = "false" end validate_clone_vapp_options(options) request( :body => generate_clone_vapp_request(vapp_uri, options), :expects => 202, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.cloneVAppParams+xml'}, :method => 'POST', :uri => vdc_uri + '/action/clonevapp', :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_network.rb, line 13 def configure_network(network_uri, network_data) validate_network_data(network_data) request( :body => generate_configure_network_request(network_data), :expects => 200, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.networkService+xml'}, :method => 'PUT', :uri => network_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_network_ip.rb, line 18 def configure_network_ip(network_ip_uri, network_ip_data) validate_network_ip_data(network_ip_data) request( :body => generate_configure_network_ip_request(network_ip_data), :expects => 200, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.ip+xml' }, :method => 'PUT', :uri => network_ip_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_node.rb, line 22 def configure_node(node_uri, node_data) validate_node_data(node_data, true) request( :body => generate_configure_node_request(node_data), :expects => 200, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.nodeService+xml'}, :method => 'PUT', :uri => node_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_org_network.rb, line 123 def configure_org_network(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall=false, port_map=nil) body = generate_configure_org_network_request(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall, port_map) #puts ("Body: #{body}") request( :body => body, :expects => 202, :headers => {'Content-Type' => 'Application/vnd.vmware.vcloud.networkConfigSection+xml' }, :method => 'PUT', :uri => "#{vapp_id}/networkConfigSection", :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vapp.rb, line 96 def configure_vapp(vapp_uri, vapp_data) validate_vapp_data(vapp_data) request( :body => generate_configure_vapp_request(vapp_uri, vapp_data), :expects => 202, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.vApp+xml' }, :method => 'PUT', :uri => vapp_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm.rb, line 93 def configure_vm(vm_uri, vm_data) validate_vm_data(vm_data) request( :body => generate_configure_vm_request(vm_uri, vm_data), :expects => 202, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.vm+xml' }, :method => 'PUT', :uri => vm_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_cpus.rb, line 6 def configure_vm_cpus(vm_data) edit_uri = vm_data.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 = <Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="#{edit_uri}" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://#{@host}/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd"> <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> <rasd:Description>Number of Virtual CPUs</rasd:Description> <rasd:ElementName>#{vm_data[:'rasd:VirtualQuantity']} virtual CPU(s)</rasd:ElementName> <rasd:InstanceID>4</rasd:InstanceID> <rasd:Reservation>0</rasd:Reservation> <rasd:ResourceType>3</rasd:ResourceType> <rasd:VirtualQuantity>#{vm_data[:'rasd:VirtualQuantity']}</rasd:VirtualQuantity> <rasd:Weight>0</rasd:Weight> <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{edit_uri}"/> </Item> request( :body => body, :expects => 202, :headers => {'Content-Type' => vm_data[:"vcloud_type"] }, :method => 'PUT', :uri => "#{edit_uri}", :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_disks.rb, line 80 def configure_vm_disks(vm_href, disk_data) disk_href = vm_href + '/virtualHardwareSection/disks' body = generate_configure_vm_disks_request(disk_href, disk_data) request( :body => body, :expects => 202, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' }, :method => 'PUT', :uri => disk_href, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_memory.rb, line 6 def configure_vm_memory(vm_data) edit_uri = vm_data.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 = <Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="#{edit_uri}" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://#{@host}/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd"> <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> <rasd:Description>Memory Size</rasd:Description> <rasd:ElementName>#{vm_data[:'rasd:VirtualQuantity']} MB of memory</rasd:ElementName> <rasd:InstanceID>5</rasd:InstanceID> <rasd:Reservation>0</rasd:Reservation> <rasd:ResourceType>4</rasd:ResourceType> <rasd:VirtualQuantity>#{vm_data[:'rasd:VirtualQuantity']}</rasd:VirtualQuantity> <rasd:Weight>0</rasd:Weight> <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{edit_uri}"/> </Item> request( :body => body, :expects => 202, :headers => {'Content-Type' => vm_data[:"vcloud_type"] }, :method => 'PUT', :uri => edit_uri, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_name_description.rb, line 6 def configure_vm_name_description(edit_href, name, description) body = <?xml version="1.0" encoding="UTF-8"?><VApp xmlns="http://www.vmware.com/vcloud/v1" name="#{name}" type="application/vnd.vmware.vcloud.vApp+xml"> <Description>#{description}</Description></VApp> request( :body => body, :expects => 202, :headers => {'Content-Type' => "application/vnd.vmware.vcloud.vApp+xml"}, :method => 'PUT', :uri => edit_href, :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_network.rb, line 6 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 = <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> request( :body => body, :expects => 202, :headers => {'Content-Type' => network_info[:"type"] }, :method => 'PUT', :uri => "#{edit_uri}", :parse => true ) end
# File lib/fog/vcloud/requests/compute/configure_vm_password.rb, line 6 def configure_vm_password(vmdata) edit_uri = vmdata[:href] body = <GuestCustomizationSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" href="https://zone01.bluelock.com/api/vApp/vm-cc8e27be-f18c-4263-87c5-58a9297bac5b/guestCustomizationSection/" ovf:required="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://zone01.bluelock.com/api/v1.5/schema/master.xsd"><ovf:Info>Specifies Guest OS Customization Settings</ovf:Info><Enabled>true</Enabled><ChangeSid>false</ChangeSid><VirtualMachineId>#{vmdata[:VirtualMachineId]}</VirtualMachineId><JoinDomainEnabled>false</JoinDomainEnabled><UseOrgSettings>false</UseOrgSettings><AdminPasswordEnabled>true</AdminPasswordEnabled><AdminPasswordAuto>false</AdminPasswordAuto><AdminPassword>#{vmdata[:AdminPassword]}</AdminPassword><ResetPasswordRequired>false</ResetPasswordRequired><ComputerName>#{vmdata[:ComputerName]}</ComputerName><Link rel="edit" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" href="#{edit_uri}"/></GuestCustomizationSection> request( :body => body, :expects => 202, :headers => {'Content-Type' => vmdata[:type] }, :method => 'PUT', :uri => "#{edit_uri}", :parse => true ) end
# File lib/fog/vcloud/compute.rb, line 207 def default_organization_uri @default_organization_uri ||= organizations.first.href @default_organization_uri end
# File lib/fog/vcloud/compute.rb, line 212 def default_vdc_href if @vdc_href.nil? unless @login_results do_login end org = organizations.first vdc = get_organization(org.href).links.find { |item| item[:type] == 'application/vnd.vmware.vcloud.vdc+xml'} @vdc_href = vdc[:href] end @vdc_href end
login handles the auth, but we just need the Set-Cookie header from that call.
# File lib/fog/vcloud/compute.rb, line 226 def do_login @login_results = login @cookie = @login_results.headers['Set-Cookie'] end
# File lib/fog/vcloud/compute.rb, line 231 def ensure_unparsed(uri) if uri.is_a?(String) uri else uri.to_s end end
# File lib/fog/vcloud/requests/compute/clone_vapp.rb, line 13 def generate_clone_vapp_request(uri, options) xml = Builder::XmlMarkup.new xml.CloneVAppParams(xmlns.merge!(:name => options[:name], :deploy => "true", :powerOn => options[:poweron])) { xml.VApp( :href => uri, :type => "application/vnd.vmware.vcloud.vApp+xml", :xmlns => "http://www.vmware.com/vcloud/v0.8") } end
# File lib/fog/vcloud/requests/compute/configure_org_network.rb, line 71 def generate_configure_org_network_request(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall=false, portmap=nil) firewall_body = "" if not enable_firewall firewall_body = "<ns0:IsEnabled>false</ns0:IsEnabled>" else firewall_rules = generate_outbound_rule + generate_tcp_rules(portmap["TCP"]) + generate_udp_rules(portmap["UDP"]) firewall_body = <ns0:IsEnabled>true</ns0:IsEnabled> <ns0:DefaultAction>drop</ns0:DefaultAction> <ns0:LogDefaultAction>false</ns0:LogDefaultAction> #{firewall_rules} end body = <ns0:NetworkConfigSection xmlns:ns0="http://www.vmware.com/vcloud/v1.5" xmlns:ns1="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" href="#{vapp_id}/networkConfigSection/" type="application/vnd.vmware.vcloud.networkConfigSection+xml" ns1:required="false" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://zone01.bluelock.com/api/v1.5/schema/master.xsd"><ns1:Info>The configuration parameters for logical networks</ns1:Info><ns0:Link href="#{vapp_id}/networkConfigSection/" rel="edit" type="application/vnd.vmware.vcloud.networkConfigSection+xml" /><ns0:NetworkConfig networkName="#{vapp_network}"><ns0:Link href="#{vapp_network_uri}" rel="repair" /><ns0:Description /> <ns0:Configuration><ns0:ParentNetwork href="#{org_network_uri}" name="#{org_network}" type="application/vnd.vmware.vcloud.network+xml" /><ns0:FenceMode>natRouted</ns0:FenceMode><ns0:RetainNetInfoAcrossDeployments>true</ns0:RetainNetInfoAcrossDeployments><ns0:Features><ns0:FirewallService>#{firewall_body}</ns0:FirewallService><ns0:NatService><ns0:IsEnabled>true</ns0:IsEnabled><ns0:NatType>ipTranslation</ns0:NatType><ns0:Policy>allowTraffic</ns0:Policy></ns0:NatService></ns0:Features></ns0:Configuration><ns0:IsDeployed>false</ns0:IsDeployed></ns0:NetworkConfig><ns0:NetworkConfig networkName="#{org_network}"><ns0:Link href="#{org_network_uri}" rel="repair" /><ns0:Description /><ns0:Configuration><ns0:ParentNetwork href="#{org_network_uri}" name="#{org_network}" type="application/vnd.vmware.vcloud.network+xml" /><ns0:FenceMode>bridged</ns0:FenceMode><ns0:RetainNetInfoAcrossDeployments>true</ns0:RetainNetInfoAcrossDeployments><ns0:SyslogServerSettings /></ns0:Configuration></ns0:NetworkConfig></ns0:NetworkConfigSection> end
# File lib/fog/vcloud/requests/compute/configure_vapp.rb, line 18 def generate_configure_vapp_request(vapp_uri, vapp_data) rasd_xmlns = { "xmlns" => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" } xml = Nokogiri::XML(request( :uri => vapp_uri).body) xml.root['name'] = vapp_data[:name] #cpu xml.at("//xmlns:ResourceType[.='3']/..", rasd_xmlns).at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:cpus] #memory xml.at("//xmlns:ResourceType[.='4']/..", rasd_xmlns).at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:memory] #disks real_disks = xml.xpath("//xmlns:ResourceType[ .='17']/..", rasd_xmlns) real_disk_numbers = real_disks.map { |disk| disk.at('.//xmlns:AddressOnParent', rasd_xmlns).content } disk_numbers = vapp_data[:disks].map { |vdisk| vdisk[:number].to_s } if vapp_data[:disks].length < real_disks.length #Assume we're removing a disk remove_disk_numbers = real_disk_numbers - disk_numbers remove_disk_numbers.each do |number| if result = xml.at("//xmlns:ResourceType[ .='17']/../xmlns:AddressOnParent[.='#{number}']/..", rasd_xmlns) result.remove end end elsif vapp_data[:disks].length > real_disks.length add_disk_numbers = disk_numbers - real_disk_numbers add_disk_numbers.each do |number| new_disk = real_disks.first.dup new_disk.at('.//xmlns:AddressOnParent', rasd_xmlns).content = -1 new_disk.at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:disks].detect { |disk| disk[:number].to_s == number.to_s }[:size] real_disks.first.parent << new_disk end end #puts xml.root.to_s xml.root.to_s #builder = Builder::XmlMarkup.new #builder.Vapp(:href => vapp_uri.to_s, # :type => 'application/vnd.vmware.vcloud.vApp+xml', # :name => vapp_data[:name], # :status => 2, # :size => 0, # :xmlns => 'http://www.vmware.com/vcloud/v0.8', # :"xmlns:xsi" => 'http://www.w3.org/2001/XMLSchema-instance', # :"xmlns:xsd" => 'http://www.w3.org/2001/XMLSchema') { # #builder.VirtualHardwareSection(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # builder.Section(:"xsi:type" => "q2:VirtualHardwareSection_Type", :xmlns => "http://schemas.dmtf.org/ovf/envelope/1", :"xmlns:q2" => "http://www.vmware.com/vcloud/v0.8") { # builder.Info('Virtual Hardware') # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # #builder.Item { # builder.InstanceID(1, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(3, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(vapp_data[:cpus], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # #builder.Item { # builder.InstanceID(2, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(4, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(vapp_data[:memory], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # vapp_data[:disks].each do |disk_data| # #builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # builder.Item { # builder.AddressOnParent(disk_data[:number], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.HostResource(disk_data[:resource], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.InstanceID(9, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(17, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(disk_data[:size], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # end # # } #} end
# File lib/fog/vcloud/requests/compute/configure_vm_disks.rb, line 39 def generate_configure_vm_disks_request(href, disk_data) xmlns = { "xmlns:rasd" => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData", "xmlns" => "http://www.vmware.com/vcloud/v1" } # Get the XML from the API, parse it. xml = Nokogiri::XML(request( :uri => href).body) #xml.root['name'] = vapp_data[:name] #disks real_disks = xml.xpath("//rasd:ResourceType[ .='17']/..", xmlns) real_disk_numbers = real_disks.map { |disk| disk.at('.//rasd:AddressOnParent', xmlns).content } disk_numbers = disk_data.map { |vdisk| vdisk[:"rasd:AddressOnParent"].to_s } if disk_data.length < real_disks.length #Assume we're removing a disk remove_disk_numbers = real_disk_numbers - disk_numbers remove_disk_numbers.each do |number| if result = xml.at("//rasd:ResourceType[ .='17']/../rasd:AddressOnParent[.='#{number}']/..", xmlns) result.remove end end elsif disk_data.length > real_disks.length add_disk_numbers = disk_numbers - real_disk_numbers add_disk_numbers.each do |number| new_disk = real_disks.first.dup new_disk.at('.//rasd:AddressOnParent', xmlns).content = number.to_i #-1 new_disk.at('.//rasd:HostResource', xmlns)["vcloud:capacity"] = disk_data.detect { |disk| disk[:'rasd:AddressOnParent'].to_s == number.to_s }[:'rasd:HostResource'][:vcloud_capacity].to_s # nokogiri bug? shouldn't need to add this explicitly. new_disk.at('.//rasd:HostResource', xmlns)["xmlns:vcloud"] = xmlns['xmlns'] new_disk.at('.//rasd:InstanceID', xmlns).content = (2000 + number.to_i).to_s new_disk.at('.//rasd:ElementName', xmlns).content = "Hard disk #{number.to_i + 1}" real_disks.first.parent << new_disk end end xml.to_s end
# File lib/fog/vcloud/requests/compute/configure_vm.rb, line 18 def generate_configure_vm_request(vm_data) xmlns = 'http://schemas.dmtf.org/ovf/envelope/1' xmlns_vcloud = 'http://www.vmware.com/vcloud/v1' xmlns_rasd = 'http://schemas.dmtf.org/wbem/wscim/1/cim‐schema/2/CIM_ResourceAllocationSettingData' xmlns_vssd = 'http://schemas.dmtf.org/wbem/wscim/1/cim‐schema/2/CIM_VirtualSystemSettingData' builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) # TODO - remove params builder.VirtualHardwareSection( :"vcloud:href" => vm_data[:"vcloud_href"], :"vcloud:type" => vm_data[:"vcloud_type"], :name => vm_data[:name], :status => 2, :size => 0, :xmlns => xmlns, :"xmlns:vcloud" => xmlns_vcloud, :"xmlns:rasd" => xmlns_rasd, :"xmlns:vssd" => xmlns_vssd) { #builder.VirtualHardwareSection(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { builder.Info(vm_data[:"ovf:Info"]) if system = vm_data[:"ovf:System"] builder.System { builder.ElementName(system[:"vssd:ElementName"], :xmlns => xmlns_vssd) if system[:"vssd:ElementName"] builder.InstanceID(system[:"vssd:InstanceID"], :xmlns => xmlns_vssd) if system[:"vssd:InstanceID"] builder.VirtualSystemIdentifier(system[:"vssd:VirtualSystemIdentifier"], :xmlns => xmlns_vssd) if system[:"vssd:VirtualSystemIdentifier"] builder.VirtualSystemType(system[:"vssd:VirtualSystemType"], :xmlns => xmlns_vssd) if system[:"vssd:VirtualSystemType"] } end vm_data[:'ovf:Item'].each do |oi| builder.Item { builder.Address(oi[:'rasd:Address'], :xmlns => xmlns_rasd) if oi[:'rasd:Address'] builder.AddressOnParent(oi[:'rasd:AddressOnParent'], :xmlns => xmlns_rasd) if oi[:'rasd:AddressOnParent'] builder.AutomaticAllocation(oi[:'rasd:AutomaticAllocation'], :xmlns => xmlns_rasd) if oi[:'rasd:AutomaticAllocation'] builder.Connection(oi[:'rasd:Connection'], :xmlns => xmlns_rasd) if oi[:'rasd:Connection'] builder.Description(oi[:'rasd:Description'], :xmlns => xmlns_rasd) if oi[:'rasd:Description'] builder.ElementName(oi[:'rasd:ElementName'], :xmlns => xmlns_rasd) if oi[:'rasd:ElementName'] builder.InstanceID(oi[:'rasd:InstanceID'], :xmlns => xmlns_rasd) if oi[:'rasd:InstanceID'] builder.ResourceSubType(oi[:'rasd:ResourceSubType'], :xmlns => xmlns_rasd) if oi[:'rasd:ResourceSubType'] builder.ResourceType(oi[:'rasd:ResourceType'], :xmlns => xmlns_rasd) if oi[:'rasd:ResourceType'] if hr = oi[:'rasd:HostResource'] attrs = {} attrs[] end } end # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # #builder.Item { # builder.InstanceID(1, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(3, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(vm_data[:cpus], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # #builder.Item { # builder.InstanceID(2, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(4, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(vm_data[:memory], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # vm_data[:disks].each do |disk_data| # #builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') { # builder.Item { # builder.AddressOnParent(disk_data[:number], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.HostResource(disk_data[:resource], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.InstanceID(9, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.ResourceType(17, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # builder.VirtualQuantity(disk_data[:size], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData') # } # end } end
# File lib/fog/vcloud/requests/compute/configure_org_network.rb, line 6 def generate_outbound_rule() outbound_rule = <ns0:FirewallRule> <ns0:IsEnabled>true</ns0:IsEnabled> <ns0:Description>OUTGOING</ns0:Description> <ns0:Policy>allow</ns0:Policy> <ns0:Protocols> <ns0:Any>true</ns0:Any> </ns0:Protocols> <ns0:Port>-1</ns0:Port> <ns0:DestinationIp>Any</ns0:DestinationIp> <ns0:SourcePort>-1</ns0:SourcePort> <ns0:SourceIp>Any</ns0:SourceIp> <ns0:Direction>out</ns0:Direction> <ns0:EnableLogging>false</ns0:EnableLogging> </ns0:FirewallRule> outbound_rule end
# File lib/fog/vcloud/requests/compute/configure_org_network.rb, line 25 def generate_tcp_rules(tcp_ports) firewall_rules = "" tcp_ports.each do |port| firewall_rules << <ns0:FirewallRule> <ns0:IsEnabled>true</ns0:IsEnabled> <ns0:Description>#{port}</ns0:Description> <ns0:Policy>allow</ns0:Policy> <ns0:Protocols> <ns0:Tcp>true</ns0:Tcp> </ns0:Protocols> <ns0:Port>#{port}</ns0:Port> <ns0:DestinationIp>Any</ns0:DestinationIp> <ns0:SourcePort>-1</ns0:SourcePort> <ns0:SourceIp>Any</ns0:SourceIp> <ns0:Direction>in</ns0:Direction> <ns0:EnableLogging>false</ns0:EnableLogging> </ns0:FirewallRule> end firewall_rules end
# File lib/fog/vcloud/requests/compute/configure_org_network.rb, line 48 def generate_udp_rules(udp_ports) firewall_rules = "" udp_ports.each do |port| firewall_rules << <ns0:FirewallRule> <ns0:IsEnabled>true</ns0:IsEnabled> <ns0:Description>#{port}</ns0:Description> <ns0:Policy>allow</ns0:Policy> <ns0:Protocols> <ns0:Udp>true</ns0:Udp> </ns0:Protocols> <ns0:Port>#{port}</ns0:Port> <ns0:DestinationIp>Any</ns0:DestinationIp> <ns0:SourcePort>-1</ns0:SourcePort> <ns0:SourceIp>Any</ns0:SourceIp> <ns0:Direction>in</ns0:Direction> <ns0:EnableLogging>false</ns0:EnableLogging> </ns0:FirewallRule> end firewall_rules end
# File lib/fog/vcloud/requests/compute/get_vm_disks.rb, line 6 def get_vm_disks(href) request( :expects => 200, :uri => href, :parse => true#false#true ) end
# File lib/fog/vcloud/requests/compute/get_vm_memory.rb, line 6 def get_vm_memory(href, parse = true) request( :expects => 200, :uri => href, :parse => parse ) end
# File lib/fog/vcloud/requests/compute/instantiate_vapp_template.rb, line 73 def instantiate_vapp_template options = {} validate_instantiate_vapp_template_options options request( :body => generate_instantiate_vapp_template_request(options), :expects => 201, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'}, :method => 'POST', :uri => options[:vdc_uri] + '/action/instantiateVAppTemplate', :parse => true ) end
# File lib/fog/vcloud/requests/compute/login.rb, line 8 def login headers = { 'Authorization' => authorization_header } uri = if version == '1.0' "#{base_url}/login" else "#{base_path_url}/sessions" end unauthenticated_request({ :expects => 200, :headers => headers, :method => 'POST', :parse => true, :uri => uri }) end
# File lib/fog/vcloud/compute.rb, line 203 def reload @connections.each_value { |k,v| v.reset if v } end
If the cookie isn't set, do a get_organizations call to set it and try the request. If we get an Unauthorized error, we assume the token expired, re-auth and try again
# File lib/fog/vcloud/compute.rb, line 256 def request(params) unless @cookie do_login end begin do_request(params) rescue Excon::Errors::Unauthorized do_login do_request(params) end end
# File lib/fog/vcloud/requests/compute/undeploy.rb, line 5 def undeploy(vapp_uri, save_state = false) # builder = Builder::XmlMarkup.new # builder.UndeployVAppParams(:xmlns => 'http://www.vmware.com/vcloud/v1', # :saveState => save_state) {} builder = if version =='1.0' "<UndeployVAppParams saveState=\"#{save_state.to_s}\" xmlns=\"http://www.vmware.com/vcloud/v1\"/>" else <UndeployVAppParams xmlns="http://www.vmware.com/vcloud/v1.5"> <UndeployPowerAction>shutdown</UndeployPowerAction> </UndeployVAppParams> end request( :body => builder, :expects => 202, :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml' }, :method => 'POST', :uri => vapp_uri + '/action/undeploy', :parse => true ) end
# File lib/fog/vcloud/requests/compute/clone_vapp.rb, line 6 def validate_clone_vapp_options(options) valid_opts = [:name, :poweron] unless valid_opts.all? { |opt| options.has_key?(opt) } raise ArgumentError.new("Required data missing: #{(valid_opts - options.keys).map(&:inspect).join(", ")}") end end
# File lib/fog/vcloud/requests/compute/configure_network.rb, line 6 def validate_network_data(network_data, configure=false) valid_opts = [:id, :href, :name, :address, :broadcast, :gateway] unless valid_opts.all? { |opt| network_data.has_key?(opt) } raise ArgumentError.new("Required data missing: #{(valid_opts - network_data.keys).map(&:inspect).join(", ")}") end end
# File lib/fog/vcloud/compute.rb, line 239 def xmlns if version == '1.0' { "xmlns" => "http://www.vmware.com/vcloud/v1", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" } else { 'xmlns' => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" } end end
Generated with the Darkfish Rdoc Generator 2.