vmfloaty 0.6.1 → 0.6.2
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 +7 -67
- data/lib/vmfloaty.rb +14 -10
- data/lib/vmfloaty/pooler.rb +4 -0
- data/lib/vmfloaty/version.rb +1 -1
- data/spec/vmfloaty/pooler_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bb5fd73f29e77b581fadb37b382fceb4131497b
|
4
|
+
data.tar.gz: c947c5941fd8d4f6b6aaaa4be3c320b5276b66f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c4cc430096ff5b521deac4a1f8c4ad70ef2739d3419f4dbe54fff3bf9da87e0f6d94c4b9cb629565ba025ba8238fe079351f3d7b31a0a4985b6b7c4433412d9
|
7
|
+
data.tar.gz: 065e1253192e6f2c48caa3b152573c63cddfc36fe2190610403469e34ce43dd7252f09c86574df91fdec0cf7721da94d0c64c65d04b32d320cbf41a560d472ff
|
data/README.md
CHANGED
@@ -94,71 +94,11 @@ This cli tool uses the [vmpooler API](https://github.com/puppetlabs/vmpooler/blo
|
|
94
94
|
|
95
95
|
## Using the Pooler class
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
### Scripting
|
100
|
-
|
101
|
-
If you want to write some ruby scripts around the vmpooler api, vmfloaty provides a `Pooler` and `Auth` class to make things easier. The ruby script below shows off an example of a script that gets a token, grabs a vm, runs some commands through ssh, and then destroys the vm.
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
require 'vmfloaty/pooler'
|
105
|
-
require 'vmfloaty/auth'
|
106
|
-
require 'io/console'
|
107
|
-
require 'net/ssh'
|
108
|
-
|
109
|
-
def aquire_token(verbose, url)
|
110
|
-
STDOUT.flush
|
111
|
-
puts "Enter username:"
|
112
|
-
user = $stdin.gets.chomp
|
113
|
-
puts "Enter password:"
|
114
|
-
password = STDIN.noecho(&:gets).chomp
|
115
|
-
token = Auth.get_token(verbose, url, user, password)
|
116
|
-
|
117
|
-
puts "Your token:\n#{token}"
|
118
|
-
token
|
119
|
-
end
|
120
|
-
|
121
|
-
def grab_vms(os_string, token, url, verbose)
|
122
|
-
response_body = Pooler.retrieve(verbose, os_string, token, url)
|
123
|
-
|
124
|
-
if response_body['ok'] == false
|
125
|
-
STDERR.puts "There was a problem with your request"
|
126
|
-
exit 1
|
127
|
-
end
|
128
|
-
|
129
|
-
response_body[os_string]
|
130
|
-
end
|
131
|
-
|
132
|
-
def run_puppet_on_host(hostname)
|
133
|
-
STDOUT.flush
|
134
|
-
puts "Enter 'root' password for vm:"
|
135
|
-
password = STDIN.noecho(&:gets).chomp
|
136
|
-
user = 'root'
|
137
|
-
# run puppet
|
138
|
-
run_puppet = "/opt/puppetlabs/puppet/bin/puppet agent -t"
|
139
|
-
|
140
|
-
begin
|
141
|
-
ssh = Net::SSH.start(hostname, user, :password => password)
|
142
|
-
output = ssh.exec!(run_puppet)
|
143
|
-
puts output
|
144
|
-
ssh.close
|
145
|
-
rescue
|
146
|
-
STDERR.puts "Unable to connect to #{hostname} using #{user}"
|
147
|
-
exit 1
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
if __FILE__ == $0
|
152
|
-
verbose = true
|
153
|
-
url = 'https://vmpooler.mycompany.net/api/v1'
|
154
|
-
token = aquire_token(verbose, url)
|
155
|
-
os = ARGV[0]
|
156
|
-
|
157
|
-
hostname = grab_vm(os, token, url, verbose)
|
158
|
-
run_puppet_on_host(hostname)
|
159
|
-
end
|
160
|
-
```
|
97
|
+
vmfloaty providers a `Pooler` class that gives users the ability to make requests to vmpooler without having to write their own requests. It also provides an `Auth` class for managing vmpooler tokens within your application.
|
161
98
|
|
162
|
-
|
163
|
-
|
164
|
-
|
99
|
+
### Example Projects
|
100
|
+
|
101
|
+
- [John McCabe: vmpooler-bitbar](https://github.com/johnmccabe/vmpooler-bitbar/)
|
102
|
+
+ vmpooler status and management in your menubar with bitbar
|
103
|
+
- [Brian Cain: vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler)
|
104
|
+
+ Use Vagrant to manage your vmpooler instances
|
data/lib/vmfloaty.rb
CHANGED
@@ -74,7 +74,7 @@ class Vmfloaty
|
|
74
74
|
end
|
75
75
|
|
76
76
|
command :list do |c|
|
77
|
-
c.syntax = 'floaty list [
|
77
|
+
c.syntax = 'floaty list [options]'
|
78
78
|
c.summary = 'Shows a list of available vms from the pooler'
|
79
79
|
c.description = ''
|
80
80
|
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
@@ -117,7 +117,7 @@ class Vmfloaty
|
|
117
117
|
end
|
118
118
|
|
119
119
|
command :query do |c|
|
120
|
-
c.syntax = 'floaty query [options]'
|
120
|
+
c.syntax = 'floaty query [hostname] [options]'
|
121
121
|
c.summary = 'Get information about a given vm'
|
122
122
|
c.description = ''
|
123
123
|
c.example 'Get information about a sample host', 'floaty query hostname --url http://vmpooler.example.com'
|
@@ -134,7 +134,7 @@ class Vmfloaty
|
|
134
134
|
end
|
135
135
|
|
136
136
|
command :modify do |c|
|
137
|
-
c.syntax = 'floaty modify [hostname]'
|
137
|
+
c.syntax = 'floaty modify [hostname] [options]'
|
138
138
|
c.summary = 'Modify a vms tags, TTL, and disk space'
|
139
139
|
c.description = ''
|
140
140
|
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"}\''
|
@@ -254,7 +254,7 @@ class Vmfloaty
|
|
254
254
|
end
|
255
255
|
|
256
256
|
command :snapshot do |c|
|
257
|
-
c.syntax = 'floaty snapshot [options]'
|
257
|
+
c.syntax = 'floaty snapshot [hostname] [options]'
|
258
258
|
c.summary = 'Takes a snapshot of a given vm'
|
259
259
|
c.description = ''
|
260
260
|
c.example 'Takes a snapshot for a given host', 'floaty snapshot myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
@@ -273,10 +273,10 @@ class Vmfloaty
|
|
273
273
|
end
|
274
274
|
|
275
275
|
command :revert do |c|
|
276
|
-
c.syntax = 'floaty revert [options]'
|
276
|
+
c.syntax = 'floaty revert [hostname] [snapshot] [options]'
|
277
277
|
c.summary = 'Reverts a vm to a specified snapshot'
|
278
278
|
c.description = ''
|
279
|
-
c.example 'Reverts to a snapshot for a given host', 'floaty revert myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl
|
279
|
+
c.example 'Reverts to a snapshot for a given host', 'floaty revert myvm.example.com n4eb4kdtp7rwv4x158366vd9jhac8btq --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
280
280
|
c.option '--verbose', 'Enables verbose output'
|
281
281
|
c.option '--url STRING', String, 'URL of vmpooler'
|
282
282
|
c.option '--token STRING', String, 'Token for vmpooler'
|
@@ -286,7 +286,11 @@ class Vmfloaty
|
|
286
286
|
url = options.url ||= config['url']
|
287
287
|
hostname = args[0]
|
288
288
|
token = options.token || config['token']
|
289
|
-
snapshot_sha = options.snapshot
|
289
|
+
snapshot_sha = args[1] || options.snapshot
|
290
|
+
|
291
|
+
if args[1] && options.snapshot
|
292
|
+
STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}"
|
293
|
+
end
|
290
294
|
|
291
295
|
revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
292
296
|
pp revert_req
|
@@ -326,10 +330,10 @@ class Vmfloaty
|
|
326
330
|
end
|
327
331
|
|
328
332
|
command :token do |c|
|
329
|
-
c.syntax = 'floaty token [get | delete | status]'
|
333
|
+
c.syntax = 'floaty token [get | delete | status] [token]'
|
330
334
|
c.summary = 'Retrieves or deletes a token'
|
331
335
|
c.description = ''
|
332
|
-
c.example '', ''
|
336
|
+
c.example 'Gets a token from the pooler', 'floaty token get'
|
333
337
|
c.option '--verbose', 'Enables verbose output'
|
334
338
|
c.option '--url STRING', String, 'URL of vmpooler'
|
335
339
|
c.option '--user STRING', String, 'User to authenticate with'
|
@@ -338,7 +342,7 @@ class Vmfloaty
|
|
338
342
|
verbose = options.verbose || config['verbose']
|
339
343
|
action = args.first
|
340
344
|
url = options.url ||= config['url']
|
341
|
-
token = options.token ||= config['token']
|
345
|
+
token = args[1] ||= options.token ||= config['token']
|
342
346
|
user = options.user ||= config['user']
|
343
347
|
|
344
348
|
case action
|
data/lib/vmfloaty/pooler.rb
CHANGED
@@ -134,6 +134,10 @@ class Pooler
|
|
134
134
|
conn = Http.get_conn(verbose, url)
|
135
135
|
conn.headers['X-AUTH-TOKEN'] = token
|
136
136
|
|
137
|
+
if snapshot_sha.nil?
|
138
|
+
raise "Snapshot SHA provided was nil, could not revert #{hostname}"
|
139
|
+
end
|
140
|
+
|
137
141
|
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
138
142
|
res_body = JSON.parse(response.body)
|
139
143
|
res_body
|
data/lib/vmfloaty/version.rb
CHANGED
@@ -174,5 +174,9 @@ describe Pooler do
|
|
174
174
|
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
175
175
|
expect(revert_req["ok"]).to be true
|
176
176
|
end
|
177
|
+
|
178
|
+
it "doesn't make a request to revert a vm if snapshot is not provided" do
|
179
|
+
expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, "Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6")
|
180
|
+
end
|
177
181
|
end
|
178
182
|
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.6.
|
4
|
+
version: 0.6.2
|
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-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|