mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#19) Update vmfloaty to expect /api/v1 in URL for disk endpoint
This commit updates floaty to use a new endpoint to modify vms. Now you can use the modify command to extend the disk space of a given vm. The downside is this new endpoint only exists at /api/v1 on the pooler, and the way Faraday works required an update to removing a leading slash for each request endpoint. Users should update their URL in the floaty dot file to include a /api/v1 at the end of the pooler url
This commit is contained in:
parent
56924fa811
commit
2e24a455a3
7 changed files with 52 additions and 24 deletions
|
|
@ -47,7 +47,7 @@ gem install vmfloaty
|
||||||
Grabbing a token for authenticated pooler requests:
|
Grabbing a token for authenticated pooler requests:
|
||||||
|
|
||||||
```
|
```
|
||||||
floaty token get --user me --url https://vmpooler.mycompany.net
|
floaty token get --user me --url https://vmpooler.mycompany.net/api/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will then ask you to log in. If successful, it will return a token that you can save either in a dotfile or use with other cli commands.
|
This command will then ask you to log in. If successful, it will return a token that you can save either in a dotfile or use with other cli commands.
|
||||||
|
|
@ -55,7 +55,7 @@ This command will then ask you to log in. If successful, it will return a token
|
||||||
Grabbing vms:
|
Grabbing vms:
|
||||||
|
|
||||||
```
|
```
|
||||||
floaty get centos-7-x86_64=2 debian-7-x86_64=1 windows-10=3 --token mytokenstring --url https://vmpooler.mycompany.net
|
floaty get centos-7-x86_64=2 debian-7-x86_64=1 windows-10=3 --token mytokenstring --url https://vmpooler.mycompany.net/api/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
### vmfloaty dotfile
|
### vmfloaty dotfile
|
||||||
|
|
@ -64,7 +64,7 @@ If you do not wish to continuely specify various config options with the cli, yo
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
#file at /Users/me/.vmfloaty.yml
|
#file at /Users/me/.vmfloaty.yml
|
||||||
url: 'http://vmpooler.mycompany.net'
|
url: 'http://vmpooler.mycompany.net/api/v1'
|
||||||
user: 'brian'
|
user: 'brian'
|
||||||
token: 'tokenstring'
|
token: 'tokenstring'
|
||||||
```
|
```
|
||||||
|
|
@ -143,7 +143,7 @@ end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
verbose = true
|
verbose = true
|
||||||
url = 'https://vmpooler.mycompany.net'
|
url = 'https://vmpooler.mycompany.net/api/v1'
|
||||||
token = aquire_token(verbose, url)
|
token = aquire_token(verbose, url)
|
||||||
os = ARGV[0]
|
os = ARGV[0]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,23 +125,27 @@ class Vmfloaty
|
||||||
|
|
||||||
command :modify do |c|
|
command :modify do |c|
|
||||||
c.syntax = 'floaty modify [hostname]'
|
c.syntax = 'floaty modify [hostname]'
|
||||||
c.summary = 'Modify a vms tags and TTL'
|
c.summary = 'Modify a vms tags, TTL, and disk space'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example 'Modifies myhost1 to have a TTL of 12 hours and adds a custom tag', 'floaty modify myhost1 --lifetime 12 --url https://myurl --token mytokenstring --tags \'{"tag":"myvalue"}\''
|
c.example 'Modifies myhost1 to have a TTL of 12 hours and adds a custom tag', 'floaty modify myhost1 --lifetime 12 --url https://myurl --token mytokenstring --tags \'{"tag":"myvalue"}\''
|
||||||
c.option '--verbose', 'Enables verbose output'
|
c.option '--verbose', 'Enables verbose output'
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.option '--token STRING', String, 'Token for vmpooler'
|
c.option '--token STRING', String, 'Token for vmpooler'
|
||||||
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
|
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
|
||||||
|
c.option '--disk INT', Integer, 'Increases VM disk space (Integer, in gb)'
|
||||||
c.option '--tags STRING', String, 'free-form VM tagging (json)'
|
c.option '--tags STRING', String, 'free-form VM tagging (json)'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
hostname = args[0]
|
hostname = args[0]
|
||||||
lifetime = options.lifetime
|
lifetime = options.lifetime
|
||||||
|
disk = options.disk
|
||||||
tags = JSON.parse(options.tags) if options.tags
|
tags = JSON.parse(options.tags) if options.tags
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
|
|
||||||
|
if lifetime || tags
|
||||||
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
||||||
|
|
||||||
if modify_req["ok"]
|
if modify_req["ok"]
|
||||||
puts "Successfully modified vm #{hostname}."
|
puts "Successfully modified vm #{hostname}."
|
||||||
else
|
else
|
||||||
|
|
@ -150,6 +154,19 @@ class Vmfloaty
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if disk
|
||||||
|
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
|
||||||
|
if disk_req["ok"]
|
||||||
|
puts "Successfully updated disk space of vm #{hostname}."
|
||||||
|
else
|
||||||
|
STDERR.puts "Could not modify given host #{hostname} at #{url}."
|
||||||
|
puts disk_req
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
command :delete do |c|
|
command :delete do |c|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class Auth
|
||||||
def self.get_token(verbose, url, user, password)
|
def self.get_token(verbose, url, user, password)
|
||||||
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
||||||
|
|
||||||
resp = conn.post "/token"
|
resp = conn.post "token"
|
||||||
|
|
||||||
res_body = JSON.parse(resp.body)
|
res_body = JSON.parse(resp.body)
|
||||||
if res_body["ok"]
|
if res_body["ok"]
|
||||||
|
|
@ -26,7 +26,7 @@ class Auth
|
||||||
|
|
||||||
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
||||||
|
|
||||||
response = conn.delete "/token/#{token}"
|
response = conn.delete "token/#{token}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
if res_body["ok"]
|
if res_body["ok"]
|
||||||
return res_body
|
return res_body
|
||||||
|
|
@ -45,7 +45,7 @@ class Auth
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
response = conn.get "/token/#{token}"
|
response = conn.get "token/#{token}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
|
|
||||||
if res_body["ok"]
|
if res_body["ok"]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class Pooler
|
||||||
def self.list(verbose, url, os_filter=nil)
|
def self.list(verbose, url, os_filter=nil)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
response = conn.get '/vm'
|
response = conn.get 'vm'
|
||||||
response_body = JSON.parse(response.body)
|
response_body = JSON.parse(response.body)
|
||||||
|
|
||||||
if os_filter
|
if os_filter
|
||||||
|
|
@ -37,7 +37,7 @@ class Pooler
|
||||||
raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
||||||
end
|
end
|
||||||
|
|
||||||
response = conn.post "/vm/#{os_string}"
|
response = conn.post "vm/#{os_string}"
|
||||||
|
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
if res_body["ok"]
|
if res_body["ok"]
|
||||||
|
|
@ -60,7 +60,7 @@ class Pooler
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
||||||
response = conn.put do |req|
|
response = conn.put do |req|
|
||||||
req.url "/vm/#{hostname}"
|
req.url "vm/#{hostname}"
|
||||||
req.body = modify_body.to_json
|
req.body = modify_body.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -68,6 +68,16 @@ class Pooler
|
||||||
res_body
|
res_body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.disk(verbose, url, hostname, token, disk)
|
||||||
|
conn = Http.get_conn(verbose, url)
|
||||||
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
||||||
|
response = conn.post "vm/#{hostname}/disk/#{disk}"
|
||||||
|
|
||||||
|
res_body = JSON.parse(response.body)
|
||||||
|
res_body
|
||||||
|
end
|
||||||
|
|
||||||
def self.delete(verbose, url, hosts, token)
|
def self.delete(verbose, url, hosts, token)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
|
|
@ -77,7 +87,7 @@ class Pooler
|
||||||
|
|
||||||
hosts.each do |host|
|
hosts.each do |host|
|
||||||
puts "Scheduling host #{host} for deletion"
|
puts "Scheduling host #{host} for deletion"
|
||||||
response = conn.delete "/vm/#{host}"
|
response = conn.delete "vm/#{host}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
if res_body['ok']
|
if res_body['ok']
|
||||||
puts "Deletion for vm #{host} successfully scheduled"
|
puts "Deletion for vm #{host} successfully scheduled"
|
||||||
|
|
@ -107,7 +117,7 @@ class Pooler
|
||||||
def self.query(verbose, url, hostname)
|
def self.query(verbose, url, hostname)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
response = conn.get "/vm/#{hostname}"
|
response = conn.get "vm/#{hostname}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
|
|
||||||
res_body
|
res_body
|
||||||
|
|
@ -117,7 +127,7 @@ class Pooler
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
||||||
response = conn.post "/vm/#{hostname}/snapshot"
|
response = conn.post "vm/#{hostname}/snapshot"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
res_body
|
res_body
|
||||||
end
|
end
|
||||||
|
|
@ -126,7 +136,7 @@ class Pooler
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
||||||
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot_sha}"
|
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
res_body
|
res_body
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
class Version
|
class Version
|
||||||
@version = '0.2.19'
|
@version = '0.3.0'
|
||||||
|
|
||||||
def self.get
|
def self.get
|
||||||
@version
|
@version
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'vmfloaty'
|
s.name = 'vmfloaty'
|
||||||
s.version = '0.2.19'
|
s.version = '0.3.0'
|
||||||
s.authors = ['Brian Cain']
|
s.authors = ['Brian Cain']
|
||||||
s.email = ['brian.cain@puppetlabs.com']
|
s.email = ['brian.cain@puppetlabs.com']
|
||||||
s.license = 'Apache'
|
s.license = 'Apache'
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
url: 'http://vmpooler.example.com'
|
url: 'http://vmpooler.example.com/api/v1'
|
||||||
user: 'brian'
|
user: 'brian'
|
||||||
|
token: 'token here'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue