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



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



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 131

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



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 171

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
  nil
end

#delete_disk_by_name(name) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 162

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)
  nil
end

#disk_exists?(name) ⇒ Boolean



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

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

#disksObject



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

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

#edge_gatewaysObject



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

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



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 112

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



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

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



106
107
108
109
110
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 106

def list_disks
  entity_xml.disks.map do |disk_link|
    disk_link.name
  end
end

#list_networksObject



85
86
87
88
89
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 85

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



57
58
59
60
61
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 57

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

#networksObject



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

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

#resourcesObject



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

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_xml_node(name) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/ruby_vcloud_sdk/vdc.rb', line 188

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

#vappsObject



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

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