Class: Fog::Compute::Vsphere::Servers

Inherits:
Fog::Collection show all
Defined in:
lib/fog/vsphere/models/compute/servers.rb

Instance Attribute Summary

Attributes inherited from Fog::Collection

#connection

Instance Method Summary collapse

Methods inherited from Fog::Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#allObject



12
13
14
15
# File 'lib/fog/vsphere/models/compute/servers.rb', line 12

def all
  response = connection.list_virtual_machines
  load(response['virtual_machines'])
end

#get(id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/vsphere/models/compute/servers.rb', line 17

def get(id)
  # Is the id a managed_object_reference?  This may be the case if we're reloading
  # a model of a VM in the process of being cloned, since it
  # will not have a instance_uuid yet.
  if id =~ /^vm-/
    response = connection.find_vm_by_ref('vm_ref' => id)
    server_attributes = response['virtual_machine']
  else
    response = connection.list_virtual_machines('instance_uuid' => id)
    server_attributes = response['virtual_machines'].first
  end
  new(server_attributes)
rescue Fog::Compute::Vsphere::NotFound
  nil
end