vmfloaty 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vmfloaty.rb +14 -15
- data/lib/vmfloaty/format.rb +8 -0
- data/lib/vmfloaty/pooler.rb +8 -7
- data/lib/vmfloaty/version.rb +1 -1
- data/spec/vmfloaty/pooler_spec.rb +169 -2
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4250176fe87450914f6c5abe68dabc6e21a6d60
|
4
|
+
data.tar.gz: f7c45fcbf597a7c09f5b233eaba6e91265494502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20fc4fc84ae8362c9967f0334979b4f7a71517e9ff10c980930dca0f5f558a7cec59c437b3da3412ec50a696fac35ff6a07d13967365c0db02541b694bb61732
|
7
|
+
data.tar.gz: a2a7481706d4845426c5c38d4bb0722e5968301fc9a935f1f80568aea28dc1e0f2d4c20ebfea966f8bf580807821d44e8ba2679a4737889085e4ad2b55d4a50c
|
data/lib/vmfloaty.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'commander'
|
5
|
+
require 'pp'
|
5
6
|
require 'vmfloaty/auth'
|
6
7
|
require 'vmfloaty/pooler'
|
7
8
|
require 'vmfloaty/version'
|
@@ -33,10 +34,6 @@ class Vmfloaty
|
|
33
34
|
user = options.user ||= config['user']
|
34
35
|
url = options.url ||= config['url']
|
35
36
|
|
36
|
-
if args.empty?
|
37
|
-
STDERR.puts "You did not provide any vms to grab"
|
38
|
-
end
|
39
|
-
|
40
37
|
os_types = {}
|
41
38
|
args.each do |arg|
|
42
39
|
os_arr = arg.split("=")
|
@@ -58,7 +55,7 @@ class Vmfloaty
|
|
58
55
|
|
59
56
|
unless os_types.nil?
|
60
57
|
response = Pooler.retrieve(verbose, os_types, token, url)
|
61
|
-
|
58
|
+
Format.get_hosts(response)
|
62
59
|
else
|
63
60
|
puts 'You did not provide an OS to get'
|
64
61
|
end
|
@@ -94,8 +91,8 @@ class Vmfloaty
|
|
94
91
|
url = options.url ||= config['url']
|
95
92
|
hostname = args[0]
|
96
93
|
|
97
|
-
|
98
|
-
|
94
|
+
query_req = Pooler.query(verbose, url, hostname)
|
95
|
+
pp query_req
|
99
96
|
end
|
100
97
|
end
|
101
98
|
|
@@ -117,8 +114,10 @@ class Vmfloaty
|
|
117
114
|
tags = JSON.parse(options.tags) if options.tags
|
118
115
|
token = options.token || config['token']
|
119
116
|
|
120
|
-
|
121
|
-
|
117
|
+
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
118
|
+
if modify_req["ok"]
|
119
|
+
puts "Successfully modified vm #{hostname}.")
|
120
|
+
end
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
@@ -154,8 +153,8 @@ class Vmfloaty
|
|
154
153
|
hostname = args[0]
|
155
154
|
token = options.token ||= config['token']
|
156
155
|
|
157
|
-
|
158
|
-
|
156
|
+
snapshot_req = Pooler.snapshot(verbose, url, hostname, token)
|
157
|
+
pp snapshot_req
|
159
158
|
end
|
160
159
|
end
|
161
160
|
|
@@ -175,8 +174,8 @@ class Vmfloaty
|
|
175
174
|
token = options.token || config['token']
|
176
175
|
snapshot_sha = options.snapshot
|
177
176
|
|
178
|
-
|
179
|
-
|
177
|
+
revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
178
|
+
pp revert_req
|
180
179
|
end
|
181
180
|
end
|
182
181
|
|
@@ -192,7 +191,7 @@ class Vmfloaty
|
|
192
191
|
url = options.url ||= config['url']
|
193
192
|
|
194
193
|
status = Pooler.status(verbose, url)
|
195
|
-
|
194
|
+
pp status
|
196
195
|
end
|
197
196
|
end
|
198
197
|
|
@@ -208,7 +207,7 @@ class Vmfloaty
|
|
208
207
|
url = options.url ||= config['url']
|
209
208
|
|
210
209
|
summary = Pooler.summary(verbose, url)
|
211
|
-
|
210
|
+
pp summary
|
212
211
|
end
|
213
212
|
end
|
214
213
|
|
data/lib/vmfloaty/format.rb
CHANGED
@@ -3,5 +3,13 @@ class Format
|
|
3
3
|
# TODO: Takes the json response body from an HTTP GET
|
4
4
|
# request and "pretty prints" it
|
5
5
|
def self.get_hosts(hostname_hash)
|
6
|
+
host_hash = {}
|
7
|
+
|
8
|
+
hostname_hash.delete("ok")
|
9
|
+
hostname_hash.each do |type, hosts|
|
10
|
+
host_hash[type] = hosts["hostname"]
|
11
|
+
end
|
12
|
+
|
13
|
+
puts host_hash.to_json
|
6
14
|
end
|
7
15
|
end
|
data/lib/vmfloaty/pooler.rb
CHANGED
@@ -33,15 +33,16 @@ class Pooler
|
|
33
33
|
|
34
34
|
os_string = os_string.chomp("+")
|
35
35
|
|
36
|
-
if os_string.size == 0
|
37
|
-
STDERR.puts "No request was made, os hash specified no vms #{os_type}"
|
38
|
-
exit 1
|
39
|
-
end
|
40
|
-
|
41
36
|
response = conn.post "/vm/#{os_string}"
|
42
37
|
|
43
38
|
res_body = JSON.parse(response.body)
|
44
|
-
res_body
|
39
|
+
if res_body["ok"]
|
40
|
+
res_body
|
41
|
+
else
|
42
|
+
STDERR.puts "There was a problem with your request"
|
43
|
+
STDERR.puts res_body
|
44
|
+
exit 1
|
45
|
+
end
|
45
46
|
end
|
46
47
|
|
47
48
|
def self.modify(verbose, url, hostname, token, lifetime, tags)
|
@@ -127,7 +128,7 @@ class Pooler
|
|
127
128
|
conn = Http.get_conn(verbose, url)
|
128
129
|
conn.headers['X-AUTH-TOKEN'] = token
|
129
130
|
|
130
|
-
response = conn.post "/vm/#{hostname}/snapshot/#{
|
131
|
+
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot_sha}"
|
131
132
|
res_body = JSON.parse(response.body)
|
132
133
|
res_body
|
133
134
|
end
|
data/lib/vmfloaty/version.rb
CHANGED
@@ -2,9 +2,176 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../../lib/vmfloaty/pooler'
|
3
3
|
|
4
4
|
describe Pooler do
|
5
|
+
before :each do
|
6
|
+
@vmpooler_url = "https://vmpooler.example.com"
|
7
|
+
end
|
8
|
+
|
5
9
|
describe "#list" do
|
6
|
-
|
7
|
-
|
10
|
+
before :each do
|
11
|
+
@list_response_body = "[\"debian-7-i386\",\"debian-7-x86_64\",\"centos-7-x86_64\"]"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a hash with operating systems from the pooler" do
|
15
|
+
stub_request(:get, "#{@vmpooler_url}/vm").
|
16
|
+
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
17
|
+
|
18
|
+
list = Pooler.list(false, @vmpooler_url, nil)
|
19
|
+
expect(list).to be_an_instance_of Array
|
20
|
+
end
|
21
|
+
|
22
|
+
it "filters operating systems based on the filter param" do
|
23
|
+
stub_request(:get, "#{@vmpooler_url}/vm").
|
24
|
+
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
25
|
+
|
26
|
+
list = Pooler.list(false, @vmpooler_url, "deb")
|
27
|
+
expect(list).to be_an_instance_of Array
|
28
|
+
expect(list.size).to equal 2
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns nothing if the filter does not match" do
|
32
|
+
stub_request(:get, "#{@vmpooler_url}/vm").
|
33
|
+
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
34
|
+
|
35
|
+
list = Pooler.list(false, @vmpooler_url, "windows")
|
36
|
+
expect(list).to be_an_instance_of Array
|
37
|
+
expect(list.size).to equal 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#retrieve" do
|
42
|
+
before :each do
|
43
|
+
@retrieve_response_body_single = "{\"ok\":true,\"debian-7-i386\":{\"hostname\":\"fq6qlpjlsskycq6\"}}"
|
44
|
+
@retrieve_response_body_double = "{\"ok\":true,\"debian-7-i386\":{\"hostname\":[\"sc0o4xqtodlul5w\",\"4m4dkhqiufnjmxy\"]},\"centos-7-x86_64\":{\"hostname\":\"zb91y9qbrbf6d3q\"}}"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "retrieves a single vm with a token" do
|
48
|
+
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386").
|
49
|
+
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.1', 'X-Auth-Token'=>'mytokenfile'}).
|
50
|
+
to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
51
|
+
|
52
|
+
vm_hash = {}
|
53
|
+
vm_hash['debian-7-i386'] = 1
|
54
|
+
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url)
|
55
|
+
expect(vm_req).to be_an_instance_of Hash
|
56
|
+
expect(vm_req["ok"]).to equal true
|
57
|
+
expect(vm_req["debian-7-i386"]["hostname"]).to eq "fq6qlpjlsskycq6"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "retrieves a multiple vms with a token" do
|
61
|
+
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64").
|
62
|
+
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.1', 'X-Auth-Token'=>'mytokenfile'}).
|
63
|
+
to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {})
|
64
|
+
|
65
|
+
vm_hash = {}
|
66
|
+
vm_hash['debian-7-i386'] = 2
|
67
|
+
vm_hash['centos-7-x86_64'] = 1
|
68
|
+
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url)
|
69
|
+
expect(vm_req).to be_an_instance_of Hash
|
70
|
+
expect(vm_req["ok"]).to equal true
|
71
|
+
expect(vm_req["debian-7-i386"]["hostname"]).to be_an_instance_of Array
|
72
|
+
expect(vm_req["debian-7-i386"]["hostname"]).to eq ["sc0o4xqtodlul5w", "4m4dkhqiufnjmxy"]
|
73
|
+
expect(vm_req["centos-7-x86_64"]["hostname"]).to eq "zb91y9qbrbf6d3q"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#modify" do
|
78
|
+
before :each do
|
79
|
+
@modify_response_body_success = "{\"ok\":true}"
|
80
|
+
@modify_response_body_fail = "{\"ok\":false}"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "modifies the TTL of a vm" do
|
84
|
+
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6").
|
85
|
+
with(:body => {"lifetime"=>"12"},
|
86
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.1', 'X-Auth-Token'=>'mytokenfile'}).
|
87
|
+
to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
|
88
|
+
|
89
|
+
modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12, nil)
|
90
|
+
expect(modify_req["ok"]).to be true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#delete" do
|
95
|
+
before :each do
|
96
|
+
@delete_response_body_success = "{\"ok\":true}"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "deletes a specified vm" do
|
100
|
+
stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6").
|
101
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.1', 'X-Auth-Token'=>'mytokenfile'}).
|
102
|
+
to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
|
103
|
+
|
104
|
+
#expect(Pooler.delete(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')).to output(/Scheduling host fq6qlpjlsskycq6 for deletion/).to_stdout
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#staus" do
|
109
|
+
before :each do
|
110
|
+
#smaller version
|
111
|
+
@status_response_body = "{\"capacity\":{\"current\":716,\"total\":717,\"percent\": 99.9},\"status\":{\"ok\":true,\"message\":\"Battle station fully armed and operational.\"}}"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "prints the status" do
|
115
|
+
stub_request(:get, "#{@vmpooler_url}/status").
|
116
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.1'}).
|
117
|
+
to_return(:status => 200, :body => @status_response_body, :headers => {})
|
118
|
+
|
119
|
+
status = Pooler.status(false, @vmpooler_url)
|
120
|
+
expect(status).to be_an_instance_of Hash
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#summary" do
|
125
|
+
before :each do
|
126
|
+
@status_response_body = ""
|
127
|
+
|
128
|
+
it "prints the summary" do
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#query" do
|
134
|
+
before :each do
|
135
|
+
@query_response_body = "{\"ok\": true,\"fq6qlpjlsskycq6\":{\"template\":\"debian-7-x86_64\",\"lifetime\": 2,\"running\": 0.08,\"state\":\"running\",\"snapshots\":[\"n4eb4kdtp7rwv4x158366vd9jhac8btq\" ],\"domain\": \"delivery.puppetlabs.net\"}}"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "makes a query about a vm" do
|
139
|
+
stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6").
|
140
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.1'}).
|
141
|
+
to_return(:status => 200, :body => @query_response_body, :headers => {})
|
142
|
+
|
143
|
+
query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6')
|
144
|
+
expect(query_req).to be_an_instance_of Hash
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#snapshot" do
|
149
|
+
before :each do
|
150
|
+
@snapshot_response_body = "{\"ok\":true}"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "makes a snapshot for a single vm" do
|
154
|
+
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot").
|
155
|
+
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.1', 'X-Auth-Token'=>'mytokenfile'}).
|
156
|
+
to_return(:status => 200, :body => @snapshot_response_body, :headers => {})
|
157
|
+
|
158
|
+
snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')
|
159
|
+
expect(snapshot_req["ok"]).to be true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#revert" do
|
164
|
+
before :each do
|
165
|
+
@revert_response_body = "{\"ok\":true}"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "makes a request to revert a vm from a snapshot" do
|
169
|
+
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve").
|
170
|
+
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.1', 'X-Auth-Token'=>'mytokenfile'}).
|
171
|
+
to_return(:status => 200, :body => @revert_response_body, :headers => {})
|
172
|
+
|
173
|
+
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
174
|
+
expect(revert_req["ok"]).to be true
|
8
175
|
end
|
9
176
|
end
|
10
177
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmfloaty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.9'
|
41
41
|
description: A helper tool for vmpooler to help you stay afloat
|
@@ -68,17 +68,17 @@ require_paths:
|
|
68
68
|
- lib
|
69
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.2.2
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: CLI application to interface with vmpooler
|