awslist 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ebe1e0a348377c273f14f96e25d83eabcb16dbc
4
- data.tar.gz: da77c0fc4588a573e4139a221be469ab2c229193
3
+ metadata.gz: 37bbf2e01ab82e3dbf4d9c6881cf224398ab4850
4
+ data.tar.gz: 538d5256694083ac519bc3dd0e69ce368758163c
5
5
  SHA512:
6
- metadata.gz: 17238145bd85f8e7d28d2d199c36aa4ce83706bf03ec15f985be4fb49fffe7496074b6ec231aeb33f7b3e34def39dd9932d87520fe358fb1a0fb7960ea05d711
7
- data.tar.gz: '0987468f19e490b18c10ab0d906c6541a554cf1106e293a879e4a5de4caa9d2df406975c02d80e2e4c1fac9f899120a37f2e9f00eb4b87a12485762293a94411'
6
+ metadata.gz: 73a86244bc4ad23d82ad8ce6ba4c7843eb411e60d3ad559bc6be6b3b92c32fa765a4623dcb2a9b21786afd0247e0c01ac924c105e402954b974befcf9f0dfe2c
7
+ data.tar.gz: 33d51a1ada721d40fd3a6c3abd3ab4bf6dd7a2de2f2f2dcac38805e85b3cd440d335b51fa2b10d2a3c16ba6b5136d61af5b973a471bb354032110ee3e4bf5093
data/README.md CHANGED
@@ -97,7 +97,8 @@ The gem is available as open source under the terms of the [MIT License](http://
97
97
  ## Code of Conduct
98
98
 
99
99
  Everyone interacting in the Awslist project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Akkks/awslist/blob/master/CODE_OF_CONDUCT.md).
100
- =======
100
+
101
101
  # gems
102
+
102
103
  My Created gems
103
104
  >>>>>>> 2fc700980e3a1721970af1c0bf41cb4f7d75ebee97db75fc33044d6270a0521b
data/awslist.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "awslist/version"
4
+ require 'awslist/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "awslist"
7
+ spec.name = 'awslist'
8
8
  spec.version = Awslist::VERSION
9
9
  spec.authors = ["Akkks"]
10
10
  spec.email = ["sngh.akanksha09@gmail.com"]
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
29
+ spec.bindir = 'bin'
30
+ spec.executables = ['awslist']
31
+ spec.require_paths = ['lib']
32
32
 
33
33
  spec.add_dependency 'rest-client'
34
34
  spec.add_dependency 'nokogiri'
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "bundler", "~> 1.15"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
+
40
41
  end
