vmfloaty 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vmfloaty.rb +7 -5
- data/lib/vmfloaty/http.rb +0 -20
- data/lib/vmfloaty/pooler.rb +28 -15
- 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: 1abf340baac66b75675a4ba1f77baa8b1d412a58
|
4
|
+
data.tar.gz: 906172ee41262e42f0166cf5ba8721bf97a170bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 173504ca54fad87fa3e9e42220f465880da532ab053ca5a8d88ac915ecff7d9fdb798407eec02c15102ddd88603da8e9554ee521bc88754f91654a8d15d0f8d2
|
7
|
+
data.tar.gz: 237a78285a88cfaef65eceb30b6a1dfc451594d21d82b2537d3e1589cfa1b5e725b6cce1596e9bb6d4686d1891c10f145c5cd8682c332f39ae82cafb0faea159
|
data/lib/vmfloaty.rb
CHANGED
@@ -10,7 +10,7 @@ class Vmfloaty
|
|
10
10
|
include Commander::Methods
|
11
11
|
|
12
12
|
def run
|
13
|
-
program :version, '0.2.
|
13
|
+
program :version, '0.2.4'
|
14
14
|
program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat'
|
15
15
|
|
16
16
|
config = read_config
|
@@ -33,7 +33,7 @@ class Vmfloaty
|
|
33
33
|
os_types = args[0]
|
34
34
|
no_token = options.notoken
|
35
35
|
|
36
|
-
|
36
|
+
if no_token
|
37
37
|
response = Pooler.retrieve(verbose, os_types, token, url)
|
38
38
|
puts response
|
39
39
|
return
|
@@ -91,7 +91,7 @@ class Vmfloaty
|
|
91
91
|
c.syntax = 'floaty modify [hostname]'
|
92
92
|
c.summary = 'Modify a vms tags and TTL'
|
93
93
|
c.description = ''
|
94
|
-
c.example '
|
94
|
+
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"}\''
|
95
95
|
c.option '--verbose', 'Enables verbose output'
|
96
96
|
c.option '--url STRING', String, 'URL of vmpooler'
|
97
97
|
c.option '--token STRING', String, 'Token for vmpooler'
|
@@ -102,7 +102,7 @@ class Vmfloaty
|
|
102
102
|
url = options.url ||= config['url']
|
103
103
|
hostname = args[0]
|
104
104
|
lifetime = options.lifetime
|
105
|
-
tags = JSON.parse(options.tags)
|
105
|
+
tags = JSON.parse(options.tags) if options.tags
|
106
106
|
token = options.token || config['token']
|
107
107
|
|
108
108
|
res_body = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
@@ -116,13 +116,15 @@ class Vmfloaty
|
|
116
116
|
c.description = ''
|
117
117
|
c.example 'Schedules the deletion of a host or hosts', 'floaty delete myhost1,myhost2 --url http://vmpooler.example.com'
|
118
118
|
c.option '--verbose', 'Enables verbose output'
|
119
|
+
c.option '--token STRING', String, 'Token for vmpooler'
|
119
120
|
c.option '--url STRING', String, 'URL of vmpooler'
|
120
121
|
c.action do |args, options|
|
121
122
|
verbose = options.verbose || config['verbose']
|
122
123
|
hosts = args[0]
|
124
|
+
token = options.token || config['token']
|
123
125
|
url = options.url ||= config['url']
|
124
126
|
|
125
|
-
Pooler.delete(verbose, url, hosts)
|
127
|
+
Pooler.delete(verbose, url, hosts, token)
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
data/lib/vmfloaty/http.rb
CHANGED
@@ -37,24 +37,4 @@ class Http
|
|
37
37
|
return conn
|
38
38
|
end
|
39
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
40
|
end
|
data/lib/vmfloaty/pooler.rb
CHANGED
@@ -20,11 +20,9 @@ class Pooler
|
|
20
20
|
|
21
21
|
def self.retrieve(verbose, os_type, token, url)
|
22
22
|
os = os_type.gsub(',','+')
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
conn = Http.get_conn_with_token(verbose, url, token)
|
27
|
-
conn.headers['X-AUTH-TOKEN']
|
23
|
+
conn = Http.get_conn(verbose, url)
|
24
|
+
if token
|
25
|
+
conn.headers['X-AUTH-TOKEN'] = token
|
28
26
|
end
|
29
27
|
|
30
28
|
response = conn.post "/vm/#{os}"
|
@@ -34,19 +32,26 @@ class Pooler
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.modify(verbose, url, hostname, token, lifetime, tags)
|
37
|
-
modify_body = {
|
38
|
-
|
39
|
-
|
35
|
+
modify_body = {}
|
36
|
+
if lifetime
|
37
|
+
modify_body['lifetime'] = lifetime
|
38
|
+
end
|
39
|
+
if tags
|
40
|
+
modify_body['tags'] = tags
|
41
|
+
end
|
42
|
+
|
43
|
+
conn = Http.get_conn(verbose, url)
|
44
|
+
conn.headers['X-AUTH-TOKEN'] = token
|
40
45
|
|
41
46
|
response = conn.put do |req|
|
42
47
|
req.url "/vm/#{hostname}"
|
48
|
+
req.body = modify_body
|
43
49
|
end
|
44
50
|
res_body = JSON.parse(response.body)
|
45
|
-
|
46
51
|
res_body
|
47
52
|
end
|
48
53
|
|
49
|
-
def self.delete(verbose, url, hostnames)
|
54
|
+
def self.delete(verbose, url, hostnames, token)
|
50
55
|
if hostnames.nil?
|
51
56
|
STDERR.puts "You did not provide any hosts to delete"
|
52
57
|
exit 1
|
@@ -55,11 +60,19 @@ class Pooler
|
|
55
60
|
hosts = hostnames.split(',')
|
56
61
|
conn = Http.get_conn(verbose, url)
|
57
62
|
|
63
|
+
if token
|
64
|
+
conn.headers['X-AUTH-TOKEN'] = token
|
65
|
+
end
|
66
|
+
|
58
67
|
hosts.each do |host|
|
59
68
|
puts "Scheduling host #{host} for deletion"
|
60
69
|
response = conn.delete "/vm/#{host}"
|
61
70
|
res_body = JSON.parse(response.body)
|
62
|
-
|
71
|
+
if res_body['ok']
|
72
|
+
puts "Deletion for vm #{host} successfully scheduled"
|
73
|
+
else
|
74
|
+
STDERR.puts "There was a problem with your request for vm #{host}"
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
@@ -89,8 +102,8 @@ class Pooler
|
|
89
102
|
end
|
90
103
|
|
91
104
|
def self.snapshot(verbose, url, hostname, token)
|
92
|
-
conn = Http.
|
93
|
-
conn.headers['X-AUTH-TOKEN']
|
105
|
+
conn = Http.get_conn(verbose, url)
|
106
|
+
conn.headers['X-AUTH-TOKEN'] = token
|
94
107
|
|
95
108
|
response = conn.post "/vm/#{hostname}/snapshot"
|
96
109
|
res_body = JSON.parse(response.body)
|
@@ -98,8 +111,8 @@ class Pooler
|
|
98
111
|
end
|
99
112
|
|
100
113
|
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
101
|
-
conn = Http.
|
102
|
-
conn.headers['X-AUTH-TOKEN']
|
114
|
+
conn = Http.get_conn(verbose, url)
|
115
|
+
conn.headers['X-AUTH-TOKEN'] = token
|
103
116
|
|
104
117
|
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot}"
|
105
118
|
res_body = JSON.parse(response.body)
|
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.4
|
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-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|