brightbox-cli 4.1.0 → 4.2.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: fc36c35cb32073368b55abc445d0720ce2e635336e1c3b8af4ef9e1dcedc0000
4
- data.tar.gz: '0351935cba15d3c1503c1e8c44d7d4f5258d3d07f67700d363a5b043e58e287e'
3
+ metadata.gz: ca69156ede91fd3e18f145220446de7c27201dab8cbfeaeb345e8ecb7e5a0b4d
4
+ data.tar.gz: 6d3490e0f8eabb5d92ed1df481f7ca2bba8a359d7fdf02b554b0265d1fee7294
5
5
  SHA512:
6
- metadata.gz: e230034d8c611139a5ed70b1508f1aef3ff3dd263e8f8f53acd58aad72c0616bdcfd5c44ae267e1fa27be66c7958e25e7de986f9169e29c484a47f4b5ceb1e0b
7
- data.tar.gz: c4672a3f3efcb30390a6fb536d2542c36988fbb1ba82b5fa59d6dfa1f58868d5518e36ac48f54d9987294b0de46531f0c9b8cb383d21817631a0436008d3e825
6
+ metadata.gz: 6e0d7038f22cf7dae99d961782761a587b7b3a13f3ad7bd00d17a95816c696b77463b681066993355c7478a935414068d98173110eefa17a38e00e24c2d9a3ec
7
+ data.tar.gz: 78db49f41e1d8d89fd1b69dfb70cd4d316a9d85b30f3c45c77af541934b2682b5c8e4eef07bafdaba19ca3cf29ea061fe0420c1a2c7b8221f754b7b0bafa154c
data/CHANGELOG.md CHANGED
@@ -1,10 +1,24 @@
1
+ ### v4.2.0 / 2022-11-01
2
+
3
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.1.0...v4.2.0)
4
+
5
+ Changes:
6
+
7
+ * Adds three new, mutually exclusive options to `images create` to specify
8
+ different sources:
9
+ * `url` can specify source as a URL for a HTTP or HTTPS download rather than
10
+ an existing FTP upload.
11
+ * `server` can specify a server ID to create a snapshot image from.
12
+ * `volume` can specify a volume ID to create a snapshot image from.
13
+
1
14
  ### v4.1.0 / 2022-08-01
2
15
 
3
16
  [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.0.0...v4.1.0)
4
17
 
5
18
  Changes:
6
19
 
7
- * Add `volume-size` to `servers create` to allow passing of arbitary sizes for network based storage types.
20
+ * Adds `volume-size` to `servers create` to allow passing of arbitrary sizes for
21
+ network based storage types.
8
22
 
9
23
  ### v4.0.0 / 2022-08-01
10
24
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightbox-cli (4.1.0)
4
+ brightbox-cli (4.2.0)
5
5
  dry-inflector (= 0.2.0)
6
6
  fog-brightbox (>= 1.8.0)
7
7
  fog-core (< 2.0)
@@ -25,7 +25,7 @@ GEM
25
25
  rexml
26
26
  diff-lcs (1.5.0)
27
27
  dry-inflector (0.2.0)
28
- excon (0.92.4)
28
+ excon (0.93.1)
29
29
  fog-brightbox (1.8.0)
30
30
  dry-inflector
31
31
  fog-core (>= 1.45, < 3.0)
@@ -11,17 +11,26 @@ module Brightbox
11
11
  c.desc "Image Username"
12
12
  c.flag [:u, "username"]
13
13
 
14
- c.desc "Archtecture of the image (i686 or x86_64)"
14
+ c.desc "Architecture of the image (i686 or x86_64)"
15
15
  c.flag [:a, "arch"]
16
16
 
17
17
  c.desc "Source filename of the image you uploaded to the image library"
18
18
  c.flag [:s, "source"]
19
19
 
20
+ c.desc "Source server ID to create image from"
21
+ c.flag ["server"]
22
+
23
+ c.desc "Source URL of the image to download via HTTP"
24
+ c.flag ["url"]
25
+
26
+ c.desc "Source volume ID to create image from"
27
+ c.flag ["volume"]
28
+
20
29
  c.desc "Set image mode to be either 'virtio' or 'compatibility'"
