vmfloaty 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70900ca54a2a255931f813c0a2030bc9d729f0e8
4
- data.tar.gz: 25e286669b6dc14e8182382cb4352937fa834f81
3
+ metadata.gz: 04b7261aa013260aba635e266b003d845e4a2c58
4
+ data.tar.gz: 83bbc1c12ace45c6a1ea288121762f13d3b841ae
5
5
  SHA512:
6
- metadata.gz: 43ec435e2a17f0da693b70ec53f5012ab45eda4a7c44b0d5844a47f14b4ddbc731b698376e157b3248dc95acac8f4cf30f57ac16ea29363b711c814f9505038e
7
- data.tar.gz: 41985d6e6da58dd9628e5ff44da683e830a742f413a2335d2cb91a6673f348ad4396780a8b38201aaf4356948929416d720c84550635c1222dba9cbbe9bed8ef
6
+ metadata.gz: 4e38aedb270708b75d9464744b73b507a6dfdab100567a079287b6b06aa0ac57fabaa03e0e18761c5d1b21e2921f15fbd36ab5beeddcbf3266cac2981d90931c
7
+ data.tar.gz: 04ddaf46164b38bf84df47ee8d5a0e96d87b6be5d64941ee72a075e5264511c7556b8fdd85a2875fadfea37820cfbc307adc6dd46eb32621c1cb552d70cbec94
@@ -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
- puts Utils.format_hosts(response)
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
 
@@ -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.format_hosts(response_body)
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
- if domain
41
- # vmpooler output
42
- response_body.each do |os, hosts|
43
- if hosts['hostname'].kind_of?(Array)
44
- hosts['hostname'].map!{ |host| hostnames << host + "." + domain + " (#{os})"}
45
- else
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
- hostnames.map { |hostname| puts "- #{hostname}" }
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)
@@ -1,3 +1,3 @@
1
1
  class Vmfloaty
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  end
@@ -5,7 +5,7 @@ require_relative '../../lib/vmfloaty/utils'
5
5
 
6
6
  describe Utils do
7
7
 
8
- describe "#format_hosts" do
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
- @vmpooler_output = <<-OUT
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 { Utils.format_hosts(JSON.parse(@vmpooler_response_body)) }.to output( @vmpooler_output).to_stdout_from_any_process
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 { Utils.format_hosts(JSON.parse(@nonstandard_response_body)) }.to output(@nonstandard_output).to_stdout_from_any_process
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.1
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: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander