awslist 2.0.1 → 3.0.0

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: 37bbf2e01ab82e3dbf4d9c6881cf224398ab4850
4
- data.tar.gz: 538d5256694083ac519bc3dd0e69ce368758163c
3
+ metadata.gz: 0ff627b621cf8728e13045bb277355a50e055ea8
4
+ data.tar.gz: 456d37bbe7c8cecf1ab5530e5c67fc11605a187e
5
5
  SHA512:
6
- metadata.gz: 73a86244bc4ad23d82ad8ce6ba4c7843eb411e60d3ad559bc6be6b3b92c32fa765a4623dcb2a9b21786afd0247e0c01ac924c105e402954b974befcf9f0dfe2c
7
- data.tar.gz: 33d51a1ada721d40fd3a6c3abd3ab4bf6dd7a2de2f2f2dcac38805e85b3cd440d335b51fa2b10d2a3c16ba6b5136d61af5b973a471bb354032110ee3e4bf5093
6
+ metadata.gz: 5d891158546fd516a838a81460ed73adb252255a2a769242179b2370498a8cdd2852052ce3852308c695246a1359f65ec126e724a64b4a68675cc94611978849
7
+ data.tar.gz: 8eb3f546a33b9842d1fc63d70dbdeb2cf247c76443213f81d54d5262df3478e091dd7d2497ef0a6578dbd8a12ca9ade5a3e33024f53721b07384a5218a4b8aa3
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'rest-client'
34
34
  spec.add_dependency 'nokogiri'
35
35
  spec.add_dependency 'json'
36
+ spec.add_dependency 'terminal-table'
36
37
 
37
38
  spec.add_development_dependency "bundler", "~> 1.15"
38
39
  spec.add_development_dependency "rake", "~> 10.0"
File without changes
@@ -3,14 +3,16 @@ require 'rest-client'
3
3
  require 'nokogiri'
4
4
  require 'json'
5
5
  require 'optparse'
6
+ require 'terminal-table'
6
7
 
7
8
  module Awslist
8
- class AwsToolCli
9
+ class AwsToolCli < StandardError
9
10
  attr_accessor :parser , :hash , :output
10
11
  def initialize
11
12
  @hash = {}
12
13
  @set = 'n'
13
- @options = {:os => 'linux' , :region => 'us-west-1' , :cpu_req => 0 , :mem_req => 0 , :reload => 'n'}
14
+ @instance_list = {}
15
+ @options = {:os => 'linux' , :region => 'us-east-1' , :cpu_req => 0 , :mem_req => 0 , :reload => 'n' , :instance => 'nil'}
14
16
  @os_list = {
15
17
  'linux' => 0,
16
18
  'rhel' => 0,
@@ -40,6 +42,9 @@ module Awslist
40
42
 
41
43
  @parser = OptionParser.new do |opts|
42
44
  opts.banner = 'Usage: awslist [options]'
45
+ opts.on('-t' , '--type INSTANCE_TYPE') do |instance|
46
+ @options[:instance] = instance.strip
47
+ end
43
48
  opts.on('-os OPERATING_SYSTEM', 'OS list : linux , rhel , sles , mswin , mswinSQL , mswinSQLWeb , mswinSQLEnterprise' ) do |os|
44
49
  @options[:os] = os.strip.downcase;
45
50
  end
@@ -100,15 +105,19 @@ module Awslist
100
105
  @hash[x][str]['vCPU'][cpu] << instance_hash
101
106
  @hash[x][str]['memoryGiB'][mem] = @hash[x][str]['memoryGiB'].fetch(mem,[])
102
107
  @hash[x][str]['memoryGiB'][mem] << instance_hash
108
+
109
+ @instance_list[instance_hash['size']] = 1
103
110
  end
104
111
  end
105
112
  end
106
113
  end
107
114
  File.open('Complete_Data','w'){ |file| file.write(@hash.to_json) }
115
+ File.open('Instance_list','w'){ |file| file.write(@instance_list.to_json)}
108
116
  end
109
117
 
110
118
  def reloaded_hash
111
119
  @hash = JSON.parse(File.read('Complete_Data'))
120
+ @instance_list = JSON.parse(File.read('Instance_list'))
112
121
  end
113
122
 
114
123
  def refine_output
@@ -117,7 +126,9 @@ module Awslist
117
126
  @hash[@options[:os]][@options[:region]]['vCPU'].each do |k,v|
118
127
  if k.to_f >= @options[:cpu_req].to_s.strip.to_f
119
128
  v.each do |c|
120
- a << c
129
+ if (@options[:instance] != 'nil' && c['size'] == @options[:instance]) || @options[:instance] == 'nil'
130
+ a << c
131
+ end
121
132
  end
122
133
  end
123
134
  end
@@ -125,7 +136,9 @@ module Awslist
125
136
  @hash[@options[:os]][@options[:region]]['memoryGiB'].each do |k,v|
126
137
  if k.to_f >= @options[:mem_req].to_s.strip.to_f
127
138
  v.each do |c|
128
- b << c
139
+ if (@options[:instance] != 'nil' && c['size'] == @options[:instance]) || @options[:instance] == 'nil'
140
+ b << c
141
+ end
129
142
  end
130
143
  end
131
144
  end
@@ -133,14 +146,17 @@ module Awslist
133
146
  end
134
147
 
135
148
  def prints
149
+ yo = []
136
150
  @output.each do |hashes_everywhere|
137
151
  value = hashes_everywhere['price'].to_f
138
- puts hashes_everywhere['size'] + ' -c ' + hashes_everywhere['vCPU'] + ' -m ' + hashes_everywhere['memoryGiB'] + ' -p ' + value.to_s + '$ per/hr and ' + (value*24*30).round(3).to_s + '$ per/month'
152
+ yo << [hashes_everywhere['size'],hashes_everywhere['vCPU'],hashes_everywhere['memoryGiB'],value.round(3),(value*24*30).round(3)]
139
153
  end
154
+ table = Terminal::Table.new :headings => ['Instance Type' , 'vCPU' , 'memoryGiB' , 'Price per hr(in USD $)' , 'Price per month(in USD $)'], :rows => yo
155
+ puts table
140
156
  end
141
157
 
142
158
  def what_to_call
143
- if @options[:reload] == 'y' || !File.exist?('Complete_Data')
159
+ if @options[:reload] == 'y' || !File.exist?('Complete_Data') || !File.exist?('Instance_list')
144
160
  reload_files
145
161
  reload_hash
146
162
  elsif @set == 'y' && @options[:reload] != 'n'
@@ -154,6 +170,16 @@ module Awslist
154
170
  raise if !Integer(@options[:mem_req])
155
171
  raise if !@os_list.key?(@options[:os])
156
172
  raise if !@region_list.key?(@options[:region])
173
+ raise AwsToolCli if @options[:instance] != 'nil' && !@instance_list.key?(@options[:instance])
174
+ rescue AwsToolCli
175
+ puts sprintf('Wrong instance name. Please try :')
176
+ yo = []
177
+ @instance_list.each do |k,v|
178
+ yo << [k]
179
+ end
180
+ table = Terminal::Table.new :headings => ['Instance Type'], :rows => yo
181
+ puts table
182
+ exit
157
183
  rescue
158
184
  puts @parser
159
185
  exit
@@ -1,3 +1,3 @@
1
1
  module Awslist
2
- VERSION = "2.0.1"
2
+ VERSION = "3.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awslist
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akkks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement