1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/libvirt/models/compute/pool.rb

89 lines
2 KiB
Ruby
Raw Normal View History

require 'fog/core/model'
module Fog
module Compute
class Libvirt
class Pool < Fog::Model
attr_reader :xml
identity :uuid
2011-08-08 17:22:55 -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
def initialize(attributes={} )
# Can be created by passing in XML
@xml = attributes.delete(:xml)
super(attributes)
end
2011-08-08 17:22:55 -04:00
def save
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
end
2011-08-08 17:22:55 -04:00
# Start the pool = make it active
# Performs a libvirt create (= start)
def start
connection.pool_action uuid, :create
end
2011-08-08 17:22:55 -04:00
# Stop the pool = make it non-active
# Performs a libvirt destroy (= stop)
def stop
connection.pool_action uuid, :destroy
end
2011-08-08 17:22:55 -04:00
# Shuts down the pool
def shutdown
stop
end
2011-08-08 17:22:55 -04:00
# Build this storage pool
def build
connection.pool_action uuid, :build
end
2011-08-08 17:22:55 -04:00
# Destroys the storage pool
def destroy
# Shutdown pool if active
connection.pool_action uuid, :destroy if active?
# If this is a persistent domain we need to undefine it
connection.pool_action uuid, :undefine if persistent?
end
2011-08-08 17:22:55 -04:00
# Is the pool active or not?
def active?
active
end
2011-08-08 17:22:55 -04:00
# Will the pool autostart or not?
def auto_start?
autostart
end
2011-08-08 17:22:55 -04:00
# Is the pool persistent or not?
def persistent?
persistent
end
2011-08-08 17:22:55 -04:00
# Retrieves the volumes of this pool
def volumes
connection.list_pool_volumes uuid
end
2011-08-08 17:22:55 -04:00
end
end
end
end