mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(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:
parent
5aa5019822
commit
4bf32be87e
2 changed files with 45 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ EOT
|
|||
)
|
||||
}
|
||||
|
||||
context 'Given a misconfigured provider name' do
|
||||
context 'Given a provider with no configuration' do
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:providers:
|
||||
|
|
@ -94,8 +94,8 @@ EOT
|
|||
EOT
|
||||
)
|
||||
}
|
||||
it 'should return nil' do
|
||||
expect(subject.provider_config).to be_nil
|
||||
it 'should return empty hash' do
|
||||
expect(subject.provider_config).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -120,6 +120,26 @@ EOT
|
|||
end
|
||||
end
|
||||
|
||||
describe '#provided_pools' do
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:pools:
|
||||
- name: 'pool1'
|
||||
provider: 'base'
|
||||
- name: 'pool2'
|
||||
provider: 'base'
|
||||
- name: 'otherpool'
|
||||
provider: 'other provider'
|
||||
- name: 'no name'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
|
||||
it "should return pools serviced by this provider" do
|
||||
expect(subject.provided_pools).to eq(['pool1','pool2'])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#vms_in_pool' do
|
||||
it 'should raise error' do
|
||||
expect{subject.vms_in_pool('pool')}.to raise_error(/does not implement vms_in_pool/)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue