bbcloud 0.8.2 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/bbcloud.gemspec +5 -0
  2. data/lib/bbcloud/api.rb +50 -24
  3. data/lib/bbcloud/cli.rb +24 -0
  4. data/lib/bbcloud/commands/accounts-list.rb +8 -1
  5. data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +7 -1
  6. data/lib/bbcloud/commands/accounts-show.rb +7 -1
  7. data/lib/bbcloud/commands/cloudips-destroy.rb +7 -7
  8. data/lib/bbcloud/commands/cloudips-list.rb +8 -2
  9. data/lib/bbcloud/commands/cloudips-map.rb +1 -4
  10. data/lib/bbcloud/commands/cloudips-show.rb +7 -1
  11. data/lib/bbcloud/commands/cloudips-unmap.rb +6 -4
  12. data/lib/bbcloud/commands/images-destroy.rb +7 -1
  13. data/lib/bbcloud/commands/images-list.rb +8 -1
  14. data/lib/bbcloud/commands/images-register.rb +24 -0
  15. data/lib/bbcloud/commands/images-show.rb +7 -1
  16. data/lib/bbcloud/commands/servers-create.rb +1 -4
  17. data/lib/bbcloud/commands/servers-destroy.rb +7 -10
  18. data/lib/bbcloud/commands/servers-list.rb +7 -1
  19. data/lib/bbcloud/commands/servers-show.rb +8 -7
  20. data/lib/bbcloud/commands/servers-shutdown.rb +5 -4
  21. data/lib/bbcloud/commands/servers-snapshot.rb +5 -3
  22. data/lib/bbcloud/commands/servers-start.rb +5 -4
  23. data/lib/bbcloud/commands/servers-stop.rb +5 -5
  24. data/lib/bbcloud/commands/types-list.rb +7 -1
  25. data/lib/bbcloud/commands/types-show.rb +7 -6
  26. data/lib/bbcloud/commands/users-list.rb +7 -1
  27. data/lib/bbcloud/commands/users-show.rb +6 -10
  28. data/lib/bbcloud/commands/users-update.rb +0 -2
  29. data/lib/bbcloud/commands/zones-list.rb +8 -1
  30. data/lib/bbcloud/config.rb +32 -0
  31. data/lib/bbcloud/images.rb +5 -0
  32. data/lib/bbcloud/types.rb +1 -5
  33. data/lib/bbcloud/version.rb +1 -1
  34. data/lib/bbcloud/zones.rb +2 -2
  35. metadata +44 -14
data/bbcloud.gemspec CHANGED
@@ -19,9 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
+ # To work around a bug with json using the wrong json_pure
23
+ s.add_dependency 'json', '=1.4.6'
24
+ s.add_dependency 'json_pure', '=1.4.6'
25
+
22
26
  s.add_dependency 'gli', '1.1.2'
23
27
  s.add_dependency 'hirb', '0.3.5'
24
28
  s.add_dependency 'fog', '=0.3.23'
25
29
  s.add_dependency 'excon', '>=0.2.4'
26
30
  s.add_dependency 'ini', '0.1.1'
31
+
27
32
  end
data/lib/bbcloud/api.rb CHANGED
@@ -6,6 +6,7 @@ module Brightbox
6
6
  class Conflict < ApiError ; end
7
7
  class InvalidRecord < ApiError ; end
8
8
  class Forbidden < ApiError ; end
9
+ class InvalidArguments < ApiError ; end
9
10
 
10
11
  @@api = nil
11
12
 
@@ -14,18 +15,21 @@ module Brightbox
14
15
  @@api
15
16
  else
16
17
  @@api = Fog::Brightbox::Compute.new CONFIG.to_fog
18
+ @@api.oauth_token = CONFIG.oauth_token
19
+ @@api
17
20
  end
18
21
  end
19
22
 
20
23
  def initialize(m = nil)
21
24
  if m.is_a? String
22
25
  @id = m
23
- elsif !m.nil?
26
+ elsif m.respond_to? :attributes and m.respond_to? :id
24
27
  @fog_model = m
