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, 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
to_xml(opts={})
click to toggle source
# 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
Public Instance Methods
parse_xml_attributes!(xml)
click to toggle source
# 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?()
click to toggle source
# File lib/ovirt/interface.rb, line 38 def persisted? @persisted || !!id end