class OVIRT::VM

Attributes

cluster[R]
cores[R]
creation_time[R]
description[R]
display[R]
host[R]
interfaces[RW]
ips[R]
memory[R]
os[R]
profile[R]
status[R]
storage[R]
template[R]
vnc[R]
volumes[RW]

Public Class Methods

new(client, xml) click to toggle source
# File lib/ovirt/vm.rb, line 11
def initialize(client, xml)
  super(client, xml[:id], xml[:href], (xml/'name').first.text)
  parse_xml_attributes!(xml)
end
ticket(options={}) click to toggle source
# File lib/ovirt/vm.rb, line 38
def self.ticket options={}
  builder = Nokogiri::XML::Builder.new do
    action_{ ticket_{ expiry_(options[:expiry] || 120) } }
  end
  Nokogiri::XML(builder.to_xml).root.to_s
end
to_xml(opts={}) click to toggle source
# File lib/ovirt/vm.rb, line 45
def self.to_xml(opts={})
  builder = Nokogiri::XML::Builder.new do
    vm{
      name_ opts[:name] || "i-#{Time.now.to_i}"
      if opts[:template]
        template_ :id => (opts[:template])
      elsif opts[:template_name]
        template_{ name_(opts[:template_name])}
      else
        template_{name_('Blank')}
      end
      if opts[:cluster]
        cluster_( :id => opts[:cluster])
      elsif opts[:cluster_name]
        cluster_{ name_(opts[:cluster_name])}
      end
      type_ opts[:hwp_id] || 'Server'
      if opts[:memory]
          memory opts[:memory]
      end
      if opts[:cores]
         cpu {
           topology( :cores => (opts[:cores] || '1'), :sockets => '1' )
         }
      end
      os{
        boot(:dev=> opts[:boot_dev1] || 'network')
        boot(:dev=> opts[:boot_dev2] || 'hd')
      }
      display_{
        type_(opts[:display])
      } if opts[:display]
      custom_properties {
        custom_property({
          :name => "floppyinject",
          :value => "#{opts[:fileinject_path] || OVIRT::FILEINJECT_PATH}:#{opts[:user_data]}",
          :regexp => "^([^:]+):(.*)$"})
      } if(opts[:user_data_method] && opts[:user_data_method] == :custom_property)
      payloads {
        payload(:type => 'floppy') {
          _file(:name => "#{opts[:fileinject_path] || OVIRT::FILEINJECT_PATH}") { content(Base64::decode64(opts[:user_data])) }
        }
      } if(opts[:user_data_method] && opts[:user_data_method] == :payload)
    }
  end
  Nokogiri::XML(builder.to_xml).root.to_s
end

Public Instance Methods

ready?() click to toggle source

In oVirt 3.1 a vm can be marked down and not locked while its volumes are locked. This method indicates if it is safe to launch the vm.

# File lib/ovirt/vm.rb, line 22
def ready?
  return false unless @status =~ %rdown/
  volumes.each do |volume|
    return false if volume.status =~ %rlocked/
  end if @client.api_version?("3","1")
  true
end
running?() click to toggle source
# File lib/ovirt/vm.rb, line 16
def running?
  !(@status =~ %rdown/) && !(@status =~ %rwait_for_launch/)
end