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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d4a4e7ae052a00c793f664be431acc0b93c1e8a32e69dc7f1263efb6fd820cd
4
- data.tar.gz: bc0001f2c9b44a19da53c9a5ea446b441de78236c787bc434820ffbb6504246b
3
+ metadata.gz: 1b58764fd578b202e42b613003289f95b778b9c409f6bcb4c9ce6d565c90016d
4
+ data.tar.gz: f8137acc0b1c0529550b5a1c135fcb808ca3e1596ea6d22b018aa117c6f44311
5
5
  SHA512:
6
- metadata.gz: 5d9d615b734291387c9adbb5ac28a619a65d359fbf584af406175496abe1450f6a8ce5a7365a16f42319744959fbbdf7eb6ae556b49e47929b7dc46521f15a79
7
- data.tar.gz: 8672668910d5c4e6de0115bb4c64466283afcb43baeb791914e3a62cd399d0b7285d8d86ad45a21692d3f447ad0249ea66463a02ef4cc47b931a291a8b0d0024
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.0)
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.1)
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
 
@@ -3,7 +3,6 @@
3
3
  require "parseconfig"
4
4
  require "excon"
5
5
  require "json"
6
- require "cloudcost/error"
7
6
 
8
7
  module Cloudcost
9
8
  # Support for cloudscale-cli style API-tokens and profiles
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
- if spinner
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
- api_connection(options).set_server_tags(server.uuid, tags)
84
- spinner.success
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 Excon::Error, TokenError, ProfileError => e
90
- error_message = "ERROR: #{e.message}"
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
- if spinner
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 options[:group_by]
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
- yield Cloudcost::VolumeList.new(volumes, options).cost_table
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)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudcost
4
- # CSV output methods for the ServerList class
4
+ # generic CSV output methods
5
5
  module CsvOutput
6
6
  def groups_to_csv(group_rows)
7
7
  CSV.generate do |csv|
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cloudcost/pricing"
4
-
5
3
  module Cloudcost
6
4
  def self.tags_to_s(tag_hash = [])
7
5
  tag_hash.map { |k, v| "#{k}=#{v}" }.join(" ")
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Cloudcost
4
4
  # InfluxDB output methods for the ServerList class
5
- module InfluxdbOutput
5
+ module ServerInfluxdbOutput
6
6
  def grouped_influx_line_protocol(group_rows)
7
7
  lines = []
8
8
  group_rows.each do |row|
@@ -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::TabularOutput
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
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "terminal-table"
4
+
3
5
  module Cloudcost
4
6
  # Tabular output methods for the ServerList class
5
- module TabularOutput
7
+ module ServerTabularOutput
6
8
  def headings
7
9
  headings = if @options[:summary]
8
10
  [""]
@@ -0,0 +1,6 @@
1
+
2
+ require_relative "server/server_tabular_output"
3
+ require_relative "server/server_influxdb_output"
4
+ require_relative "csv_output"
5
+ require_relative "server/server"
6
+ require_relative "server/server_list"
@@ -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
@@ -0,0 +1,4 @@
1
+
2
+ require_relative "csv_output"
3
+ require_relative "volume/volume"
4
+ require_relative "volume/volume_list"
@@ -6,4 +6,6 @@ module Cloudcost
6
6
  class ProfileError < Error; end
7
7
 
8
8
  class TokenError < Error; end
9
+
10
+ class PricingError < StandardError; end
9
11
  end
@@ -7,9 +7,6 @@ PRICING = YAML.load_file(File.join(
7
7
  ))
8
8
 
9
9
  module Cloudcost
10
- class PricingError < StandardError
11
- end
12
-
13
10
  # pricing class which implements cost calculation methods for cloudscale.ch resources
14
11
  module Pricing
15
12
  def self.server_costs_per_day(flavor)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudcost
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
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/server"
10
- require "cloudcost/tabular_output"
11
- require "cloudcost/influxdb_output"
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.0
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-19 00:00:00.000000000 Z
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