ec2-host 0.1.0 → 0.1.1

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: d0bc795de2c9dd28b237cf8a442d13434532d13e
4
- data.tar.gz: 417e73f78134b37a660bc614dfc07e74ebfd1890
3
+ metadata.gz: 71fdb977a6c700081fd8af2f3274b70778854458
4
+ data.tar.gz: 380fbcf200f1fb57fca95d1b8a8a1f5f8a431873
5
5
  SHA512:
6
- metadata.gz: 19efa5260b4e445e9f3024c7228a02e8477736feb678aa52ed6596846551b520f74c97f82c04044fa93d4f3b52b2322179379db63841f1622c2001daca2f12fc
7
- data.tar.gz: 720fa2e40471c42fd373a6bba4a00dd16eb596d548f325e376fa693da6cb6d54e0610537190d6d9a26d82d6e3bca99e8b16cba4b44524aa6f426103a65264ffc
6
+ metadata.gz: b9deed0d8a1921c188193536c519f3be9f918767c174e4cf2116517a5ae1bc8403d33d5f82d434e0b2d7d62236f8f4a2686be45fab71ba40823289d15e2b991c
7
+ data.tar.gz: 901615c730d1a69786586c864a55a53f1e00d6da90c0f8e924cd02f4fedabc3deaf8a4e0e6410f9a9e920b0e5ba5b8f4254772701ec1ce6fd763329e325fecc9
@@ -1,3 +1,15 @@
1
+ # 0.1.1 (2015/08/11)
2
+
3
+ Changes:
4
+
5
+ * Rename `--json` to `--line-delimited-json`. Alias is kept as `-j`.
6
+ * Add `--json` which returns an arrayed json
7
+ * Add `--pretty-json` which returns json in pretty print
8
+
9
+ Fixes:
10
+
11
+ * Stop using Aws.config.update, it changes the default config
12
+
1
13
  # 0.1.0 (2015/08/11)
2
14
 
3
15
  Enhancements:
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "ec2-host"
3
- gem.version = '0.1.0'
3
+ gem.version = '0.1.1'
4
4
  gem.author = ['Naotoshi Seo']
5
5
  gem.email = ['sonots@gmail.com']
6
6
  gem.homepage = 'https://github.com/sonots/ec2-host'
@@ -49,33 +49,44 @@ class EC2
49
49
  option :info,
50
50
  :aliases => %w[-i],
51
51
  :type => :boolean,
52
- :desc => "show host info, not only hostname"
53
- option :json,
52
+ :desc => "show host info"
53
+ option :line_delimited_json,
54
54
  :aliases => %w[-j],
55
55
  :type => :boolean,
56
- :desc => "show detailed host info in json"
56
+ :desc => "show host info in line delimited json"
57
+ option :json,
58
+ :type => :boolean,
59
+ :desc => "show host info in json"
60
+ option :pretty_json,
61
+ :type => :boolean,
62
+ :desc => "show host info in pretty json"
57
63
  option :debug,
58
64
  :type => :boolean,
59
65
  :desc => "debug mode"
60
66
  def get_hosts
67
+ hosts = EC2::Host.new(condition)
61
68
  if options[:info]
62
- EC2::Host.new(condition).each do |host|
69
+ hosts.each do |host|
63
70
  $stdout.puts host.info
64
71
  end
65
- elsif options[:json]
66
- EC2::Host.new(condition).each do |host|
67
- $stdout.puts host.json
72
+ elsif options[:line_delimited_json]
73
+ hosts.each do |host|
74
+ $stdout.puts host.to_hash.to_json
68
75
  end
76
+ elsif options[:json]
77
+ $stdout.puts hosts.map(&:to_hash).to_json
78
+ elsif options[:pretty_json]
79
+ $stdout.puts JSON.pretty_generate(hosts.map(&:to_hash))
69
80
  elsif options[:private_ip]
70
- EC2::Host.new(condition).each do |host|
81
+ hosts.each do |host|
71
82
  $stdout.puts host.private_ip_address
72
83
  end
73
84
  elsif options[:public_ip]
74
- EC2::Host.new(condition).each do |host|
85
+ hosts.each do |host|
75
86
  $stdout.puts host.public_ip_address
76
87
  end
77
88
  else
78
- EC2::Host.new(condition).each do |host|
89
+ hosts.each do |host|
79
90
  $stdout.puts host.hostname
80
91
  end
81
92
  end
@@ -85,7 +96,7 @@ class EC2
85
96
 
86
97
  def condition
87
98
  return @condition if @condition
88
- _condition = HashUtil.except(options, :info, :json, :debug, :private_ip, :public_ip)
99
+ _condition = HashUtil.except(options, :info, :line_delimited_json, :json, :pretty_json, :debug, :private_ip, :public_ip)
89
100
  @condition = {}
90
101
  _condition.each do |key, val|
91
102
  if tag = Config.optional_options[key.to_s]
@@ -6,8 +6,7 @@ class EC2
6
6
  class ClientUtil
7
7
  def self.ec2(reload = false)
8
8
  if @ec2.nil? || reload
9
- Aws.config.update(region: Config.aws_region, credentials: Config.aws_credentials)
10
- @ec2 = Aws::EC2::Client.new
9
+ @ec2 = Aws::EC2::Client.new(region: Config.aws_region, credentials: Config.aws_credentials)
11
10
  end
12
11
  @ec2
13
12
  end
@@ -71,19 +71,19 @@ class EC2
71
71
  info << "{#{service}}" unless service.empty?
72
72
  info
73
73
  else
74
- HashUtil.except(self, :instance).to_s
74
+ to_hash.to_s
75
75
  end
76
76
  end
77
77
 
78
- def json
79
- HashUtil.except(self, :instance).merge(
78
+ def to_hash
79
+ HashUtil.except(self, :instance).to_h.merge(
80
80
  instance_id: instance_id,
81
81
  private_ip_address: private_ip_address,
82
82
  public_ip_address: public_ip_address,
83
83
  launch_time: launch_time,
84
84
  state: state,
85
85
  monitoring: monitoring,
86
- ).to_json
86
+ )
87
87
  end
88
88
 
89
89
  # private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk