Class: OVIRT::Interface

Inherits:
BaseObject show all
Defined in:
lib/ovirt/interface.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#client, #href, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

#parse_bool, #parse_version

Constructor Details

#initialize(client = nil, xml = {}) ⇒ Interface

Returns a new instance of Interface.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ovirt/interface.rb', line 6

def initialize(client=nil, xml={})
  if xml.is_a?(Hash)
    super(client, xml[:id], xml[:href], xml[:name])
    @network = xml[:network]
    @persisted = xml[:persisted]
    @interface = xml[:interface]
    @plugged = xml[:plugged]
    @linked = xml[:linked]
  else
    super(client, xml[:id], xml[:href], (xml/'name').first.text)
    parse_xml_attributes!(xml)
  end
  self
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def interface
  @interface
end

#linkedObject (readonly)

Returns the value of attribute linked.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def linked
  @linked
end

#macObject (readonly)

Returns the value of attribute mac.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def mac
  @mac
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def name
  @name
end

#networkObject (readonly)

Returns the value of attribute network.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def network
  @network
end

#pluggedObject (readonly)

Returns the value of attribute plugged.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def plugged
  @plugged
end

#vmObject (readonly)

Returns the value of attribute vm.



4
5
6
# File 'lib/ovirt/interface.rb', line 4

def vm
  @vm
end

Class Method Details

.to_xml(opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ovirt/interface.rb', line 21

def self.to_xml(opts={})
  builder = Nokogiri::XML::Builder.new do
    nic{
      name_(opts[:name] || "nic-#{Time.now.to_i}")
      if opts[:network]
        network :id => opts[:network]
      else
        network{ name_(opts[:network_name] || 'ovirtmgmt') }
      end
      interface_(opts[:interface]) if opts[:interface]
      plugged_(opts[:plugged]) if opts[:plugged]
      linked_(opts[:linked]) if opts[:linked]
    }
  end
  Nokogiri::XML(builder.to_xml).root.to_s
end

Instance Method Details

#parse_xml_attributes!(xml) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ovirt/interface.rb', line 42

def parse_xml_attributes!(xml)
 @mac = (xml/'mac').first[:address] rescue nil #template interfaces doesn't have MAC address.
 @interface = (xml/'interface').first.text
 @network = ((xml/'network').first[:id] rescue nil)
 @plugged = (xml/'plugged').first.text if (xml/'plugged').first
 @linked = (xml/'linked').first.text if (xml/'linked').first
 @vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href]) if (xml/'vm') rescue nil
 @template = Link::new(@client, (xml/'template').first[:id], (xml/'template').first[:href]) rescue nil
end

#persisted?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ovirt/interface.rb', line 38

def persisted?
  @persisted || !!id
end