vmfloaty 0.8.1 → 0.8.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/lib/vmfloaty.rb +7 -1
- data/lib/vmfloaty/utils.rb +15 -20
- data/lib/vmfloaty/version.rb +1 -1
- data/spec/vmfloaty/utils_spec.rb +31 -7
- 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: 04b7261aa013260aba635e266b003d845e4a2c58
|
4
|
+
data.tar.gz: 83bbc1c12ace45c6a1ea288121762f13d3b841ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e38aedb270708b75d9464744b73b507a6dfdab100567a079287b6b06aa0ac57fabaa03e0e18761c5d1b21e2921f15fbd36ab5beeddcbf3266cac2981d90931c
|
7
|
+
data.tar.gz: 04ddaf46164b38bf84df47ee8d5a0e96d87b6be5d64941ee72a075e5264511c7556b8fdd85a2875fadfea37820cfbc307adc6dd46eb32621c1cb552d70cbec94
|
data/lib/vmfloaty.rb
CHANGED
@@ -35,6 +35,7 @@ class Vmfloaty
|
|
35
35
|
c.option '--token STRING', String, 'Token for pooler service'
|
36
36
|
c.option '--notoken', 'Makes a request without a token'
|
37
37
|
c.option '--force', 'Forces vmfloaty to get requested vms'
|
38
|
+
c.option '--json', 'Prints retrieved vms in JSON format'
|
38
39
|
c.action do |args, options|
|
39
40
|
verbose = options.verbose || config['verbose']
|
40
41
|
service = Service.new(options, config)
|
@@ -62,7 +63,12 @@ class Vmfloaty
|
|
62
63
|
end
|
63
64
|
|
64
65
|
response = service.retrieve(verbose, os_types, use_token)
|
65
|
-
|
66
|
+
hosts = Utils.standardize_hostnames(response)
|
67
|
+
if options.json
|
68
|
+
puts JSON.pretty_generate(hosts)
|
69
|
+
else
|
70
|
+
puts Utils.format_host_output(hosts)
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
data/lib/vmfloaty/utils.rb
CHANGED
@@ -4,7 +4,7 @@ require 'vmfloaty/nonstandard_pooler'
|
|
4
4
|
class Utils
|
5
5
|
# TODO: Takes the json response body from an HTTP GET
|
6
6
|
# request and "pretty prints" it
|
7
|
-
def self.
|
7
|
+
def self.standardize_hostnames(response_body)
|
8
8
|
# vmpooler response body example when `floaty get` arguments are `ubuntu-1610-x86_64=2 centos-7-x86_64`:
|
9
9
|
# {
|
10
10
|
# "ok": true,
|
@@ -32,31 +32,26 @@ class Utils
|
|
32
32
|
raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}"
|
33
33
|
end
|
34
34
|
|
35
|
-
hostnames = []
|
36
|
-
|
37
35
|
# vmpooler reports the domain separately from the hostname
|
38
36
|
domain = response_body.delete('domain')
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
hostnames << hosts["hostname"] + ".#{domain} (#{os})"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
else
|
50
|
-
response_body.each do |os, hosts|
|
51
|
-
if hosts['hostname'].kind_of?(Array)
|
52
|
-
hosts['hostname'].map!{ |host| hostnames << host + " (#{os})" }
|
53
|
-
else
|
54
|
-
hostnames << hosts['hostname'] + " (#{os})"
|
55
|
-
end
|
38
|
+
result = {}
|
39
|
+
|
40
|
+
response_body.each do |os, value|
|
41
|
+
hostnames = Array(value['hostname'])
|
42
|
+
if domain
|
43
|
+
hostnames.map! {|host| "#{host}.#{domain}"}
|
56
44
|
end
|
45
|
+
result[os] = hostnames
|
57
46
|
end
|
58
47
|
|
59
|
-
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.format_host_output(hosts)
|
52
|
+
hosts.flat_map do |os, names|
|
53
|
+
names.map { |name| "- #{name} (#{os})" }
|
54
|
+
end.join("\n")
|
60
55
|
end
|
61
56
|
|
62
57
|
def self.generate_os_hash(os_args)
|
data/lib/vmfloaty/version.rb
CHANGED
data/spec/vmfloaty/utils_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative '../../lib/vmfloaty/utils'
|
|
5
5
|
|
6
6
|
describe Utils do
|
7
7
|
|
8
|
-
describe "#
|
8
|
+
describe "#standardize_hostnames" do
|
9
9
|
before :each do
|
10
10
|
@vmpooler_response_body ='{
|
11
11
|
"ok": true,
|
@@ -26,24 +26,48 @@ describe Utils do
|
|
26
26
|
"hostname": "power8-ubuntu16.04-6.delivery.mycompany.net"
|
27
27
|
}
|
28
28
|
}'
|
29
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
it "formats a result from vmpooler into a hash of os to hostnames" do
|
32
|
+
result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
|
33
|
+
expect(result).to eq('centos-7-x86_64' => ["dlgietfmgeegry2.delivery.mycompany.net"],
|
34
|
+
'ubuntu-1610-x86_64' => ["gdoy8q3nckuob0i.delivery.mycompany.net", "ctnktsd0u11p9tm.delivery.mycompany.net"])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "formats a result from the nonstandard pooler into a hash of os to hostnames" do
|
38
|
+
result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body))
|
39
|
+
expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
40
|
+
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#format_host_output" do
|
45
|
+
before :each do
|
46
|
+
@vmpooler_results = {
|
47
|
+
'centos-7-x86_64' => ["dlgietfmgeegry2.delivery.mycompany.net"],
|
48
|
+
'ubuntu-1610-x86_64' => ["gdoy8q3nckuob0i.delivery.mycompany.net", "ctnktsd0u11p9tm.delivery.mycompany.net"]
|
49
|
+
}
|
50
|
+
@nonstandard_results = {
|
51
|
+
'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
|
52
|
+
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net']
|
53
|
+
}
|
54
|
+
@vmpooler_output = <<-OUT.chomp
|
55
|
+
- dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
|
30
56
|
- gdoy8q3nckuob0i.delivery.mycompany.net (ubuntu-1610-x86_64)
|
31
57
|
- ctnktsd0u11p9tm.delivery.mycompany.net (ubuntu-1610-x86_64)
|
32
|
-
- dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
|
33
58
|
OUT
|
34
|
-
@nonstandard_output = <<-OUT
|
59
|
+
@nonstandard_output = <<-OUT.chomp
|
35
60
|
- sol10-10.delivery.mycompany.net (solaris-10-sparc)
|
36
61
|
- sol10-11.delivery.mycompany.net (solaris-10-sparc)
|
37
62
|
- power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8)
|
38
63
|
OUT
|
39
64
|
end
|
40
|
-
|
41
65
|
it "formats a hostname hash from vmpooler into a list that includes the os" do
|
42
|
-
expect
|
66
|
+
expect(Utils.format_host_output(@vmpooler_results)).to eq(@vmpooler_output)
|
43
67
|
end
|
44
68
|
|
45
69
|
it "formats a hostname hash from the nonstandard pooler into a list that includes the os" do
|
46
|
-
expect
|
70
|
+
expect(Utils.format_host_output(@nonstandard_results)).to eq(@nonstandard_output)
|
47
71
|
end
|
48
72
|
end
|
49
73
|
|
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.8.
|
4
|
+
version: 0.8.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:
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|