diff --git a/lib/ruby_vcloud_sdk/vdc.rb b/lib/ruby_vcloud_sdk/vdc.rb index 4837f12..64fd61c 100644 --- a/lib/ruby_vcloud_sdk/vdc.rb +++ b/lib/ruby_vcloud_sdk/vdc.rb @@ -145,7 +145,8 @@ def create_disk( capacity, vm = nil, bus_type = "scsi", - bus_sub_type = "lsilogic") + bus_sub_type = "lsilogic", + storage_profile = nil) fail(CloudError, "Invalid size in MB #{capacity}") if capacity <= 0 @@ -163,7 +164,7 @@ def create_disk( .info "Creating independent disk #{name} of #{capacity}MB." disk = connection.post(entity_xml.add_disk_link, - disk_create_params(name, capacity, bus_type, bus_sub_type, vm), + disk_create_params(name, capacity, bus_type, bus_sub_type, vm, storage_profile), Xml::MEDIA_TYPE[:DISK_CREATE_PARAMS]) wait_for_running_tasks(disk, "Disk #{name}") @@ -217,13 +218,14 @@ def storage_profile_records .org_vdc_storage_profile_records end - def disk_create_params(name, capacity, bus_type, bus_sub_type, vm) + def disk_create_params(name, capacity, bus_type, bus_sub_type, vm, storage_profile = nil) Xml::WrapperFactory.create_instance("DiskCreateParams").tap do |params| params.name = name params.size_bytes = capacity * 1024 * 1024 # VCD expects bytes params.bus_type = bus_type params.bus_sub_type = bus_sub_type params.add_locality(connection.get(vm.href)) if vm # Use xml form of vm + params.add_storage_profile(storage_profile) if storage_profile end end diff --git a/lib/ruby_vcloud_sdk/vdc_storage_profile.rb b/lib/ruby_vcloud_sdk/vdc_storage_profile.rb index 5d9eec8..8d699f3 100644 --- a/lib/ruby_vcloud_sdk/vdc_storage_profile.rb +++ b/lib/ruby_vcloud_sdk/vdc_storage_profile.rb @@ -1,11 +1,12 @@ module VCloudSdk class VdcStorageProfile - attr_reader :name + attr_reader :name,:href def initialize(storage_profile_xml_obj) @storage_profile_xml_obj = storage_profile_xml_obj @name = @storage_profile_xml_obj[:name] + @href = @storage_profile_xml_obj[:href] @storage_used_mb = @storage_profile_xml_obj[:storageUsedMB].to_i @storage_limit_mb = @storage_profile_xml_obj[:storageLimitMB].to_i @vdc_name = @storage_profile_xml_obj[:vdcName] diff --git a/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_create_params.rb b/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_create_params.rb index 52a1e18..c83b22f 100644 --- a/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_create_params.rb +++ b/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_create_params.rb @@ -31,6 +31,12 @@ def add_locality(local) disk.node.after(node) end + def add_storage_profile(storage_profile) + node = create_child("StorageProfile") + node["href"] = storage_profile.href + node["name"] = storage_profile.name + disk.node.add_child(node) + end private def disk