vmfloaty 0.2.5 → 0.2.6
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 +98 -0
- data/lib/vmfloaty.rb +5 -13
- data/lib/vmfloaty/conf.rb +14 -0
- data/lib/vmfloaty/format.rb +7 -0
- data/lib/vmfloaty/version.rb +8 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6d9fbc28754d8b0ab518b73f62d6b20057b1d2
|
4
|
+
data.tar.gz: d328a16a9430b324a4ba5a050f1a72e0c5cf8f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9a5361e957db68222c1112912b17264417d19995f9b31ba7a19f3901454cf94c00d331e348cce6b8565daa0ca51848afb14fcdbd3d468a6548cd7ae68faf7a8
|
7
|
+
data.tar.gz: 1c1aea226b929c869930c5e65eb6814bc343116ffac03bfd729e0c72e604e5f7071912819769f19c75426798d1f4508caf030be49462686b9dbae22448631fc6
|
data/README.md
CHANGED
@@ -40,6 +40,22 @@ gem install vmfloaty
|
|
40
40
|
Display backtrace when an error occurs
|
41
41
|
```
|
42
42
|
|
43
|
+
### Example workflow
|
44
|
+
|
45
|
+
Grabbing a token for authenticated pooler requests:
|
46
|
+
|
47
|
+
```
|
48
|
+
floaty token get --user me --url https://vmpooler.mycompany.net
|
49
|
+
```
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
Grabbing vms:
|
54
|
+
|
55
|
+
```
|
56
|
+
floaty get centos-7,debian-7,windows-10 --token mytokenstring --url https://vmpooler.mycompany.net
|
57
|
+
```
|
58
|
+
|
43
59
|
### vmfloaty dotfile
|
44
60
|
|
45
61
|
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:
|
@@ -48,10 +64,92 @@ If you do not wish to continuely specify various config options with the cli, yo
|
|
48
64
|
#file at /Users/me/.vmfloaty.yml
|
49
65
|
url: 'http://vmpooler.mycompany.net'
|
50
66
|
user: 'brian'
|
67
|
+
token: 'tokenstring'
|
51
68
|
```
|
52
69
|
|
53
70
|
Now vmfloaty will use those config files if no flag was specified.
|
54
71
|
|
72
|
+
#### Valid config keys
|
73
|
+
|
74
|
+
Here are the keys that vmfloaty currently supports:
|
75
|
+
|
76
|
+
- verbose
|
77
|
+
+ true
|
78
|
+
+ false
|
79
|
+
- token
|
80
|
+
+ :token-string
|
81
|
+
- user
|
82
|
+
+ :username
|
83
|
+
- url
|
84
|
+
+ :pooler-url
|
85
|
+
|
55
86
|
## vmpooler API
|
56
87
|
|
57
88
|
This cli tool uses the [vmpooler API](https://github.com/puppetlabs/vmpooler/blob/master/API.md).
|
89
|
+
|
90
|
+
## Using the Pooler class
|
91
|
+
|
92
|
+
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.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require 'vmfloaty/pooler'
|
96
|
+
require 'vmfloaty/auth'
|
97
|
+
require 'io/console'
|
98
|
+
require 'net/ssh'
|
99
|
+
|
100
|
+
def aquire_token(verbose, url)
|
101
|
+
STDOUT.flush
|
102
|
+
puts "Enter username:"
|
103
|
+
user = $stdin.gets.chomp
|
104
|
+
puts "Enter password:"
|
105
|
+
password = STDIN.noecho(&:gets).chomp
|
106
|
+
token = Auth.get_token(verbose, url, user, password)
|
107
|
+
|
108
|
+
puts "Your token:\n#{token}"
|
109
|
+
token
|
110
|
+
end
|
111
|
+
|
112
|
+
def grab_vms(os_string, token, url, verbose)
|
113
|
+
response_body = Pooler.retrieve(verbose, os_string, token, url)
|
114
|
+
|
115
|
+
if response_body['ok'] == false
|
116
|
+
STDERR.puts "There was a problem with your request"
|
117
|
+
exit 1
|
118
|
+
end
|
119
|
+
|
120
|
+
response_body[os_string]
|
121
|
+
end
|
122
|
+
|
123
|
+
def run_puppet_on_host(hostname)
|
124
|
+
STDOUT.flush
|
125
|
+
puts "Enter 'root' password for vm:"
|
126
|
+
password = STDIN.noecho(&:gets).chomp
|
127
|
+
user = 'root'
|
128
|
+
# run puppet
|
129
|
+
run_puppet = "/opt/puppetlabs/puppet/bin/puppet agent -t"
|
130
|
+
|
131
|
+
begin
|
132
|
+
ssh = Net::SSH.start(hostname, user, :password => password)
|
133
|
+
output = ssh.exec!(run_puppet)
|
134
|
+
puts output
|
135
|
+
ssh.close
|
136
|
+
rescue
|
137
|
+
STDERR.puts "Unable to connect to #{hostname} using #{user}"
|
138
|
+
exit 1
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
if __FILE__ == $0
|
143
|
+
verbose = true
|
144
|
+
url = 'https://vmpooler.mycompany.net'
|
145
|
+
token = aquire_token(verbose, url)
|
146
|
+
os = ARGV[0]
|
147
|
+
|
148
|
+
hostname = grab_vm(os, token, url, verbose)
|
149
|
+
run_puppet_on_host(hostname)
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
153
|
+
```
|
154
|
+
ruby myscript.rb centos-7-x86_64
|
155
|
+
```
|
data/lib/vmfloaty.rb
CHANGED
@@ -2,18 +2,20 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'commander'
|
5
|
-
require 'yaml'
|
6
5
|
require 'vmfloaty/auth'
|
7
6
|
require 'vmfloaty/pooler'
|
7
|
+
require 'vmfloaty/version'
|
8
|
+
require 'vmfloaty/conf'
|
9
|
+
require 'vmfloaty/format'
|
8
10
|
|
9
11
|
class Vmfloaty
|
10
12
|
include Commander::Methods
|
11
13
|
|
12
14
|
def run
|
13
|
-
program :version,
|
15
|
+
program :version, Version.get
|
14
16
|
program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat'
|
15
17
|
|
16
|
-
config = read_config
|
18
|
+
config = Conf.read_config
|
17
19
|
|
18
20
|
command :get do |c|
|
19
21
|
c.syntax = 'floaty get [hostname,...]'
|
@@ -234,14 +236,4 @@ class Vmfloaty
|
|
234
236
|
|
235
237
|
run!
|
236
238
|
end
|
237
|
-
|
238
|
-
def read_config
|
239
|
-
conf = {}
|
240
|
-
begin
|
241
|
-
conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml")
|
242
|
-
rescue
|
243
|
-
STDERR.puts "There was no config file at #{Dir.home}/.vmfloaty.yml"
|
244
|
-
end
|
245
|
-
conf
|
246
|
-
end
|
247
239
|
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.2.
|
4
|
+
version: 0.2.6
|
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-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
27
41
|
description: A helper tool for vmpooler to help you stay afloat
|
28
42
|
email:
|
29
43
|
- brian.cain@puppetlabs.com
|
@@ -37,8 +51,11 @@ files:
|
|
37
51
|
- bin/floaty
|
38
52
|
- lib/vmfloaty.rb
|
39
53
|
- lib/vmfloaty/auth.rb
|
54
|
+
- lib/vmfloaty/conf.rb
|
55
|
+
- lib/vmfloaty/format.rb
|
40
56
|
- lib/vmfloaty/http.rb
|
41
57
|
- lib/vmfloaty/pooler.rb
|
58
|
+
- lib/vmfloaty/version.rb
|
42
59
|
- spec/spec_helper.rb
|
43
60
|
homepage: https://github.com/briancain/vmfloaty
|
44
61
|
licenses:
|