lib/azure/virtual_machine_management/serialization.rb in azure-0.6.3 vs lib/azure/virtual_machine_management/serialization.rb in azure-0.6.4
- old
+ new
@@ -261,10 +261,11 @@
)
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)
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
@@ -274,10 +275,24 @@
end
vms
end
end
+ def self.data_disks_from_xml(rolesXML)
+ data_disks = []
+ virtual_hard_disks = rolesXML.css('DataVirtualHardDisks DataVirtualHardDisk')
+ virtual_hard_disks.each do |disk|
+ data_disk = {}
+ data_disk[:name] = xml_content(disk, 'DiskName')
+ data_disk[:lun] = xml_content(disk, 'Lun')
+ data_disk[:size_in_gb] = xml_content(disk, 'LogicalDiskSizeInGB')
+ data_disk[:media_link] = xml_content(disk, 'MediaLink')
+ data_disks << data_disk
+ end
+ data_disks
+ end
+
def self.endpoints_from_xml(rolesXML, vm)
vm.tcp_endpoints = []
vm.udp_endpoints = []
endpoints = rolesXML.css('ConfigurationSets ConfigurationSet InputEndpoints InputEndpoint')
endpoints.each do |endpoint|
@@ -368,24 +383,24 @@
xml.EnableDirectServerReturn endpoint[:direct_server_return] unless endpoint[:direct_server_return].nil?
end
end
end
- def self.add_data_disk_to_xml(lun, media_link, options)
+ 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."
end
+ media_link = vm.media_link
builder = Nokogiri::XML::Builder.new do |xml|
xml.DataVirtualHardDisk(
'xmlns' => 'http://schemas.microsoft.com/windowsazure',
'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'
) do
xml.HostCaching options[:host_caching] || 'ReadOnly'
xml.DiskLabel options[:disk_label]
xml.DiskName options[:disk_name] if options[:import]
- xml.Lun lun
- xml.LogicalDiskSizeInGB options[:disk_size] || 1
+ 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')
xml.MediaLink media_link
end
@@ -397,10 +412,10 @@
private
def self.port_already_opened?(existing_ports, port)
return false if existing_ports.nil?
raise "Port #{port} conflicts with a port already opened. "\
- "Please select a different port." if existing_ports.include?(port)
+ "Please select a different port." if existing_ports.include?(port)
false
end
def self.assign_random_port(preferred_port, used_ports)
random_port = nil