cumulus 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b48deed6888c1c227070ded977361dfd8f0d5c62
4
+ data.tar.gz: a763901cc357b5fecdb5c484e7f1bdecbf0b44ce
5
+ SHA512:
6
+ metadata.gz: 0f2ff9c8c724c5fb38068ddba814695522117834b549499fea111fe0bd892a1884d825668a292275f1ad20023deac17b12dd722c4aeaef82df37cb9de7d8c4cc
7
+ data.tar.gz: 9f0d4ffb9dc57f3d68a74272a16ea1d9e4ccd008161aec8f0484fc7937f3a83ffbf3d9d87dac6f177dfdc25f214baac5739a1415edcf54039ee9f844e530f5b6
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cumulus.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Colby Aley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ Cumulus
2
+ ===
3
+
4
+ Simple CLI for analyzing cloud cost data through the Cloduability API, using the [cloudability gem](https://github.com/ColbyAley/cloudability). Caches your API key in your [.netrc](http://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-File.html) file for convenience.
5
+
6
+ ## Installation
7
+
8
+ $ gem install cumulus
9
+
10
+ ## Usage
11
+
12
+ $ cumulus budgets # Get a list of your budgets.
13
+ $ cumulus credentials # Get a list of your credentials.
14
+ $ cumulus billing # Get your 10 most recent billing reports.
15
+ $ cumulus billing --count=20 # Get your 20(N) most recent billing reports.
16
+ $ cumulus invites # Get a list of your organization user invites. (must be org admin)
17
+ $ cumulus invites --role=user --state=pending # Get a list of pending user invites.
18
+
19
+ For a list of all the commands:
20
+
21
+ $ cumulus help
22
+
23
+ And for help on a single command:
24
+
25
+ $ cumulus help [COMMAND]
26
+
27
+ As always, email me at colby@cloudability.com if you have any questions.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :irb do
4
+ require File.expand_path('../lib/cumulus.rb', __FILE__)
5
+ sh 'irb -r ./lib/cumulus.rb'
6
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cumulus'
4
+
5
+ Cumulus::CLI.start
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cumulus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cumulus"
8
+ spec.version = Cumulus::VERSION
9
+ spec.authors = ["Colby Aley"]
10
+ spec.email = ["colby@aley.me"]
11
+ spec.description = %q{Access the Cloudability API through the command line}
12
+ spec.summary = %q{Access the Cloudability API through the command line}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "cloudability"
22
+ spec.add_runtime_dependency "netrc"
23
+ spec.add_runtime_dependency "thor"
24
+ spec.add_runtime_dependency "terminal-table"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,126 @@
1
+ require 'cumulus/version'
2
+ require 'terminal-table'
3
+ require 'cloudability'
4
+ require 'netrc'
5
+ require 'thor'
6
+
7
+ module Cumulus
8
+ class CLI < Thor
9
+ include Cloudability
10
+
11
+ method_options type: :string
12
+ desc 'budgets', 'Displays a table of budgets'
13
+ def budgets
14
+ budgets = Client.new(auth_token: token).budgets
15
+
16
+ budgets.select!{|b| b.type.downcase == options[:type] } if options[:type]
17
+
18
+ rows = []
19
+ budgets.each do |budget|
20
+ if budget.is_active
21
+ rows << [c_to_d(budget.predicted_monthly_spend.cents),
22
+ '$' + number_with_delimiter(budget.threshold.to_i).to_s,
23
+ budget.type, budget.subject]
24
+ end
25
+ end
26
+ puts Terminal::Table.new(headings: ['Predicted spend', 'Budget threshold', 'Type', 'Subject'], rows: rows)
27
+ end
28
+
29
+ desc 'credentials', 'Displays a table of your connected credentials'
30
+ def credentials
31
+ credentials = Client.new(auth_token: token).credentials
32
+ rows = []
33
+ credentials.each do |cred|
34
+ rows << [cred.vendor_key, cred.nickname]
35
+ end
36
+ puts Terminal::Table.new(headings: ['Vendor key', 'Nickname'], rows: rows)
37
+ end
38
+
39
+ method_options count: :numeric
40
+ desc 'billing', 'Displays a table of recent billing reports'
41
+ def billing
42
+ count = options[:count] || 10
43
+ reports = Client.new(auth_token: token).billing_report(by: :period).reverse[0..count]
44
+ rows = []
45
+ reports.each do |report|
46
+ rows << [report.period, '$' + number_with_delimiter(report.spend).to_s]
47
+ end
48
+ puts Terminal::Table.new(headings: ['Period', 'Spend'], rows: rows)
49
+ end
50
+
51
+ method_options state: :string
52
+ method_options role: :string
53
+ desc 'invites', 'Displays a table of organization invitations'
54
+ def invites
55
+ invites = Client.new(auth_token: token).organization_invitations
56
+
57
+ invites.select!{|i| i.organization_role.label.downcase == options[:role] } if options[:role]
58
+ invites.select!{|i| i.state.downcase == options[:state] } if options[:state]
59
+
60
+ rows = []
61
+ invites.each do |invite|
62
+ rows << [invite.user.full_name, invite.user.email, invite.organization_role.label, invite.state]
63
+ end
64
+ puts Terminal::Table.new(headings: ['Name', 'Email', 'Role', 'State'], rows: rows)
65
+ end
66
+
67
+ method_options token: :string
68
+ desc 'set_token', 'Reset your API token'
69
+ def set_token
70
+ n = Netrc.read
71
+
72
+ if options[:token]
73
+ n.new_item_prefix = "# Added by the Cumulus gem\n"
74
+ n["app.cloudability.com"] = options[:token], options[:token]
75
+ n.save
76
+ puts "Your token has been saved."
77
+ else
78
+ puts "Please enter your Cloudability API token and hit enter: "
79
+ token = STDIN.gets.chomp
80
+ n.new_item_prefix = "# Added by the Cumulus gem\n"
81
+ n["app.cloudability.com"] = token, token
82
+ n.save
83
+ puts "Your token has been saved."
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def token
90
+ n = Netrc.read
91
+ if !n["app.cloudability.com"].nil? && token = n["app.cloudability.com"][0]
92
+ return token
93
+ else
94
+ get_token
95
+ end
96
+ end
97
+
98
+ def get_token
99
+ puts "Please enter your Cloudability API token and hit enter: "
100
+ token = STDIN.gets.chomp
101
+ n = Netrc.read
102
+ n.new_item_prefix = "# Added by the Cumulus gem\n"
103
+ n["app.cloudability.com"] = token, token
104
+ n.save
105
+ token
106
+ end
107
+
108
+ # Convert cents to dollars
109
+ def c_to_d(cents)
110
+ dollars = number_with_delimiter(cents.to_i / 100)
111
+ '$' + dollars.to_s
112
+ end
113
+
114
+ # Source: https://gist.github.com/jpemberthy/484764
115
+ def number_with_delimiter(number, delimiter=",", separator=".")
116
+ begin
117
+ parts = number.to_s.split('.')
118
+ parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
119
+ parts.join separator
120
+ rescue
121
+ number
122
+ end
123
+ end
124
+
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module Cumulus
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cumulus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colby Aley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cloudability
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: netrc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Access the Cloudability API through the command line
98
+ email:
99
+ - colby@aley.me
100
+ executables:
101
+ - cumulus
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/cumulus
111
+ - cumulus.gemspec
112
+ - lib/cumulus.rb
113
+ - lib/cumulus/version.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Access the Cloudability API through the command line
138
+ test_files: []