cloudcost 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -2
- data/lib/cloudcost/api_token.rb +0 -1
- data/lib/cloudcost/cli.rb +30 -24
- data/lib/cloudcost/{csv_output.rb → commands/csv_output.rb} +1 -1
- data/lib/cloudcost/{server.rb → commands/server/server.rb} +0 -2
- data/lib/cloudcost/{influxdb_output.rb → commands/server/server_influxdb_output.rb} +1 -1
- data/lib/cloudcost/{server_list.rb → commands/server/server_list.rb} +2 -2
- data/lib/cloudcost/{tabular_output.rb → commands/server/server_tabular_output.rb} +3 -1
- data/lib/cloudcost/commands/server.rb +6 -0
- data/lib/cloudcost/{volume.rb → commands/volume/volume.rb} +0 -0
- data/lib/cloudcost/{volume_list.rb → commands/volume/volume_list.rb} +4 -11
- data/lib/cloudcost/commands/volume.rb +4 -0
- data/lib/cloudcost/error.rb +2 -0
- data/lib/cloudcost/pricing.rb +0 -3
- data/lib/cloudcost/version.rb +1 -1
- data/lib/cloudcost.rb +4 -8
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b58764fd578b202e42b613003289f95b778b9c409f6bcb4c9ce6d565c90016d
|
4
|
+
data.tar.gz: f8137acc0b1c0529550b5a1c135fcb808ca3e1596ea6d22b018aa117c6f44311
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a277fafc87edfc66ea733900e62bb801879cc8434974901b8e1c34532bc4e5fddbc3b3b3ba04a14c478e6045de999aaf3bbfa72297b8f69a718da5461f9751
|
7
|
+
data.tar.gz: 74f8f13db587ccc0bfd0ca94ac5444a6238cde48744c23957432235bb7ed2e7d06d91a6ab0ba38f7911bb2de8abe0993ccd59539c51deef20edd2ef72c5c9327
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cloudcost (0.3.
|
4
|
+
cloudcost (0.3.1)
|
5
5
|
excon (~> 0.85.0)
|
6
6
|
parseconfig (~> 1.1.0)
|
7
7
|
terminal-table (~> 3.0.1)
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
specs:
|
14
14
|
excon (0.85.0)
|
15
15
|
parseconfig (1.1.0)
|
16
|
-
terminal-table (3.0.
|
16
|
+
terminal-table (3.0.2)
|
17
17
|
unicode-display_width (>= 1.1.1, < 3)
|
18
18
|
thor (1.1.0)
|
19
19
|
tty-cursor (0.7.1)
|
data/README.md
CHANGED
@@ -19,8 +19,7 @@ gem install cloudcost
|
|
19
19
|
|
20
20
|
cloudcost does support the same auth configuration options as [cloudscale-cli](https://cloudscale-ch.github.io/cloudscale-cli/).
|
21
21
|
|
22
|
-
You can manage multiple profiles using `cloudscale.ini` files ([see here](https://cloudscale-ch.github.io/cloudscale-cli/auth/) for instructions).
|
23
|
-
|
22
|
+
You can manage multiple profiles using `cloudscale.ini` files ([see here](https://cloudscale-ch.github.io/cloudscale-cli/auth/) for instructions).
|
24
23
|
|
25
24
|
Otherwise you can export a `CLOUDSCALE_API_TOKEN` in your environment:
|
26
25
|
|
data/lib/cloudcost/api_token.rb
CHANGED
data/lib/cloudcost/cli.rb
CHANGED
@@ -45,11 +45,7 @@ module Cloudcost
|
|
45
45
|
end
|
46
46
|
rescue Excon::Error, TokenError, ProfileError, PricingError => e
|
47
47
|
error_message = "ERROR: #{e.message}"
|
48
|
-
|
49
|
-
spinner.error("(#{error_message})")
|
50
|
-
else
|
51
|
-
puts error_message
|
52
|
-
end
|
48
|
+
spinner ? spinner.error(error_message) : puts(error_message)
|
53
49
|
end
|
54
50
|
|
55
51
|
desc "server-tags", "show and assign tags of servers"
|
@@ -80,19 +76,18 @@ module Cloudcost
|
|
80
76
|
(options[:remove_tags] || []).each do |tag|
|
81
77
|
tags.reject! { |k| k == tag.to_sym }
|
82
78
|
end
|
83
|
-
|
84
|
-
|
79
|
+
begin
|
80
|
+
api_connection(options).set_server_tags(server.uuid, tags)
|
81
|
+
spinner.success
|
82
|
+
rescue Excon::Error => e
|
83
|
+
spinner.error "ERROR: #{e.message}"
|
84
|
+
end
|
85
85
|
end
|
86
86
|
end
|
87
87
|
spinners.auto_spin
|
88
88
|
end
|
89
|
-
rescue
|
90
|
-
|
91
|
-
if defined?(spinner)
|
92
|
-
spinner.error("(#{error_message})")
|
93
|
-
else
|
94
|
-
puts error_message
|
95
|
-
end
|
89
|
+
rescue Cloudcost::TokenError, Cloudcost::ProfileError => e
|
90
|
+
puts "ERROR: #{e.message}"
|
96
91
|
end
|
97
92
|
|
98
93
|
desc "volumes", "explore volumes"
|
@@ -101,6 +96,7 @@ module Cloudcost
|
|
101
96
|
option :summary, desc: "display totals only", type: :boolean, aliases: %w[-S]
|
102
97
|
option :type, enum: %w[ssd bulk], desc: "volume type"
|
103
98
|
option :attached, type: :boolean, desc: "volume attached to servers"
|
99
|
+
option :output, default: "table", enum: %w[table csv], desc: "output format", aliases: %w[-o]
|
104
100
|
def volumes
|
105
101
|
volumes = load_volumes(options)
|
106
102
|
if options[:output] == "table"
|
@@ -111,13 +107,9 @@ module Cloudcost
|
|
111
107
|
spinner&.success("(done)")
|
112
108
|
puts result
|
113
109
|
end
|
114
|
-
rescue Excon::Error, TokenError, ProfileError, PricingError => e
|
110
|
+
rescue Excon::Error, Cloudcost::TokenError, Cloudcost::ProfileError, Cloudcost::PricingError => e
|
115
111
|
error_message = "ERROR: #{e.message}"
|
116
|
-
|
117
|
-
spinner.error("(#{error_message})")
|
118
|
-
else
|
119
|
-
puts error_message
|
120
|
-
end
|
112
|
+
spinner ? spinner.error(error_message) : puts(error_message)
|
121
113
|
end
|
122
114
|
|
123
115
|
no_tasks do
|
@@ -140,9 +132,12 @@ module Cloudcost
|
|
140
132
|
spinner = TTY::Spinner.new("[:spinner] Loading servers...", clear: options[:csv])
|
141
133
|
spinner.auto_spin
|
142
134
|
end
|
143
|
-
servers = api_connection(options).get_servers(options).map { |server| Server.new(server) }
|
135
|
+
servers = api_connection(options).get_servers(options).map { |server| Cloudcost::Server.new(server) }
|
144
136
|
spinner&.success "(#{servers.size} found)"
|
145
137
|
servers
|
138
|
+
rescue Excon::Error => e
|
139
|
+
spinner&.error "ERROR: #{e.message}"
|
140
|
+
[]
|
146
141
|
end
|
147
142
|
|
148
143
|
def load_volumes(options)
|
@@ -150,13 +145,18 @@ module Cloudcost
|
|
150
145
|
spinner = TTY::Spinner.new("[:spinner] Loading volumes...", clear: options[:csv])
|
151
146
|
spinner.auto_spin
|
152
147
|
end
|
153
|
-
volumes = api_connection(options).get_volumes(options).map { |volume| Volume.new(volume) }
|
148
|
+
volumes = api_connection(options).get_volumes(options).map { |volume| Cloudcost::Volume.new(volume) }
|
154
149
|
spinner&.success "(#{volumes.size} found)"
|
155
150
|
volumes
|
151
|
+
rescue Excon::Error => e
|
152
|
+
spinner&.error "\ERROR: #{e.message}"
|
153
|
+
[]
|
156
154
|
end
|
157
155
|
|
158
156
|
def output_servers(servers, options)
|
159
|
-
if
|
157
|
+
if servers.size < 1
|
158
|
+
yield "WARNING: No servers found."
|
159
|
+
elsif options[:group_by]
|
160
160
|
yield Cloudcost::ServerList.new(servers, options).grouped_costs
|
161
161
|
elsif options[:output] == "csv"
|
162
162
|
yield Cloudcost::ServerList.new(servers, options).to_csv
|
@@ -170,7 +170,13 @@ module Cloudcost
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def output_volumes(volumes, options)
|
173
|
-
|
173
|
+
if volumes.size < 1
|
174
|
+
yield "WARNING: No volumes found."
|
175
|
+
elsif options[:output] == "csv"
|
176
|
+
yield Cloudcost::VolumeList.new(volumes, options).to_csv
|
177
|
+
else
|
178
|
+
yield Cloudcost::VolumeList.new(volumes, options).cost_table
|
179
|
+
end
|
174
180
|
end
|
175
181
|
|
176
182
|
def tag_option_to_s(options)
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Cloudcost
|
4
4
|
# ServerList represents a list of servers and integrates several output methods
|
5
5
|
class ServerList
|
6
|
-
include Cloudcost::
|
6
|
+
include Cloudcost::ServerTabularOutput
|
7
|
+
include Cloudcost::ServerInfluxdbOutput
|
7
8
|
include Cloudcost::CsvOutput
|
8
|
-
include Cloudcost::InfluxdbOutput
|
9
9
|
|
10
10
|
def initialize(servers, options = {})
|
11
11
|
@servers = servers
|
File without changes
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "terminal-table"
|
4
|
+
|
3
5
|
module Cloudcost
|
4
6
|
# volumeList represents a list of volumes and integrates several output methods
|
5
7
|
class VolumeList
|
6
8
|
|
9
|
+
include Cloudcost::CsvOutput
|
10
|
+
|
7
11
|
def initialize(volumes, options = {})
|
8
12
|
@volumes = volumes
|
9
13
|
@options = options
|
@@ -71,16 +75,5 @@ module Cloudcost
|
|
71
75
|
table
|
72
76
|
end
|
73
77
|
|
74
|
-
def grouped_cost_table(group_rows)
|
75
|
-
table = Terminal::Table.new do |t|
|
76
|
-
t.title = "cloudscale.ch volume costs grouped by tag \"#{@options[:group_by]}\""
|
77
|
-
t.title += " (#{@options[:profile]})" if @options[:profile]
|
78
|
-
t.headings = headings
|
79
|
-
end
|
80
|
-
table.rows = group_rows
|
81
|
-
(1..table.columns.size).each { |column| table.align_column(column, :right) }
|
82
|
-
table
|
83
|
-
end
|
84
|
-
|
85
78
|
end
|
86
79
|
end
|
data/lib/cloudcost/error.rb
CHANGED
data/lib/cloudcost/pricing.rb
CHANGED
data/lib/cloudcost/version.rb
CHANGED
data/lib/cloudcost.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "terminal-table"
|
4
3
|
require "csv"
|
5
4
|
|
6
5
|
require "cloudcost/version"
|
6
|
+
require "cloudcost/error"
|
7
7
|
require "cloudcost/api_token"
|
8
8
|
require "cloudcost/api_connection"
|
9
|
-
require "cloudcost/
|
10
|
-
require "cloudcost/
|
11
|
-
require "cloudcost/
|
12
|
-
require "cloudcost/csv_output"
|
13
|
-
require "cloudcost/server_list"
|
14
|
-
require "cloudcost/volume"
|
15
|
-
require "cloudcost/volume_list"
|
9
|
+
require "cloudcost/pricing"
|
10
|
+
require "cloudcost/commands/server"
|
11
|
+
require "cloudcost/commands/volume"
|
16
12
|
require "cloudcost/cli"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudcost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nik Wolfgramm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -102,16 +102,18 @@ files:
|
|
102
102
|
- lib/cloudcost/api_connection.rb
|
103
103
|
- lib/cloudcost/api_token.rb
|
104
104
|
- lib/cloudcost/cli.rb
|
105
|
-
- lib/cloudcost/csv_output.rb
|
105
|
+
- lib/cloudcost/commands/csv_output.rb
|
106
|
+
- lib/cloudcost/commands/server.rb
|
107
|
+
- lib/cloudcost/commands/server/server.rb
|
108
|
+
- lib/cloudcost/commands/server/server_influxdb_output.rb
|
109
|
+
- lib/cloudcost/commands/server/server_list.rb
|
110
|
+
- lib/cloudcost/commands/server/server_tabular_output.rb
|
111
|
+
- lib/cloudcost/commands/volume.rb
|
112
|
+
- lib/cloudcost/commands/volume/volume.rb
|
113
|
+
- lib/cloudcost/commands/volume/volume_list.rb
|
106
114
|
- lib/cloudcost/error.rb
|
107
|
-
- lib/cloudcost/influxdb_output.rb
|
108
115
|
- lib/cloudcost/pricing.rb
|
109
|
-
- lib/cloudcost/server.rb
|
110
|
-
- lib/cloudcost/server_list.rb
|
111
|
-
- lib/cloudcost/tabular_output.rb
|
112
116
|
- lib/cloudcost/version.rb
|
113
|
-
- lib/cloudcost/volume.rb
|
114
|
-
- lib/cloudcost/volume_list.rb
|
115
117
|
homepage: https://gitlab.puzzle.ch/nwolfgramm/cloudcost
|
116
118
|
licenses:
|
117
119
|
- MIT
|