(POOLER-70) Update base VM provider

Previously the base VM provider class was added however it was missing various
functions from its definition.  This commit:
- Modifies the VMPooler configuration to add an empty provider config. if the
  provider config is missing
- Helper method to return all of the pools this provider is responsible for
This commit is contained in:
Glenn Sarti 2017-04-03 14:22:07 -07:00
parent 5aa5019822
commit 4bf32be87e
2 changed files with 45 additions and 6 deletions

View file

@ -18,7 +18,15 @@ module Vmpooler
@metrics = metrics
@provider_name = name
# Ensure that there is not a nil provider configuration
@config[:providers] = {} if @config[:providers].nil?
@config[:providers][@provider_name] = {} if provider_config.nil?
# Ensure that there is not a nil pool configuration
@config[:pools] = {} if @config[:pools].nil?
@provider_options = options
logger.log('s', "[!] Creating provider '#{name}'")
end
# Helper Methods
@ -41,7 +49,7 @@ module Vmpooler
def provider_config
@config[:providers].each do |provider|
# Convert the symbol from the config into a string for comparison
return provider[1] if provider[0].to_s == @provider_name
return (provider[1].nil? ? {} : provider[1]) if provider[0].to_s == @provider_name
end
nil
@ -60,6 +68,16 @@ module Vmpooler
@provider_name
end
# returns
# Array[String] : Array of pool names this provider services
def provided_pools
list = []
@config[:pools].each do |pool|
list << pool['name'] if pool['provider'] == name
end
list
end
# Pool Manager Methods
# inputs
@ -146,8 +164,8 @@ module Vmpooler
# [String] new_snapshot_name : Name of the new snapshot to create
# returns
# [Boolean] : true if success, false if snapshot could not be created
# Raises RuntimeError if the Pool does not exist
# Raises RuntimeError if the VM does not exist
# Raises RuntimeError if the snapshot already exists
def create_snapshot(_pool_name, _vm_name, _new_snapshot_name)
raise("#{self.class.name} does not implement create_snapshot")
end
@ -158,8 +176,9 @@ module Vmpooler
# [String] snapshot_name : Name of the snapshot to restore to
# returns
# [Boolean] : true if success, false if snapshot could not be revertted
# Raises RuntimeError if the Pool does not exist
# Raises RuntimeError if the VM does not exist
# Raises RuntimeError if the snapshot already exists
# Raises RuntimeError if the snapshot does not exist
def revert_snapshot(_pool_name, _vm_name, _snapshot_name)
raise("#{self.class.name} does not implement revert_snapshot")
end