Class: OVIRT::VM
- Inherits:
-
BaseObject
- Object
- BaseObject
- OVIRT::VM
- Defined in:
- lib/ovirt/vm.rb
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#cores ⇒ Object
readonly
Returns the value of attribute cores.
-
#creation_time ⇒ Object
readonly
Returns the value of attribute creation_time.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#interfaces ⇒ Object
Returns the value of attribute interfaces.
-
#ips ⇒ Object
readonly
Returns the value of attribute ips.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#quota ⇒ Object
readonly
Returns the value of attribute quota.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#vnc ⇒ Object
readonly
Returns the value of attribute vnc.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Attributes inherited from BaseObject
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, xml) ⇒ VM
constructor
A new instance of VM.
-
#ready? ⇒ Boolean
In oVirt 3.1 a vm can be marked down and not locked while its volumes are locked.
- #running? ⇒ Boolean
Methods inherited from BaseObject
Constructor Details
#initialize(client, xml) ⇒ VM
Returns a new instance of VM.
11 12 13 14 |
# 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 |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def cluster @cluster end |
#cores ⇒ Object (readonly)
Returns the value of attribute cores.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def cores @cores end |
#creation_time ⇒ Object (readonly)
Returns the value of attribute creation_time.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def creation_time @creation_time end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def description @description end |
#display ⇒ Object (readonly)
Returns the value of attribute display.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def display @display end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def host @host end |
#interfaces ⇒ Object
Returns the value of attribute interfaces.
9 10 11 |
# File 'lib/ovirt/vm.rb', line 9 def interfaces @interfaces end |
#ips ⇒ Object (readonly)
Returns the value of attribute ips.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def ips @ips end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def memory @memory end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def os @os end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def profile @profile end |
#quota ⇒ Object (readonly)
Returns the value of attribute quota.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def quota @quota end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def status @status end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def storage @storage end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
7 8 9 |
# File 'lib/ovirt/vm.rb', line 7 def template @template end |
#vnc ⇒ Object (readonly)
Returns the value of attribute vnc.
8 9 10 |
# File 'lib/ovirt/vm.rb', line 8 def vnc @vnc end |
#volumes ⇒ Object
Returns the value of attribute volumes.
9 10 11 |
# File 'lib/ovirt/vm.rb', line 9 def volumes @volumes end |
Class Method Details
.ticket(options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/ovirt/vm.rb', line 42 def self.ticket ={} builder = Nokogiri::XML::Builder.new do action_{ ticket_{ expiry_([:expiry] || 120) } } end Nokogiri::XML(builder.to_xml).root.to_s end |
.to_xml(opts = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ovirt/vm.rb', line 49 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[:quota] quota_( :id => opts[:quota]) 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({:type => opts[:os_type] || 'unassigned' }){ if(opts[:first_boot_dev] && opts[:first_boot_dev] == 'network') boot(:dev=> opts[:boot_dev1] || 'network') boot(:dev=> opts[:boot_dev2] || 'hd') else boot(:dev=> opts[:boot_dev2] || 'hd') boot(:dev=> opts[:boot_dev1] || 'network') end kernel (opts[:os_kernel]) initrd (opts[:os_initrd]) cmdline (opts[:os_cmdline]) } display_{ type_(opts[:display][:type]) } 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 |
Instance Method Details
#ready? ⇒ Boolean
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.
22 23 24 25 26 27 28 |
# File 'lib/ovirt/vm.rb', line 22 def ready? return false unless @status =~ /down/i volumes.each do |volume| return false if volume.status =~ /locked/i end true end |
#running? ⇒ Boolean
16 17 18 |
# File 'lib/ovirt/vm.rb', line 16 def running? !(@status =~ /down/i) && !(@status =~ /wait_for_launch/i) end |