From 971b7e2bf05e0cae0fb3cbc256a290e3be75a86c Mon Sep 17 00:00:00 2001 From: Tim Lawrence Date: Mon, 20 Jun 2016 13:42:59 +0100 Subject: [PATCH 1/2] Storage Profiles for Indy Disks --- lib/ruby_vcloud_sdk/vdc.rb | 12 ++++++++---- lib/ruby_vcloud_sdk/vdc_storage_profile.rb | 3 ++- .../xml/wrapper_classes/disk_create_params.rb | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/ruby_vcloud_sdk/vdc.rb b/lib/ruby_vcloud_sdk/vdc.rb index 4837f12..c5f28f3 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,14 +218,17 @@ def storage_profile_records .org_vdc_storage_profile_records end - def disk_create_params(name, capacity, bus_type, bus_sub_type, vm) - Xml::WrapperFactory.create_instance("DiskCreateParams").tap do |params| + def disk_create_params(name, capacity, bus_type, bus_sub_type, vm, storage_profile = nil) + x=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 + puts x + x end def delete_single_disk(disk) 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 From a7c94d5d6acda77540b56bf1a2856464bf7a58a2 Mon Sep 17 00:00:00 2001 From: Tim Lawrence Date: Mon, 20 Jun 2016 14:40:33 +0100 Subject: [PATCH 2/2] remove debug characters --- lib/ruby_vcloud_sdk/vdc.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/ruby_vcloud_sdk/vdc.rb b/lib/ruby_vcloud_sdk/vdc.rb index c5f28f3..64fd61c 100644 --- a/lib/ruby_vcloud_sdk/vdc.rb +++ b/lib/ruby_vcloud_sdk/vdc.rb @@ -219,7 +219,7 @@ def storage_profile_records end def disk_create_params(name, capacity, bus_type, bus_sub_type, vm, storage_profile = nil) - x=Xml::WrapperFactory.create_instance("DiskCreateParams").tap do |params| + 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 @@ -227,8 +227,6 @@ def disk_create_params(name, capacity, bus_type, bus_sub_type, vm, storage_profi params.add_locality(connection.get(vm.href)) if vm # Use xml form of vm params.add_storage_profile(storage_profile) if storage_profile end - puts x - x end def delete_single_disk(disk)