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, link) ⇒ VDC

Returns a new instance of VDC.



24
25
26
27
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 24

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

Instance Method Details

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



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# 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) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# 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) ⇒ Object



174
175
176
177
178
179
180
181
# 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) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
141
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 137

def disk_exists?(name)
  list_disks.any? do |disk_name|
    disk_name == name
  end
end

#disksObject



112
113
114
115
116
# 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_gatewaysObject



103
104
105
106
107
108
109
110
# 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) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# 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) ⇒ Object



41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



69
70
71
72
73
74
75
76
77
# 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_disksObject



118
119
120
121
122
# 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_networksObject



97
98
99
100
101
# 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_profilesObject



35
36
37
38
39
# 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_vappsObject



63
64
65
66
67
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 63

def list_vapps
  entity_xml.vapps.map do |vapp_link|
    vapp_link.name
  end
end

#networksObject



91
92
93
94
95
# 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

#resourcesObject



85
86
87
88
89
# 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) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# 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) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
# 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_profilesObject



29
30
31
32
33
# 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) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 79

def vapp_exists?(name)
  entity_xml.vapps.any? do |vapp|
    vapp.name == name
  end
end

#vappsObject



57
58
59
60
61
# 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