Skip to content

Commit

Permalink
Merge pull request #244 from puppetlabs/POOLER-92
Browse files Browse the repository at this point in the history
(POOLER-92) Add the alias information in the API status page for each…
  • Loading branch information
mattkirby authored Oct 20, 2017
2 parents 0b5abd9 + f6813f7 commit abdc86f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
74 changes: 74 additions & 0 deletions examples/vmpooler.yaml.dummy-example.aliasedpools
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions lib/vmpooler/api/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def atomically_allocate_vms(payload)
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,
Expand All @@ -207,6 +208,10 @@ def atomically_allocate_vms(payload)
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] ||= []
Expand Down
21 changes: 16 additions & 5 deletions spec/integration/api/v1/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def app()
'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'}
]
}
}

Expand Down Expand Up @@ -98,13 +98,24 @@ def app()
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
Expand Down

0 comments on commit abdc86f

Please sign in to comment.