vmfloaty 0.1.0 → 0.2.0
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/README.md +41 -10
- data/bin/floaty +2 -1
- data/lib/vmfloaty.rb +243 -8
- data/lib/vmfloaty/auth.rb +59 -0
- data/lib/vmfloaty/http.rb +60 -0
- data/lib/vmfloaty/pooler.rb +108 -0
- metadata +7 -21
- data/lib/vmfloaty/cli.rb +0 -87
- data/lib/vmfloaty/hosts.rb +0 -29
- data/lib/vmfloaty/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f715c6bc71cf2d991c9bc09108f5e6e64b768de6
|
4
|
+
data.tar.gz: 2f8bc1572c8a84e0cdf540ea91b41a38787d4eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d099a22da7c021c17ed35253267ef2fa4ae19955d3fc823fcb7679d9c770ecfd40815959d3a20bc05f86c4522f395fc35acb8bd49116b722bea66e8118d3fc
|
7
|
+
data.tar.gz: 7c32c73f23839861a0edcf9fa0f08e167058e3141c72fffbc4913d2d791b993d391ea09433b94e95c05e335c6576c925156f1da318707973e5715d5b461ed638
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
vmfloaty
|
2
2
|
========
|
3
3
|
|
4
|
-
A CLI helper tool for Puppet Labs vmpooler to help you stay afloat.
|
4
|
+
A CLI helper tool for [Puppet Labs vmpooler](https://github.com/puppetlabs/vmpooler) to help you stay afloat.
|
5
|
+
|
6
|
+
<img src="http://i.imgur.com/xGcGwuH.jpg" width=200 height=200>
|
5
7
|
|
6
8
|
## Install
|
7
9
|
|
8
|
-
|
10
|
+
Grab the latest from ruby gems...
|
9
11
|
|
10
12
|
```
|
11
13
|
gem install vmfloaty
|
@@ -13,14 +15,43 @@ gem install vmfloaty
|
|
13
15
|
|
14
16
|
## Usage
|
15
17
|
|
16
|
-
|
18
|
+
```
|
19
|
+
delete Schedules the deletion of a host or hosts
|
20
|
+
get Gets a vm or vms based on the os flag
|
21
|
+
help Display global or [command] help documentation
|
22
|
+
list Shows a list of available vms from the pooler
|
23
|
+
modify Modify a vms tags and TTL
|
24
|
+
query Get information about a given vm
|
25
|
+
revert Reverts a vm to a specified snapshot
|
26
|
+
snapshot Takes a snapshot of a given vm
|
27
|
+
status Prints the status of vmpooler
|
28
|
+
summary Prints the summary of vmpooler
|
29
|
+
token Retrieves or deletes a token
|
30
|
+
|
31
|
+
GLOBAL OPTIONS:
|
17
32
|
|
33
|
+
-h, --help
|
34
|
+
Display help documentation
|
35
|
+
|
36
|
+
-v, --version
|
37
|
+
Display version information
|
38
|
+
|
39
|
+
-t, --trace
|
40
|
+
Display backtrace when an error occurs
|
18
41
|
```
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
42
|
+
|
43
|
+
### vmfloaty dotfile
|
44
|
+
|
45
|
+
If you do not wish to continuely specify various config options with the cli, you can have a dotfile in your home directory for some defaults. For example:
|
46
|
+
|
47
|
+
```yaml
|
48
|
+
#file at /Users/me/.vmpooler.yml
|
49
|
+
url: 'http://vmpooler.mycompany.net'
|
50
|
+
user: 'brian'
|
26
51
|
```
|
52
|
+
|
53
|
+
Now vmfloaty will use those config files if no flag was specified.
|
54
|
+
|
55
|
+
## vmpooler API
|
56
|
+
|
57
|
+
This cli tool uses the [vmpooler API](https://github.com/puppetlabs/vmpooler/blob/master/API.md).
|
data/bin/floaty
CHANGED
data/lib/vmfloaty.rb
CHANGED
@@ -1,17 +1,252 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander'
|
5
|
+
require 'yaml'
|
6
|
+
require 'vmfloaty/auth'
|
7
|
+
require 'vmfloaty/pooler'
|
3
8
|
|
4
9
|
class Vmfloaty
|
10
|
+
include Commander::Methods
|
11
|
+
|
12
|
+
def run
|
13
|
+
program :version, '0.2.0'
|
14
|
+
program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat'
|
15
|
+
|
16
|
+
config = read_config
|
17
|
+
|
18
|
+
command :get do |c|
|
19
|
+
c.syntax = 'floaty get [options]'
|
20
|
+
c.summary = 'Gets a vm or vms based on the os flag'
|
21
|
+
c.description = ''
|
22
|
+
c.example 'Gets 3 vms', 'floaty get --user brian --url http://vmpooler.example.com --os centos,centos,debian'
|
23
|
+
c.option '--verbose', 'Enables verbose output'
|
24
|
+
c.option '--user STRING', String, 'User to authenticate with'
|
25
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
26
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
27
|
+
c.option '--os STRING', String, 'Operating systems to retrieve'
|
28
|
+
c.option '--notoken', 'Makes a request without a token'
|
29
|
+
c.action do |args, options|
|
30
|
+
verbose = options.verbose || config['verbose']
|
31
|
+
token = options.token || config['token']
|
32
|
+
user = options.user ||= config['user']
|
33
|
+
url = options.url ||= config['url']
|
34
|
+
os_types = options.os
|
35
|
+
no_token = options.notoken
|
36
|
+
|
37
|
+
unless no_token.nil?
|
38
|
+
response = Pooler.retrieve(verbose, os_types, token, url)
|
39
|
+
puts response
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
unless options.token
|
44
|
+
pass = password "Enter your password please:", '*'
|
45
|
+
token = Auth.get_token(verbose, url, user, pass)
|
46
|
+
end
|
47
|
+
|
48
|
+
unless os_types.nil?
|
49
|
+
response = Pooler.retrieve(verbose, os_types, token, url)
|
50
|
+
puts response
|
51
|
+
else
|
52
|
+
puts 'You did not provide an OS to get'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
command :list do |c|
|
58
|
+
c.syntax = 'floaty list [options]'
|
59
|
+
c.summary = 'Shows a list of available vms from the pooler'
|
60
|
+
c.description = ''
|
61
|
+
c.example 'Filter the list on centos', 'floaty list --filter centos --url http://vmpooler.example.com'
|
62
|
+
c.option '--verbose', 'Enables verbose output'
|
63
|
+
c.option '--filter STRING', String, 'A filter to apply to the list'
|
64
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
65
|
+
c.action do |args, options|
|
66
|
+
verbose = options.verbose || config['verbose']
|
67
|
+
filter = options.filter
|
68
|
+
url = options.url ||= config['url']
|
69
|
+
|
70
|
+
os_list = Pooler.list(verbose, url, filter)
|
71
|
+
puts os_list
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
command :query do |c|
|
76
|
+
c.syntax = 'floaty query [options]'
|
77
|
+
c.summary = 'Get information about a given vm'
|
78
|
+
c.description = ''
|
79
|
+
c.example 'Get information about a sample host', 'floaty query --url http://vmpooler.example.com --host myvmhost.example.com'
|
80
|
+
c.option '--verbose', 'Enables verbose output'
|
81
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
82
|
+
c.option '--host STRING', String, 'Hostname to query'
|
83
|
+
c.action do |args, options|
|
84
|
+
verbose = options.verbose || config['verbose']
|
85
|
+
url = options.url ||= config['url']
|
86
|
+
hostname = options.host
|
87
|
+
|
88
|
+
query = Pooler.query(verbose, url, hostname)
|
89
|
+
puts query
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
command :modify do |c|
|
94
|
+
c.syntax = 'floaty modify [options]'
|
95
|
+
c.summary = 'Modify a vms tags and TTL'
|
96
|
+
c.description = ''
|
97
|
+
c.example 'description', 'command example'
|
98
|
+
c.option '--verbose', 'Enables verbose output'
|
99
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
100
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
101
|
+
c.option '--host STRING', String, 'Hostname to modify'
|
102
|
+
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
|
103
|
+
c.option '--tags HASH', Hash, 'free-form VM tagging'
|
104
|
+
c.action do |args, options|
|
105
|
+
verbose = options.verbose || config['verbose']
|
106
|
+
url = options.url ||= config['url']
|
107
|
+
hostname = options.host
|
108
|
+
lifetime = options.lifetime
|
109
|
+
tags = options.tags
|
110
|
+
token = options.token || config['token']
|
111
|
+
|
112
|
+
res_body = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
113
|
+
puts res_body
|
114
|
+
end
|
115
|
+
end
|
5
116
|
|
6
|
-
|
7
|
-
|
117
|
+
command :delete do |c|
|
118
|
+
c.syntax = 'floaty delete [options]'
|
119
|
+
c.summary = 'Schedules the deletion of a host or hosts'
|
120
|
+
c.description = ''
|
121
|
+
c.example 'Schedules the deletion of a host or hosts', 'floaty delete --hosts myhost1,myhost2 --url http://vmpooler.example.com'
|
122
|
+
c.option '--verbose', 'Enables verbose output'
|
123
|
+
c.option '--hosts STRING', String, 'Hostname(s) to delete'
|
124
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
125
|
+
c.action do |args, options|
|
126
|
+
verbose = options.verbose || config['verbose']
|
127
|
+
hosts = options.hosts
|
128
|
+
url = options.url ||= config['url']
|
8
129
|
|
9
|
-
|
10
|
-
|
130
|
+
Pooler.delete(verbose, url, hosts)
|
131
|
+
end
|
11
132
|
end
|
133
|
+
|
134
|
+
command :snapshot do |c|
|
135
|
+
c.syntax = 'floaty snapshot [options]'
|
136
|
+
c.summary = 'Takes a snapshot of a given vm'
|
137
|
+
c.description = ''
|
138
|
+
c.example 'Takes a snapshot for a given host', 'floaty snapshot --url http://vmpooler.example.com --host myvm.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
139
|
+
c.option '--verbose', 'Enables verbose output'
|
140
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
141
|
+
c.option '--host STRING', String, 'Hostname to modify'
|
142
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
143
|
+
c.action do |args, options|
|
144
|
+
verbose = options.verbose || config['verbose']
|
145
|
+
url = options.url ||= config['url']
|
146
|
+
hostname = options.host
|
147
|
+
token = options.token ||= config['token']
|
148
|
+
|
149
|
+
res_body = Pooler.snapshot(verbose, url, hostname, token)
|
150
|
+
puts res_body
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
command :revert do |c|
|
155
|
+
c.syntax = 'floaty revert [options]'
|
156
|
+
c.summary = 'Reverts a vm to a specified snapshot'
|
157
|
+
c.description = ''
|
158
|
+
c.example 'Reverts to a snapshot for a given host', 'floaty revert --url http://vmpooler.example.com --host myvm.example.com --token a9znth9dn01t416hrguu56ze37t790bl --snapshot n4eb4kdtp7rwv4x158366vd9jhac8btq'
|
159
|
+
c.option '--verbose', 'Enables verbose output'
|
160
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
161
|
+
c.option '--host STRING', String, 'Hostname to modify'
|
162
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
163
|
+
c.option '--snapshot STRING', String, 'SHA of snapshot'
|
164
|
+
c.action do |args, options|
|
165
|
+
verbose = options.verbose || config['verbose']
|
166
|
+
url = options.url ||= config['url']
|
167
|
+
hostname = options.host
|
168
|
+
token = options.token || config['token']
|
169
|
+
snapshot_sha = options.snapshot
|
170
|
+
|
171
|
+
res_body = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
172
|
+
puts res_body
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
command :status do |c|
|
177
|
+
c.syntax = 'floaty status [options]'
|
178
|
+
c.summary = 'Prints the status of vmpooler'
|
179
|
+
c.description = ''
|
180
|
+
c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
|
181
|
+
c.option '--verbose', 'Enables verbose output'
|
182
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
183
|
+
c.action do |args, options|
|
184
|
+
verbose = options.verbose || config['verbose']
|
185
|
+
url = options.url ||= config['url']
|
186
|
+
|
187
|
+
status = Pooler.status(verbose, url)
|
188
|
+
puts status
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
command :summary do |c|
|
193
|
+
c.syntax = 'floaty summary [options]'
|
194
|
+
c.summary = 'Prints the summary of vmpooler'
|
195
|
+
c.description = ''
|
196
|
+
c.example 'Gets the current day summary of vmpooler', 'floaty summary --url http://vmpooler.example.com'
|
197
|
+
c.option '--verbose', 'Enables verbose output'
|
198
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
199
|
+
c.action do |args, options|
|
200
|
+
verbose = options.verbose || config['verbose']
|
201
|
+
url = options.url ||= config['url']
|
202
|
+
|
203
|
+
summary = Pooler.summary(verbose, url)
|
204
|
+
puts summary
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
command :token do |c|
|
209
|
+
c.syntax = 'floaty token [get | delete | status]'
|
210
|
+
c.summary = 'Retrieves or deletes a token'
|
211
|
+
c.description = ''
|
212
|
+
c.example '', ''
|
213
|
+
c.option '--verbose', 'Enables verbose output'
|
214
|
+
c.option '--url STRING', String, 'URL of vmpooler'
|
215
|
+
c.option '--user STRING', String, 'User to authenticate with'
|
216
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
217
|
+
c.action do |args, options|
|
218
|
+
verbose = options.verbose || config['verbose']
|
219
|
+
action = args.first
|
220
|
+
url = options.url ||= config['url']
|
221
|
+
token = options.token ||= config['token']
|
222
|
+
user = options.user ||= config['user']
|
223
|
+
pass = password "Enter your password please:", '*'
|
224
|
+
|
225
|
+
case action
|
226
|
+
when "get"
|
227
|
+
puts Auth.get_token(verbose, url, user, pass)
|
228
|
+
when "delete"
|
229
|
+
Auth.delete_token(verbose, url, user, pass, token)
|
230
|
+
when "status"
|
231
|
+
Auth.token_status(verbose, url, user, pass, token)
|
232
|
+
when nil
|
233
|
+
STDERR.puts "No action provided"
|
234
|
+
else
|
235
|
+
STDERR.puts "Unknown action: #{action}"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
run!
|
12
241
|
end
|
13
242
|
|
14
|
-
def
|
15
|
-
|
243
|
+
def read_config
|
244
|
+
conf = {}
|
245
|
+
begin
|
246
|
+
conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml")
|
247
|
+
rescue
|
248
|
+
STDERR.puts "There was no config file at #{Dir.home}/.vmfloaty.yml"
|
249
|
+
end
|
250
|
+
conf
|
16
251
|
end
|
17
252
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'vmfloaty/http'
|
4
|
+
|
5
|
+
class Auth
|
6
|
+
def self.get_token(verbose, url, user, password)
|
7
|
+
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
8
|
+
|
9
|
+
resp = conn.post "/token"
|
10
|
+
|
11
|
+
res_body = JSON.parse(resp.body)
|
12
|
+
if res_body["ok"]
|
13
|
+
return res_body["token"]
|
14
|
+
else
|
15
|
+
STDERR.puts "There was a problem with your request:"
|
16
|
+
puts res_body
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.delete_token(verbose, url, user, password, token)
|
22
|
+
if token.nil?
|
23
|
+
STDERR.puts 'You did not provide a token'
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
28
|
+
|
29
|
+
response = conn.delete "/token/#{token}"
|
30
|
+
res_body = JSON.parse(response.body)
|
31
|
+
if res_body["ok"]
|
32
|
+
puts res_body
|
33
|
+
else
|
34
|
+
STDERR.puts "There was a problem with your request:"
|
35
|
+
puts res_body
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.token_status(verbose, url, user, password, token)
|
41
|
+
if token.nil?
|
42
|
+
STDERR.puts 'You did not provide a token'
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
47
|
+
|
48
|
+
response = conn.get "/token/#{token}"
|
49
|
+
res_body = JSON.parse(response.body)
|
50
|
+
|
51
|
+
if res_body["ok"]
|
52
|
+
puts res_body
|
53
|
+
else
|
54
|
+
STDERR.puts "There was a problem with your request:"
|
55
|
+
puts res_body
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
class Http
|
4
|
+
def self.get_conn(verbose, url)
|
5
|
+
if url.nil?
|
6
|
+
STDERR.puts "The url you provided was empty"
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
11
|
+
faraday.request :url_encoded
|
12
|
+
faraday.response :logger if verbose
|
13
|
+
faraday.adapter Faraday.default_adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
return conn
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_conn_with_auth(verbose, url, user, password)
|
20
|
+
if url.nil?
|
21
|
+
STDERR.puts "The url you provided was empty"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
if user.nil?
|
26
|
+
STDERR.puts "You did not provide a user to authenticate with"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
31
|
+
faraday.request :url_encoded
|
32
|
+
faraday.request :basic_auth, user, password
|
33
|
+
faraday.response :logger if verbose
|
34
|
+
faraday.adapter Faraday.default_adapter
|
35
|
+
end
|
36
|
+
|
37
|
+
return conn
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.get_conn_with_token(verbose, url, token)
|
41
|
+
if url.nil?
|
42
|
+
STDERR.puts "The url you provided was empty"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
if token.nil?
|
47
|
+
STDERR.puts "The token you provided was empty"
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
52
|
+
faraday.request :url_encoded
|
53
|
+
faraday.request :token_auth, token
|
54
|
+
faraday.response :logger if verbose
|
55
|
+
faraday.adapter Faraday.default_adapter
|
56
|
+
end
|
57
|
+
|
58
|
+
return conn
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'vmfloaty/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class Pooler
|
6
|
+
def self.list(verbose, url, os_filter=nil)
|
7
|
+
conn = Http.get_conn(verbose, url)
|
8
|
+
|
9
|
+
response = conn.get '/vm'
|
10
|
+
response_body = JSON.parse(response.body)
|
11
|
+
|
12
|
+
if os_filter
|
13
|
+
hosts = response_body.select { |i| i[/#{os_filter}/] }
|
14
|
+
else
|
15
|
+
hosts = response_body
|
16
|
+
end
|
17
|
+
|
18
|
+
hosts
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.retrieve(verbose, os_type, token, url)
|
22
|
+
os = os_type.gsub(',','+')
|
23
|
+
if token.nil?
|
24
|
+
conn = Http.get_conn(verbose, url)
|
25
|
+
else
|
26
|
+
conn = Http.get_conn_with_token(verbose, url, token)
|
27
|
+
conn.headers['X-AUTH-TOKEN']
|
28
|
+
end
|
29
|
+
|
30
|
+
response = conn.post "/vm/#{os}"
|
31
|
+
|
32
|
+
res_body = JSON.parse(response.body)
|
33
|
+
res_body
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.modify(verbose, url, hostname, token, lifetime, tags)
|
37
|
+
modify_body = {'lifetime'=>lifetime, 'tags'=>tags}
|
38
|
+
conn = Http.get_conn_with_token(verbose, url, token)
|
39
|
+
conn.headers['X-AUTH-TOKEN']
|
40
|
+
|
41
|
+
response = conn.put do |req|
|
42
|
+
req.url "/vm/#{hostname}"
|
43
|
+
end
|
44
|
+
res_body = JSON.parse(response.body)
|
45
|
+
|
46
|
+
res_body
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.delete(verbose, url, hostnames)
|
50
|
+
if hostnames.nil?
|
51
|
+
STDERR.puts "You did not provide any hosts to delete"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
|
55
|
+
hosts = hostnames.split(',')
|
56
|
+
conn = Http.get_conn(verbose, url)
|
57
|
+
|
58
|
+
hosts.each do |host|
|
59
|
+
puts "Scheduling host #{host} for deletion"
|
60
|
+
response = conn.delete "/vm/#{host}"
|
61
|
+
res_body = JSON.parse(response.body)
|
62
|
+
puts res_body
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.status(verbose, url)
|
67
|
+
conn = Http.get_conn(verbose, url)
|
68
|
+
|
69
|
+
response = conn.get '/status'
|
70
|
+
res_body = JSON.parse(response.body)
|
71
|
+
res_body
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.summary(verbose, url)
|
75
|
+
conn = Http.get_conn(verbose, url)
|
76
|
+
|
77
|
+
response = conn.get '/summary'
|
78
|
+
res_body = JSON.parse(response.body)
|
79
|
+
res_body
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.query(verbose, url, hostname)
|
83
|
+
conn = Http.get_conn(verbose, url)
|
84
|
+
|
85
|
+
response = conn.get "/vm/#{hostname}"
|
86
|
+
res_body = JSON.parse(response.body)
|
87
|
+
|
88
|
+
res_body
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.snapshot(verbose, url, hostname, token)
|
92
|
+
conn = Http.get_conn_with_token(verbose, url, token)
|
93
|
+
conn.headers['X-AUTH-TOKEN']
|
94
|
+
|
95
|
+
response = conn.post "/vm/#{hostname}/snapshot"
|
96
|
+
res_body = JSON.parse(response.body)
|
97
|
+
res_body
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
101
|
+
conn = Http.get_conn_with_token(verbose, url, token)
|
102
|
+
conn.headers['X-AUTH-TOKEN']
|
103
|
+
|
104
|
+
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot}"
|
105
|
+
res_body = JSON.parse(response.body)
|
106
|
+
res_body
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmfloaty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: thor
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.19'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.19'
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: A helper tool for vmpooler to help you stay afloat
|
28
14
|
email:
|
29
15
|
- brian.cain@puppetlabs.com
|
@@ -36,9 +22,9 @@ files:
|
|
36
22
|
- README.md
|
37
23
|
- bin/floaty
|
38
24
|
- lib/vmfloaty.rb
|
39
|
-
- lib/vmfloaty/
|
40
|
-
- lib/vmfloaty/
|
41
|
-
- lib/vmfloaty/
|
25
|
+
- lib/vmfloaty/auth.rb
|
26
|
+
- lib/vmfloaty/http.rb
|
27
|
+
- lib/vmfloaty/pooler.rb
|
42
28
|
- spec/spec_helper.rb
|
43
29
|
homepage: https://github.com/briancain/vmfloaty
|
44
30
|
licenses:
|
@@ -60,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
46
|
version: '0'
|
61
47
|
requirements: []
|
62
48
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
49
|
+
rubygems_version: 2.4.8
|
64
50
|
signing_key:
|
65
51
|
specification_version: 4
|
66
52
|
summary: CLI application to interface with vmpooler
|
data/lib/vmfloaty/cli.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'net/http'
|
3
|
-
require 'uri'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
class CLI < Thor
|
7
|
-
desc "get <OPERATING SYSTEM,...>", "Gets a VM"
|
8
|
-
def get(os_list)
|
9
|
-
# HTTP POST -d os_list vmpooler.company.com/vm
|
10
|
-
|
11
|
-
uri = URI.parse("#{$vmpooler_url}/vm/#{os_list.gsub(",","+")}")
|
12
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
14
|
-
response = http.request(request)
|
15
|
-
|
16
|
-
if response.code.to_i == 200
|
17
|
-
hosts = JSON.parse(response.body)
|
18
|
-
|
19
|
-
# puts hosts
|
20
|
-
|
21
|
-
save_hosts = {}
|
22
|
-
hosts.each do |k,v|
|
23
|
-
unless k == 'ok' || k == 'domain'
|
24
|
-
save_hosts[k] = v['hostname']
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
puts 'New Hosts:'
|
29
|
-
puts save_hosts
|
30
|
-
|
31
|
-
#hosts.add_host save_hosts
|
32
|
-
end
|
33
|
-
|
34
|
-
# parse host names/os's and save
|
35
|
-
end
|
36
|
-
|
37
|
-
desc "modify <HOSTNAME>", "Modify a VM"
|
38
|
-
def modify(hostname)
|
39
|
-
say 'Modify a vm'
|
40
|
-
end
|
41
|
-
|
42
|
-
desc "status", "List status of all active VMs"
|
43
|
-
def status
|
44
|
-
#$hosts.print_host_list
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "list [PATTERN]", "List all open VMs"
|
48
|
-
def list(pattern=nil)
|
49
|
-
# HTTP GET vmpooler.company.com/vm
|
50
|
-
uri = URI.parse("#{$vmpooler_url}/vm")
|
51
|
-
response = Net::HTTP.get_response(uri)
|
52
|
-
host_res = JSON.parse(response.body)
|
53
|
-
|
54
|
-
if pattern
|
55
|
-
# Filtering VMs based on pattern
|
56
|
-
hosts = host_res.select { |i| i[/#{pattern}/] }
|
57
|
-
else
|
58
|
-
hosts = host_res
|
59
|
-
end
|
60
|
-
|
61
|
-
puts hosts
|
62
|
-
end
|
63
|
-
|
64
|
-
desc "release <HOSTNAME,...> [--all]", "Schedules a VM for deletion"
|
65
|
-
option :all
|
66
|
-
def release(hostname_list=nil)
|
67
|
-
# HTTP DELETE vmpooler.company.com/vm/#{hostname}
|
68
|
-
# { "ok": true }
|
69
|
-
|
70
|
-
if options[:all]
|
71
|
-
# release all hosts managed by vmfloaty
|
72
|
-
else
|
73
|
-
hostname_arr = hostname_list.split(',')
|
74
|
-
|
75
|
-
hostname_arr.each do |hostname|
|
76
|
-
say "Releasing host #{hostname}..."
|
77
|
-
uri = URI.parse("#{$vmpooler_url}/vm/#{hostname}")
|
78
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
79
|
-
request = Net::HTTP::Delete.new(uri.request_uri)
|
80
|
-
response = http.request(request)
|
81
|
-
res = JSON.parse(response.body)
|
82
|
-
|
83
|
-
puts res
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/vmfloaty/hosts.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# manage hosts used from vm pooler
|
2
|
-
class Hosts
|
3
|
-
def initialize
|
4
|
-
@host_list = {}
|
5
|
-
end
|
6
|
-
|
7
|
-
def add_host(host_hash)
|
8
|
-
host_hash.each do |k,v|
|
9
|
-
if @host_list[k]
|
10
|
-
@host_list[k].push(v)
|
11
|
-
else
|
12
|
-
if v.is_a?(Array)
|
13
|
-
@host_list[k] = v
|
14
|
-
else
|
15
|
-
@host_list[k] = [v]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
puts @host_list
|
21
|
-
end
|
22
|
-
|
23
|
-
def remove_host(host_id)
|
24
|
-
end
|
25
|
-
|
26
|
-
def print_host_list
|
27
|
-
puts @host_list
|
28
|
-
end
|
29
|
-
end
|