Sha256: a816070f8e28aa1aa1072bb5ec3d9761e7044c85f75030b747a8f7692c8157a5

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

module OVIRT

  class Interface < BaseObject
    attr_reader :name, :mac, :interface, :network, :vm

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

    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
        }
      end
      Nokogiri::XML(builder.to_xml).root.to_s
    end

    def persisted?
      @persisted || !!id
    end

    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]
     @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

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rbovirt-0.0.22 lib/ovirt/interface.rb
rbovirt-0.0.21 lib/ovirt/interface.rb
rbovirt-0.0.20 lib/ovirt/interface.rb
rbovirt-0.0.19 lib/ovirt/interface.rb
rbovirt-0.0.18 lib/ovirt/interface.rb
rbovirt-0.0.17 lib/ovirt/interface.rb
rbovirt-0.0.16 lib/ovirt/interface.rb
rbovirt-0.0.15 lib/ovirt/interface.rb
rbovirt-0.0.14 lib/ovirt/interface.rb
rbovirt-0.0.13 lib/ovirt/interface.rb
rbovirt-0.0.12 lib/ovirt/interface.rb
rbovirt-0.0.11 lib/ovirt/interface.rb
rbovirt-0.0.10 lib/ovirt/interface.rb
rbovirt-0.0.9 lib/ovirt/interface.rb
rbovirt-0.0.8 lib/ovirt/interface.rb