mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Adding VM-tagging support via PUT /vm/:hostname endpoint
This commit is contained in:
parent
1b8435a63a
commit
99a18c781a
2 changed files with 38 additions and 2 deletions
18
README.md
18
README.md
|
|
@ -168,6 +168,15 @@ $ curl --url vmpooler.company.com/vm/pxpmtoonx7fiqg6
|
||||||
|
|
||||||
Modify a checked-out VM.
|
Modify a checked-out VM.
|
||||||
|
|
||||||
|
The following are valid PUT parameters and their required data structures:
|
||||||
|
|
||||||
|
parameter | description | required structure
|
||||||
|
--------- | ----------- | ------------------
|
||||||
|
*lifetime* | VM TTL (in hours) | integer
|
||||||
|
*tags* | free-form VM tagging | hash
|
||||||
|
|
||||||
|
Any modifications can be verified using the [GET /vm/<hostname>](#get-vmhostname) endpoint.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.company.com/vm/fq6qlpjlsskycq6
|
$ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.company.com/vm/fq6qlpjlsskycq6
|
||||||
```
|
```
|
||||||
|
|
@ -177,6 +186,15 @@ $ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.company.com/vm/fq6qlpjlsskycq
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"sschneid"}}' --url vmpooler.company.com/vm/fq6qlpjlsskycq6
|
||||||
|
```
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ok": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
##### DELETE /vm/<hostname>
|
##### DELETE /vm/<hostname>
|
||||||
|
|
||||||
Schedule a checked-out VM for deletion.
|
Schedule a checked-out VM for deletion.
|
||||||
|
|
|
||||||
|
|
@ -445,12 +445,21 @@ module Vmpooler
|
||||||
status 200
|
status 200
|
||||||
result['ok'] = true
|
result['ok'] = true
|
||||||
|
|
||||||
|
rdata = $redis.hgetall('vmpooler__vm__' + params[:hostname])
|
||||||
|
|
||||||
result[params[:hostname]] = {}
|
result[params[:hostname]] = {}
|
||||||
|
|
||||||
result[params[:hostname]]['template'] = $redis.hget('vmpooler__vm__' + params[:hostname], 'template')
|
result[params[:hostname]]['template'] = rdata['template']
|
||||||
result[params[:hostname]]['lifetime'] = $redis.hget('vmpooler__vm__' + params[:hostname], 'lifetime') || $config[:config]['vm_lifetime']
|
result[params[:hostname]]['lifetime'] = rdata['lifetime'] || $config[:config]['vm_lifetime']
|
||||||
result[params[:hostname]]['running'] = ((Time.now - Time.parse($redis.hget('vmpooler__active__' + result[params[:hostname]]['template'], params[:hostname]))) / 60 / 60).round(2)
|
result[params[:hostname]]['running'] = ((Time.now - Time.parse($redis.hget('vmpooler__active__' + result[params[:hostname]]['template'], params[:hostname]))) / 60 / 60).round(2)
|
||||||
|
|
||||||
|
rdata.keys.each do |key|
|
||||||
|
if key.match('^tag\:(.+?)$')
|
||||||
|
result[params[:hostname]]['tags'] ||= {}
|
||||||
|
result[params[:hostname]]['tags'][$1] = rdata[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if $config[:config]['domain']
|
if $config[:config]['domain']
|
||||||
result[params[:hostname]]['domain'] = $config[:config]['domain']
|
result[params[:hostname]]['domain'] = $config[:config]['domain']
|
||||||
end
|
end
|
||||||
|
|
@ -503,6 +512,15 @@ module Vmpooler
|
||||||
if arg > 0
|
if arg > 0
|
||||||
$redis.hset('vmpooler__vm__' + params[:hostname], param, arg)
|
$redis.hset('vmpooler__vm__' + params[:hostname], param, arg)
|
||||||
|
|
||||||
|
status 200
|
||||||
|
result['ok'] = true
|
||||||
|
end
|
||||||
|
when 'tags'
|
||||||
|
if arg.is_a?(Hash)
|
||||||
|
arg.keys.each do |tag|
|
||||||
|
$redis.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag])
|
||||||
|
end
|
||||||
|
|
||||||
status 200
|
status 200
|
||||||
result['ok'] = true
|
result['ok'] = true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue