bbcloud 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +3 -2
  2. data/Gemfile +3 -0
  3. data/README +11 -1
  4. data/README.rdoc +11 -1
  5. data/Rakefile +12 -0
  6. data/bbcloud.gemspec +10 -10
  7. data/bin/brightbox-accounts +7 -2
  8. data/bin/brightbox-cloudips +7 -2
  9. data/bin/brightbox-config +7 -2
  10. data/bin/brightbox-images +7 -2
  11. data/bin/brightbox-lbs +7 -2
  12. data/bin/brightbox-servers +7 -2
  13. data/bin/brightbox-types +7 -2
  14. data/bin/brightbox-users +7 -2
  15. data/bin/brightbox-zones +7 -2
  16. data/lib/bbcloud.rb +43 -0
  17. data/lib/bbcloud/accounts.rb +5 -3
  18. data/lib/bbcloud/command_generator.rb +50 -0
  19. data/lib/bbcloud/commands/accounts-list.rb +13 -11
  20. data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +26 -23
  21. data/lib/bbcloud/commands/accounts-show.rb +20 -16
  22. data/lib/bbcloud/commands/cloudips-create.rb +16 -14
  23. data/lib/bbcloud/commands/cloudips-destroy.rb +29 -26
  24. data/lib/bbcloud/commands/cloudips-list.rb +13 -11
  25. data/lib/bbcloud/commands/cloudips-map.rb +48 -46
  26. data/lib/bbcloud/commands/cloudips-show.rb +15 -12
  27. data/lib/bbcloud/commands/cloudips-unmap.rb +28 -25
  28. data/lib/bbcloud/commands/config-client-add.rb +33 -31
  29. data/lib/bbcloud/commands/config-client-default.rb +18 -16
  30. data/lib/bbcloud/commands/config-client-list.rb +19 -16
  31. data/lib/bbcloud/commands/config-client-remove.rb +18 -16
  32. data/lib/bbcloud/commands/images-destroy.rb +18 -16
  33. data/lib/bbcloud/commands/images-list.rb +20 -18
  34. data/lib/bbcloud/commands/images-register.rb +21 -19
  35. data/lib/bbcloud/commands/images-show.rb +17 -15
  36. data/lib/bbcloud/commands/lbs-add-nodes.rb +15 -13
  37. data/lib/bbcloud/commands/lbs-create.rb +65 -63
  38. data/lib/bbcloud/commands/lbs-destroy.rb +13 -11
  39. data/lib/bbcloud/commands/lbs-list.rb +13 -11
  40. data/lib/bbcloud/commands/lbs-remove-nodes.rb +15 -13
  41. data/lib/bbcloud/commands/lbs-show.rb +15 -13
  42. data/lib/bbcloud/commands/lbs-update.rb +59 -57
  43. data/lib/bbcloud/commands/servers-activate-cloud.rb +18 -16
  44. data/lib/bbcloud/commands/servers-create.rb +80 -77
  45. data/lib/bbcloud/commands/servers-destroy.rb +17 -15
  46. data/lib/bbcloud/commands/servers-list.rb +14 -14
  47. data/lib/bbcloud/commands/servers-show.rb +39 -37
  48. data/lib/bbcloud/commands/servers-shutdown.rb +14 -12
  49. data/lib/bbcloud/commands/servers-snapshot.rb +14 -12
  50. data/lib/bbcloud/commands/servers-start.rb +15 -13
  51. data/lib/bbcloud/commands/servers-stop.rb +14 -12
  52. data/lib/bbcloud/commands/types-list.rb +13 -11
  53. data/lib/bbcloud/commands/types-show.rb +18 -16
  54. data/lib/bbcloud/commands/users-list.rb +13 -11
  55. data/lib/bbcloud/commands/users-show.rb +17 -15
  56. data/lib/bbcloud/commands/users-update.rb +27 -25
  57. data/lib/bbcloud/commands/zones-list.rb +13 -11
  58. data/lib/bbcloud/config.rb +125 -111
  59. data/lib/bbcloud/error_parser.rb +34 -0
  60. data/lib/bbcloud/fog_extensions.rb +19 -0
  61. data/lib/bbcloud/gli_global_hooks.rb +56 -0
  62. data/lib/bbcloud/logging.rb +40 -0
  63. data/lib/bbcloud/ruby_core_ext.rb +9 -0
  64. data/lib/bbcloud/servers.rb +7 -2
  65. data/lib/bbcloud/tables.rb +78 -73
  66. data/lib/bbcloud/vendor/gli/.gitignore +10 -0
  67. data/lib/bbcloud/vendor/gli/.rvmrc +1 -0
  68. data/lib/bbcloud/vendor/gli/Gemfile +5 -0
  69. data/lib/bbcloud/vendor/gli/LICENSE.txt +201 -0
  70. data/lib/bbcloud/vendor/gli/README.rdoc +54 -0
  71. data/lib/bbcloud/vendor/gli/Rakefile +84 -0
  72. data/lib/bbcloud/vendor/gli/bin/gli +72 -0
  73. data/lib/bbcloud/vendor/gli/bin/report_on_rake_results +10 -0
  74. data/lib/bbcloud/vendor/gli/bin/test_all_rubies.sh +2 -0
  75. data/lib/bbcloud/vendor/gli/features/gli_executable.feature +88 -0
  76. data/lib/bbcloud/vendor/gli/features/gli_init.feature +122 -0
  77. data/lib/bbcloud/vendor/gli/features/step_definitions/gli_executable_steps.rb +12 -0
  78. data/lib/bbcloud/vendor/gli/features/step_definitions/gli_init_steps.rb +4 -0
  79. data/lib/bbcloud/vendor/gli/features/support/env.rb +21 -0
  80. data/lib/bbcloud/vendor/gli/gli.cheat +80 -0
  81. data/lib/bbcloud/vendor/gli/gli.gemspec +46 -0
  82. data/lib/bbcloud/vendor/gli/gli.rdoc +51 -0
  83. data/lib/bbcloud/vendor/gli/lib/gli.rb +560 -0
  84. data/lib/bbcloud/vendor/gli/lib/gli/command.rb +124 -0
  85. data/lib/bbcloud/vendor/gli/lib/gli/command_line_token.rb +58 -0
  86. data/lib/bbcloud/vendor/gli/lib/gli/copy_options_to_aliases.rb +33 -0
  87. data/lib/bbcloud/vendor/gli/lib/gli/exceptions.rb +45 -0
  88. data/lib/bbcloud/vendor/gli/lib/gli/flag.rb +67 -0
  89. data/lib/bbcloud/vendor/gli/lib/gli/options.rb +19 -0
  90. data/lib/bbcloud/vendor/gli/lib/gli/switch.rb +63 -0
  91. data/lib/bbcloud/vendor/gli/lib/gli/terminal.rb +79 -0
  92. data/lib/bbcloud/vendor/gli/lib/gli_version.rb +3 -0
  93. data/lib/bbcloud/vendor/gli/lib/support/help.rb +180 -0
  94. data/lib/bbcloud/vendor/gli/lib/support/initconfig.rb +34 -0
  95. data/lib/bbcloud/vendor/gli/lib/support/rdoc.rb +119 -0
  96. data/lib/bbcloud/vendor/gli/lib/support/scaffold.rb +284 -0
  97. data/lib/bbcloud/vendor/gli/test/config.yaml +9 -0
  98. data/lib/bbcloud/vendor/gli/test/gli.reek +116 -0
  99. data/lib/bbcloud/vendor/gli/test/roodi.yaml +9 -0
  100. data/lib/bbcloud/vendor/gli/test/tc_command.rb +329 -0
  101. data/lib/bbcloud/vendor/gli/test/tc_flag.rb +67 -0
  102. data/lib/bbcloud/vendor/gli/test/tc_gli.rb +429 -0
  103. data/lib/bbcloud/vendor/gli/test/tc_options.rb +31 -0
  104. data/lib/bbcloud/vendor/gli/test/tc_parsing.rb +279 -0
  105. data/lib/bbcloud/vendor/gli/test/tc_switch.rb +80 -0
  106. data/lib/bbcloud/vendor/gli/test/tc_terminal.rb +91 -0
  107. data/lib/bbcloud/version.rb +1 -1
  108. data/pkg/bbcloud-0.12.0.gem +0 -0
  109. data/spec/fixtures/vcr_cassettes/server_list.yml +117 -0
  110. data/spec/servers_spec.rb +36 -0
  111. data/spec/spec_helper.rb +24 -0
  112. data/spec/support/common_helpers.rb +47 -0
  113. metadata +129 -135
  114. data/lib/bbcloud/cli.rb +0 -160
  115. data/lib/bbcloud/vendor/fog/lib/fog.rb +0 -14
  116. data/lib/bbcloud/vendor/fog/lib/fog/compute.rb +0 -43
  117. data/lib/bbcloud/vendor/fog/lib/fog/compute/brightbox.rb +0 -162
  118. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/account.rb +0 -51
  119. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ip.rb +0 -47
  120. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ips.rb +0 -34
  121. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavor.rb +0 -33
  122. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavors.rb +0 -28
  123. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/image.rb +0 -56
  124. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/images.rb +0 -28
  125. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancer.rb +0 -50
  126. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancers.rb +0 -28
  127. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/server.rb +0 -108
  128. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/servers.rb +0 -29
  129. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/user.rb +0 -39
  130. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/users.rb +0 -29
  131. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zone.rb +0 -21
  132. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zones.rb +0 -29
  133. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/activate_console_server.rb +0 -20
  134. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +0 -20
  135. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +0 -20
  136. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_api_client.rb +0 -19
  137. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +0 -19
  138. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_image.rb +0 -19
  139. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_load_balancer.rb +0 -19
  140. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_server.rb +0 -19
  141. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_api_client.rb +0 -20
  142. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +0 -20
  143. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_image.rb +0 -20
  144. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +0 -20
  145. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_server.rb +0 -20
  146. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_account.rb +0 -19
  147. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_api_client.rb +0 -20
  148. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +0 -20
  149. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_image.rb +0 -20
  150. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_interface.rb +0 -20
  151. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_load_balancer.rb +0 -20
  152. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server.rb +0 -20
  153. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server_type.rb +0 -20
  154. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_user.rb +0 -20
  155. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_zone.rb +0 -20
  156. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_api_clients.rb +0 -19
  157. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +0 -19
  158. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_images.rb +0 -19
  159. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_load_balancers.rb +0 -19
  160. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_server_types.rb +0 -19
  161. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_servers.rb +0 -19
  162. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_users.rb +0 -19
  163. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_zones.rb +0 -19
  164. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +0 -20
  165. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +0 -20
  166. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +0 -20
  167. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +0 -19
  168. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/resize_server.rb +0 -19
  169. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/shutdown_server.rb +0 -20
  170. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/snapshot_server.rb +0 -20
  171. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/start_server.rb +0 -20
  172. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/stop_server.rb +0 -20
  173. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +0 -20
  174. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_account.rb +0 -20
  175. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_api_client.rb +0 -21
  176. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_image.rb +0 -21
  177. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_load_balancer.rb +0 -21
  178. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_server.rb +0 -21
  179. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_user.rb +0 -21
  180. data/lib/bbcloud/vendor/fog/lib/fog/core.rb +0 -32
  181. data/lib/bbcloud/vendor/fog/lib/fog/core/attributes.rb +0 -178
  182. data/lib/bbcloud/vendor/fog/lib/fog/core/collection.rb +0 -127
  183. data/lib/bbcloud/vendor/fog/lib/fog/core/connection.rb +0 -35
  184. data/lib/bbcloud/vendor/fog/lib/fog/core/credentials.rb +0 -92
  185. data/lib/bbcloud/vendor/fog/lib/fog/core/deprecation.rb +0 -23
  186. data/lib/bbcloud/vendor/fog/lib/fog/core/errors.rb +0 -20
  187. data/lib/bbcloud/vendor/fog/lib/fog/core/hmac.rb +0 -48
  188. data/lib/bbcloud/vendor/fog/lib/fog/core/mock.rb +0 -68
  189. data/lib/bbcloud/vendor/fog/lib/fog/core/model.rb +0 -57
  190. data/lib/bbcloud/vendor/fog/lib/fog/core/parser.rb +0 -99
  191. data/lib/bbcloud/vendor/fog/lib/fog/core/provider.rb +0 -18
  192. data/lib/bbcloud/vendor/fog/lib/fog/core/scp.rb +0 -67
  193. data/lib/bbcloud/vendor/fog/lib/fog/core/service.rb +0 -175
  194. data/lib/bbcloud/vendor/fog/lib/fog/core/ssh.rb +0 -120
  195. data/lib/bbcloud/vendor/fog/lib/fog/core/time.rb +0 -27
  196. data/lib/bbcloud/vendor/fog/lib/fog/core/wait_for.rb +0 -17
  197. data/lib/bbcloud/vendor/fog/lib/fog/providers.rb +0 -9
  198. data/lib/bbcloud/vendor/fog/lib/fog/providers/brightbox.rb +0 -9
