Class: Libvirt::Network

Inherits:
Object
  • Object
show all
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)

Constructor Details

- (Network) initialize(pointer)

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

- (Boolean) ==(other)

Provide a meaningful equality check for two networks by comparing UUID.

Returns:

  • (Boolean)


105
106
107
# File 'lib/libvirt/network.rb', line 105

def ==(other)
  other.is_a?(Network) && other.uuid == uuid
end

- (Boolean) active?

Determine if the network is active or not.

Returns:

  • (Boolean)


63
64
65
# File 'lib/libvirt/network.rb', line 63

def active?
  FFI::Libvirt.virNetworkIsActive(self) == 1
end

- (Boolean) autostart=(value)

Set the autostart value on the network.

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/libvirt/network.rb', line 55

def autostart=(value)
  FFI::Libvirt.virNetworkSetAutostart(self, value ? 1 : 0)
  value
end

- (Boolean) autostart?

Determine if the network is set to autostart on boot or not.

Returns:

  • (Boolean)


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

- (String) bridge

Returns the bridge that this network is attached to.

Returns:

  • (String)


39
40
41
# File 'lib/libvirt/network.rb', line 39

def bridge
  FFI::Libvirt.virNetworkGetBridgeName(self)
end

- (Object) create Also known as: start

Starts a network.



75
76
77
# File 'lib/libvirt/network.rb', line 75

def create
  FFI::Libvirt.virNetworkCreate(self)
end

- (Object) destroy Also known as: stop

Stops a network.



81
82
83
# File 'lib/libvirt/network.rb', line 81

def destroy
  FFI::Libvirt.virNetworkDestroy(self)
end

- (String) name

Returns the name of the network as a string.

Returns:

  • (String)


16
17
18
# File 'lib/libvirt/network.rb', line 16

def name
  FFI::Libvirt.virNetworkGetName(self)
end

- (Boolean) persistent?

Determine if the network is persistent or not.

Returns:

  • (Boolean)


70
71
72
# File 'lib/libvirt/network.rb', line 70

def persistent?
  FFI::Libvirt.virNetworkIsPersistent(self) == 1
end

- (FFI::Pointer) to_ptr

Converts to the actual virNetworkPtr of this structure. This allows this object to be used directly with the FFI layer which expects a virNetworkPtr.

Returns:

  • (FFI::Pointer)


97
98
99
# File 'lib/libvirt/network.rb', line 97

def to_ptr
  @pointer
end

- (Object) undefine

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

- (String) uuid

Returns the UUID of the network as a string.

Returns:

  • (String)


30
31
32
33
34
# File 'lib/libvirt/network.rb', line 30

def uuid
  output_ptr = FFI::MemoryPointer.new(:char, 36)
  FFI::Libvirt.virNetworkGetUUIDString(self, output_ptr)
  output_ptr.read_string
end

- (String) xml

Returns the XML descriptions of this network.

Returns:

  • (String)


23
24
25
# File 'lib/libvirt/network.rb', line 23

def xml
  FFI::Libvirt.virNetworkGetXMLDesc(self, 0)
end