25
28
  @id = m.id
29
+ else
30
+ raise InvalidArguments, "Can't initialize #{self.class} with #{m.inspect}"
26
31
  end
27
- CONFIG.cache_id @id unless @id.nil?
28
- @id
32
+ CONFIG.cache_id @id
29
33
  end
30
34
 
31
35
  def fog_model
@@ -43,38 +47,58 @@ module Brightbox
43
47
  end
44
48
 
45
49
  def self.find(args = :all, options = {})
46
- return nil if args.nil?
50
+ raise InvalidArguments, "find(nil)" if args.nil?
51
+ raise InvalidArguments, "find([])" if args.respond_to?(:empty?) and args.empty?
47
52
  options = {
48
53
  :order => :created_at,
49
54
  }.merge options
50
- objects = []
55
+ objects = nil
56
+ object = nil
51
57
  # get the data from the Api
52
- if args == :all or (args.respond_to?(:empty?) and args.empty?)
58
+ if args == :all
53
59
  objects = all
60
+ elsif args.is_a? String
61
+ object = cached_get(args.to_s)
62
+ raise NotFound, "Couldn't find '#{args.to_s}'" if object.nil?
54
63
  elsif args.respond_to? :collect
55
64
  objects = args.collect do |arg|
56
- cached_get(arg)
65
+ o = cached_get(arg.to_s)
66
+ raise NotFound, "Couldn't find '#{arg.to_s}'" if o.nil?
67
+ o
57
68
  end
58
- elsif args.respond_to? :to_s
59
- objects = [cached_get(args.to_s)]
69
+ else
70
+ raise InvalidArguments, "Couldn't find '#{arg.class}'"
60
71
  end
61
- # wrap in our objects
62
- objects.collect! { |o| new(o) unless o.nil? }
63
- # Sort
64
- objects.sort! do |a,b|
65
- sort_method = options[:order]
66
- begin
67
- a.send(sort_method) <=> b.send(sort_method)
68
- rescue NoMethodError
69
- 0
72
+ if objects
73
+ # wrap in our objects
74
+ objects.collect! { |o| new(o) }
75
+ # Sort
76
+ objects.sort! do |a,b|
77
+ sort_method = options[:order]
78
+ begin
79
+ a.send(sort_method) <=> b.send(sort_method)
80
+ rescue NoMethodError
81
+ 0
82
+ end
70
83
  end
71
- end
72
- if objects.size <= 1 and args.is_a? String
73
- # This was a single lookup
74
- objects.first
75
- else
76
84
  objects
85
+ elsif object
86
+ new(object)
87
+ end
88
+ end
89
+
90
+ # Find each id in the given array. Yield the block with any ids
91
+ # that couldn't be found
92
+ def self.find_or_call(ids, &block)
93
+ objects = []
94
+ ids.each do |id|
95
+ begin
96
+ objects << find(id)
97
+ rescue Api::NotFound
98
+ yield id
99
+ end
77
100
  end
101
+ objects
78
102
  end
79
103
 
80
104
  def method_missing(m, *args)
@@ -97,7 +121,9 @@ module Brightbox
97
121
  end
98
122
 
99
123
  def self.find_by_handle(h)
100
- find(:all).find { |o| o.handle == h }
124
+ object = find(:all).find { |o| o.handle == h }
125
+ raise Api::NotFound, h if object.nil?
126
+ object
101
127
  end
102
128
 
103
129
  def self.cache_all!
data/lib/bbcloud/cli.rb CHANGED
@@ -3,6 +3,8 @@ require os_config if File.exist? os_config
3
3
 
4
4
  unless defined?(DISABLE_RUBYGEMS)
5
5
  require "rubygems"
6
+ gem "json", "=1.4.6"
7
+ gem "json_pure", "=1.4.6"
6
8
  gem "fog", "=0.3.23"
7
9
  end
8
10
 
@@ -22,6 +24,26 @@ require 'gli'
22
24
  require 'bbcloud/tables'