21
30
  c.default_value "virtio"
22
31
  c.flag [:m, "mode"]
23
32
 
24
- c.desc "Set image to be publically visible (true or false)"
33
+ c.desc "Set image to be publicly visible (true or false)"
25
34
  c.default_value "false"
26
35
  c.flag [:p, "public"]
27
36
 
@@ -30,22 +39,38 @@ module Brightbox
30
39
 
31
40
  c.action do |global_options, options, _args|
32
41
  raise "You must specify the architecture" unless options[:a]
33
- raise "You must specify the source filename" unless options[:s]
34
42
  raise "Mode must be 'virtio' or 'compatibility'" unless options[:m] == "virtio" || options[:m] == "compatibility"
35
43
  raise "Public must be true or false" unless options[:p] == "true" || options[:p] == "false"
36
44
 
45
+ # Sources are mutually exclusive but at least one is required from this list
46
+ source_options = [:s, :server, :url, :volume].map { |k| options[k] }
47
+
48
+ if source_options.none?
49
+ raise "You must specify one of 'server', 'source', 'url', or 'volume'"
50
+ elsif !source_options.one?
51
+ raise "You cannot register from multiple sources. Use either 'source', 'server', 'url', or 'volume'"
52
+ end
53
+
37
54
  compatibility_flag = options[:m] == "compatibility"
38
55
 
39
56
  public_flag = options[:p] == "true"
40
57
 
41
58
  image_options = {
42
- :name => options[:n], :arch => options[:a],
43
- :username => options[:u], :source => options[:s],
59
+ :arch => options[:a],
44
60
  :compatibility_mode => compatibility_flag,
45
- :description => options[:d], :public => public_flag,
46
- :min_ram => options["min-ram"].to_i
61
+ :description => options[:d],
62
+ :min_ram => options["min-ram"].to_i,
63
+ :name => options[:n],
64
+ :public => public_flag,
65
+ :username => options[:u]
47
66
  }
48
67
 
68
+ # These should be limited to one by the mutually exclusive check earlier
69
+ image_options[:http_url] = options[:url] if options[:url]
70
+ image_options[:server] = options[:server] if options[:server]
71
+ image_options[:source] = options[:s] if options[:s]
72
+ image_options[:volume] = options[:volume] if options[:volume]
73
+
49
74
  image = Image.register(image_options)
50
75
 
51
76
  render_table([image], global_options)
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "4.1.0".freeze unless defined?(Brightbox::VERSION)
2
+ VERSION = "4.2.0".freeze unless defined?(Brightbox::VERSION)
3
3
  end
@@ -23,7 +23,67 @@ describe "brightbox images" do
23
23
  end
24
24
  end
25
25
 