data/bin/awslist ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'awslist'
4
+
5
+ hope = Awslist::AwsToolCli.new
6
+
7
+ begin hope.parser.parse! ARGV
8
+ rescue OptionParser::InvalidOption => e
9
+ puts e
10
+ puts hope.parser
11
+ exit 1
12
+ end
13
+
14
+ hope.what_to_call
15
+ hope.reloaded_hash
16
+ hope.refine_output
17
+ hope.prints
data/lib/awslist.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'awslist/version'
2
+ require 'rest-client'
3
+ require 'nokogiri'
4
+ require 'json'
5
+ require 'optparse'
6
+
7
+ module Awslist
8
+ class AwsToolCli
9
+ attr_accessor :parser , :hash , :output
10
+ def initialize
11
+ @hash = {}
12
+ @set = 'n'
13
+ @options = {:os => 'linux' , :region => 'us-west-1' , :cpu_req => 0 , :mem_req => 0 , :reload => 'n'}
14
+ @os_list = {
15
+ 'linux' => 0,
16
+ 'rhel' => 0,
17
+ 'sles' => 0,
18
+ 'mswin' => 0,
19
+ 'mswinSQL' => 0,
20
+ 'mswinSQLWeb' => 0,
21
+ 'mswinSQLEnterprise' => 0
22
+ }
23
+ @region_list = {
24
+ 'us-east-1' => 0,
25
+ 'us-east-2' => 0,
26
+ 'us-west-2' => 0,
27
+ 'us-west-1' => 0,
28
+ 'ca-central-1' => 0,
29
+ 'eu-west-1' => 0,
30
+ 'eu-west-2' => 0,
31
+ 'eu-central-1' => 0,
32
+ 'ap-southeast-1' => 0,
33
+ 'ap-northeast-1' => 0,
34
+ 'ap-southeast-2' => 0,
35
+ 'ap-northeast-2' => 0,
36
+ 'ap-south-1' => 0,
37
+ 'sa-east-1' => 0,
38
+ 'us-gov-west-1' => 0
39
+ }
40
+
41
+ @parser = OptionParser.new do |opts|
42
+ opts.banner = 'Usage: awslist [options]'
43
+ opts.on('-os OPERATING_SYSTEM', 'OS list : linux , rhel , sles , mswin , mswinSQL , mswinSQLWeb , mswinSQLEnterprise' ) do |os|
44
+ @options[:os] = os.strip.downcase;
45
+ end
46
+ opts.on('-c', '--cpu CPU_REQUIREMENT', 'Basic value of cpu required in integer') do |cpu|
47
+ @options[:cpu_req] = cpu.strip;
48
+ end
49
+ opts.on('-m', '--mem MEMORY_REQUIREMENT', 'Basic value of memory required in integer') do |memory|
50
+ @options[:mem_req] = memory.strip;
51
+ end
52
+ opts.on('-r', '--region REGION', 'Required region , list : us-east-1 , us-east-2 , us-west-2 , us-west-1 , ca-central-1 , eu-west-1 , eu-west-2 , eu-central-1 , ap-southeast-1 , ap-northeast-1 , ap-southeast-2 , ap-northeast-2 , ap-south-1 , sa-east-1 , us-gov-west-1') do |reg|
53
+ @options[:region] = reg.strip.downcase;
54
+ end
55
+ opts.on('--reload y/n' , 'Fetch fresh data from website') do |get|
56
+ @options[:reload] = get.strip.downcase;
57
+ @set = 'y'
58
+ end
59
+ opts.on('-h', '--help', 'Displays Help') do
60
+ puts opts
61
+ exit
62
+ end
63
+ end
64
+ end
65
+ def reload_files
66
+ ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
67
+ s = RestClient.get "https://a0.awsstatic.com/pricing/1/ec2/#{x}-od.min.js"
68
+ s.gsub!(/^.*callback\(/, '') # removes the comment and callback function from the start of the string
69
+ s.gsub!(/\);$/, '') # removes the end of the callback function
70
+ s.gsub!(/(\w+):/, '"\1":')
71
+ hash = JSON.parse(s)
72
+ File.open("#{x}","w") { |file| file.write(hash.to_json) }
73
+ end
74
+ end
75
+
76
+ def reload_hash
77
+ ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
78
+ s = JSON.parse(File.read(x))
79
+ @hash[x] = @hash.fetch(x,{})
80
+ s['config']['regions'].each do |region_spec|
81
+ str = region_spec['region']
82
+ @hash[x][str] = @hash[x].fetch(str,{})
83
+ @hash[x][str]['vCPU'] = @hash[x][str].fetch('vCPU',{})
84
+ @hash[x][str]['memoryGiB'] = @hash[x][str].fetch('memoryGiB',{})
85
+
86
+ region_spec['instanceTypes'].each do |type|
87
+ type['sizes'].each do |instance_spec|
88
+ instance_hash = {}
89
+ instance_hash['size'] = instance_spec['size']
90
+ instance_hash['vCPU'] = instance_spec['vCPU']
91
+ instance_hash['ECU'] = instance_spec['ECU']
92
+ instance_hash['memoryGiB'] = instance_spec['memoryGiB']
93
+ instance_hash['storageGB'] = instance_spec['storageGB']
94
+ instance_hash['price'] = instance_spec['valueColumns'][0]['prices']['USD']
95
+
96
+ cpu = instance_hash['vCPU']
97
+ mem = instance_hash['memoryGiB']
98
+
99
+ @hash[x][str]['vCPU'][cpu] = @hash[x][str]['vCPU'].fetch(cpu,[])
100
+ @hash[x][str]['vCPU'][cpu] << instance_hash
101
+ @hash[x][str]['memoryGiB'][mem] = @hash[x][str]['memoryGiB'].fetch(mem,[])
102
+ @hash[x][str]['memoryGiB'][mem] << instance_hash
103
+ end
104
+ end
105
+ end
106
+ end
107
+ File.open('Complete_Data','w'){ |file| file.write(@hash.to_json) }
108
+ end
109
+
110
+ def reloaded_hash
111
+ @hash = JSON.parse(File.read('Complete_Data'))
112
+ end
113
+
114
+ def refine_output
115
+ a = []
116
+ b = []
117
+ @hash[@options[:os]][@options[:region]]['vCPU'].each do |k,v|
118
+ if k.to_f >= @options[:cpu_req].to_s.strip.to_f
119
+ v.each do |c|
120
+ a << c
121
+ end
122
+ end
123
+ end
124
+
125
+ @hash[@options[:os]][@options[:region]]['memoryGiB'].each do |k,v|
126
+ if k.to_f >= @options[:mem_req].to_s.strip.to_f
127
+ v.each do |c|
128
+ b << c
129
+ end
130
+ end
131
+ end
132
+ @output = a & b
133
+ end
134
+
135
+ def prints
136
+ @output.each do |hashes_everywhere|
137
+ 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'
139
+ end
140
+ end
141
+
142
+ def what_to_call
143
+ if @options[:reload] == 'y' || !File.exist?('Complete_Data')
144
+ reload_files
145
+ reload_hash
146
+ elsif @set == 'y' && @options[:reload] != 'n'
147
+ puts @parser
148
+ exit
149
+ else
150
+ reloaded_hash
151
+ end
152
+ begin
153
+ raise if !Integer(@options[:cpu_req])
154
+ raise if !Integer(@options[:mem_req])
155
+ raise if !@os_list.key?(@options[:os])
156
+ raise if !@region_list.key?(@options[:region])
157
+ rescue
158
+ puts @parser
159
+ exit
160
+ end
161
+ end
162
+ end
163
+ end
@@ -1,3 +1,3 @@
1
1
  module Awslist
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
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.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akkks
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -97,7 +97,8 @@ dependencies:
97
97
  description: Filter instances according to your choices