23
25
  require 'fog'
24
26
 
27
+ # Hack to force persistent connections in fog
28
+ module Fog
29
+ class Connection
30
+ def initialize(url, persistent=false)
31
+ @excon = Excon.new(url)
32
+ @persistent = true
33
+ end
34
+ end
35
+ end
36
+
37
+ module Fog
38
+ module Brightbox
39
+ class Compute
40
+ class Real
41
+ attr_accessor :oauth_token
42
+ end
43
+ end
44
+ end
45
+ end
46
+
25
47
  %w{api servers images types zones cloud_ips users accounts config version}.each do |f|
26
48
  require File.join(File.dirname(__FILE__), f)
27
49
  end
@@ -128,3 +150,5 @@ command [:version] do |c|
128
150
  end
129
151
 
130
152
  run ARGV
153
+
154
+ CONFIG.finish
@@ -3,7 +3,14 @@ arg_name '[account-id...]'
3
3
  command [:list] do |c|
4
4
  c.action do |global_options, options, args|
5
5
 
6
- accounts = Account.find(args).compact
6
+ if args.empty?
7
+ accounts = Account.find(:all)
8
+ else
9
+ accounts = Account.find_or_call(args) do |id|
10
+ warn "Couldn't find account #{id}"
11
+ end
12
+ end
13
+
7
14
  render_table(accounts, global_options)
8
15
  end
9
16
  end
@@ -4,7 +4,13 @@ command [:reset_ftp_password] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- accounts = Account.find(args)
7
+ if args.empty?
8
+ raise "You must specify the accounts to reset ftp passwords for"
9
+ end
10
+
11
+ accounts = Account.find_or_call(args) do |id|
12
+ raise "Couldn't find account #{id}"
13
+ end
8
14
 
9
15
  rows = []
10
16
 
@@ -4,7 +4,13 @@ command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- accounts = Account.find(args).compact
7
+ if args.empty?
8
+ raise "You must specify the accounts to show"
9
+ end
10
+
11
+ accounts = Account.find_or_call(args) do |id|
12
+ warn "Couldn't find account #{id}"
13
+ end
8
14
 
