brightbox-cli 4.2.0 → 4.3.0

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: ca69156ede91fd3e18f145220446de7c27201dab8cbfeaeb345e8ecb7e5a0b4d
4
- data.tar.gz: 6d3490e0f8eabb5d92ed1df481f7ca2bba8a359d7fdf02b554b0265d1fee7294
3
+ metadata.gz: 517f21d7fc3e156180d8558868220e332943bd12ee492754e727d3f23d03d89c
4
+ data.tar.gz: ba05065d1729812c1aa1b41f44767872ea863a8295f8074ae8050742c1903e68
5
5
  SHA512:
6
- metadata.gz: 6e0d7038f22cf7dae99d961782761a587b7b3a13f3ad7bd00d17a95816c696b77463b681066993355c7478a935414068d98173110eefa17a38e00e24c2d9a3ec
7
- data.tar.gz: 78db49f41e1d8d89fd1b69dfb70cd4d316a9d85b30f3c45c77af541934b2682b5c8e4eef07bafdaba19ca3cf29ea061fe0420c1a2c7b8221f754b7b0bafa154c
6
+ metadata.gz: 1218d3d1956bac00755dde84bc1546f43dc05f4ea3386420b47745039326ad01f50f016faee353474e620beba0105e059de437085334da2bb4c6545392426880
7
+ data.tar.gz: 8ca4763dfbc21624b85ca97ea70525da34e4a2adb19abb405b2f95b8f8df500180a7780d0d13ffc6bc9cfade8306ed904a0fbbd56e95af1ad33ab913f16c6e7a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,29 @@
1
+ ### v4.3.0 / 2023-01-11
2
+
3
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.2.1...v4.3.0)
4
+
5
+ Enhancements:
6
+
7
+ * Adds `volumes` subcommand for Volume management.
8
+
9
+ Changes:
10
+
11
+ * Update `fog-brightbox` to `v1.7.0`
12
+
13
+ ### v4.2.1 / 2022-11-16
14
+
15
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.2.0...v4.2.1)
16
+
17
+ Bug fixes:
18
+
19
+ * Bumped version of `highline` gem to fix issue when prompting for password during `brightbox login` command on Ruby 3.0+.
20
+ * Fixed help output for `brightbox login` by correcting DSL declaration.
21
+
1
22
  ### v4.2.0 / 2022-11-01
2
23
 
3
24
  [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.1.0...v4.2.0)
4
25
 
5
- Changes:
26
+ Enhancements:
6
27
 
7
28
  * Adds three new, mutually exclusive options to `images create` to specify
8
29
  different sources:
@@ -15,7 +36,7 @@ Changes:
15
36
 
16
37
  [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.0.0...v4.1.0)
17
38
 
18
- Changes:
39
+ Enhancements:
19
40
 
20
41
  * Adds `volume-size` to `servers create` to allow passing of arbitrary sizes for
21
42
  network based storage types.
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightbox-cli (4.2.0)
4
+ brightbox-cli (4.3.0)
5
5
  dry-inflector (= 0.2.0)
6
- fog-brightbox (>= 1.8.0)
6
+ fog-brightbox (>= 1.9.1)
7
7
  fog-core (< 2.0)
8
8
  gli (~> 2.21)
9
- highline (~> 1.6)
9
+ highline (~> 2.0)
10
10
  hirb (~> 0.6)
11
11
  i18n (>= 0.6, < 1.11)
12
12
  mime-types (~> 3.0)
@@ -25,8 +25,8 @@ GEM
25
25
  rexml
26
26
  diff-lcs (1.5.0)
27
27
  dry-inflector (0.2.0)
28
- excon (0.93.1)
29
- fog-brightbox (1.8.0)
28
+ excon (0.97.0)
29
+ fog-brightbox (1.9.1)
30
30
  dry-inflector
31
31
  fog-core (>= 1.45, < 3.0)
32
32
  fog-json
@@ -40,7 +40,7 @@ GEM
40
40
  formatador (0.3.0)
41
41
  gli (2.21.0)
42
42
  hashdiff (1.0.1)
