Skip to content

Commit 2e24a45

Browse files
committed
(#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
1 parent 56924fa commit 2e24a45

File tree

7 files changed

+52
-24
lines changed

7 files changed

+52
-24
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ gem install vmfloaty
4747
Grabbing a token for authenticated pooler requests:
4848

4949
```
50-
floaty token get --user me --url https://vmpooler.mycompany.net
50+
floaty token get --user me --url https://vmpooler.mycompany.net/api/v1
5151
```
5252

5353
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.
5454

5555
Grabbing vms:
5656

5757
```
58-
floaty get centos-7-x86_64=2 debian-7-x86_64=1 windows-10=3 --token mytokenstring --url https://vmpooler.mycompany.net
58+
floaty get centos-7-x86_64=2 debian-7-x86_64=1 windows-10=3 --token mytokenstring --url https://vmpooler.mycompany.net/api/v1
5959
```
6060

6161
### vmfloaty dotfile
@@ -64,7 +64,7 @@ If you do not wish to continuely specify various config options with the cli, yo
6464

6565
```yaml
6666
#file at /Users/me/.vmfloaty.yml
67-
url: 'http://vmpooler.mycompany.net'
67+
url: 'http://vmpooler.mycompany.net/api/v1'
6868
user: 'brian'
6969
token: 'tokenstring'
7070
```
@@ -143,7 +143,7 @@ end
143143
144144
if __FILE__ == $0
145145
verbose = true
146-
url = 'https://vmpooler.mycompany.net'
146+
url = 'https://vmpooler.mycompany.net/api/v1'
147147
token = aquire_token(verbose, url)
148148
os = ARGV[0]
149149

Diff for: lib/vmfloaty.rb

+24-7
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,46 @@ def run
125125

126126
command :modify do |c|
127127
c.syntax = 'floaty modify [hostname]'
128-
c.summary = 'Modify a vms tags and TTL'
128+
c.summary = 'Modify a vms tags, TTL, and disk space'
129129
c.description = ''
130130
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"}\''
131131
c.option '--verbose', 'Enables verbose output'
132132
c.option '--url STRING', String, 'URL of vmpooler'
133133
c.option '--token STRING', String, 'Token for vmpooler'
134134
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
135+
c.option '--disk INT', Integer, 'Increases VM disk space (Integer, in gb)'
135136
c.option '--tags STRING', String, 'free-form VM tagging (json)'
136137
c.action do |args, options|
137138
verbose = options.verbose || config['verbose']
138139
url = options.url ||= config['url']
139140
hostname = args[0]
140141
lifetime = options.lifetime
142+
disk = options.disk
141143
tags = JSON.parse(options.tags) if options.tags
142144
token = options.token || config['token']
143145

144-
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
145-
if modify_req["ok"]
146-
puts "Successfully modified vm #{hostname}."
146+
if lifetime || tags
147+
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
148+
149+
if modify_req["ok"]
150+
puts "Successfully modified vm #{hostname}."
151+
else
152+
STDERR.puts "Could not modify given host #{hostname} at #{url}."
153+
puts modify_req
154+
exit 1
155+
end
156+
end
157+
158+
if disk
159+
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
160+
if disk_req["ok"]
161+
puts "Successfully updated disk space of vm #{hostname}."
162+
else
163+
STDERR.puts "Could not modify given host #{hostname} at #{url}."
164+
puts disk_req
165+
exit 1
166+
end
147167
else
148-
STDERR.puts "Could not modify given host #{hostname} at #{url}."
149-
puts modify_req
150-
exit 1
151168
end
152169
end
153170
end

Diff for: lib/vmfloaty/auth.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Auth
66
def self.get_token(verbose, url, user, password)
77
conn = Http.get_conn_with_auth(verbose, url, user, password)
88

9-
resp = conn.post "/token"
9+
resp = conn.post "token"
1010

1111
res_body = JSON.parse(resp.body)
1212
if res_body["ok"]
@@ -26,7 +26,7 @@ def self.delete_token(verbose, url, user, password, token)
2626

2727
conn = Http.get_conn_with_auth(verbose, url, user, password)
2828

29-
response = conn.delete "/token/#{token}"
29+
response = conn.delete "token/#{token}"
3030
res_body = JSON.parse(response.body)
3131
if res_body["ok"]
3232
return res_body
@@ -45,7 +45,7 @@ def self.token_status(verbose, url, token)
4545

4646
conn = Http.get_conn(verbose, url)
4747

48-
response = conn.get "/token/#{token}"
48+
response = conn.get "token/#{token}"
4949
res_body = JSON.parse(response.body)
5050

5151
if res_body["ok"]

Diff for: lib/vmfloaty/pooler.rb

+17-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Pooler
66
def self.list(verbose, url, os_filter=nil)
77
conn = Http.get_conn(verbose, url)
88

9-
response = conn.get '/vm'
9+
response = conn.get 'vm'
1010
response_body = JSON.parse(response.body)
1111

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

40-
response = conn.post "/vm/#{os_string}"
40+
response = conn.post "vm/#{os_string}"
4141

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

6262
response = conn.put do |req|
63-
req.url "/vm/#{hostname}"
63+
req.url "vm/#{hostname}"
6464
req.body = modify_body.to_json
6565
end
6666

6767
res_body = JSON.parse(response.body)
6868
res_body
6969
end
7070

71+
def self.disk(verbose, url, hostname, token, disk)
72+
conn = Http.get_conn(verbose, url)
73+
conn.headers['X-AUTH-TOKEN'] = token
74+
75+
response = conn.post "vm/#{hostname}/disk/#{disk}"
76+
77+
res_body = JSON.parse(response.body)
78+
res_body
79+
end
80+
7181
def self.delete(verbose, url, hosts, token)
7282
conn = Http.get_conn(verbose, url)
7383

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

7888
hosts.each do |host|
7989
puts "Scheduling host #{host} for deletion"
80-
response = conn.delete "/vm/#{host}"
90+
response = conn.delete "vm/#{host}"
8191
res_body = JSON.parse(response.body)
8292
if res_body['ok']
8393
puts "Deletion for vm #{host} successfully scheduled"
@@ -107,7 +117,7 @@ def self.summary(verbose, url)
107117
def self.query(verbose, url, hostname)
108118
conn = Http.get_conn(verbose, url)
109119

110-
response = conn.get "/vm/#{hostname}"
120+
response = conn.get "vm/#{hostname}"
111121
res_body = JSON.parse(response.body)
112122

113123
res_body
@@ -117,7 +127,7 @@ def self.snapshot(verbose, url, hostname, token)
117127
conn = Http.get_conn(verbose, url)
118128
conn.headers['X-AUTH-TOKEN'] = token
119129

120-
response = conn.post "/vm/#{hostname}/snapshot"
130+
response = conn.post "vm/#{hostname}/snapshot"
121131
res_body = JSON.parse(response.body)
122132
res_body
123133
end
@@ -126,7 +136,7 @@ def self.revert(verbose, url, hostname, token, snapshot_sha)
126136
conn = Http.get_conn(verbose, url)
127137
conn.headers['X-AUTH-TOKEN'] = token
128138

129-
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot_sha}"
139+
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
130140
res_body = JSON.parse(response.body)
131141
res_body
132142
end

Diff for: lib/vmfloaty/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
class Version
3-
@version = '0.2.19'
3+
@version = '0.3.0'
44

55
def self.get
66
@version

Diff for: vmfloaty.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'vmfloaty'
3-
s.version = '0.2.19'
3+
s.version = '0.3.0'
44
s.authors = ['Brian Cain']
55
s.email = ['[email protected]']
66
s.license = 'Apache'

Diff for: vmfloaty.yml.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
url: 'http://vmpooler.example.com'
1+
url: 'http://vmpooler.example.com/api/v1'
22
user: 'brian'
3+
token: 'token here'

0 commit comments

Comments
 (0)