2011-06-28 09:47:16 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Pool < Fog::Model
|
2012-04-04 08:03:17 -04:00
|
|
|
attr_reader :xml
|
2011-06-28 09:47:16 -04:00
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
identity :uuid
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2012-04-04 08:03:17 -04:00
|
|
|
attribute :persistent
|
|
|
|
attribute :autostart
|
|
|
|
attribute :active
|
|
|
|
attribute :name
|
|
|
|
attribute :allocation
|
|
|
|
attribute :capacity
|
|
|
|
attribute :num_of_volumes
|
|
|
|
attribute :state
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
def initialize(attributes={} )
|
2012-04-04 08:03:17 -04:00
|
|
|
# Can be created by passing in XML
|
|
|
|
@xml = attributes.delete(:xml)
|
|
|
|
super(attributes)
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
def save
|
2012-04-04 08:03:17 -04:00
|
|
|
raise Fog::Errors::Error.new('Creating a new pool requires proper xml') unless xml
|
|
|
|
self.uuid = (persistent ? connection.define_pool(xml) : connection.create_pool(xml)).uuid
|
|
|
|
reload
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Start the pool = make it active
|
|
|
|
# Performs a libvirt create (= start)
|
|
|
|
def start
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.pool_action uuid, :create
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Stop the pool = make it non-active
|
|
|
|
# Performs a libvirt destroy (= stop)
|
|
|
|
def stop
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.pool_action uuid, :destroy
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Shuts down the pool
|
2011-06-28 09:47:16 -04:00
|
|
|
def shutdown
|
2012-04-04 08:03:17 -04:00
|
|
|
stop
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Build this storage pool
|
|
|
|
def build
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.pool_action uuid, :build
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Destroys the storage pool
|
2012-04-04 08:03:17 -04:00
|
|
|
def destroy
|
2011-08-01 08:00:13 -04:00
|
|
|
# Shutdown pool if active
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.pool_action uuid, :destroy if active?
|
2011-08-01 08:00:13 -04:00
|
|
|
# If this is a persistent domain we need to undefine it
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.pool_action uuid, :undefine if persistent?
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Is the pool active or not?
|
|
|
|
def active?
|
2012-04-04 08:03:17 -04:00
|
|
|
active
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Will the pool autostart or not?
|
|
|
|
def auto_start?
|
2012-04-04 08:03:17 -04:00
|
|
|
autostart
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Is the pool persistent or not?
|
|
|
|
def persistent?
|
2012-04-04 08:03:17 -04:00
|
|
|
persistent
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
# Retrieves the volumes of this pool
|
2011-08-01 08:00:13 -04:00
|
|
|
def volumes
|
2012-04-04 08:03:17 -04:00
|
|
|
connection.list_pool_volumes uuid
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|