9
15
  table_opts = global_options.merge({
10
16
  :vertical => true,
@@ -6,15 +6,15 @@ command [:destroy] do |c|
6
6
 
7
7
  c.action do |global_options,options,args|
8
8
 
9
- if args.size < 1
10
- raise "You must specify the cloud ip id you want to destroy"
9
+ if args.empty?
10
+ raise "You must specify the cloud ips you want to destroy"
11
11
  end
12
12
 
13
- args.each do |ip_id|
14
-
15
- ip = CloudIP.find ip_id
13
+ ips = CloudIP.find_or_call(args) do |id|
14
+ raise "Couldn't find cloud ip #{id}"
15
+ end
16
16
 
17
- raise "Cannot find cloud ip #{ip_id}" if ip.nil?
17
+ ips.each do |ip|
18
18
 
19
19
  if ip.mapped?
20
20
  if options[:u]
@@ -29,7 +29,7 @@ command [:destroy] do |c|
29
29
  raise "Cannot destroy mapped cloud ip #{ip}"
30
30
  end
31
31
  end
32
- info "Destroying cloud ip #{ip.public_ip} (#{ip})"
32
+ info "Destroying cloud ip #{ip}"
33
33
  ip.destroy
34
34
  end
35
35
 
@@ -4,8 +4,14 @@ command [:list] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- ips = CloudIP.find args
7
+ if args.empty?
8
+ ips = CloudIP.find(:all)
9
+ else
10
+ ips = CloudIP.find_or_call(args) do |id|
11
+ warn "Couldn't find cloud ip #{id}"
12
+ end
13
+ end
8
14
 
9
- render_table(ips.compact.sort, global_options)
15
+ render_table(ips.sort, global_options)
10
16
  end
11
17
  end
@@ -18,8 +18,6 @@ command [:map] do |c|
18
18
 
19
19
  ip = CloudIP.find ip_id
20
20
 
21
- raise "Cannot find ip #{ip_id}" if ip.nil?
22
-
23
21
  if ip.mapped?
24
22
  if options[:u]
25
23
  info "Unmapping ip #{ip}"
@@ -36,7 +34,6 @@ command [:map] do |c|
36
34
 
37
35
  server_id = args.last
38
36
  server = Server.find server_id
39
- raise "Cannot find server #{server_id}" if server.nil?
40
37
 
41
38
  interface_id = server.interfaces.first["id"]
42
39
  info "Mapping #{ip} to interface #{interface_id} on #{server}"
@@ -45,9 +42,9 @@ command [:map] do |c|
45
42
 
46
43
  # Wait up to 3 seconds for mapping to complete
47
44
  3.times do
48
- sleep 1
49
45
  ip.reload
50
46
  break if ip.mapped?
47
+ sleep 1
51
48
  end
52
49
 
53
50
  render_table([ip], global_options)
@@ -4,7 +4,13 @@ command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- ips = CloudIP.find args
7
+ if args.empty?
8
+ raise "You must specify the cloud ips you want to show"
9
+ end
10
+
11
+ ips = CloudIP.find_or_call(args) do |id|
12
+ warn "Couldn't find cloud ip #{id}"
13
+ end
8
14
 
9
15
  fields = [:id, :status, :public_ip, :reverse_dns, :server_id, :interface_id]
10
16
 
@@ -4,11 +4,13 @@ command [:unmap] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- raise "you must specify the cloud ip ids to unmap as arguments" if args.empty?
8
-
9
- ips = CloudIP.find args
7
+ if args.empty?
8
+ raise "You must specify the cloud ips you want to unmap"
9
+ end
10
10
 
11
- ips.compact!
11
+ ips = CloudIP.find_or_call(args) do |id|
12
+ raise "Couldn't find cloud ip #{id}"
13
+ end
12
14
 
13
15
  ips.each do |ip|
14
16
  if ip.mapped?
@@ -4,7 +4,13 @@ command [:destroy] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- images = Image.find(args).compact
7
+ if args.empty?
8
+ raise "You must specify the images you want to destroy"
9
+ end
10
+
11
+ images = Image.find_or_call(args) do |id|
12
+ raise "Couldn't find image #{id}"
13
+ end
8
14
 
9
15
  images.each do |i|
10
16
  info "Destroying image #{i}"
@@ -2,7 +2,14 @@ desc 'List available images'
2
2
  arg_name '[image-id...]'
3
3
  command [:list] do |c|
4
4
  c.action do |global_options, options, args|
5
- images = Image.find args
5
+
6
+ if args.empty?
7
+ images = Image.find(:all)
8
+ else
9
+ images = Image.find_or_call(args) do |id|
10
+ warn "Couldn't find image #{id}"
11
+ end
12
+ end
6
13
 
7
14
  snapshots = images.select { |i| i.source_type == 'snapshot' }
8
15
 
@@ -0,0 +1,24 @@
1
+ desc 'Register an image'
2
+ command [:register] do |c|
3
+
4
+ c.desc "Name to give the image"
5
+ c.flag [:n, "name"]
6
+
7
+ c.desc "Archtecture of the image (i686 or x86_64)"
8
+ c.flag [:a, "arch"]
9
+
10
+ c.desc "Source filename of the image you uploaded to the image library"
11
+ c.flag [:s, "source"]
12
+
13
+ c.action do |global_options,options,args|
14
+
15
+ raise "You must specify the architecture" unless options[:a]
16
+ raise "You must specify the source filename" unless options[:s]
17
+
18
+ image = Image.register :name => options[:n], :arch => options[:a],
19
+ :source => options[:s]
20
+
21
+ render_table([image])
22
+
23
+ end
24
+ end
@@ -4,7 +4,13 @@ command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- images = Image.find(args).compact
7
+ if args.empty?
8
+ raise "You must specify the images you want to show"
9
+ end
10
+
11
+ images = Image.find_or_call(args) do |id|
12
+ warn "Couldn't find image #{id}"
13
+ end
8
14
 
9
15
  table_opts = global_options.merge({
10
16
  :vertical => true,
@@ -39,7 +39,6 @@ command [:create] do |c|
39
39
 
40
40
  image_id = args.shift
41
41
  image = Image.find image_id
42
- raise "Couldn't find image #{image_id}" unless image
43
42
 
44
43
  type_id = options[:t]
45
44
  if type_id =~ /^typ\-/
@@ -47,7 +46,6 @@ command [:create] do |c|
47
46
  else
48
47
  type = Type.find_by_handle type_id
49
48
  end
50
- raise "Couldn't find server type #{type_id}" unless type
51
49
 
52
50
  if options[:z]
53
51
  zone = options[:z]
@@ -57,7 +55,6 @@ command [:create] do |c|
57
55
  zone = Zone.find_by_handle zone
58
56
  end
59
57
  end
60
- raise "Couldn't find server type #{type_id}" unless type
61
58
 
62
59
  user_data = options[:m]
63
60
  user_data_file = options[:f]
@@ -81,7 +78,7 @@ command [:create] do |c|
81
78
  msg = "Creating #{options[:i] > 1 ? options[:i] : 'a'} #{type.handle} (#{type.id})"
82
79
  msg << " server#{options[:i] > 1 ? 's' : ''} with image #{image.name.strip} (#{image.id})"
83
80
  msg << " in zone #{zone.handle} (#{zone})" if zone
84
- msg << " with #{user_data.size / 1024}k of user data" if user_data
81
+ msg << " with %.2fk of user data" % (user_data.size / 1024.0) if user_data
85
82
  info msg
86
83
  servers = []
87
84
  options[:i].times do
@@ -3,23 +3,20 @@ arg_name '[server-id...]'
3
3
  command [:destroy] do |c|
4
4
  c.action do |global_options, options, args|
5
5
 
6
- if args.empty?
7
- raise "you must specify the id of the server(s) you want to destroy"
6
+ raise "You must specify servers to destroy" if args.empty?
7
+
8
+ servers = Server.find_or_call(args) do |id|
9
+ raise "Couldn't find server #{id}"
8
10
  end
9
11
 
10
- servers = args.collect do |sid|
11
- info "Destroying server #{sid}"
12
- server = Server.find sid
13
- raise "Server #{sid} does not exist" if server.nil?
12
+ servers.each do |server|
13
+ info "Destroying server #{server}"
14
14
  begin
15
15
  server.destroy
16
16
  rescue Brightbox::Api::Conflict => e
17
- error "Could not destroy #{sid}"
17
+ error "Could not destroy #{server}"
18
18
  end
19
- server.reload
20
- server
21
19
  end
22
20
 
23
- render_table(servers, global_options)
24
21
  end
25
22
  end
@@ -6,7 +6,13 @@ command [:list] do |c|
6
6
  Type.cache_all!
7
7
  Zone.cache_all!
8
8
 
9
- servers = Server.find(args).compact
9
+ if args.empty?
10
+ servers = Server.find(:all)
11
+ else
12
+ servers = Server.find_or_call(args) do |id|
13
+ warn "Couldn't find server #{id}"
14
+ end
15
+ end
10
16
 
11
17
  render_table(servers, global_options)
12
18
  end
@@ -3,14 +3,15 @@ arg_name 'server-id...'
3
3
  command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
-
7
- servers = Server.find(args).compact
6
+
7
+ raise "You must specify servers to show" if args.empty?
8
+
9
+ servers = Server.find_or_call(args) do |id|
10
+ raise "Couldn't find server #{id}"
11
+ end
12
+
8
13
  rows = []
9
14
  servers.each do |s|
10
- if s.is_a? String
11
- error "Could not find server #{s}"
12
- next
13
- end
14
15
  o = s.to_row
15
16
  if s.server_type.exists?
16
17
  o[:type] = s.server_type.id
@@ -21,7 +22,7 @@ command [:show] do |c|
21
22
  o[:disk] = s.server_type.disk.to_i
22
23
  end
23
24
 
24
- if s.image.exists? and false
25
+ if s.image.exists?
25
26
  o[:image_name] = s.image.name
26
27
  o[:arch] = s.image.arch
27
28
  end
@@ -3,15 +3,16 @@ arg_name 'server-id...'
3
3
  command [:shutdown] do |c|
4
4
  c.action do |global_options,options,args|
5
5
 
6
- servers = Server.find(args).compact
6
+ raise "You must specify servers to shutdown" if args.empty?
7
+
8
+ servers = Server.find_or_call(args) do |id|
9
+ raise "Couldn't find server #{id}"
10
+ end
7
11
 
8
12
  servers.each do |s|
9
13
  info "Shutting down server #{s}"
10
14
  s.shutdown
11
- s.reload
12
15
  end
13
16
 
14
- render_table(servers)
15
-
16
17
  end
17
18
  end
@@ -4,14 +4,16 @@ command [:snapshot] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- servers = Server.find(args).compact
7
+ raise "You must specify servers to snapshot" if args.empty?
8
+
9
+ servers = Server.find_or_call(args) do |id|
10
+ raise "Couldn't find server #{id}"
11
+ end
8
12
 
9
13
  servers.each do |s|
10
14
  info "Snapshotting server #{s}"
11
15
  s.snapshot
12
16
  end
13
17
 
14
- render_table(servers)
15
-
16
18
  end
17
19
  end
@@ -4,15 +4,16 @@ command [:start] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- servers = Server.find(args).compact
7
+ raise "You must specify servers to start" if args.empty?
8
+
9
+ servers = Server.find_or_call(args) do |id|
10
+ raise "Couldn't find server #{id}"
11
+ end
8
12
 
9
13
  servers.each do |s|
10
14
  info "Starting server #{s}"
11
15
  s.start
12
- s.reload
13
16
  end
14
17
 
15
- render_table(servers)
16
-
17
18
  end
18
19
  end
@@ -4,15 +4,15 @@ command [:stop] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- servers = Server.find(args).compact
7
+ raise "You must specify servers to stop" if args.empty?
8
+
9
+ servers = Server.find_or_call(args) do |id|
10
+ raise "Couldn't find server #{id}"
11
+ end
8
12
 
9
13
  servers.each do |s|
10
14
  info "Stopping server #{s}"
11
15
  s.stop
12
- s.reload
13
16
  end
14
-
15
- render_table(servers)
16
-
17
17
  end
18
18
  end
@@ -3,7 +3,13 @@ arg_name '[type-id...]'
3
3
  command [:list] do |c|
4
4
  c.action do |global_options,options,args|
5
5
 
6
- types = Type.find args, :order => :ram
6
+ if args.empty?
7
+ types = Type.find :all
8
+ else
9
+ types = Type.find_or_call(args) do |id|
10
+ warn "Couldn't find type #{id}"
11
+ end
12
+ end
7
13
 
8
14
  render_table(types, global_options)
9
15
  end
@@ -4,11 +4,12 @@ command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- types = Type.find(args)
8
- rows = []
9
- types.each do |t|
10
- next if t.nil?
11
- rows << t
7
+ if args.empty?
8
+ raise "You must specify the types you want to show"
9
+ end
10
+
11
+ types = Type.find_or_call(args) do |id|
12
+ warn "Couldn't find type #{id}"
12
13
  end
13
14
 
14
15
  table_opts = global_options.merge({
@@ -16,7 +17,7 @@ command [:show] do |c|
16
17
  :fields => [:id, :handle, :status, :name, :ram, :disk, :cores, :description]
17
18
  })
18
19
 
19
- render_table(rows, table_opts)
20
+ render_table(types, table_opts)
20
21
 
21
22
  end
22
23
  end
@@ -3,7 +3,13 @@ arg_name '[user-id...]'
3
3
  command [:list] do |c|
4
4
  c.action do |global_options, options, args|
5
5
 
6
- users = User.find args
6
+ if args.empty?
7
+ users = User.find(:all)
8
+ else
9
+ users = User.find_or_call(args) do |id|
10
+ warn "Couldn't find user #{id}"
11
+ end
12
+ end
7
13
 
8
14
  render_table(users, global_options)
9
15
  end
@@ -4,16 +4,12 @@ command [:show] do |c|
4
4
 
5
5
  c.action do |global_options,options,args|
6
6
 
7
- users = User.find(args)
8
-
9
- rows = []
7
+ if args.empty?
8
+ raise "You must specify the users you want to show"
9
+ end
10
10
 
11
- users.each do |s|
12
- s.reload # to get ssh_key
13
- o = s.to_row
14
- o[:ssh_key] = s.ssh_key.to_s.strip
15
- o[:accounts] = s.accounts.collect { |a| a.id }.join(", ")
16
- rows << o
11
+ users = User.find_or_call(args) do |id|
12
+ warn "Couldn't find user #{id}"
17
13
  end
18
14
 
19
15
  table_opts = global_options.merge({
@@ -21,7 +17,7 @@ command [:show] do |c|
21
17
  :fields => [:id, :name, :email_address, :accounts, :ssh_key ]
22
18
  })
23
19
 
24
- render_table(rows, table_opts)
20
+ render_table(users, table_opts)
25
21
 
26
22
  end
27
23
  end
@@ -13,8 +13,6 @@ command [:update] do |c|
13
13
  raise "You must specify the user id as the first argument" if args.empty?
14
14
 
15
15
  user = User.find args.first
16
-
17
- raise "Could not find user #{args.first}" if user.nil?
18
16
 
19
17
  if options[:f] == '-'
20
18
  user.ssh_key = STDIN.read
@@ -3,7 +3,14 @@ arg_name '[zone-id...]'
3
3
  command [:list] do |c|
4
4
  c.action do |global_options, options, args|
5
5
 
6
- zones = Zone.find args
6
+ if args.empty?
7
+ zones = Zone.find(:all)
8
+ else
9
+ zones = Zone.find_or_call(args) do |id|
10
+ warn "Couldn't find zone #{id}"
11
+ end
12
+ end
13
+
7
14
  render_table(zones, global_options)
8
15
  end
9
16
  end
@@ -36,6 +36,10 @@ class BBConfig
36
36
  @config_filename
37
37
  end
38
38
 
39
+ def oauth_token_filename
40
+ @oauth_token_filename ||= File.join(dir, client_name + '.oauth_token')
41
+ end
42
+
39
43
  def cache_path
40
44
  if @cache_path
41
45
  @cache_path
@@ -107,5 +111,33 @@ class BBConfig
107
111
  }
108
112
  end
109
113
 
114
+ def oauth_token
115
+ if @oauth_token.nil?
116
+ if File.exists? oauth_token_filename
117
+ File.open(oauth_token_filename, "r") do |f|
118
+ @oauth_token = f.read.chomp
119
+ end
120
+ @oauth_token
121
+ else
122
+ @oauth_token = false
123
+ end
124
+ else
125
+ @oauth_token ? @oauth_token : nil
126
+ end
127
+ end
128
+
129
+ def finish
130
+ begin
131
+ if @oauth_token != Api.conn.oauth_token
132
+ File.open(oauth_token_filename + ".#{$$}", "w") do |f|
133
+ f.write Api.conn.oauth_token
134
+ end
135
+ FileUtils.mv oauth_token_filename + ".#{$$}", oauth_token_filename
136
+ end
137
+ rescue StandardError => e
138
+ warn "Error writing auth token #{oauth_token_filename}: #{e.class}: #{e}"
139
+ end
140
+
141
+ end
110
142
 
111
143
  end
@@ -25,6 +25,11 @@ module Brightbox
25
25
  o
26
26
  end
27
27
 
28
+ def self.register(options = {})
29
+ image = conn.create_image(options)
30
+ find image['id']
31
+ end
32
+
28
33
  def public?
29
34
  public
30
35
  end
data/lib/bbcloud/types.rb CHANGED
@@ -21,11 +21,7 @@ module Brightbox
21
21
  end
22
22
 
23
23
  def render_cell
24
- handle
25
- end
26
-
27
- def id
28
- fog_model.id
24
+ fog_model.handle
29
25
  end
30
26
 
31
27
  def self.all
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9"
3
3
  end
data/lib/bbcloud/zones.rb CHANGED
@@ -17,11 +17,11 @@ module Brightbox
17
17
  end
18
18
 
19
19
  def to_s
20
- @id
20
+ id
21
21
  end
22
22
 
23
23
  def render_cell
24
- handle if fog_model
24
+ handle
25
25
  end
26
26
  end
27
27
  end
metadata CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 8
8
- - 2
9
- version: 0.8.2
7
+ - 9
8
+ version: "0.9"
10
9
  platform: ruby
11
10
  authors:
12
11
  - John Leach
@@ -14,13 +13,43 @@ autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
15
 
17
- date: 2010-11-21 00:00:00 +00:00
16
+ date: 2010-11-26 00:00:00 +00:00
18
17
  default_executable:
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
21
- name: gli
20
+ name: json
22
21
  prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 6
31
+ version: 1.4.6
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: json_pure
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - "="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 4
45
+ - 6
46
+ version: 1.4.6
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: gli
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
24
53
  none: false
25
54
  requirements:
26
55
  - - "="
@@ -31,11 +60,11 @@ dependencies:
31
60
  - 2
32
61
  version: 1.1.2
33
62
  type: :runtime
34
- version_requirements: *id001
63
+ version_requirements: *id003
35
64
  - !ruby/object:Gem::Dependency
36
65
  name: hirb
37
66
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
39
68
  none: false
40
69
  requirements:
41
70
  - - "="
@@ -46,11 +75,11 @@ dependencies:
46
75
  - 5
47
76
  version: 0.3.5
48
77
  type: :runtime
49
- version_requirements: *id002
78
+ version_requirements: *id004
50
79
  - !ruby/object:Gem::Dependency
51
80
  name: fog
52
81
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
54
83
  none: false
55
84
  requirements:
56
85
  - - "="
@@ -61,11 +90,11 @@ dependencies:
61
90
  - 23
62
91
  version: 0.3.23
63
92
  type: :runtime
64
- version_requirements: *id003
93
+ version_requirements: *id005
65
94
  - !ruby/object:Gem::Dependency
66
95
  name: excon
67
96
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
69
98
  none: false
70
99
  requirements:
71
100
  - - ">="
@@ -76,11 +105,11 @@ dependencies:
76
105
  - 4
77
106
  version: 0.2.4
78
107
  type: :runtime
79
- version_requirements: *id004
108
+ version_requirements: *id006
80
109
  - !ruby/object:Gem::Dependency
81
110
  name: ini
82
111
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
112
+ requirement: &id007 !ruby/object:Gem::Requirement
84
113
  none: false
85
114
  requirements:
86
115
  - - "="
@@ -91,7 +120,7 @@ dependencies:
91
120
  - 1
92
121
  version: 0.1.1
93
122
  type: :runtime
94
- version_requirements: *id005
123
+ version_requirements: *id007
95
124
  description: Scripts to interact with the Brightbox cloud API
96
125
  email:
97
126
  - john@brightbox.co.uk
@@ -142,6 +171,7 @@ files:
142
171
  - lib/bbcloud/commands/config-client-remove.rb
143
172
  - lib/bbcloud/commands/images-destroy.rb
144
173
  - lib/bbcloud/commands/images-list.rb
174
+ - lib/bbcloud/commands/images-register.rb
145
175
  - lib/bbcloud/commands/images-show.rb
146
176
  - lib/bbcloud/commands/servers-create.rb
147
177
  - lib/bbcloud/commands/servers-destroy.rb