@@ -1,37 +1,39 @@
1
- desc 'Update user details'
2
- arg_name 'user-id...'
3
- command [:update] do |c|
4
- c.desc "Path to public ssh key file"
5
- c.long_desc "This is the path to the public ssh key that you'd like to use for new servers. You can specify '-' to read from stdin"
6
- c.flag [:f, "ssh-key"]
1
+ module Brightbox
2
+ desc 'Update user details'
3
+ arg_name 'user-id...'
4
+ command [:update] do |c|
5
+ c.desc "Path to public ssh key file"
6
+ c.long_desc "This is the path to the public ssh key that you'd like to use for new servers. You can specify '-' to read from stdin"
7
+ c.flag [:f, "ssh-key"]
7
8
 
8
- c.desc "Name"
9
- c.flag [:n, "name"]
9
+ c.desc "Name"
10
+ c.flag [:n, "name"]
10
11
 
11
- c.action do |global_options, options, args|
12
+ c.action do |global_options, options, args|
12
13
 
13
- raise "You must specify the user id as the first argument" if args.empty?
14
+ raise "You must specify the user id as the first argument" if args.empty?
14
15
 
15
- user = User.find args.first
16
+ user = User.find args.first
16
17
 
17
- if options[:f] == '-'
18
- user.ssh_key = STDIN.read
19
- elsif options[:f]
20
- File.open(File.expand_path(options[:f])) { |f| user.ssh_key = f.read }
21
- end
18
+ if options[:f] == '-'
19
+ user.ssh_key = STDIN.read
20
+ elsif options[:f]
21
+ File.open(File.expand_path(options[:f])) { |f| user.ssh_key = f.read }
22
+ end
22
23
 
