brightbox-cli 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,10 +11,6 @@ module Brightbox
11
11
  def self.create
12
12
  r = conn.create_cloud_ip
13
13
  new(r["id"])
14
- rescue Excon::Errors::Forbidden => e
15
- response = JSON.parse(e.response.body) rescue {}
16
- response = response.fetch("error", {})
17
- raise Forbidden, "#{response["details"]}: #{response["summary"]}"
18
14
  end
19
15
 
20
16
  def attributes
@@ -47,8 +43,6 @@ module Brightbox
47
43
  self.class.conn.update_cloud_ip(id, options)
48
44
  self.reload
49
45
  self
50
- rescue Excon::Errors::BadRequest => e
51
- raise Conflict, JSON.parse(e.response.body)['error']['details']
52
46
  end
53
47
 
54
48
  end
@@ -23,6 +23,10 @@ module Brightbox
23
23
  raise "You must specify the api client-id"
24
24
  end
25
25
 
26
+ unless client_id[/^cli-.{5}$/]
27
+ raise "You must specify a valid api client-id in the format cli-xxxxx"
28
+ end
29
+
26
30
  if secret.nil?
27
31
  raise "You must specify the api secret"
28
32
  end
@@ -10,7 +10,7 @@ module Brightbox
10
10
  end
11
11
 
12
12
  display_options = { :fields => [
13
- :id, :protocol,:source, :sport,:destination, :dport, :icmp_type, :firewall_policy
13
+ :id, :protocol,:source, :sport, :destination, :dport, :icmp_type, :firewall_policy, :description
14
14
  ],
15
15
  :vertical => true
16
16
  }
@@ -5,7 +5,7 @@ module Brightbox
5
5
 
6
6
  c.action do |global_options, options, args|
7
7
  grp_id = args.shift
8
- raise "You must specify the server group and the server ids to add" unless grp_id && grp_id[/^grp-/] && !args.empty?
8
+ raise "You must specify the server group and then the server ids to add" unless grp_id && grp_id[/^grp-/] && !args.empty?
9
9
 
10
10
  sg = ServerGroup.find grp_id
11
11
 
@@ -15,7 +15,7 @@ module Brightbox
15
15
 
16
16
  table_opts = global_options.merge({
17
17
  :vertical => true,
18
- :fields => [:id, :type, :owner, :created_at, :status, :arch, :name, :description, :virtual_size, :disk_size, :public, :"compatibility_mode", :official, :ancestor_id ]
18
+ :fields => [:id, :type, :owner, :created_at, :status, :arch, :name, :description, :username, :virtual_size, :disk_size, :public, :"compatibility_mode", :official, :ancestor_id ]
19
19
  })
20
20
 
21
21
  render_table(images, table_opts)
@@ -12,13 +12,16 @@ module Brightbox
12
12
  c.desc "Set image mode to be either 'virtio' or 'compatibility'"
13
13
  c.flag [:m, "mode"]
14
14
 
15
- c.desc "Set image to be publically visible (true or false)"
15
+ c.desc "Set image to be publicly visible (true or false)"
16
16
  c.flag [:p, "public"]
17
17
 
18
+ c.desc "Set image to be deprecated (true or false)"
19
+ c.flag "deprecated"
20
+
18
21
  c.desc "Image description"
19
22
  c.flag [:d, "description"]
20
23
 
21
- c.desc "Image Usernmae"
24
+ c.desc "Image Username"
22
25
  c.flag [:u, "username"]
23
26
 
24
27
  c.action do |global_options,options,args|
@@ -44,6 +47,10 @@ module Brightbox
44
47
  params[:public] = true if options[:p] == "true"
45
48
  params[:public] = false if options[:p] == "false"
46
49
 
50
+ # If options[:deprecated] isn't specified, leave the status alone
51
+ params[:status] = "deprecated" if options[:deprecated] == "true"
52
+ params[:status] = "available" if options[:deprecated] == "false"
53
+
47
54
  image = Image.find img_id
48
55
 
49
56
  info "Updating image #{image}"
@@ -2,7 +2,14 @@ module Brightbox
2
2
  desc 'List servers'
3
3
  arg_name '[server-id...]'
4
4
  command [:list] do |c|