98
98
  email:
99
99
  - sngh.akanksha09@gmail.com
100
- executables: []
100
+ executables:
101
+ - awslist
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
@@ -110,10 +111,11 @@ files:
110
111
  - README.md
111
112
  - Rakefile
112
113
  - awslist.gemspec
114
+ - bin/awslist
113
115
  - bin/console
114
116
  - bin/setup
117
+ - lib/awslist.rb
115
118
  - lib/awslist/version.rb
116
- - lib/awstool
117
119
  homepage: https://github.com/Akkks/awslist
118
120
  licenses:
119
121
  - MIT
data/lib/awstool DELETED
@@ -1,177 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'awslist/version'
4
- require 'rest-client'
5
- require 'nokogiri'
6
- require 'json'
7
- require 'optparse'
8
-
9
- class Awslist
10
- # Your code goes here...
11
- attr_accessor :parser , :hash , :output
12
- def initialize
13
- @hash = {}
14
- @set = 'n'
15
- @options = {:os => 'linux' , :region => 'us-west-1' , :cpu_req => 0 , :mem_req => 0 , :reload => 'n'}
16
- @os_list = {
17
- 'linux' => 0,
18
- 'rhel' => 0,
19
- 'sles' => 0,
20
- 'mswin' => 0,
21
- 'mswinSQL' => 0,
22
- 'mswinSQLWeb' => 0,
23
- 'mswinSQLEnterprise' => 0
24
- }
25
- @region_list = {
26
- 'us-east-1' => 0,
27
- 'us-east-2' => 0,
28
- 'us-west-2' => 0,
29
- 'us-west-1' => 0,
30
- 'ca-central-1' => 0,
31
- 'eu-west-1' => 0,
32
- 'eu-west-2' => 0,
33
- 'eu-central-1' => 0,
34
- 'ap-southeast-1' => 0,
35
- 'ap-northeast-1' => 0,
36
- 'ap-southeast-2' => 0,
37
- 'ap-northeast-2' => 0,
38
- 'ap-south-1' => 0,
39
- 'sa-east-1' => 0,
40
- 'us-gov-west-1' => 0
41
- }
42
-
43
- @parser = OptionParser.new do |opts|
44
- opts.banner = 'Usage: awslist [options]'
45
- opts.on('-os OPERATING_SYSTEM', 'OS list : linux , rhel , sles , mswin , mswinSQL , mswinSQLWeb , mswinSQLEnterprise' ) do |os|
46
- @options[:os] = os.strip.downcase;
47
- end
48
- opts.on('-c', '--cpu CPU_REQUIREMENT', 'Basic value of cpu required in integer') do |cpu|
49
- @options[:cpu_req] = cpu.strip;
50
- end
51
- opts.on('-m', '--mem MEMORY_REQUIREMENT', 'Basic value of memory required in integer') do |memory|
52
- @options[:mem_req] = memory.strip;
53
- end
54
- opts.on('-r', '--region REGION', 'Required region , list : us-east-1 , us-east-2 , us-west-2 , us-west-1 , ca-central-1 , eu-west-1 , eu-west-2 , eu-central-1 , ap-southeast-1 , ap-northeast-1 , ap-southeast-2 , ap-northeast-2 , ap-south-1 , sa-east-1 , us-gov-west-1') do |reg|
55
- @options[:region] = reg.strip.downcase;
56
- end
57
- opts.on('--reload y/n' , 'Fetch fresh data from website') do |get|
58
- @options[:reload] = get.strip.downcase;
59
- @set = 'y'
60
- end
61
- opts.on('-h', '--help', 'Displays Help') do
62
- puts opts
63
- exit
64
- end
65
- end
66
- end
67
-
68
- def reload_files
69
- ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
70
- s = RestClient.get "https://a0.awsstatic.com/pricing/1/ec2/#{x}-od.min.js"
71
- s.gsub!(/^.*callback\(/, '') # removes the comment and callback function from the start of the string
72
- s.gsub!(/\);$/, '') # removes the end of the callback function
73
- s.gsub!(/(\w+):/, '"\1":')
74
- hash = JSON.parse(s)
75
- File.open("#{x}","w") { |file| file.write(hash.to_json) }
76
- end
77
- end
78
-
79
- def reload_hash
80
- ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
81
- s = JSON.parse(File.read(x))
82
- @hash[x] = @hash.fetch(x,{})
83
- s['config']['regions'].each do |region_spec|
84
- str = region_spec['region']
85
- @hash[x][str] = @hash[x].fetch(str,{})
86
- @hash[x][str]['vCPU'] = @hash[x][str].fetch('vCPU',{})
87
- @hash[x][str]['memoryGiB'] = @hash[x][str].fetch('memoryGiB',{})
88
-
89
- region_spec['instanceTypes'].each do |type|
90
- type['sizes'].each do |instance_spec|
91
- instance_hash = {}
92
- instance_hash['size'] = instance_spec['size']
93
- instance_hash['vCPU'] = instance_spec['vCPU']
94
- instance_hash['ECU'] = instance_spec['ECU']
95
- instance_hash['memoryGiB'] = instance_spec['memoryGiB']
96
- instance_hash['storageGB'] = instance_spec['storageGB']
97
- instance_hash['price'] = instance_spec['valueColumns'][0]['prices']['USD']
98
-
99
- cpu = instance_hash['vCPU']
100
- mem = instance_hash['memoryGiB']
101
-
102
- @hash[x][str]['vCPU'][cpu] = @hash[x][str]['vCPU'].fetch(cpu,[])
103
- @hash[x][str]['vCPU'][cpu] << instance_hash
104
- @hash[x][str]['memoryGiB'][mem] = @hash[x][str]['memoryGiB'].fetch(mem,[])
105
- @hash[x][str]['memoryGiB'][mem] << instance_hash
106
- end
107
- end
108
- end
109
- end
110
- File.open('Complete_Data','w'){ |file| file.write(@hash.to_json) }
111
- end
112
-
113
- def reloaded_hash
114
- @hash = JSON.parse(File.read('Complete_Data'))
115
- end
116
-
117
- def refine_output
118
- a = []
119
- b = []
120
- @hash[@options[:os]][@options[:region]]['vCPU'].each do |k,v|
121
- if k.to_f >= @options[:cpu_req].to_s.strip.to_f
122
- v.each do |c|
123
- a << c
124
- end
125
- end
126
- end
127
-
128
- @hash[@options[:os]][@options[:region]]['memoryGiB'].each do |k,v|
129
- if k.to_f >= @options[:mem_req].to_s.strip.to_f
130
- v.each do |c|
131
- b << c
132
- end
133
- end
134
- end
135
- @output = a & b
136
- end
137
-
138
- def prints
139
- @output.each do |hashes_everywhere|
140
- value = hashes_everywhere['price'].to_f
141
- 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'
142
- end
143
- end
144
-
145
- def what_to_call
146
- if @options[:reload] == 'y' || !File.exist?('Complete_Data')
147
- reload_files
148
- reload_hash
149
- elsif @set == 'y' && @options[:reload] != 'n'
150
- puts @parser
151
- exit
152
- end
153
- begin
154
- raise if !Integer(@options[:cpu_req])
155
- raise if !Integer(@options[:mem_req])
156
- raise if !@os_list.key?(@options[:os])
157
- raise if !@region_list.key?(@options[:region])
158
- rescue
159
- puts @parser
160
- exit
161
- end
162
- reloaded_hash
163
- end
164
- end
165
-
166
- hope = Awslist.new
167
- #hope.initialize
168
- begin hope.parser.parse! ARGV
169
- rescue OptionParser::InvalidOption => e
170
- puts e
171
- puts hope.parser
172
- exit 1
173
- end
174
- hope.what_to_call
175
- hope.reloaded_hash
176
- hope.refine_output
177
- hope.prints