Class: Libvirt::Collection::NetworkCollection

Inherits:
AbstractCollection show all
Defined in:
lib/libvirt/collection/network_collection.rb

Overview

Represents a collection of networks. This is an enumerable (in the Ruby sense) object, but it is not directly an Array.

Instance Attribute Summary

Attributes inherited from AbstractCollection

#interface

Instance Method Summary collapse

Methods inherited from AbstractCollection

#initialize

Constructor Details

This class inherits a constructor from Libvirt::Collection::AbstractCollection

Instance Method Details

#activeArray<Network>

Returns all the active networks for the connection which this collection belongs to.

Returns:



33
34
35
36
37
# File 'lib/libvirt/collection/network_collection.rb', line 33

def active
  read_array(:virConnectListNetworks, :virConnectNumOfNetworks, :string).collect do |name|
    find_by_name(name)
  end
end

#allArray<Netowrk>

Returns all networks (active and inactive) for the connection this collection belongs to.

Returns:

  • (Array<Netowrk>)


53
54
55
# File 'lib/libvirt/collection/network_collection.rb', line 53

def all
  active + inactive
end

#find(value) ⇒ Network

Searches for a network. This will first search by name, then by UUID.

Returns:



10
11
12
13
# File 'lib/libvirt/collection/network_collection.rb', line 10

def find(value)
  result = find_by_name(value) rescue nil
  result ||= find_by_uuid(value) rescue nil
end

#find_by_name(name) ⇒ Network

Searches for a network by name.

Returns:



18
19
20
# File 'lib/libvirt/collection/network_collection.rb', line 18

def find_by_name(name)
  nil_or_object(FFI::Libvirt.virNetworkLookupByName(interface, name), Network)
end

#find_by_uuid(uuid) ⇒ Network

Searches for a network by UUID.

Returns:



25
26
27
# File 'lib/libvirt/collection/network_collection.rb', line 25

def find_by_uuid(uuid)
  nil_or_object(FFI::Libvirt.virNetworkLookupByUUIDString(interface, uuid), Network)
end

#inactiveArray<Network>

Returns all the inactive networks for the connection which this collection belongs to.

Returns:



43
44
45
46
47
# File 'lib/libvirt/collection/network_collection.rb', line 43

def inactive
  read_array(:virConnectListDefinedNetworks, :virConnectNumOfDefinedNetworks, :string).collect do |name|
    find_by_name(name)
  end
end