Class: Fog::Compute::Vsphere::Interfaces

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

Instance Attribute Summary

Attributes inherited from Fog::Collection

#service

Instance Method Summary collapse

Methods inherited from Fog::Collection

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

Methods included from Attributes::ClassMethods

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

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(filters = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/vsphere/models/compute/interfaces.rb', line 14

def all(filters = {})
  requires :server

  case server
    when Fog::Compute::Vsphere::Server
      load service.list_vm_interfaces(server.id)
    when Fog::Compute::Vsphere::Template
      load service.list_template_interfaces(server.id)
    else
    raise 'interfaces should have vm or template'
  end

  self.each { |interface| interface.server_id = server.id }
  self
end

#get(id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/vsphere/models/compute/interfaces.rb', line 30

def get(id)
  requires :server

  case server
    when Fog::Compute::Vsphere::Server
      interface = service.get_vm_interface(server.id, :key => id, :mac=> id, :name => id)
    when Fog::Compute::Vsphere::Template
      interface = service.get_template_interfaces(server.id, :key => id, :mac=> id, :name => id)
    else

    raise 'interfaces should have vm or template'
  end

  if interface 
    Fog::Compute::Vsphere::Interface.new(interface.merge(:server_id => server.id, :service => service))
  else
    nil         
  end
end

#new(attributes = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/fog/vsphere/models/compute/interfaces.rb', line 50

def new(attributes = {})
  if server
    super({ :server_id => server.id  }.merge(attributes))
  else
    super
  end
end