43
- highline (1.7.10)
43
+ highline (2.1.0)
44
44
  hirb (0.7.3)
45
45
  i18n (1.10.0)
46
46
  concurrent-ruby (~> 1.0)
@@ -117,4 +117,4 @@ DEPENDENCIES
117
117
  webmock
118
118
 
119
119
  BUNDLED WITH
120
- 2.1.4
120
+ 2.2.33
@@ -21,10 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency "fog-brightbox", ">= 1.8.0"
24
+ s.add_dependency "fog-brightbox", ">= 1.9.1"
25
25
  s.add_dependency "fog-core", "< 2.0"
26
26
  s.add_dependency "gli", "~> 2.21"
27
- s.add_dependency "highline", "~> 1.6"
27
+ s.add_dependency "highline", "~> 2.0"
28
28
  s.add_dependency "hirb", "~> 0.6"
29
29
  s.add_dependency "i18n", ">= 0.6", "< 1.11"
30
30
  s.add_dependency "mime-types", "~> 3.0"
@@ -1,13 +1,12 @@
1
1
  module Brightbox
2
+ desc I18n.t("login.desc")
3
+ arg :email
2
4
  command [:login] do |cmd|
3
- cmd.desc I18n.t("login.desc")
4
- cmd.arg_name "email"
5
-
6
5
  cmd.desc "password, if not specified you will be prompted"
7
- cmd.flag [:p, "password"]
6
+ cmd.flag [:p, "password"], arg_name: "password"
8
7
 
9
- cmd.desc "default account"
10
- cmd.flag [:"default-account"]
8
+ cmd.desc "Set a default account"
9
+ cmd.flag [:"default-account"], arg_name: "acc-12345"
11
10
 
12
11
  cmd.flag [:"application-id"]
13
12
  cmd.flag [:"application-secret"]
