Skip to content

(#19) Update vmfloaty to expect /api/v1 in URL for disk endpoint #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ gem install vmfloaty
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.

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
Expand All @@ -64,7 +64,7 @@ If you do not wish to continuely specify various config options with the cli, yo

```yaml
#file at /Users/me/.vmfloaty.yml
url: 'http://vmpooler.mycompany.net'
url: 'http://vmpooler.mycompany.net/api/v1'
user: 'brian'
token: 'tokenstring'
```
Expand Down Expand Up @@ -143,7 +143,7 @@ end

if __FILE__ == $0
verbose = true
url = 'https://vmpooler.mycompany.net'
url = 'https://vmpooler.mycompany.net/api/v1'
token = aquire_token(verbose, url)
os = ARGV[0]

Expand Down
31 changes: 24 additions & 7 deletions lib/vmfloaty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,46 @@ def run

command :modify do |c|
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.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 '--url STRING', String, 'URL of vmpooler'
c.option '--token STRING', String, 'Token for vmpooler'
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.action do |args, options|
verbose = options.verbose || config['verbose']
url = options.url ||= config['url']
hostname = args[0]
lifetime = options.lifetime
disk = options.disk
tags = JSON.parse(options.tags) if options.tags
token = options.token || config['token']

modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
if modify_req["ok"]
puts "Successfully modified vm #{hostname}."
if lifetime || tags
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)

if modify_req["ok"]
puts "Successfully modified vm #{hostname}."
else
STDERR.puts "Could not modify given host #{hostname} at #{url}."
puts modify_req
exit 1
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
STDERR.puts "Could not modify given host #{hostname} at #{url}."
puts modify_req
exit 1
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/vmfloaty/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Auth
def self.get_token(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)
if res_body["ok"]
Expand All @@ -26,7 +26,7 @@ def self.delete_token(verbose, url, user, password, token)

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)
if res_body["ok"]
return res_body
Expand All @@ -45,7 +45,7 @@ def self.token_status(verbose, url, token)

conn = Http.get_conn(verbose, url)

response = conn.get "/token/#{token}"
response = conn.get "token/#{token}"
res_body = JSON.parse(response.body)

if res_body["ok"]
Expand Down
24 changes: 17 additions & 7 deletions lib/vmfloaty/pooler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Pooler
def self.list(verbose, url, os_filter=nil)
conn = Http.get_conn(verbose, url)

response = conn.get '/vm'
response = conn.get 'vm'
response_body = JSON.parse(response.body)

if os_filter
Expand Down Expand Up @@ -37,7 +37,7 @@ def self.retrieve(verbose, os_type, token, url)
raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
end

response = conn.post "/vm/#{os_string}"
response = conn.post "vm/#{os_string}"

res_body = JSON.parse(response.body)
if res_body["ok"]
Expand All @@ -60,14 +60,24 @@ def self.modify(verbose, url, hostname, token, lifetime, tags)
conn.headers['X-AUTH-TOKEN'] = token

response = conn.put do |req|
req.url "/vm/#{hostname}"
req.url "vm/#{hostname}"
req.body = modify_body.to_json
end

res_body = JSON.parse(response.body)
res_body
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)
conn = Http.get_conn(verbose, url)

Expand All @@ -77,7 +87,7 @@ def self.delete(verbose, url, hosts, token)

hosts.each do |host|
puts "Scheduling host #{host} for deletion"
response = conn.delete "/vm/#{host}"
response = conn.delete "vm/#{host}"
res_body = JSON.parse(response.body)
if res_body['ok']
puts "Deletion for vm #{host} successfully scheduled"
Expand Down Expand Up @@ -107,7 +117,7 @@ def self.summary(verbose, url)
def self.query(verbose, url, hostname)
conn = Http.get_conn(verbose, url)

response = conn.get "/vm/#{hostname}"
response = conn.get "vm/#{hostname}"
res_body = JSON.parse(response.body)

res_body
Expand All @@ -117,7 +127,7 @@ def self.snapshot(verbose, url, hostname, token)
conn = Http.get_conn(verbose, url)
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
end
Expand All @@ -126,7 +136,7 @@ def self.revert(verbose, url, hostname, token, snapshot_sha)
conn = Http.get_conn(verbose, url)
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
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vmfloaty/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

class Version
@version = '0.2.19'
@version = '0.3.0'

def self.get
@version
Expand Down
2 changes: 1 addition & 1 deletion vmfloaty.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'vmfloaty'
s.version = '0.2.19'
s.version = '0.3.0'
s.authors = ['Brian Cain']
s.email = ['[email protected]']
s.license = 'Apache'
Expand Down
3 changes: 2 additions & 1 deletion vmfloaty.yml.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
url: 'http://vmpooler.example.com'
url: 'http://vmpooler.example.com/api/v1'
user: 'brian'
token: 'token here'