23
- if options[:n]
24
- user.name = options[:n]
25
- end
24
+ if options[:n]
25
+ user.name = options[:n]
26
+ end
26
27
 
27
- user.save
28
+ user.save
28
29
 
29
- table_opts = global_options.merge({
30
- :vertical => true,
31
- :fields => [:id, :name, :email_address, :ssh_key ]
32
- })
30
+ table_opts = global_options.merge({
31
+ :vertical => true,
32
+ :fields => [:id, :name, :email_address, :ssh_key ]
33
+ })
33
34
 
34
- render_table([user], table_opts)
35
+ render_table([user], table_opts)
35
36
 
37
+ end
36
38
  end
37
39
  end
@@ -1,16 +1,18 @@
1
- desc 'List zones'
2
- arg_name '[zone-id...]'
3
- command [:list] do |c|
4
- c.action do |global_options, options, args|
1
+ module Brightbox
2
+ desc 'List zones'
3
+ arg_name '[zone-id...]'
4
+ command [:list] do |c|
5
+ c.action do |global_options, options, args|
5
6
 
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}"
7
+ if args.empty?
8
+ zones = Zone.find(:all)
9
+ else
10
+ zones = Zone.find_or_call(args) do |id|
11
+ warn "Couldn't find zone #{id}"
12
+ end
11
13
  end