5
+
6
+ c.desc "Group identifier"
7
+ c.flag [:g, :group]
8
+
5
9
  c.action do |global_options,options,args|
10
+ # Check this here before we make any network connections
11
+ raise "A valid server group identifier is required for the group argument" unless options[:g].nil? || options[:g] =~ /^grp-.{5}$/
12
+
6
13
  if args.empty?
7
14
  servers = Server.find(:all)
8
15
  else
@@ -10,6 +17,10 @@ module Brightbox
10
17
  warn "Couldn't find server #{id}"
11
18
  end
12
19
  end
20
+
21
+ # Scope by group if a group identifier is specified
22
+ servers = servers.select {|server| server.server_groups.any? {|grp| grp["id"] == options[:g] } } if options[:g]
23
+
13
24
  render_table(servers, global_options)
14
25
  end
15
26
  end
@@ -11,24 +11,29 @@ module Brightbox
11
11
  case socket_error
12
12
  when Excon::Errors::ServiceUnavailable
13
13
  error "Api currently unavailable"
14
- when Excon::Errors::Error
15
- parse_http_error(socket_error)
16
14
  else
17
- error "ERROR: #{socket_error}"
15
+ parse_http_error(socket_error)
18
16
  end
19
17
  end
20
18
 
21
19
  def parse_http_error(e)
22
20
  if e.respond_to?(:response) and e.response.respond_to?(:body)
23
21
  json_response = JSON.parse(e.response.body) rescue {}
24
- if json_error = json_response['errors']
25
- error "ERROR: #{json_error.join(" ")}"
26
- else
27
- error "ERROR: #{e}"
28
- end
22
+ extract_response_from_json(json_response,e)
23
+ else
24
+ error "ERROR: #{e}"
25
+ end
26
+ end
27
+
28
+ def extract_response_from_json(error_json,e)
29
+ json_error = error_json['errors'] || error_json['error']
30
+ if json_error && !json_error.empty?
31
+ error_string = Array(json_error).join(" ")
32
+ error "ERROR: #{error_string}"
29
33
  else
30
34
  error "ERROR: #{e}"
31
35
  end
32
36
  end
37
+
33
38
  end
34
39
  end
@@ -33,7 +33,7 @@ module Brightbox
33
33
  end
34
34
 
35
35
  def self.default_field_order
36
- [:id, :protocol,:source, :sport,:destination, :dport, :icmp_type]
36
+ [:id, :protocol,:source, :sport, :destination, :dport, :icmp_type, :description]
37
37
  end
38
38
  end
39
39
  end
@@ -15,15 +15,13 @@ module Brightbox
15
15
  end
16
16
 
17
17
  def self.default_field_order
18
- [:id, :owner, :type, :created_on, :status, :size, :username,:name]
18
+ [:id, :owner, :type, :created_on, :status, :size, :username, :name]
19
19
  end
20
20
 
21
21
  def update options
22
22
  self.class.conn.update_image(id, options)
23
23
  self.reload
24
24
  self
25
- rescue Excon::Errors::BadRequest => e
26
- raise Conflict, JSON.parse(e.response.body)['error']['details']
27
25
  end
28
26
 
29
27
  def to_row
@@ -50,24 +50,17 @@ module Brightbox
50
50
  def add_nodes(nodes)
51
51
  node_hashes = nodes.collect { |n| { :node => n.id } }
52
52
  LoadBalancer.conn.add_nodes_load_balancer(id, :nodes => node_hashes)
53
- rescue Excon::Errors::BadRequest => e
54
- raise Conflict, JSON.parse(e.response.body)['error']['details']
55
53
  end
56
54
 
57
55
  def remove_nodes(nodes)
58
56
  node_hashes = nodes.collect { |n| { :node => n.id } }
59
57
  LoadBalancer.conn.remove_nodes_load_balancer(id, :nodes => node_hashes)
60
- rescue Excon::Errors::BadRequest => e
61
- raise Conflict, JSON.parse(e.response.body)['error']['details']
62
58
  end
63
59
 
64
60
  def update(options)
65
- debug options.inspect
66
61
  LoadBalancer.conn.update_load_balancer(id, options)
67
62
  self.reload
68
63
  self
69
- rescue Excon::Errors::BadRequest => e
70
- raise Conflict, JSON.parse(e.response.body)['error']['details']
71
64
  end
