class VCloudSdk::VDC
Public Class Methods
new(session, link)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 24 def initialize(session, link) @session = session @link = link end
Public Instance Methods
create_disk( name, capacity, vm = nil, bus_type = "scsi", bus_sub_type = "lsilogic")
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 143 def create_disk( name, capacity, vm = nil, bus_type = "scsi", bus_sub_type = "lsilogic") fail(CloudError, "Invalid size in MB #{capacity}") if capacity <= 0 bus_type = Xml::BUS_TYPE_NAMES[bus_type.downcase] fail(CloudError, "Invalid bus type!") unless bus_type bus_sub_type = Xml::BUS_SUB_TYPE_NAMES[bus_sub_type.downcase] fail(CloudError, "Invalid bus sub type!") unless bus_sub_type Config .logger .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), Xml::MEDIA_TYPE[:DISK_CREATE_PARAMS]) wait_for_running_tasks(disk, "Disk #{name}") VCloudSdk::Disk.new(@session, disk.href) end
delete_all_disks_by_name(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 183 def delete_all_disks_by_name(name) disks = find_disks_by_name(name) success = true disks.each do |disk| begin delete_single_disk(disk) rescue RuntimeError => e success = false Config.logger.error("Disk deletion failed with exception: #{e}") end end fail CloudError, "Failed to delete one or more of the disks with name '#{name}'. Check logs for details." unless success self end
delete_disk_by_name(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 174 def delete_disk_by_name(name) disks = find_disks_by_name(name) fail CloudError, "#{disks.size} disks with name #{name} were found" if disks.size > 1 delete_single_disk(disks.first) self end
disk_exists?(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 137 def disk_exists?(name) list_disks.any? do |disk_name| disk_name == name end end
disks()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 112 def disks entity_xml.disks.map do |disk_link| VCloudSdk::Disk.new(@session, disk_link) end end
edge_gateways()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 103 def edge_gateways connection .get(entity_xml.edge_gateways_link) .edge_gateway_records .map do |edge_gateway_link| VCloudSdk::EdgeGateway.new(@session, edge_gateway_link.href) end end
find_disks_by_name(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 124 def find_disks_by_name(name) disks = entity_xml .disks .select { |disk_link| disk_link.name == name } .map { |disk_link| VCloudSdk::Disk.new(@session, disk_link.href) } if disks.empty? fail ObjectNotFoundError, "Disk '#{name}' is not found" end disks end
find_storage_profile_by_name(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 41 def find_storage_profile_by_name(name) storage_profile_records.each do |storage_profile| if storage_profile.name == name return VCloudSdk::VdcStorageProfile.new(storage_profile) end end fail ObjectNotFoundError, "Storage profile '#{name}' is not found" end
find_vapp_by_name(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 69 def find_vapp_by_name(name) entity_xml.vapps.each do |vapp_link| if vapp_link.name == name return VCloudSdk::VApp.new(@session, vapp_link) end end fail ObjectNotFoundError, "VApp '#{name}' is not found" end
list_disks()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 118 def list_disks entity_xml.disks.map do |disk_link| disk_link.name end end
list_networks()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 97 def list_networks @session.org.networks.map do |network_link| network_link.name end end
list_storage_profiles()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 35 def list_storage_profiles storage_profile_records.map do |storage_profile| storage_profile.name end end
list_vapps()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 63 def list_vapps entity_xml.vapps.map do |vapp_link| vapp_link.name end end
networks()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 91 def networks @session.org.networks.map do |network_link| VCloudSdk::Network.new(@session, network_link) end end
resources()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 85 def resources cpu = VCloudSdk::CPU.new(entity_xml.available_cpu_cores) memory = VCloudSdk::Memory.new(entity_xml.available_memory_mb) VCloudSdk::Resources.new(cpu, memory) end
storage_profile_exists?(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 51 def storage_profile_exists?(name) storage_profile_records.any? do |storage_profile| storage_profile.name == name end end
storage_profile_xml_node(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 200 def storage_profile_xml_node(name) return nil if name.nil? storage_profile = entity_xml.storage_profile(name) unless storage_profile fail ObjectNotFoundError, "Storage profile '#{name}' does not exist" end storage_profile end
storage_profiles()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 29 def storage_profiles storage_profile_records.map do |storage_profile| VCloudSdk::VdcStorageProfile.new(storage_profile) end end
vapp_exists?(name)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 79 def vapp_exists?(name) entity_xml.vapps.any? do |vapp| vapp.name == name end end
vapps()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 57 def vapps entity_xml.vapps.map do |vapp_link| VCloudSdk::VApp.new(@session, vapp_link) end end
Private Instance Methods
delete_single_disk(disk)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 230 def delete_single_disk(disk) Config.logger.info "Deleting disk '#{disk.name}', link #{disk.href}" fail CloudError, "Disk '#{disk.name}', link #{disk.href} is attached to VM '#{disk.vm.name}'" if disk.attached? entity_xml = connection.get(disk.href) task = connection.delete(entity_xml.remove_link.href) monitor_task(task) Config.logger.info "Disk deleted successfully" end
disk_create_params(name, capacity, bus_type, bus_sub_type, vm)
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 220 def disk_create_params(name, capacity, bus_type, bus_sub_type, vm) 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 end end
storage_profile_records()
click to toggle source
# File lib/ruby_vcloud_sdk/vdc.rb, line 214 def storage_profile_records connection .get("/api/query?type=orgVdcStorageProfile&filter=vdcName==#{URI.encode(name)}") .org_vdc_storage_profile_records end