12
- end
13
14
 
14
- render_table(zones, global_options)
15
+ render_table(zones, global_options)
16
+ end
15
17
  end
16
18
  end
@@ -1,148 +1,162 @@
1
- class BBConfigError < StandardError ; end
1
+ module Brightbox
2
+ class BBConfigError < StandardError ; end
2
3
 
3
- class BBConfig
4
- require 'fileutils'
5
- require 'ini'
4
+ class BBConfig
5
+ require 'fileutils'
6
+ require 'ini'
6
7
 
7
- attr_writer :client_name
8
+ attr_writer :client_name
8
9
 
9
- def initialize(options = {})
10
- @options = options
11
- end
10
+ def initialize(options = {})
11
+ @options = options
12
+ end
12
13
 
13
- def dir
14
- return @dir if @dir
15
- return nil if @dir == false
16
- @dir = File.expand_path(@options[:dir] || "~/.brightbox")
17
- @config_filename = File.join(@dir, 'config')
18
- # Make the directory if necessary
19
- unless File.exists? @dir
20
- begin
21
- FileUtils.mkdir @dir
22
- rescue Errno::EEXIST
23
- end
14
+ def self.config
15
+ Brightbox.const_set(:CONFIG, new())
16
+ require "bbcloud/gli_global_hooks"
17
+ yield
18
+ ensure
19
+ CONFIG.finish()
24
20
  end
