Method: Fog::Vcloud::Compute::Real#generate_configure_vapp_request
- Defined in:
- lib/fog/vcloud/requests/compute/configure_vapp.rb
#generate_configure_vapp_request(vapp_uri, vapp_data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 |