Class: VCloudSdk::VDC

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Infrastructure
Defined in:
lib/ruby_vcloud_sdk/vdc.rb

Constant Summary

Constants included from Infrastructure

Infrastructure::ERROR_STATUSES, Infrastructure::SUCCESS_STATUS

Instance Method Summary collapse

Constructor Details

#initialize(session, vdc_xml_obj) ⇒ VDC

Returns a new instance of VDC.



32
33
34
35
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 32

def initialize(session, vdc_xml_obj)
  @session = session
  @vdc_xml_obj = vdc_xml_obj
end

Instance Method Details

#create_disk(name, size_mb, vm = nil, bus_type = "scsi", bus_sub_type = "lsilogic") ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 149

def create_disk(
      name,
      size_mb,
      vm = nil,
      bus_type = "scsi",
      bus_sub_type = "lsilogic")

  fail(CloudError,
       "Invalid size in MB #{size_mb}") if size_mb <= 0

  bus_type = BUS_TYPE[bus_type.downcase]
  fail(CloudError,
       "Invalid bus type!") unless bus_type

  bus_sub_type = BUS_SUB_TYPE[bus_sub_type.downcase]
  fail(CloudError,
       "Invalid bus sub type!") unless bus_sub_type

  Config
    .logger
    .info "Creating independent disk #{name} of #{size_mb}MB."

  disk = connection.post(@vdc_xml_obj.add_disk_link,
                         disk_create_params(name, size_mb, 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

#disk_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
146
147
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 143

def disk_exists?(name)
  disks.any? do |disk|
    disk.name == name
  end
end

#disksObject



118
119
120
121
122
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 118

def disks
  @vdc_xml_obj.disks.map do |disk_link|
    VCloudSdk::Disk.new(@session, disk_link)
  end
end

#edge_gatewaysObject



109
110
111
112
113
114
115
116
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 109

def edge_gateways
  connection
    .get(@vdc_xml_obj.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) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 130

def find_disks_by_name(name)
  disks = @vdc_xml_obj
            .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_network_by_name(name) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 99

def find_network_by_name(name)
  @session.org.networks.each do |network_link|
    if network_link.name == name
      return VCloudSdk::Network.new(@session, network_link)
    end
  end

  fail ObjectNotFoundError, "Network '#{name}' is not found"
end

#find_storage_profile_by_name(name) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 49

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) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 71

def find_vapp_by_name(name)
  @vdc_xml_obj.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_disksObject



124
125
126
127
128
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 124

def list_disks
  @vdc_xml_obj.disks.map do |disk_link|
    disk_link.name
  end
end

#list_networksObject



93
94
95
96
97
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 93

def list_networks
  @session.org.networks.map do |network_link|
    network_link.name
  end
end

#list_storage_profilesObject



43
44
45
46
47
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 43

def list_storage_profiles
  storage_profile_records.map do |storage_profile|
    storage_profile.name
  end
end

#list_vappsObject



65
66
67
68
69
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 65

def list_vapps
  @vdc_xml_obj.vapps.map do |vapp_link|
    vapp_link.name
  end
end

#networksObject



87
88
89
90
91
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 87

def networks
  @session.org.networks.map do |network_link|
    VCloudSdk::Network.new(@session, network_link)
  end
end

#resourcesObject



81
82
83
84
85
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 81

def resources
  cpu = VCloudSdk::CPU.new(@vdc_xml_obj.available_cpu_cores)
  memory = VCloudSdk::Memory.new(@vdc_xml_obj.available_memory_mb)
  VCloudSdk::Resources.new(cpu, memory)
end

#storage_profile_xml_node(name) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 180

def storage_profile_xml_node(name)
  return nil if name.nil?

  storage_profile = @vdc_xml_obj.storage_profile(name)
  unless storage_profile
    fail ObjectNotFoundError,
         "Storage profile '#{name}' does not exist"
  end

  storage_profile
end

#storage_profilesObject



37
38
39
40
41
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 37

def storage_profiles
  storage_profile_records.map do |storage_profile|
    VCloudSdk::VdcStorageProfile.new(storage_profile)
  end
end

#vappsObject



59
60
61
62
63
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 59

def vapps
  @vdc_xml_obj.vapps.map do |vapp_link|
    VCloudSdk::VApp.new(@session, vapp_link)
  end
end