26
- context "with minimal arguments" do
26
+ context "without any source" do
27
+ let(:argv) { %w[images register --arch x86_64] }
28
+
29
+ it "does not error" do
30
+ expect { output }.to_not raise_error
31
+
32
+ expect(stderr).to match("ERROR: You must specify one of 'server', 'source', 'url', or 'volume'")
33
+ expect(stdout).to match("")
34
+ end
35
+ end
36
+
37
+ context "with mutually exclusive arguments" do
38
+ let(:argv) { %w[images register --arch x86_64 --source test.img --url http://example.com/test.img] }
39
+
40
+ it "does not error" do
41
+ expect { output }.to_not raise_error
42
+
43
+ expect(stderr).to match("ERROR: You cannot register from multiple sources. Use either 'source', 'server', 'url', or 'volume'")
44
+ expect(stdout).to match("")
45
+ end
46
+ end
47
+
48
+ context "with 'server' argument" do
49
+ let(:argv) { %w[images register --arch x86_64 --server srv-12345] }
50
+
51
+ before do
52
+ expect(Brightbox::Image).to receive(:register)
53
+ .with(hash_including(
54
+ arch: "x86_64",
55
+ server: "srv-12345"
56
+ ))
57
+ .and_call_original
58
+
59
+ stub_request(:post, "#{api_url}/1.0/images?account_id=acc-12345")
60
+ .with(body: /"server":"srv-12345"/)
61
+ .to_return(
62
+ status: 201,
63
+ body: {
64
+ id: "img-12345"
65
+ }.to_json
66
+ )
67
+
68
+ stub_request(:get, "#{api_url}/1.0/images/img-12345?account_id=acc-12345")
69
+ .to_return(
70
+ status: 200,
71
+ body: {
72
+ id: "img-12345"
73
+ }.to_json
74
+ )
75
+ end
76
+
77
+ it "does not error" do
78
+ expect { output }.to_not raise_error
79
+
80
+ expect(stderr).to match("")
81
+ expect(stderr).not_to match("ERROR")
82
+ expect(stdout).to match("img-12345")
83
+ end
84
+ end
85
+
86
+ context "with 'source' argument" do
27
87
  let(:argv) { %w[images register --arch x86_64 --source custom.img] }
28
88
 
29
89
  before do
@@ -61,6 +121,82 @@ describe "brightbox images" do
61
121
  end
62
122
  end
63
123
 
124
+ context "with 'url' argument" do
125
+ let(:argv) { %w[images register --arch x86_64 --url https://example.com/os-22.iso] }
126
+
127
+ before do
128
+ expect(Brightbox::Image).to receive(:register)
129
+ .with(hash_including(
130
+ arch: "x86_64",
131
+ http_url: "https://example.com/os-22.iso"
132
+ ))
133
+ .and_call_original
134
+
135
+ stub_request(:post, "#{api_url}/1.0/images?account_id=acc-12345")
136
+ .with(body: %r{"http_url":"https://example.com/os-22.iso"})
137
+ .to_return(
138
+ status: 201,
139
+ body: {
140
+ id: "img-12345"
141
+ }.to_json
142
+ )
143
+
144
+ stub_request(:get, "#{api_url}/1.0/images/img-12345?account_id=acc-12345")
145
+ .to_return(
146
+ status: 200,
147
+ body: {
148
+ id: "img-12345"
149
+ }.to_json
150
+ )
151
+ end
152
+
153
+ it "does not error" do
154
+ expect { output }.to_not raise_error
155
+
156
+ expect(stderr).to match("")
157
+ expect(stderr).not_to match("ERROR")
158
+ expect(stdout).to match("img-12345")
159
+ end
160
+ end
161
+
162
+ context "with 'volume' argument" do
163
+ let(:argv) { %w[images register --arch x86_64 --volume vol-12345] }
164
+
165
+ before do
166
+ expect(Brightbox::Image).to receive(:register)
167
+ .with(hash_including(
168
+ arch: "x86_64",
169
+ volume: "vol-12345"
170
+ ))
171
+ .and_call_original
172
+
173
+ stub_request(:post, "#{api_url}/1.0/images?account_id=acc-12345")
174
+ .with(body: /"volume":"vol-12345"/)
175
+ .to_return(
176
+ status: 201,
177
+ body: {
178
+ id: "img-12345"
179
+ }.to_json
180
+ )
181
+
182
+ stub_request(:get, "#{api_url}/1.0/images/img-12345?account_id=acc-12345")
183
+ .to_return(
184
+ status: 200,
185
+ body: {
186
+ id: "img-12345"
187
+ }.to_json
188
+ )
189
+ end
190
+
191
+ it "does not error" do
192
+ expect { output }.to_not raise_error
193
+
194
+ expect(stderr).to match("")
195
+ expect(stderr).not_to match("ERROR")
196
+ expect(stdout).to match("img-12345")
197
+ end
198
+ end
199
+
64
200
  context "with min-ram argument" do
65
201
  let(:argv) { %w[images register --arch x86_64 --source custom.img --min-ram 2048] }
66
202
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-08-31 00:00:00.000000000 Z
12
+ date: 1980-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog-brightbox