From f10bcadf7eec0bf57a487ff27f3b2e2686a8e630 Mon Sep 17 00:00:00 2001 From: Samuel Beaulieu Date: Wed, 18 Oct 2017 12:26:39 -0500 Subject: [PATCH 1/2] (POOLER-92) Add the alias information in the API status page for each pool Before this change if a pool had an alias configured, the information would not be made public in the API. This commit adds the alias key in the pool object for each pool if configured. The alias key can be abscent, a string or an one or multiple array of strings. The value of the alias is copied from the configuration and can represent another name for the pool, or another configured pool. --- lib/vmpooler/api/v1.rb | 5 ++ spec/integration/api/v1/status_spec.rb | 21 ++++++-- vmpooler.yaml.aliasedpools | 74 ++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 vmpooler.yaml.aliasedpools diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 22a0ef1..6ceb5c3 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -199,6 +199,7 @@ module Vmpooler running = backend.scard('vmpooler__running__' + pool['name']).to_i pending = backend.scard('vmpooler__pending__' + pool['name']).to_i max = pool['size'] + aka = pool['alias'] result[:pools][pool['name']] = { ready: ready, @@ -207,6 +208,10 @@ module Vmpooler max: max } + if aka + result[:pools][pool['name']][:alias] = aka + end + # for backwards compatibility, include separate "empty" stats in "status" block if ready == 0 result[:status][:empty] ||= [] diff --git a/spec/integration/api/v1/status_spec.rb b/spec/integration/api/v1/status_spec.rb index 6abe942..96b54f1 100644 --- a/spec/integration/api/v1/status_spec.rb +++ b/spec/integration/api/v1/status_spec.rb @@ -32,10 +32,10 @@ describe Vmpooler::API::V1 do 'vm_lifetime_auth' => 2, }, pools: [ - {'name' => 'pool1', 'size' => 5}, - {'name' => 'pool2', 'size' => 10} - ], - alias: { 'poolone' => 'pool1' }, + {'name' => 'pool1', 'size' => 5, 'alias' => ['poolone', 'poolun']}, + {'name' => 'pool2', 'size' => 10}, + {'name' => 'pool3', 'size' => 10, 'alias' => 'NotArray'} + ] } } @@ -98,13 +98,24 @@ describe Vmpooler::API::V1 do expect(result["pools"]["pool2"]["pending"]).to be(4) end + it 'returns aliases if configured in the pool' do + get "#{prefix}/status/" + + # of course /status doesn't conform to the weird standard everything else uses... + expect(last_response.header['Content-Type']).to eq('application/json') + result = JSON.parse(last_response.body) + expect(result["pools"]["pool1"]["alias"]).to eq(['poolone', 'poolun']) + expect(result["pools"]["pool2"]["alias"]).to be(nil) + expect(result["pools"]["pool3"]["alias"]).to eq('NotArray') + end + it '(for v1 backwards compatibility) lists any empty pools in the status section' do get "#{prefix}/status/" # of course /status doesn't conform to the weird standard everything else uses... expect(last_response.header['Content-Type']).to eq('application/json') result = JSON.parse(last_response.body) - expect(result["status"]["empty"].sort).to eq(["pool1", "pool2"]) + expect(result["status"]["empty"].sort).to eq(["pool1", "pool2", "pool3"]) end end end diff --git a/vmpooler.yaml.aliasedpools b/vmpooler.yaml.aliasedpools new file mode 100644 index 0000000..dcc604f --- /dev/null +++ b/vmpooler.yaml.aliasedpools @@ -0,0 +1,74 @@ +--- +:providers: + :dummy: + filename: '/tmp/dummy-backing.yaml' + +:redis: + server: 'localhost' + +:auth: + provider: 'dummy' + +:tagfilter: + url: '(.*)\/' + +:config: + site_name: 'vmpooler' + logfile: '/Users/samuel/workspace/vmpooler/vmpooler.log' + task_limit: 10 + timeout: 15 + vm_checktime: 15 + vm_lifetime: 12 + vm_lifetime_auth: 24 + allowed_tags: + - 'created_by' + - 'project' + domain: 'company.com' + prefix: 'poolvm-' + +:pools: + - name: 'debian-7-i386' + alias: [ 'debian-7-32' ] + template: 'Templates/debian-7-i386' + folder: 'Pooled VMs/debian-7-i386' + datastore: 'vmstorage' + size: 5 + timeout: 15 + ready_ttl: 1440 + provider: dummy + - name: 'debian-7-i386-stringalias' + alias: 'debian-7-32-stringalias' + template: 'Templates/debian-7-i386' + folder: 'Pooled VMs/debian-7-i386' + datastore: 'vmstorage' + size: 5 + timeout: 15 + ready_ttl: 1440 + provider: dummy + - name: 'debian-7-x86_64' + alias: [ 'debian-7-64', 'debian-7-amd64' ] + template: 'Templates/debian-7-x86_64' + folder: 'Pooled VMs/debian-7-x86_64' + datastore: 'vmstorage' + size: 5 + timeout: 15 + ready_ttl: 1440 + provider: dummy + - name: 'debian-7-i386-noalias' + template: 'Templates/debian-7-i386' + folder: 'Pooled VMs/debian-7-i386' + datastore: 'vmstorage' + size: 5 + timeout: 15 + ready_ttl: 1440 + provider: dummy + - name: 'debian-7-x86_64-alias-otherpool-extended' + alias: [ 'debian-7-x86_64' ] + template: 'Templates/debian-7-x86_64' + folder: 'Other Pooled VMs/debian-7-x86_64' + datastore: 'other-vmstorage' + size: 5 + timeout: 15 + ready_ttl: 1440 + provider: dummy + From f6813f75c2ac40bf80e873cabfaa41a25dfc61e9 Mon Sep 17 00:00:00 2001 From: Samuel Beaulieu Date: Thu, 19 Oct 2017 16:28:11 -0500 Subject: [PATCH 2/2] move the dummy provider with aliases to the example directory --- .../vmpooler.yaml.dummy-example.aliasedpools | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename vmpooler.yaml.aliasedpools => examples/vmpooler.yaml.dummy-example.aliasedpools (100%) diff --git a/vmpooler.yaml.aliasedpools b/examples/vmpooler.yaml.dummy-example.aliasedpools similarity index 100% rename from vmpooler.yaml.aliasedpools rename to examples/vmpooler.yaml.dummy-example.aliasedpools