awslist 1.0.2 → 2.0.0

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: 624828a66d6b4cd6dc65021510fb50fef43d259f
4
- data.tar.gz: df9c98073ec60600a84d70b1e6c3755155d5e93e
3
+ metadata.gz: 9ebe1e0a348377c273f14f96e25d83eabcb16dbc
4
+ data.tar.gz: da77c0fc4588a573e4139a221be469ab2c229193
5
5
  SHA512:
6
- metadata.gz: 8c85fea384523f100f02041361675cd6afcc7cb90ae89f2b9fad77f560e0f83d3dd323d21a756d4de7172ac792263e884ccb89743d5ce0e7ede1784b03785586
7
- data.tar.gz: 90cfe9d42ef9b98e5360a2af67c0be6d63296893e5f0f34a81f6897a68aac6d05f91d4bf52cc34d790b24048c7a1ba50f930302aa87fbbad8b4152b93b4563f6
6
+ metadata.gz: 17238145bd85f8e7d28d2d199c36aa4ce83706bf03ec15f985be4fb49fffe7496074b6ec231aeb33f7b3e34def39dd9932d87520fe358fb1a0fb7960ea05d711
7
+ data.tar.gz: '0987468f19e490b18c10ab0d906c6541a554cf1106e293a879e4a5de4caa9d2df406975c02d80e2e4c1fac9f899120a37f2e9f00eb4b87a12485762293a94411'
data/README.md CHANGED
@@ -23,13 +23,31 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
+ The new update makes this gem available to be used as command line tool.
27
+
28
+ Usage: awslist [options]
29
+
30
+
31
+ -os OPERATING_SYSTEM OS list : linux , rhel , sles , mswin , mswinSQL , mswinSQLWeb , mswinSQLEnterprise
32
+
33
+ -c, --cpu CPU_REQUIREMENT Basic value of cpu required in integer
34
+
35
+ -m, --mem MEMORY_REQUIREMENT Basic value of memory required in integer
36
+
37
+ -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
38
+
39
+ --reload y/n Fetch fresh data from website
40
+
41
+ -h, --help Displays Help
42
+
43
+
26
44
  The gem contains basically 3 functions
27
45
 
28
46
  1. get_input :
29
47
 
30
48
  This function returns 5 parameters , which are later used to call main functionality.
31
49
 
32
- @os , @region , @memory , @cpu_req , @hash = get_input
50
+ @os , @region , @memory , @cpu_req , @hash = Awslist.get_input
33
51
 
34
52
  a. @os is the operating system value
35
53
 
@@ -49,7 +67,7 @@ The gem contains basically 3 functions
49
67
 
50
68
  After taking the input from the user , refine output is called , with all above 5 paramenters , i.e.
51
69
 
52
- @output = refine_output(@os , @region , @memory , @cpu_req , @hash)
70
+ @output = Awslist.refine_output(@os , @region , @memory , @cpu_req , @hash)
53
71
 
54
72
  It will output a resulted array of the requirements matching instances
55
73
 
@@ -59,7 +77,7 @@ The gem contains basically 3 functions
59
77
 
60
78
  It will take input as output of refine_output , and print the results
61
79
 
62
- print(@output)
80
+ Awslist.print(@output)
63
81
 
64
82
 
65
83
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Awslist
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/awstool ADDED
@@ -0,0 +1,177 @@
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
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: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akkks
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -112,8 +112,8 @@ files:
112
112
  - awslist.gemspec
113
113
  - bin/console
114
114
  - bin/setup
115
- - lib/awslist.rb
116
115
  - lib/awslist/version.rb
116
+ - lib/awstool
117
117
  homepage: https://github.com/Akkks/awslist
118
118
  licenses:
119
119
  - MIT
