class OVIRT::Interface

Attributes

interface[R]
linked[R]
mac[R]
name[R]
network[R]
plugged[R]
vm[R]

Public Class Methods

new(client=nil, xml={}) click to toggle source
Calls superclass method OVIRT::BaseObject::new
   # File lib/ovirt/interface.rb
 6 def initialize(client=nil, xml={})
 7   if xml.is_a?(Hash)
 8     super(client, xml[:id], xml[:href], xml[:name])
 9     @network = xml[:network]
10     @persisted = xml[:persisted]
11     @interface = xml[:interface]
12     @plugged = xml[:plugged]
13     @linked = xml[:linked]
14   else
15     super(client, xml[:id], xml[:href], (xml/'name').first.text)
16     parse_xml_attributes!(xml)
17   end
18   self
19 end
to_xml(opts={}) click to toggle source
   # File lib/ovirt/interface.rb
21 def self.to_xml(opts={})
22   builder = Nokogiri::XML::Builder.new do
23     nic{
24       name_(opts[:name] || "nic-#{Time.now.to_i}")
25       if opts[:network]
26         network :id => opts[:network]
27       else
28         network{ name_(opts[:network_name] || 'ovirtmgmt') }
29       end
30       interface_(opts[:interface]) if opts[:interface]
31       plugged_(opts[:plugged]) if opts[:plugged]
32       linked_(opts[:linked]) if opts[:linked]
33     }
34   end
35   Nokogiri::XML(builder.to_xml).root.to_s
36 end

Public Instance Methods

parse_xml_attributes!(xml) click to toggle source
   # File lib/ovirt/interface.rb
42 def parse_xml_attributes!(xml)
43  @mac = (xml/'mac').first[:address] rescue nil #template interfaces doesn't have MAC address.
44  @interface = (xml/'interface').first.text
45  @network = ((xml/'network').first[:id] rescue nil)
46  @plugged = (xml/'plugged').first.text if (xml/'plugged').first
47  @linked = (xml/'linked').first.text if (xml/'linked').first
48  @vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href]) if (xml/'vm') rescue nil
49  @template = Link::new(@client, (xml/'template').first[:id], (xml/'template').first[:href]) rescue nil
50 end
persisted?() click to toggle source
   # File lib/ovirt/interface.rb
38 def persisted?
39   @persisted || !!id
40 end