Class: Fog::VcloudDirector::Compute::Collection

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/vcloud_director/compute.rb

Instance Method Summary collapse

Instance Method Details

#_item_listObject



347
348
349
# File 'lib/fog/vcloud_director/compute.rb', line 347

def _item_list
  @items || item_list || []
end

#all(lazy_load = true) ⇒ Object



312
313
314
# File 'lib/fog/vcloud_director/compute.rb', line 312

def all(lazy_load=true)
  lazy_load ? index : get_everyone
end

#get(item_id) ⇒ Object



316
317
318
319
320
# File 'lib/fog/vcloud_director/compute.rb', line 316

def get(item_id)
  item = get_by_id(item_id)
  return nil unless item
  new(item)
end

#get_by_name(item_name) ⇒ Object



322
323
324
325
326
# File 'lib/fog/vcloud_director/compute.rb', line 322

def get_by_name(item_name)
  item_found = _item_list.find { |item| item[:name] == item_name }
  return nil unless item_found
  get(item_found[:id])
end

#get_everyoneObject



332
333
334
335
# File 'lib/fog/vcloud_director/compute.rb', line 332

def get_everyone
  items = _item_list.map { |item| get_by_id(item[:id]) }
  load(items)
end

#indexObject



328
329
330
# File 'lib/fog/vcloud_director/compute.rb', line 328

def index
  load(_item_list)
end

#with_item_list(hashes) ⇒ Object

Use pre-fetched list of items. Particularly useful when parent’s XML already contains enough information about child entities, hence we can parse them on parent already to reduce API requests. Some examples:

- vApp XML contains all the information about each of its child VMs, so we can pre-fetch `vapp.vms`
- VM XML contains all the information about customization, so we can pre-fecth `vm.guest_customization`
- VM XML contains all the information about disks, so we can pre-fetch `vm.disks`


342
343
344
345
# File 'lib/fog/vcloud_director/compute.rb', line 342

def with_item_list(hashes)
  @items = Array(hashes)
  self
end