25
- #
26
- if File.directory? @dir
27
- @dir
28
- else
29
- @dir = false
30
- nil
21
+
22
+ def dir
23
+ return @dir if @dir
24
+ return nil if @dir == false
25
+ @dir = File.expand_path(@options[:dir] || default_config_dir)
26
+ @config_filename = File.join(@dir, 'config')
27
+ # Make the directory if necessary
28
+ unless File.exists? @dir
29
+ begin
30
+ FileUtils.mkdir @dir
31
+ rescue Errno::EEXIST
32
+ end
33
+ end
34
+ #
35
+ if File.directory? @dir
36
+ @dir
37
+ else
38
+ @dir = false
39
+ nil
40
+ end
31
41
  end
32
- end
33
42
 
34
- def config_filename
35
- dir
36
- @config_filename
37
- end
43
+ def config_filename
44
+ dir
45
+ @config_filename
46
+ end
38
47
 
39
- def oauth_token_filename
40
- @oauth_token_filename ||= File.join(dir, client_name + '.oauth_token')
41
- end
48
+ def oauth_token_filename
49
+ @oauth_token_filename ||= File.join(dir, client_name + '.oauth_token')
50
+ end
42
51
 
43
- def cache_path
44
- if @cache_path
45
- @cache_path
46
- else
47
- @cache_path = File.join(@dir, 'cache')
48
- unless File.exists? @cache_path
49
- begin
50
- FileUtils.mkdir @cache_path
51
- rescue Errno::EEXIST
52
+ def cache_path
53
+ if @cache_path
54
+ @cache_path
55
+ else
56
+ @cache_path = File.join(@dir, 'cache')
57
+ unless File.exists? @cache_path
58
+ begin
59
+ FileUtils.mkdir @cache_path
60
+ rescue Errno::EEXIST
61
+ end
52
62
  end
63
+ @cache_path
53
64
  end
54
- @cache_path
55
65
  end
56
- end
57
66
 
58
- def cache_id(cid)
59
- FileUtils.touch(File.join(cache_path, cid)) unless cid.nil?
60
- end
67
+ def cache_id(cid)
68
+ FileUtils.touch(File.join(cache_path, cid)) unless cid.nil?
69
+ end
61
70
 
62
- def config
63
- return @config if @config
64
- return {} if @config == false
65
- @config ||= Ini.new config_filename
66
- @config
67
- rescue Ini::Error => e
68
- raise BBConfigError, "Config problem in #{config_filename}: #{e}"
69
- end
71
+ def config
72
+ return @config if @config
73
+ return {} if @config == false
74
+ @config ||= Ini.new config_filename
75
+ @config
76
+ rescue Ini::Error => e
77
+ raise BBConfigError, "Config problem in #{config_filename}: #{e}"
78
+ end
70
79
 
