Class: PoolParty::Remote::LibvirtInstance

Inherits:
RemoteInstance show all
Includes:
Dslify
Defined in:
lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb

Instance Method Summary collapse

Methods inherited from RemoteInstance

#[], #[]=, #each, #elapsed_runtime, #has_key?, #keys, #load, #on_init, #pending?, #running?, #terminated?, #terminating?, #valid?, #values

Constructor Details

#initialize(o = {}) ⇒ LibvirtInstance

Returns a new instance of LibvirtInstance.



20
21
22
23
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 20

def initialize(o={})
  set_vars_from_options o
  # super
end

Instance Method Details

#descriptionObject



47
48
49
50
51
52
53
54
55
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 47

def description
  p command = "virsh dumpxml #{instance_id || image_id || name}"
  xml = `#{command}`
  hsh = XmlSimple.xml_in(xml, 'KeyToSymbol'=>true)
  hsh[:state] = `virsh domstate #{instance_id || image_id || name}`
  hsh[:mac_address] = mac_addresses( hsh ).first
  dsl_options.merge! hsh
  self
end

#keypair(*n) ⇒ Object



29
30
31
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 29

def keypair(*n)
  dsl_options[:keypair] ||= Key.new(keypair_name)
end

#mac_addressObject

TODO: this needs to be extended for selecting between multiple interfaces



34
35
36
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 34

def mac_address(hsh=nil)
  mac_addresses.first(hsh)
end

#mac_addresses(hsh = nil) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 38

def mac_addresses(hsh=nil)
  data = hsh || description
  data[:devices].select{|el| 
    el.has_key? :interface 
    }.collect{|eth|
      eth.interface.collect{|n| n.mac}
    }.flatten.collect{|c| c.values}.flatten
end

#to_hashObject



25
26
27
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb', line 25

def to_hash
  dsl_options
end