data/lib/awslist.rb DELETED
@@ -1,182 +0,0 @@
1
- require 'awslist/version'
2
- require 'rest-client'
3
- require 'nokogiri'
4
- require 'json'
5
-
6
- module Awslist
7
- # Your code goes here...
8
- #def initialize
9
- #@aws = Awslist.new
10
- #end
11
-
12
- def self.get_os(os_str)
13
- os_list = {
14
- '1' => 'linux' ,
15
- '2' => 'rhel' ,
16
- '3' => 'sles' ,
17
- '4' => 'mswin' ,
18
- '5' => 'mswinSQL' ,
19
- '6' => 'mswinSQLWeb' ,
20
- '7' => 'mswinSQLEnterprise'
21
- }
22
- return os_list[os_str.strip.to_s] if os_list.key?(os_str.strip.to_s)
23
- puts 'Please input correct choice for Operating system'
24
- abort
25
- end
26
-
27
- def self.get_region(region_str)
28
- region_list = {
29
- '1' => 'us-east-1' ,
30
- '2' => 'us-east-2' ,
31
- '3' => 'us-west-2' ,
32
- '4' => 'us-west-1' ,
33
- '5' => 'ca-central-1' ,
34
- '6' => 'eu-west-1' ,
35
- '7' => 'eu-west-2' ,
36
- '8' => 'eu-central-1' ,
37
- '9' => 'ap-southeast-1' ,
38
- '10' => 'ap-northeast-1' ,
39
- '11' => 'ap-southeast-2' ,
40
- '12' => 'ap-northeast-2' ,
41
- '13' => 'ap-south-1' ,
42
- '14' => 'sa-east-1' ,
43
- '15' => 'us-gov-west-1'
44
- }
45
- return region_list[region_str.strip.to_s] if region_list.key?(region_str.strip.to_s)
46
- puts 'Please input correct choice for Region'
47
- abort
48
- end
49
-
50
- def self.reload_files
51
- ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
52
- s = RestClient.get "https://a0.awsstatic.com/pricing/1/ec2/#{x}-od.min.js"
53
- s.gsub!(/^.*callback\(/, '') # removes the comment and callback function from the start of the string
54
- s.gsub!(/\);$/, '') # removes the end of the callback function
55
- s.gsub!(/(\w+):/, '"\1":')
56
- hash = JSON.parse(s)
57
- File.open("#{x}","w") { |file| file.write(hash.to_json) }
58
- end
59
- end
60
-
61
- def self.reload_hash
62
- hash = {}
63
- ['linux','rhel','sles','mswin','mswinSQL','mswinSQLWeb','mswinSQLEnterprise'].each do |x|
64
- s = JSON.parse(File.read(x))
65
- hash[x] = hash.fetch(x,{})
66
- s['config']['regions'].each do |region_spec|
67
- str = region_spec['region']
68
- hash[x][str] = hash[x].fetch(str,{})
69
- hash[x][str]['vCPU'] = hash[x][str].fetch('vCPU',{})
70
- hash[x][str]['memoryGiB'] = hash[x][str].fetch('memoryGiB',{})
71
-
72
- region_spec['instanceTypes'].each do |type|
73
- type['sizes'].each do |instance_spec|
74
- instance_hash = {}
75
- instance_hash['size'] = instance_spec['size']
76
- instance_hash['vCPU'] = instance_spec['vCPU']
77
- instance_hash['ECU'] = instance_spec['ECU']
78
- instance_hash['memoryGiB'] = instance_spec['memoryGiB']
79
- instance_hash['storageGB'] = instance_spec['storageGB']
80
- instance_hash['price'] = instance_spec['valueColumns'][0]['prices']['USD']
81
-
82
- cpu = instance_hash['vCPU']
83
- mem = instance_hash['memoryGiB']
84
-
85
- hash[x][str]['vCPU'][cpu] = hash[x][str]['vCPU'].fetch(cpu,[])
86
- hash[x][str]['vCPU'][cpu] << instance_hash
87
- hash[x][str]['memoryGiB'][mem] = hash[x][str]['memoryGiB'].fetch(mem,[])
88
- hash[x][str]['memoryGiB'][mem] << instance_hash
89
- end
90
- end
91
- end
92
- end
93
- File.open('Complete_Data','w'){ |file| file.write(hash.to_json) }
94
- end
95
-
96
- def self.reloaded_hash
97
- hash = JSON.parse(File.read('Complete_Data'))
98
- return hash
99
- end
100
-
101
- def self.get_input
102
- puts 'Want to reload data?y/n'
103
- @decision = STDIN.gets
104
- if @decision.strip == 'y' || ! File.exist?('Complete_Data')
105
- reload_files
106
- reload_hash
107
- end
108
- @hash = reloaded_hash
109
-
110
- puts 'Enter your choice of Operating system'
111
- puts '
112
- 1 : linux
113
- 2 : rhel
114
- 3 : sles
115
- 4 : mswin
116
- 5 : mswinSQL
117
- 6 : mswinSQLWeb
118
- 7 : mswinSQLEnterprise'
119
- @os = get_os(STDIN.gets)
120
- puts 'Enter your choice of Region'
121
- puts '
122
- 1 : us-east-1
123
- 2 : us-east-2
124
- 3 : us-west-2
125
- 4 : us-west-1
126
- 5 : ca-central-1
127
- 6 : eu-west-1
128
- 7 : eu-west-2
129
- 8 : eu-central-1
130
- 9 : ap-southeast-1
131
- 10 : ap-northeast-1
132
- 11 : ap-southeast-2
133
- 12 : ap-northeast-2
134
- 13 : ap-south-1
135
- 14 : sa-east-1
136
- 15 : us-gov-west-1'
137
- @region = get_region(STDIN.gets)
138
- puts 'Enter your memory requirement , else nil'
139
- @memory = STDIN.gets
140
- puts 'Enter your cpu requirement , else nil'
141
- @cpu_req = STDIN.gets
142
-
143
- return @os , @region , @memory , @cpu_req , @hash
144
- end
145
-
146
- def self.refine_output(os,region,memory,cpu_req,hash)
147
- a = []
148
- b = []
149
- memory = '0' if memory.strip == 'nil'
150
- cpu_req = '0' if cpu_req.strip == 'nil'
151
-
152
- hash[os][region]['vCPU'].each do |k,v|
153
- if k.to_f >= cpu_req.strip.to_f
154
- v.each do |c|
155
- a << c
156
- end
157
- end
158
- end
159
-
160
- hash[os][region]['memoryGiB'].each do |k,v|
161
- if k.to_f >= memory.strip.to_f
162
- v.each do |c|
163
- b << c
164
- end
165
- end
166
- end
167
- output = a & b
168
-
169
- return output
170
- end
171
-
172
- def self.print(output)
173
- output.each do |hashes_everywhere|
174
- value = hashes_everywhere['price'].to_f
175
- puts hashes_everywhere['size'] + ' -c ' + hashes_everywhere['vCPU'] + ' -m ' + hashes_everywhere['memoryGiB'] + ' -p ' + value.to_s + '$ perhr and ' + (value*24).round(3).to_s + '$ perday'
176
- end
177
- end
178
-
179
- #@os , @region , @memory , @cpu_req , @hash = get_input
180
- #@output = refine_output(@os , @region , @memory , @cpu_req , @hash)
181
- #print(@output)
182
- end