Class: Libvirt::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt/interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ Interface

Returns a new instance of Interface.

Parameters:

  • pointer (FFI::Pointer)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/libvirt/interface.rb', line 14

def initialize(pointer)
  @ptr = pointer

  free = ->(obj_id) do
    dbg { "Finalize Libvirt::Interface object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" }
    return unless @ptr

    warn "Couldn't free Libvirt::Interface object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" if FFI::Interface.virInterfaceFree(@ptr).negative?
  end
  ObjectSpace.define_finalizer(self, free)
end

Class Method Details

.load_ref(pointer) ⇒ Object

Parameters:

  • pointer (FFI::Pointer)

Raises:



6
7
8
9
10
11
# File 'lib/libvirt/interface.rb', line 6

def self.load_ref(pointer)
  result = FFI::Interface.virInterfaceRef(pointer)
  raise Errors::LibError, "Couldn't retrieve interface reference" if result.negative?

  new(pointer)
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

Raises:



61
62
63
64
65
66
# File 'lib/libvirt/interface.rb', line 61

def active?
  result = FFI::Interface.virInterfaceIsActive(@ptr)
  raise Errors::LibError, "Couldn't get interface is active" if result.nil?

  result == 1
end

#destroyObject



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

def destroy
  result = FFI::Interface.virInterfaceDestroy(@ptr, 0)
  raise Errors::LibError, "Couldn't destroy interface" if result.negative?
end

#macString

Returns:

  • (String)

Raises:



42
43
44
45
46
47
# File 'lib/libvirt/interface.rb', line 42

def mac
  result = FFI::Interface.virInterfaceGetMACString(@ptr)
  raise Errors::LibError, "Couldn't get interface mac" if result.nil?

  result
end

#nameString

Returns:

  • (String)

Raises:



33
34
35
36
37
38
# File 'lib/libvirt/interface.rb', line 33

def name
  result = FFI::Interface.virInterfaceGetName(@ptr)
  raise Errors::LibError, "Couldn't get interface name" if result.nil?

  result
end

#startObject



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

def start
  result = FFI::Interface.virInterfaceCreate(@ptr, 0)
  raise Errors::LibError, "Couldn't start interface" if result.negative?
end

#to_ptrFFI::Pointer

Returns:

  • (FFI::Pointer)


27
28
29
# File 'lib/libvirt/interface.rb', line 27

def to_ptr
  @ptr
end

#undefineObject



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

def undefine
  result = FFI::Interface.virInterfaceUndefine(@ptr)
  raise Errors::LibError, "Couldn't undefine interface" if result.negative?
end

#xml_desc(options_or_flags = nil) ⇒ Object

Parameters:

  • options_or_flags (Array<Symbol>, Hash{Symbol=>Boolean}, Integer, Symbol, nil) (defaults to: nil)

Raises:



51
52
53
54
55
56
57
# File 'lib/libvirt/interface.rb', line 51

def xml_desc(options_or_flags = nil)
  flags = Util.parse_flags options_or_flags, FFI::Interface.enum_type(:xml_flags)
  result = FFI::Interface.virInterfaceGetXMLDesc(@ptr, flags)
  raise Errors::LibError, "Couldn't get interface xml desc" if result.nil?

  result
end