Class: Fog::Compute::Libvirt::Networks

Inherits:
Fog::Collection show all
Defined in:
lib/fog/libvirt/models/compute/networks.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

#all(filter = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/libvirt/models/compute/networks.rb', line 12

def all(filter=nil)
  data=[]
  if filter.nil?
    connection.list_networks.each do |networkname|
      network=connection.lookup_network_by_name(networkname)
      data << { :raw => network }
    end
    connection.list_defined_networks.each do |networkname|
      network=connection.lookup_network_by_name(networkname)
      data << { :raw => network}
    end
  else
    network=nil
    begin
      network=get_by_uuid(filter[:uuid]) if filter.has_key?(:uuid)
      network=get_by_name(filter[:name]) if filter.has_key?(:name)
    rescue ::Libvirt::RetrieveError
      return nil
    end
    data << { :raw => network}
  end

  load(data)
end

#get(uuid) ⇒ Object



37
38
39
# File 'lib/fog/libvirt/models/compute/networks.rb', line 37

def get(uuid)
  self.all(:uuid => uuid).first
end

#get_by_name(name) ⇒ Object

Retrieve the network by name



50
51
52
53
54
# File 'lib/fog/libvirt/models/compute/networks.rb', line 50

def get_by_name(name)
  network=connection.lookup_network_by_name(name)
  return network
  #          new(:raw => network)
end

#get_by_uuid(uuid) ⇒ Object

private # Making these private, screws up realod Retrieve the network by uuid



43
44
45
46
47
# File 'lib/fog/libvirt/models/compute/networks.rb', line 43

def get_by_uuid(uuid)
  network=connection.lookup_network_by_uuid(uuid)
  return network
  #          new(:raw => network)
end