@@ -0,0 +1,36 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.attach.desc")
4
+ cmd.arg_name I18n.t("volumes.attach.args")
5
+
6
+ cmd.command [:attach] do |c|
7
+ c.desc I18n.t("volumes.options.boot")
8
+ c.default_value false
9
+ c.switch [:boot], negatable: true
10
+
11
+ c.action do |global_options, options, args|
12
+ vol_id = args.shift
13
+
14
+ if vol_id.nil? || !vol_id.start_with?("vol-")
15
+ raise I18n.t("volumes.args.specify_one_id_first")
16
+ end
17
+
18
+ srv_id = args.shift
19
+
20
+ if srv_id.nil? || !srv_id.start_with?("srv-")
21
+ raise I18n.t("volumes.attach.specify_server_id_second")
22
+ end
23
+
24
+ boot_flag = options[:boot]
25
+
26
+ volume = Volume.find(vol_id)
27
+
28
+ info I18n.t("volumes.attach.acting", volume: volume)
29
+ volume.attach(server: srv_id, boot: boot_flag)
30
+ volume.reload
31
+
32
+ render_table([volume], global_options)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.copy.desc")
4
+ cmd.arg_name I18n.t("volumes.args.one")
5
+
6
+ cmd.command [:copy] do |c|
7
+ c.desc I18n.t("options.description.desc")
8
+ c.flag %i[d description]
9
+
10
+ c.desc I18n.t("volumes.options.delete_with_server")
11
+ c.default_value false
12
+ c.switch ["delete-with-server"], negatable: true
13
+
14
+ c.desc I18n.t("options.name.desc")
15
+ c.flag %i[n name]
16
+
17
+ c.desc I18n.t("volumes.options.serial")
18
+ c.flag [:serial]
19
+
20
+ c.action do |global_options, options, args|
21
+ vol_id = args.shift
22
+
23
+ if vol_id.nil? || !vol_id.start_with?("vol-")
24
+ raise I18n.t("volumes.args.specify_one_id_first")
25
+ end
26
+
27
+ params = {
28
+ delete_with_server: options["delete-with-server"]
29
+ }
30
+ params[:description] = options[:description] if options[:description]
31
+ params[:name] = options[:name] if options[:name]
32
+ params[:serial] = options[:serial] if options[:serial]
33
+
34
+ volume = Volume.find(vol_id)
35
+
36
+ unless params.empty?
37
+ info I18n.t("volumes.copy.acting", volume: volume)
38
+ volume.copy(params)
39
+ end
40
+
41
+ render_table([volume], global_options)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.create.desc")
4
+
5
+ cmd.command [:create] do |c|
6
+ c.desc I18n.t("options.description.desc")
7
+ c.flag %i[d description]
8
+
9
+ c.desc I18n.t("volumes.options.delete_with_server")
10
+ c.default_value false
11
+ c.switch ["delete-with-server"], negatable: true
12
+
13
+ c.desc I18n.t("volumes.options.encrypted")
14
+ c.switch %i[e encrypted], negatable: true
15
+
16
+ c.desc I18n.t("volumes.options.fs_label")
17
+ c.flag ["fs-label"]
18
+
19
+ c.desc I18n.t("volumes.options.fs_type")
20
+ c.flag ["fs-type"]
21
+
22
+ c.desc I18n.t("volumes.options.image")
23
+ c.flag %i[i image]
24
+
25
+ c.desc I18n.t("options.name.desc")
26
+ c.flag %i[n name]
27
+
28
+ c.desc I18n.t("volumes.options.serial")
29
+ c.flag [:serial]
30
+
31
+ c.desc I18n.t("volumes.options.size")
32
+ c.flag %i[s size]
33
+
34
+ c.action do |global_options, options, _args|
35
+ if options[:image].nil? && options[:"fs-type"].nil?
36
+ raise I18n.t("volumes.create.image_or_type_required")
37
+ end
38
+
39
+ if !options[:image].nil? && !options[:"fs-type"].nil?
40
+ raise I18n.t("volumes.create.either_image_or_type")
41
+ end
42
+
43
+ params = {
44
+ delete_with_server: options[:"delete-with-server"],
45
+ encrypted: options[:encrypted]
46
+ }
47
+
48
+ params[:filesystem_label] = options[:"fs-label"] if options[:"fs-label"]
49
+ params[:filesystem_type] = options[:"fs-type"] if options[:"fs-type"]
50
+ params[:image_id] = options[:image] if options[:image]
51
+
52
+ params[:description] = options[:description] if options[:description]
53
+ params[:name] = options[:name] if options[:name]
54
+ params[:serial] = options[:serial] if options[:serial]
55
+ params[:size] = options[:size] if options[:size]
56
+
57
+ info I18n.t("volumes.create.acting")
58
+ volume = Volume.create(params)
59
+ render_table([volume], global_options)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.destroy.desc")
4
+ cmd.arg_name I18n.t("volumes.args.many")
5
+
6
+ cmd.command [:destroy] do |c|
7
+ c.action do |_global_options, _options, args|
8
+ raise I18n.t("volumes.args.specify_many_ids") if args.empty?
9
+
10
+ volumes = Volume.find_or_call(args) do |id|
11
+ raise I18n.t("volumes.args.unknown_id", volume: volume)
12
+ end
13
+
14
+ volumes.each do |volume|
15
+ info I18n.t("volumes.destroy.acting", volume: volume)
16
+
17
+ begin
18
+ volume.destroy
19
+ rescue Brightbox::Api::Conflict
20
+ error "Could not destroy #{id}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.detach.desc")
4
+ cmd.arg_name I18n.t("volumes.args.many")
5
+
6
+ cmd.command [:detach] do |c|
7
+ c.action do |global_options, _options, args|
8
+ raise I18n.t("volumes.args.specify_many_ids") if args.empty?
9
+
10
+ volumes = Volume.find_or_call(args) do |volume|
11
+ raise I18n.t("volumes.args.unknown_id", volume: volume)
12
+ end
13
+
14
+ volumes.each do |volume|
15
+ info I18n.t("volumes.detach.acting", volume: volume)
16
+ volume.detach
17
+ end
18
+
19
+ render_table(volumes, global_options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.default_command :list
4
+
5
+ cmd.desc I18n.t("volumes.list.desc")
6
+ cmd.arg_name I18n.t("volumes.args.optional")
7
+
8
+ cmd.command [:list] do |c|
9
+ c.action do |global_options, _options, args|
10
+ volumes = Volume.find_all_or_warn(args)
11
+
12
+ render_table(volumes, global_options)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.lock.desc")
4
+ cmd.arg_name I18n.t("volumes.args.many")
5
+
6
+ cmd.command [:lock] do |c|
7
+ c.action do |_global_options, _options, args|
8
+ raise I18n.t("volumes.args.specify_many_ids") if args.empty?
9
+
10
+ volumes = Volume.find_or_call(args) do |volume|
11
+ raise I18n.t("volumes.args.unknown_id", volume: volume)
12
+ end
13
+
14
+ volumes.each do |volume|
15
+ info I18n.t("volumes.lock.acting", volume: volume)
16
+ volume.lock!
17
+ end
18
+ end
19
+ end
20
+
21
+ cmd.desc I18n.t("volumes.unlock.desc")
22
+ cmd.arg_name I18n.t("volumes.args.many")
23
+
24
+ cmd.command [:unlock] do |c|
25
+ c.action do |_global_options, _options, args|
26
+ raise I18n.t("volumes.args.specify_many_ids") if args.empty?
27
+
28
+ volumes = Volume.find_or_call(args) do |volume|
29
+ raise I18n.t("volumes.args.unknown_id", volume: volume)
30
+ end
31
+
32
+ volumes.each do |volume|
33
+ info I18n.t("volumes.unlock.acting", volume: volume)
34
+ volume.unlock!
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.resize.desc")
4
+ cmd.arg_name I18n.t("volumes.args.one")
5
+
6
+ cmd.command [:resize] do |c|
7
+ c.desc I18n.t("volumes.options.size")
8
+ c.flag %i[s size]
9
+
10
+ c.action do |global_options, options, args|
11
+ vol_id = args.shift
12
+
13
+ if vol_id.nil? || !vol_id.start_with?("vol-")
14
+ raise I18n.t("volumes.args.specify_one_id_first")
15
+ end
16
+
17
+ if options[:size].nil?
18
+ raise I18n.t("volumes.resize.size_option_needed")
19
+ end
20
+
21
+ new_size = options[:size].to_i
22
+
23
+ volume = Volume.find(vol_id)
24
+ old_size = volume.size
25
+
26
+ info I18n.t("volumes.resize.acting", volume: volume)
27
+ volume.resize(
28
+ from: old_size,
29
+ to: new_size
30
+ )
31
+
32
+ render_table([volume], global_options)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.show.desc")
4
+ cmd.arg_name I18n.t("volumes.args.optional")
5
+
6
+ cmd.command [:show] do |c|
7
+ c.action do |global_options, _options, args|
8
+ volumes = Volume.find_all_or_warn(args)
9
+
10
+ table_opts = global_options.merge(
11
+ :vertical => true,
12
+ :fields => Volume.detailed_fields
13
+ )
14
+ render_table(volumes, table_opts)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ module Brightbox
2
+ command [:volumes] do |cmd|
3
+ cmd.desc I18n.t("volumes.update.desc")
4
+ cmd.arg_name I18n.t("volumes.args.one")
5
+
6
+ cmd.command [:update] do |c|
7
+ c.desc I18n.t("options.description.desc")
8
+ c.flag %i[d description]
9
+
10
+ c.desc I18n.t("volumes.options.delete_with_server")
11
+ c.default_value :ignore # So we can discard unless deliberately passed
12
+ c.switch ["delete-with-server"], negatable: true
13
+
14
+ c.desc I18n.t("options.name.desc")
15
+ c.flag %i[n name]
16
+
17
+ c.desc I18n.t("volumes.options.serial")
18
+ c.flag [:serial]
19
+
20
+ c.action do |global_options, options, args|
21
+ vol_id = args.shift
22
+
23
+ if vol_id.nil? || !vol_id.start_with?("vol-")
24
+ raise I18n.t("volumes.args.specify_one_id_first")
25
+ end
26
+
27
+ params = {}
28
+
29
+ # Switches will always appear in the options so we need a non-boolean
30
+ # setting to determine if the user did not add it to their command
31
+ unless options["delete-with-server"] == :ignore
32
+ params[:delete_with_server] = options["delete-with-server"]
33
+ end
34
+
35
+ params[:description] = options[:description] if options[:description]
36
+ params[:name] = options[:name] if options[:name]
37
+ params[:serial] = options[:serial] if options[:serial]
38
+
39
+ volume = Volume.find(vol_id)
40
+
41
+ unless params.empty?
42
+ info I18n.t("volumes.update.acting", volume: volume)
43
+ volume.update(params)
44
+ end
45
+
46
+ render_table([volume], global_options)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -31,9 +31,21 @@ module Brightbox
31
31
  row_attributes[:server_groups] = server_groups.map { |sg| sg["id"] }.join(", ")
32
32
  end
33
33
 
34
+ row_attributes[:volumes] = volume_ids if volumes
35
+
34
36
  row_attributes
35
37
  end
36
38
 
39
+ def volume_ids
40
+ volumes.map do |vol|
41
+ if vol["boot"] == true
42
+ "*#{vol['id']}*"
43
+ else
44
+ vol["id"]
45
+ end
46
+ end.join(", ")
47
+ end
48
+
37
49
  def self.default_field_order
38
50
  %i[
39
51
  id
@@ -65,6 +77,7 @@ module Brightbox
65
77
  cloud_ipv6s
66
78
  snapshots
67
79
  server_groups
80
+ volumes
68
81
  ]
69
82
  end
70
83
  end
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "4.2.0".freeze unless defined?(Brightbox::VERSION)
2
+ VERSION = "4.3.0".freeze unless defined?(Brightbox::VERSION)
3
3
  end
@@ -0,0 +1,81 @@
1
+ module Brightbox
2
+ class Volume < Api
3
+ def self.require_account?; true; end
4
+
5
+ def self.all
6
+ conn.volumes
7
+ end
8
+
9
+ def self.create(options)
10
+ new(conn.volumes.create(options))
11
+ end
12
+
13
+ def self.get(id)
14
+ conn.volumes.get(id)
15
+ end
16
+
17
+ def self.default_field_order
18
+ %i[
19
+ id
20
+ type
21
+ size
22
+ status
23
+ server
24
+ boot
25
+ name
26
+ ]
27
+ end
28
+
29
+ def self.detailed_fields
30
+ %i[
31
+ id
32
+ name
33
+ description
34
+ type
35
+ size
36
+ status
37
+ created_at
38
+ encrypted
39
+ serial
40
+ locked
41
+ filesystem_label
42
+ filesystem_type
43
+ image
44
+ source
45
+ source_type
46
+ server
47
+ boot
48
+ delete_with_server
49
+ zone
50
+ ]
51
+ end
52
+
53
+ def attach(server:, boot: false)
54
+ self.class.conn.attach_volume(id, server: server, boot: boot)
55
+ reload
56
+ self
57
+ end
58
+
59
+ def attributes
60
+ a = fog_model.attributes
61
+ a[:id] = fog_model.id
62
+ a[:image] = image_id
63
+ a[:locked] = locked?
64
+ a[:server] = server_id
65
+ a[:status] = state
66
+ a[:type] = storage_type
67
+ a[:zone] = zone_id
68
+ a
69
+ end
70
+
71
+ def to_row
72
+ attributes
73
+ end
74
+
75
+ def update(options)
76
+ self.class.conn.update_volume(id, options)
77
+ reload
78
+ self
79
+ end
80
+ end
81
+ end
data/lib/brightbox_cli.rb CHANGED
@@ -56,6 +56,7 @@ module Brightbox
56
56
  autoload :DatabaseType, File.expand_path("brightbox-cli/database_type", __dir__)
57
57
  autoload :DatabaseServer, File.expand_path("brightbox-cli/database_server", __dir__)
58
58
  autoload :DatabaseSnapshot, File.expand_path("brightbox-cli/database_snapshot", __dir__)
59
+ autoload :Volume, File.expand_path("brightbox-cli/volume", __dir__)
59
60
  autoload :Token, File.expand_path("brightbox-cli/token", __dir__)
60
61
 
61
62
  module Config