Class: Libvirt::Network
- Inherits:
-
Object
- Object
- Libvirt::Network
- Defined in:
- lib/libvirt/network.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #auto_start? ⇒ Boolean
- #bridge_name ⇒ String
- #destroy ⇒ Object
- #dhcp_leases(mac = nil) ⇒ Array<Libvirt::NetworkDhcpLease>, Array
- #dhcp_leases_qty(mac = nil) ⇒ Integer
-
#initialize(pointer) ⇒ Network
constructor
A new instance of Network.
- #name ⇒ String
- #persistent? ⇒ Boolean
- #set_auto_start(value) ⇒ Object
- #start ⇒ Object
- #to_ptr ⇒ FFI::Pointer
- #undefine ⇒ Object
- #update(xml, command, section, flags, parent_index = -1)) ⇒ Object
- #uuid ⇒ String
- #xml_desc(options_or_flags = nil) ⇒ Object
Constructor Details
#initialize(pointer) ⇒ Network
Returns a new instance of Network.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/libvirt/network.rb', line 14 def initialize(pointer) @ptr = pointer free = ->(obj_id) do dbg { "Finalize Libvirt::Network object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" } return unless @ptr warn "Couldn't free Libvirt::Network object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" if FFI::Network.virNetworkFree(@ptr).negative? end ObjectSpace.define_finalizer(self, free) end |
Class Method Details
Instance Method Details
#active? ⇒ Boolean
62 63 64 65 66 67 |
# File 'lib/libvirt/network.rb', line 62 def active? result = FFI::Network.virNetworkIsActive(@ptr) raise Errors::LibError, "Couldn't get network is active" if result.nil? result == 1 end |
#auto_start? ⇒ Boolean
89 90 91 92 93 94 95 |
# File 'lib/libvirt/network.rb', line 89 def auto_start? value = ::FFI::MemoryPointer.new(:int) result = FFI::Network.virNetworkGetAutostart(@ptr, value) raise Errors::LibError, "Couldn't get network auto_start" if result.negative? value.read_int == 1 end |
#bridge_name ⇒ String
80 81 82 83 84 85 |
# File 'lib/libvirt/network.rb', line 80 def bridge_name result = FFI::Network.virNetworkGetBridgeName(@ptr) raise Errors::LibError, "Couldn't get network bridge_name" if result.nil? result end |
#destroy ⇒ Object
137 138 139 140 |
# File 'lib/libvirt/network.rb', line 137 def destroy result = FFI::Network.virNetworkDestroy(@ptr) raise Errors::LibError, "Couldn't destroy network" if result.negative? end |
#dhcp_leases(mac = nil) ⇒ Array<Libvirt::NetworkDhcpLease>, Array
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/libvirt/network.rb', line 118 def dhcp_leases(mac = nil) size = dhcp_leases_qty(mac) return [] if size.zero? dhcp_leases_ptr = ::FFI::MemoryPointer.new(:pointer, size) result = FFI::Network.virNetworkGetDHCPLeases(@ptr, mac, dhcp_leases_ptr, 0) raise Errors::LibError, "Couldn't retrieve network dhcp leases" if result.negative? ptr = dhcp_leases_ptr.read_pointer ptr.get_array_of_pointer(0, size).map { |dhcpl_ptr| NetworkDhcpLease.new(dhcpl_ptr) } end |
#dhcp_leases_qty(mac = nil) ⇒ Integer
108 109 110 111 112 113 |
# File 'lib/libvirt/network.rb', line 108 def dhcp_leases_qty(mac = nil) result = FFI::Network.virNetworkGetDHCPLeases(@ptr, mac, nil, 0) raise Errors::LibError, "Couldn't get network dhcp leases qty" if result.nil? result end |
#name ⇒ String
43 44 45 46 47 48 |
# File 'lib/libvirt/network.rb', line 43 def name result = FFI::Network.virNetworkGetName(@ptr) raise Errors::LibError, "Couldn't get network name" if result.nil? result end |
#persistent? ⇒ Boolean
71 72 73 74 75 76 |
# File 'lib/libvirt/network.rb', line 71 def persistent? result = FFI::Network.virNetworkIsPersistent(@ptr) raise Errors::LibError, "Couldn't get network is persistent" if result.nil? result == 1 end |
#set_auto_start(value) ⇒ Object
99 100 101 102 103 |
# File 'lib/libvirt/network.rb', line 99 def set_auto_start(value) value = value ? 1 : 0 result = FFI::Network.virNetworkSetAutostart(@ptr, value) raise Errors::LibError, "Couldn't set network auto_start" if result.negative? end |
#start ⇒ Object
131 132 133 134 |
# File 'lib/libvirt/network.rb', line 131 def start result = FFI::Network.virNetworkCreate(@ptr) raise Errors::LibError, "Couldn't start network" if result.negative? end |
#to_ptr ⇒ FFI::Pointer
27 28 29 |
# File 'lib/libvirt/network.rb', line 27 def to_ptr @ptr end |
#undefine ⇒ Object
143 144 145 146 |
# File 'lib/libvirt/network.rb', line 143 def undefine result = FFI::Network.virNetworkUndefine(@ptr) raise Errors::LibError, "Couldn't undefine network" if result.negative? end |
#update(xml, command, section, flags, parent_index = -1)) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/libvirt/network.rb', line 154 def update(xml, command, section, flags, parent_index = -1) command = Util.parse_flags command, FFI::Network.enum_type(:update_command) section = Util.parse_flags section, FFI::Network.enum_type(:update_section) flags = Util.parse_flags flags, FFI::Network.enum_type(:update_flags) result = FFI::Network.virNetworkUpdate( @ptr, command, section, parent_index, xml, flags ) raise Errors::LibError, "Couldn't update network" if result.negative? end |
#uuid ⇒ String
33 34 35 36 37 38 39 |
# File 'lib/libvirt/network.rb', line 33 def uuid buff = ::FFI::MemoryPointer.new(:char, Util::UUID_STRING_BUFLEN) result = FFI::Network.virNetworkGetUUIDString(@ptr, buff) raise Errors::LibError, "Couldn't get network uuid" if result.negative? buff.read_string end |
#xml_desc(options_or_flags = nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/libvirt/network.rb', line 52 def xml_desc( = nil) flags = Util.parse_flags , FFI::Network.enum_type(:xml_flags) result = FFI::Network.virNetworkGetXMLDesc(@ptr, flags) raise Errors::LibError, "Couldn't get network xml_desc" if result.nil? result end |