mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
(#1) Update query, snapshot, and revert
This commit is contained in:
parent
f773e0a5a6
commit
02527b9665
4 changed files with 91 additions and 29 deletions
|
|
@ -1,17 +1,19 @@
|
|||
require 'faraday'
|
||||
require 'json'
|
||||
require 'vmfloaty/http'
|
||||
|
||||
class Auth
|
||||
def self.get_token(user, url, password)
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
#resp = conn.post do |req|
|
||||
# req.url '/v1/token'
|
||||
# req.headers['Content-Type'] = 'application/json'
|
||||
# req.user = user
|
||||
# end
|
||||
resp = conn.post do |req|
|
||||
req.url '/v1/token'
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.user = user
|
||||
end
|
||||
# if ok: true, return token
|
||||
puts 'Got token'
|
||||
resp_body = JSON.parse(resp.body)
|
||||
resp_body
|
||||
end
|
||||
|
||||
def self.delete_token(user, token)
|
||||
|
|
|
|||
|
|
@ -40,12 +40,18 @@ class Pooler
|
|||
puts JSON.parse(response.body)
|
||||
end
|
||||
|
||||
def self.modify(hostname, token, url, lifetime, tags)
|
||||
def self.modify(url, hostname, token, lifetime, tags)
|
||||
modify_body = {'lifetime'=>lifetime, 'tags'=>tags}
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
# need to use token
|
||||
response = conn.put "/v1/#{hostname}"
|
||||
res_body = JSON.parse(response.body)
|
||||
|
||||
puts res_body
|
||||
end
|
||||
|
||||
def self.delete(hostnames, url)
|
||||
def self.delete(url, hostname)
|
||||
hosts = hostnames.split(',')
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
|
|
@ -72,4 +78,31 @@ class Pooler
|
|||
res_body = JSON.parse(response.body)
|
||||
puts res_body
|
||||
end
|
||||
|
||||
def self.query(url, hostname)
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
response = conn.get "/v1/vm/#{hostname}"
|
||||
res_body = JSON.parse(response.body)
|
||||
|
||||
puts res_body
|
||||
end
|
||||
|
||||
def self.snapshot(url, hostname, token)
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
# need to use token
|
||||
response = conn.post "/v1/#{hostname}/snapshot"
|
||||
res_body = JSON.parse(response.body)
|
||||
puts res_body
|
||||
end
|
||||
|
||||
def self.revert(url, hostname, token, snapshot_sha)
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
# need to use token
|
||||
response = conn.post "/v1/#{hostname}/snapshot/#{snapshot}"
|
||||
res_body = JSON.parse(response.body)
|
||||
puts res_body
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue