vmfloaty 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bfa904ec8ca9ec10fa9c6c9571d5ebbb3a0647e
4
- data.tar.gz: c6d347f9075dd4ecf5056ae39c4ff4f5f2b7e6e7
3
+ metadata.gz: c5a8aa5f96b46944ccf39b5218791ade53d56834
4
+ data.tar.gz: 5ba89a4493c1bbe5aa14caaecf58d992af59fdc2
5
5
  SHA512:
6
- metadata.gz: 231d4ef21dc8ebb75b57511c4e4d33d8c77b2b0566027973c0a9e9cc790bc79a9bca532ab433b42600473e9811e867523a74927988524a11b4330542b639b85c
7
- data.tar.gz: 88b32545eae35d0b49e366c5883052b20dcb38445c4ae534987b7de0bbb6246635ca5004c5cd8e095308692e0c817649655cf82aceab02b38a27bb380bb6d26f
6
+ metadata.gz: 46df128c9da17337d0c4880eedd3288d367b928134d3c931115d27801ddf22a776834926cd0c55896cba13b944915666fe4610f237b44efb179a8088313ca722
7
+ data.tar.gz: da0865befca262fcb10b32f05ea233a724f5b1c56bbd40f4b015ff455050b738900c6d7da55ac888eeb01dfc2a914f06d700819f58565e15ee4c9044961df733
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- vmpooler
1
+ vmfloaty
2
2
 
3
- Copyright (C) 2014 Puppet Labs
3
+ Copyright (C) 2014-2016 Puppet
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
data/lib/vmfloaty.rb CHANGED
@@ -177,7 +177,12 @@ class Vmfloaty
177
177
  token = options.token || config['token']
178
178
 
179
179
  if lifetime || tags
180
- modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
180
+ begin
181
+ modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
182
+ rescue TokenError => e
183
+ STDERR.puts e
184
+ exit 1
185
+ end
181
186
 
182
187
  if modify_req["ok"]
183
188
  puts "Successfully modified vm #{hostname}."
@@ -189,7 +194,13 @@ class Vmfloaty
189
194
  end
190
195
 
191
196
  if disk
192
- disk_req = Pooler.disk(verbose, url, hostname, token, disk)
197
+ begin
198
+ disk_req = Pooler.disk(verbose, url, hostname, token, disk)
199
+ rescue TokenError => e
200
+ STDERR.puts e
201
+ exit 1
202
+ end
203
+
193
204
  if disk_req["ok"]
194
205
  puts "Successfully updated disk space of vm #{hostname}."
195
206
  else
@@ -290,7 +301,13 @@ class Vmfloaty
290
301
  hostname = args[0]
291
302
  token = options.token ||= config['token']
292
303
 
293
- snapshot_req = Pooler.snapshot(verbose, url, hostname, token)
304
+ begin
305
+ snapshot_req = Pooler.snapshot(verbose, url, hostname, token)
306
+ rescue TokenError => e
307
+ STDERR.puts e
308
+ exit 1
309
+ end
310
+
294
311
  pp snapshot_req
295
312
  end
296
313
  end
@@ -315,7 +332,13 @@ class Vmfloaty
315
332
  STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}"
316
333
  end
317
334
 
318
- revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
335
+ begin
336
+ revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
337
+ rescue TokenError => e
338
+ STDERR.puts e
339
+ exit 1
340
+ end
341
+
319
342
  pp revert_req
320
343
  end
321
344
  end
@@ -55,6 +55,10 @@ class Pooler
55
55
  end
56
56
 
57
57
  def self.modify(verbose, url, hostname, token, lifetime, tags)
58
+ if token.nil?
59
+ raise TokenError, "Token provided was nil. Request cannot be made to modify vm"
60
+ end
61
+
58
62
  modify_body = {}
59
63
  if lifetime
60
64
  modify_body['lifetime'] = lifetime
@@ -76,6 +80,10 @@ class Pooler
76
80
  end
77
81
 
78
82
  def self.disk(verbose, url, hostname, token, disk)
83
+ if token.nil?
84
+ raise TokenError, "Token provided was nil. Request cannot be made to modify vm"
85
+ end
86
+
79
87
  conn = Http.get_conn(verbose, url)
80
88
  conn.headers['X-AUTH-TOKEN'] = token
81
89
 
@@ -129,6 +137,10 @@ class Pooler
129
137
  end
130
138
 
131
139
  def self.snapshot(verbose, url, hostname, token)
140
+ if token.nil?
141
+ raise TokenError, "Token provided was nil. Request cannot be made to snapshot vm"
142
+ end
143
+
132
144
  conn = Http.get_conn(verbose, url)
133
145
  conn.headers['X-AUTH-TOKEN'] = token
134
146
 
@@ -138,6 +150,10 @@ class Pooler
138
150
  end
139
151
 
140
152
  def self.revert(verbose, url, hostname, token, snapshot_sha)
153
+ if token.nil?
154
+ raise TokenError, "Token provided was nil. Request cannot be made to revert vm"
155
+ end
156
+
141
157
  conn = Http.get_conn(verbose, url)
142
158
  conn.headers['X-AUTH-TOKEN'] = token
143
159
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Version
3
- @version = '0.7.0'
3
+ @version = '0.7.1'
4
4
 
5
5
  def self.get
6
6
  @version
@@ -90,6 +90,10 @@ describe Pooler do
90
90
  @modify_response_body_fail = "{\"ok\":false}"
91
91
  end
92
92
 
93
+ it "raises a TokenError if token provided is nil" do
94
+ expect{ Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, 12, nil) }.to raise_error(TokenError)
95
+ end
96
+
93
97
  it "modifies the TTL of a vm" do
94
98
  stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6").
95
99
  with(:body => {"{\"lifetime\":12}"=>true},
@@ -116,7 +120,7 @@ describe Pooler do
116
120
  end
117
121
  end
118
122
 
119
- describe "#staus" do
123
+ describe "#status" do
120
124
  before :each do
121
125
  #smaller version
122
126
  @status_response_body = "{\"capacity\":{\"current\":716,\"total\":717,\"percent\": 99.9},\"status\":{\"ok\":true,\"message\":\"Battle station fully armed and operational.\"}}"
@@ -188,5 +192,28 @@ describe Pooler do
188
192
  it "doesn't make a request to revert a vm if snapshot is not provided" do
189
193
  expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, "Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6")
190
194
  end
195
+
196
+ it "raises a TokenError if no token was provided" do
197
+ expect{ Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError)
198
+ end
199
+ end
200
+
201
+ describe "#disk" do
202
+ before :each do
203
+ @disk_response_body_success = "{\"ok\":true}"
204
+ @disk_response_body_fail = "{\"ok\":false}"
205
+ end
206
+
207
+ it "makes a request to extend disk space of a vm" do
208
+ stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12").
209
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @disk_response_body_success, :headers => {})
210
+
211
+ disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12)
212
+ expect(disk_req["ok"]).to be true
213
+ end
214
+
215
+ it "raises a TokenError if no token was provided" do
216
+ expect{ Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError)
217
+ end
191
218
  end
192
219
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander