Allow pool 'alias' names

The following pool configuration would allow a pool to be aliased in POST
requests as 'centos-6-x86_64', 'centos-6-amd64', or 'centos-6-64':

````yaml
- name: 'centos-6-x86_64'
  alias: [ 'centos-6-amd64', 'centos-6-64' ]
  template: 'templates/centos-6-x86_64'
  folder: 'vmpooler/centos-6-x86_64'
  datastore: 'instance1'
  size: 5
````

The 'alias' configuration can be either a string or an array.

Note that even when requesting an alias, the pool's 'name' is returned in
the JSON response:

````
$ curl -d '{"centos-6-64":"1"}' --url vmpooler/api/v1/vm
````
````json
{
  "ok": true,
  "centos-6-x86_64": {
    "hostname": "cuna2qeahwlzji7"
  },
  "domain": "company.com"
}
````
This commit is contained in:
Scott Schneider 2015-11-04 19:31:32 -08:00
parent 12da1e07d2
commit 17b24d69ad
3 changed files with 95 additions and 81 deletions

View file

@ -33,6 +33,20 @@ module Vmpooler
parsed_config[:config]['vm_checktime'] ||= 15
parsed_config[:config]['vm_lifetime'] ||= 24
# Create an index of pool aliases
parsed_config[:pools].each do |pool|
if pool['alias']
if pool['alias'].kind_of?(Array)
pool['alias'].each do |a|
parsed_config[:alias] ||= {}
parsed_config[:alias][a] = pool['name']
end
elsif pool['alias'].kind_of?(String)
parsed_config[:alias][pool['alias']] = pool['name']
end
end
end
if parsed_config[:graphite]['server']
parsed_config[:graphite]['prefix'] ||= 'vmpooler'
end