lib/azure/virtual_machine_management/serialization.rb in azure-0.6.4 vs lib/azure/virtual_machine_management/serialization.rb in azure-0.7.0.pre

- old
+ new

@@ -16,10 +16,11 @@ require 'base64' module Azure module VirtualMachineManagement module Serialization + extend Azure::Core::Utility def self.shutdown_virtual_machine_to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.ShutdownRoleOperation( 'xmlns' => 'http://schemas.microsoft.com/windowsazure', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance' @@ -53,11 +54,11 @@ end end builder.doc.to_xml end - def self.deployment_to_xml(params, options) + def self.deployment_to_xml(params, image, options) options[:deployment_name] ||= options[:cloud_service_name] builder = Nokogiri::XML::Builder.new do |xml| xml.Deployment( 'xmlns' => 'http://schemas.microsoft.com/windowsazure', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance' @@ -67,28 +68,30 @@ xml.Label Base64.encode64(options[:deployment_name]).strip xml.RoleList { xml.Role('i:type' => 'PersistentVMRole') } if options[:virtual_network_name] xml.VirtualNetworkName options[:virtual_network_name] end + if options[:reserved_ip_name] + xml.ReservedIPName options[:reserved_ip_name] + end end end - builder.doc.at_css('Role') << role_to_xml(params, options).at_css('PersistentVMRole').children.to_s + builder.doc.at_css('Role') << role_to_xml(params, image, options).at_css('PersistentVMRole').children.to_s builder.doc.to_xml end - def self.role_to_xml(params, options) + def self.role_to_xml(params, image, options) builder = Nokogiri::XML::Builder.new do |xml| xml.PersistentVMRole( 'xmlns' => 'http://schemas.microsoft.com/windowsazure', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance' ) do xml.RoleName { xml.text params[:vm_name] } xml.OsVersion('i:nil' => 'true') xml.RoleType 'PersistentVMRole' - xml.ConfigurationSets do - provisioning_configuration_to_xml(xml, params, options) + provisioning_configuration_to_xml(xml, params, options) if image.image_type == 'OS' xml.ConfigurationSet('i:type' => 'NetworkConfigurationSet') do xml.ConfigurationSetType 'NetworkConfiguration' xml.InputEndpoints do default_endpoints_to_xml(xml, options) tcp_endpoints_to_xml( @@ -99,19 +102,28 @@ end if options[:virtual_network_name] && options[:subnet_name] xml.SubnetNames do xml.SubnetName options[:subnet_name] end + xml.StaticVirtualNetworkIPAddress options[:static_virtual_network_ipaddress] if options[:static_virtual_network_ipaddress] end end end + xml.VMImageName image.name if image.image_type == 'VM' xml.AvailabilitySetName options[:availability_set_name] xml.Label Base64.encode64(params[:vm_name]).strip - xml.OSVirtualHardDisk do - xml.MediaLink 'http://' + options[:storage_account_name] + '.blob.core.windows.net/vhds/' + (Time.now.strftime('disk_%Y_%m_%d_%H_%M')) + '.vhd' - xml.SourceImageName params[:image] + if image.category == 'User' + storage_host = URI.parse( image.media_link ).host + else + storage_host = options[:storage_account_name] + '.blob.core.windows.net' end + if image.image_type == 'OS' + xml.OSVirtualHardDisk do + xml.MediaLink 'http://' + storage_host + '/vhds/' + (Time.now.strftime('disk_%Y_%m_%d_%H_%M_%S_%L')) + '.vhd' + xml.SourceImageName params[:image] + end + end xml.RoleSize options[:vm_size] end end builder.doc end @@ -141,10 +153,11 @@ xml.Path "/home/#{params[:vm_user]}/.ssh/id_rsa" end end end end + xml.CustomData params[:custom_data] if params[:custom_data] end elsif options[:os_type] == 'Windows' xml.ConfigurationSet('i:type' => 'WindowsProvisioningConfigurationSet') do xml.ConfigurationSetType 'WindowsProvisioningConfiguration' xml.ComputerName params[:vm_name] @@ -246,15 +259,15 @@ vms = [] instances.each do |instance| vm = VirtualMachine.new role_name = xml_content(instance, 'RoleName') vm.status = xml_content(instance, 'InstanceStatus') - vm.vm_name = role_name.downcase + vm.vm_name = role_name vm.ipaddress = xml_content(ip, 'Address') vm.role_size = xml_content(instance, 'InstanceSize') vm.hostname = xml_content(instance, 'HostName') - vm.cloud_service_name = cloud_service_name.downcase + vm.cloud_service_name = cloud_service_name vm.deployment_name = xml_content(deployXML, 'Deployment Name') vm.deployment_status = xml_content(deployXML, 'Deployment Status') vm.virtual_network_name = xml_content( deployXML.css('Deployment'), 'VirtualNetworkName' @@ -262,10 +275,14 @@ roles.each do |role| if xml_content(role, 'RoleName') == role_name vm.availability_set_name = xml_content(role, 'AvailabilitySetName') endpoints_from_xml(role, vm) vm.data_disks = data_disks_from_xml(role) + subnet = xml_content(role, + 'ConfigurationSets ConfigurationSet SubnetNames SubnetName' + ) + vm.subnet = subnet unless subnet.empty? vm.os_type = xml_content(role, 'OSVirtualHardDisk OS') vm.disk_name = xml_content(role, 'OSVirtualHardDisk DiskName') vm.media_link = xml_content(role, 'OSVirtualHardDisk MediaLink') vm.image = xml_content(role, 'OSVirtualHardDisk SourceImageName') break @@ -345,10 +362,13 @@ xml.ConfigurationSet do xml.ConfigurationSetType 'NetworkConfiguration' xml.InputEndpoints do endpoints_to_xml(xml, endpoints) end + xml.SubnetNames do + xml.SubnetName vm.subnet if vm.subnet + end end end xml.OSVirtualHardDisk do end end @@ -385,11 +405,11 @@ end end def self.add_data_disk_to_xml(vm, options) if options[:import] && options[:disk_name].nil? - Loggerx.error_with_exit "The data disk name is not valid." + Azure::Loggerx.error_with_exit "The data disk name is not valid." end media_link = vm.media_link builder = Nokogiri::XML::Builder.new do |xml| xml.DataVirtualHardDisk( 'xmlns' => 'http://schemas.microsoft.com/windowsazure', @@ -399,10 +419,10 @@ xml.DiskLabel options[:disk_label] xml.DiskName options[:disk_name] if options[:import] xml.LogicalDiskSizeInGB options[:disk_size] || 100 unless options[:import] disk_name = media_link[/([^\/]+)$/] - media_link = media_link.gsub(/#{disk_name}/, (Time.now.strftime('disk_%Y_%m_%d_%H_%M')) + '.vhd') + media_link = media_link.gsub(/#{disk_name}/, (Time.now.strftime('disk_%Y_%m_%d_%H_%M_%S')) + '.vhd') xml.MediaLink media_link end end end builder.doc.to_xml