2012-01-22 10:38:02 -05:00
|
|
|
require 'fog/compute/models/server'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Ovirt
|
|
|
|
|
|
|
|
class Server < Fog::Compute::Server
|
|
|
|
|
|
|
|
# This will be the instance uuid which is globally unique across
|
|
|
|
# a oVirt deployment.
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
|
|
|
attribute :description
|
|
|
|
attribute :profile
|
|
|
|
attribute :display
|
|
|
|
attribute :storage, :aliases => 'disk_size'
|
|
|
|
attribute :creation_time
|
|
|
|
attribute :os
|
|
|
|
attribute :ip
|
|
|
|
attribute :status
|
|
|
|
attribute :cores, :aliases => 'cpus'
|
|
|
|
attribute :memory
|
|
|
|
attribute :host
|
|
|
|
attribute :cluster
|
|
|
|
attribute :template
|
|
|
|
attribute :raw
|
|
|
|
|
|
|
|
def ready?
|
|
|
|
!(status =~ /down/i)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stopped?
|
|
|
|
!!(status =~ /down/i)
|
|
|
|
end
|
|
|
|
|
|
|
|
def mac
|
|
|
|
raw.interfaces.first.mac if raw.interfaces
|
|
|
|
end
|
|
|
|
|
|
|
|
def start(options = {})
|
2012-02-19 07:51:06 -05:00
|
|
|
wait_for { stopped? } if options[:blocking]
|
2012-02-08 06:58:10 -05:00
|
|
|
connection.vm_action(:id =>id, :action => :start)
|
2012-01-22 10:38:02 -05:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop(options = {})
|
2012-02-08 06:58:10 -05:00
|
|
|
connection.vm_action(:id =>id, :action => :stop)
|
2012-01-22 10:38:02 -05:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def reboot(options = {})
|
2012-02-08 06:58:10 -05:00
|
|
|
stop unless stopped?
|
2012-02-19 07:51:06 -05:00
|
|
|
start options.merge(:blocking => true)
|
2012-02-08 06:58:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def suspend(options = {})
|
|
|
|
connection.vm_action(:id =>id, :action => :suspend)
|
2012-01-22 10:38:02 -05:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(options = {})
|
2012-02-08 06:58:10 -05:00
|
|
|
(stop unless stopped?) rescue nil #ignore failure, destroy the machine anyway.
|
2012-01-22 10:38:02 -05:00
|
|
|
wait_for { stopped? }
|
2012-02-08 06:58:10 -05:00
|
|
|
connection.destroy_vm(:id => id)
|
2012-01-22 10:38:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2012-02-20 07:18:54 -05:00
|
|
|
if identity
|
|
|
|
connection.update_vm(attributes)
|
|
|
|
else
|
|
|
|
self.id = connection.create_vm(attributes).id
|
|
|
|
end
|
2012-01-22 10:38:02 -05:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|