71
- def [](k)
72
- config[k]
73
- end
80
+ def [](k)
81
+ config[k]
82
+ end
74
83
 
75
- def delete_section(name)
76
- config.delete_section name
77
- end
84
+ def delete_section(name)
85
+ config.delete_section name
86
+ end
78
87
 
79
- def save!
80
- if @config.is_a? Ini
81
- @config.write
88
+ def save!
89
+ if @config.is_a? Ini
90
+ @config.write
91
+ end
82
92
  end
83
- end
84
93
 
85
- def clients
86
- config.sections.find_all { |s| s != 'core' }
87
- end
94
+ def clients
95
+ config.sections.find_all { |s| s != 'core' }
96
+ end
88
97
 
89
- def client_name
90
- if @client_name
91
- @client_name
92
- else
93
- default_client = config['core']['default_client']
94
- @client_name = default_client || clients.first
98
+ def client_name
99
+ if @client_name
100
+ @client_name
101
+ else
102
+ default_client = config['core']['default_client']
103
+ @client_name = default_client || clients.first
104
+ end
95
105
  end
96
- end
97
106
 
98
- def to_fog
99
- raise Ini::Error, "No api client configured" unless configured?
100
- c = config[client_name]
101
- %w{api_url client_id secret}.each do |k|
102
- if c[k].to_s.empty?
103
- raise BBConfigError, "#{k} option missing from config in section #{client_name}"
107
+ def to_fog
108
+ raise Ini::Error, "No api client configured" unless configured?
109
+ c = config[client_name]
110
+ %w{api_url client_id secret}.each do |k|
111
+ if c[k].to_s.empty?
112
+ raise BBConfigError, "#{k} option missing from config in section #{client_name}"
113
+ end
104
114
  end
115
+ {
116
+ :provider => 'Brightbox',
117
+ :brightbox_api_url => c['api_url'],
118
+ :brightbox_auth_url => c['auth_url'] || c['api_url'],
119
+ :brightbox_client_id => c['client_id'],
120
+ :brightbox_secret => c['secret']
121
+ }
105
122
  end
106
- {
107
- :provider => 'Brightbox',
108
- :brightbox_api_url => c['api_url'],
109
- :brightbox_auth_url => c['auth_url'] || c['api_url'],
110
- :brightbox_client_id => c['client_id'],
111
- :brightbox_secret => c['secret']
112
- }
113
- end
114
123
 
115
- def oauth_token
116
- if @oauth_token.nil?
117
- if File.exists? oauth_token_filename
118
- File.open(oauth_token_filename, "r") do |f|
119
- @oauth_token = f.read.chomp
124
+ def oauth_token
125
+ if @oauth_token.nil?
126
+ if File.exists? oauth_token_filename
127
+ File.open(oauth_token_filename, "r") do |f|
128
+ @oauth_token = f.read.chomp
129
+ end
130
+ @oauth_token
131
+ else
132
+ @oauth_token = false
120
133
  end
121
- @oauth_token
122
134
  else
123
- @oauth_token = false
135
+ @oauth_token ? @oauth_token : nil
124
136
  end
125
- else
126
- @oauth_token ? @oauth_token : nil
127
137
  end
128
- end
129
138
 
130
- def finish
131
- begin
132
- if configured? and @oauth_token != Api.conn.oauth_token
133
- File.open(oauth_token_filename + ".#{$$}", "w") do |f|
134
- f.write Api.conn.oauth_token
139
+ def finish
140
+ begin
141
+ if configured? and @oauth_token != Api.conn.oauth_token
142
+ File.open(oauth_token_filename + ".#{$$}", "w") do |f|
143
+ f.write Api.conn.oauth_token
144
+ end
145
+ FileUtils.mv oauth_token_filename + ".#{$$}", oauth_token_filename
135
146
  end
