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

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

Instance Method Summary collapse

Instance Method Details

#all(filters = {}) ⇒ Object



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

def all(filters = {})
  requires :server_id

  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



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

def get(id)
  requires :server_id

  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



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

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

#serverObject



56
57
58
59
# File 'lib/fog/vsphere/models/compute/interfaces.rb', line 56

def server
  return nil if server_id.nil?
  service.servers.get(server_id)
end

#server=(new_server) ⇒ Object



61
62
63
# File 'lib/fog/vsphere/models/compute/interfaces.rb', line 61

def server=(new_server)
  server_id = new_server.id
end