72
65
 
73
66
  def self.get(id)
@@ -27,8 +27,6 @@ module Brightbox
27
27
  self.class.conn.update_server_group(id, options)
28
28
  self.reload
29
29
  self
30
- rescue Excon::Errors::BadRequest => e
31
- raise Conflict, JSON.parse(e.response.body)['error']['details']
32
30
  end
33
31
 
34
32
  def destroy
@@ -25,8 +25,6 @@ module Brightbox
25
25
  self.class.conn.update_server id, options
26
26
  self.reload
27
27
  self
28
- rescue Excon::Errors::BadRequest => e
29
- raise Conflict, JSON.parse(e.response.body)['error']['details']
30
28
  end
31
29
 
32
30
  def destroy
@@ -32,8 +32,6 @@ module Brightbox
32
32
 
33
33
  def save
34
34
  fog_model.save
35
- rescue Excon::Errors::UnprocessableEntity
36
- raise InvalidRecord, "Could not save user #{self.id}"
37
35
  end
38
36
 
39
37
  def ssh_key_set?
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "0.15.0" unless defined?(Brightbox::VERSION)
2
+ VERSION = "0.16.0" unless defined?(Brightbox::VERSION)
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-cli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 35
4
+ hash: 95
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 15
8
+ - 16
9
9
  - 0
10
- version: 0.15.0
10
+ version: 0.16.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Leach
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-02 00:00:00 Z
18
+ date: 2011-12-01 00:00:00 +00:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: json
@@ -2283,6 +2284,7 @@ files:
2283
2284
  - spec/spec_helper.rb
2284
2285
  - spec/support/common_helpers.rb
2285
2286
  - tools/bash_completion_script
2287
+ has_rdoc: true
2286
2288
  homepage: http://docs.brightbox.com/cli
2287
2289
  licenses: []
2288
2290
 
@@ -2312,9 +2314,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2312
2314
  requirements: []
2313
2315
 
2314
2316
  rubyforge_project: brightbox-cli
2315
- rubygems_version: 1.8.10
2317
+ rubygems_version: 1.5.3
2316
2318
  signing_key:
2317
2319
  specification_version: 3
2318
2320
  summary: The Brightbox cloud management system
2319
- test_files: []
2320
-
2321
+ test_files:
2322
+ - spec/brightbox/config.example
2323
+ - spec/cloud_ips_spec.rb
2324
+ - spec/firewall_policy_spec.rb
2325
+ - spec/firewall_rule_spec.rb
2326
+ - spec/fixtures/vcr_cassettes/apply_firewall_policy.yml
2327
+ - spec/fixtures/vcr_cassettes/create_firewall_policy.yml
2328
+ - spec/fixtures/vcr_cassettes/destroy_firewall_policy.yml
2329
+ - spec/fixtures/vcr_cassettes/firewall_rule.yml
2330
+ - spec/fixtures/vcr_cassettes/firewall_rule_create.yml
2331
+ - spec/fixtures/vcr_cassettes/firewall_rule_destroy.yml
2332
+ - spec/fixtures/vcr_cassettes/firewall_rule_list.yml
2333
+ - spec/fixtures/vcr_cassettes/firewall_rule_show.yml
2334
+ - spec/fixtures/vcr_cassettes/list_cloud_ip.yml
2335
+ - spec/fixtures/vcr_cassettes/list_firewall_policy.yml
2336
+ - spec/fixtures/vcr_cassettes/list_server_groups.yml
2337
+ - spec/fixtures/vcr_cassettes/server_destroy.yml
2338
+ - spec/fixtures/vcr_cassettes/server_list.yml
2339
+ - spec/fixtures/vcr_cassettes/server_show.yml
2340
+ - spec/fixtures/vcr_cassettes/server_shutdown.yml
2341
+ - spec/fixtures/vcr_cassettes/server_start.yml
2342
+ - spec/fixtures/vcr_cassettes/server_stop.yml
2343
+ - spec/fixtures/vcr_cassettes/show_firewall_policy.yml
2344
+ - spec/server_group_spec.rb
2345
+ - spec/servers_spec.rb
2346
+ - spec/spec_helper.rb
2347
+ - spec/support/common_helpers.rb