136
- FileUtils.mv oauth_token_filename + ".#{$$}", oauth_token_filename
147
+ rescue StandardError => e
148
+ warn "Error writing auth token #{oauth_token_filename}: #{e.class}: #{e}"
137
149
  end
138
- rescue StandardError => e
139
- warn "Error writing auth token #{oauth_token_filename}: #{e.class}: #{e}"
140
150
  end
141
151
 
142
- end
152
+ def configured?
153
+ client_name != nil and !clients.empty?
154
+ end
143
155
 
144
- def configured?
145
- client_name != nil and !clients.empty?
146
- end
156
+ private
157
+ def default_config_dir
158
+ File.join(ENV['HOME'],'.brightbox')
159
+ end
147
160
 
161
+ end
148
162
  end
@@ -0,0 +1,34 @@
1
+ module Brightbox
2
+ class ErrorParser
3
+ include Brightbox::Logging
4
+ attr_accessor :socket_error
5
+
6
+ def initialize(socket_error)
7
+ @socket_error = socket_error
8
+ end
9
+
10
+ def pretty_print
11
+ case socket_error
12
+ when Excon::Errors::ServiceUnavailable
13
+ error "Api currently unavailable"
14
+ when Excon::Errors::Error
15
+ parse_http_error(socket_error)
16
+ else
17
+ error "ERROR: #{socket_error}"
18
+ end
19
+ end
20
+
21
+ def parse_http_error(e)
22
+ if e.respond_to?(:response) and e.response.respond_to?(:body)
23
+ 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
29
+ else
30
+ error "ERROR: #{e}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # Hack to force persistent connections in fog
2
+ module Fog
3
+ class Connection
4
+ def initialize(url, persistent=false)
5
+ @excon = Excon.new(url)
6
+ @persistent = true
7
+ end
8
+ end
9
+ end
10
+
11
+ module Fog
12
+ module Brightbox
13
+ class Compute
14
+ class Real
15
+ attr_accessor :oauth_token
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ module Brightbox
2
+ extend GLI
3
+ # Global options
4
+ desc "Simple output (tab separated, don't draw fancy tables)"
5
+ switch [:s, :simple]
6
+
7
+ desc "Set the api client to use (named in #{CONFIG.config_filename})"
8
+ flag [:c, :client]
9
+
10
+ desc "Disable peer SSL certificate verification"
11
+ switch [:k, :insecure]
12
+
13
+ desc "Display Help"
14
+ switch [:h, :help]
15
+
16
+ # Load the command libraries for the current group
17
+ cmd_group_name = File.basename($0).gsub(/brightbox\-/, '')
18
+ cmd_group_files = File.join(File.dirname(__FILE__), "commands/#{cmd_group_name}*.rb")
19
+ Dir.glob(cmd_group_files).each do |f|
20
+ load f
21
+ end
22
+
23
+ pre do |global_options, command, options, args|
24
+ CONFIG.client_name = ENV["CLIENT"] if ENV["CLIENT"]
25
+ CONFIG.client_name = global_options[:c] if global_options[:c]
26
+
27
+ if global_options[:k] or ENV["INSECURE"]
28
+ Excon.ssl_verify_peer = false
29
+ # FIXME: Overriding this here is not good. Excon calls
30
+ # post_connection_check so it should have an option not to.
31
+ class OpenSSL::SSL::SSLSocket
32
+ def post_connection_check(hostname)
33
+ true
34
+ end
35
+ end
36
+ end
37
+ command = commands[:help] if global_options[:h]
38
+ info "INFO: client_id: #{CONFIG.client_name}" if CONFIG.clients.size > 1
39
+ true
40
+ end
41
+
42
+ on_error do |e|
43
+ ErrorParser.new(e).pretty_print()
44
+ debug e
45
+ debug e.class.to_s
46
+ debug e.backtrace.join("\n")
47
+ exit 1
48
+ end
49
+
50
+ desc 'Display version information'
51
+ command [:version] do |c|
52
+ c.action do |global_options, options, args|
53
+ info "Brightbox CLI version: #{Brightbox::VERSION}, Fog version: #{Fog::VERSION}"
54
+ end
55
+ end
56
+ end