Class: Libvirt::Collection::NetworkCollection
- Inherits:
-
AbstractCollection
- Object
- AbstractCollection
- Libvirt::Collection::NetworkCollection
- 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
Instance Method Summary collapse
-
#active ⇒ Array<Network>
Returns all the active networks for the connection which this collection belongs to.
-
#all ⇒ Array<Netowrk>
Returns all networks (active and inactive) for the connection this collection belongs to.
-
#find(value) ⇒ Network
Searches for a network.
-
#find_by_name(name) ⇒ Network
Searches for a network by name.
-
#find_by_uuid(uuid) ⇒ Network
Searches for a network by UUID.
-
#inactive ⇒ Array<Network>
Returns all the inactive networks for the connection which this collection belongs to.
Methods inherited from AbstractCollection
Constructor Details
This class inherits a constructor from Libvirt::Collection::AbstractCollection
Instance Method Details
#active ⇒ Array<Network>
Returns all the active networks for the connection which this collection belongs to.
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 |
#all ⇒ Array<Netowrk>
Returns all networks (active and inactive) for the connection this collection belongs to.
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.
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.
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.
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 |
#inactive ⇒ Array<Network>
Returns all the inactive networks for the connection which this collection belongs to.
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 |