Class: Libvirt::Network
- Inherits:
-
Object
- Object
- Libvirt::Network
- Defined in:
- lib/libvirt/network.rb
Overview
Represents a network within libvirt, which is a network interface such as a host-only network for VirtualBox, for example.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Provide a meaningful equality check for two networks by comparing UUID.
-
#active? ⇒ Boolean
Determine if the network is active or not.
-
#autostart=(value) ⇒ Boolean
Set the autostart value on the network.
-
#autostart? ⇒ Boolean
Determine if the network is set to autostart on boot or not.
-
#bridge ⇒ String
Returns the bridge that this network is attached to.
-
#create ⇒ Object
(also: #start)
Starts a network.
-
#destroy ⇒ Object
(also: #stop)
Stops a network.
-
#initialize(pointer) ⇒ Network
constructor
Initializes a new Network object given a
virNetworkPtr
. -
#name ⇒ String
Returns the name of the network as a string.
-
#persistent? ⇒ Boolean
Determine if the network is persistent or not.
-
#to_ptr ⇒ FFI::Pointer
Converts to the actual
virNetworkPtr
of this structure. -
#undefine ⇒ Object
Undefines the network, but will not stop it if it is running.
-
#uuid ⇒ String
Returns the UUID of the network as a string.
-
#xml ⇒ String
Returns the XML descriptions of this network.
Constructor Details
#initialize(pointer) ⇒ Network
Initializes a new Libvirt::Network object given a virNetworkPtr
. Please
do not call this directly. Instead, use the Connection#networks
object.
8 9 10 11 |
# File 'lib/libvirt/network.rb', line 8 def initialize(pointer) @pointer = pointer ObjectSpace.define_finalizer(self, method(:finalize)) end |
Instance Method Details
#==(other) ⇒ Boolean
Provide a meaningful equality check for two networks by comparing UUID.
105 106 107 |
# File 'lib/libvirt/network.rb', line 105 def ==(other) other.is_a?(Network) && other.uuid == uuid end |
#active? ⇒ Boolean
Determine if the network is active or not.
63 64 65 |
# File 'lib/libvirt/network.rb', line 63 def active? FFI::Libvirt.virNetworkIsActive(self) == 1 end |
#autostart=(value) ⇒ Boolean
Set the autostart value on the network.
55 56 57 58 |
# File 'lib/libvirt/network.rb', line 55 def autostart=(value) FFI::Libvirt.virNetworkSetAutostart(self, value ? 1 : 0) value end |
#autostart? ⇒ Boolean
Determine if the network is set to autostart on boot or not.
46 47 48 49 50 |
# File 'lib/libvirt/network.rb', line 46 def autostart? output_ptr = FFI::MemoryPointer.new(:int) return nil if FFI::Libvirt.virNetworkGetAutostart(self, output_ptr) < 0 output_ptr.read_int == 1 end |
#bridge ⇒ String
Returns the bridge that this network is attached to.
39 40 41 |
# File 'lib/libvirt/network.rb', line 39 def bridge FFI::Libvirt.virNetworkGetBridgeName(self) end |
#create ⇒ Object Also known as: start
Starts a network.
75 76 77 |
# File 'lib/libvirt/network.rb', line 75 def create FFI::Libvirt.virNetworkCreate(self) end |
#destroy ⇒ Object Also known as: stop
Stops a network.
81 82 83 |
# File 'lib/libvirt/network.rb', line 81 def destroy FFI::Libvirt.virNetworkDestroy(self) end |
#name ⇒ String
Returns the name of the network as a string.
16 17 18 |
# File 'lib/libvirt/network.rb', line 16 def name FFI::Libvirt.virNetworkGetName(self) end |
#persistent? ⇒ Boolean
Determine if the network is persistent or not.
70 71 72 |
# File 'lib/libvirt/network.rb', line 70 def persistent? FFI::Libvirt.virNetworkIsPersistent(self) == 1 end |
#to_ptr ⇒ FFI::Pointer
Converts to the actual virNetworkPtr
of this structure. This allows
this object to be used directly with the FFI layer which expects a
virNetworkPtr
.
97 98 99 |
# File 'lib/libvirt/network.rb', line 97 def to_ptr @pointer end |
#undefine ⇒ Object
Undefines the network, but will not stop it if it is running.
88 89 90 |
# File 'lib/libvirt/network.rb', line 88 def undefine FFI::Libvirt.virNetworkUndefine(self) end |