bbcloud 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -2
- data/Gemfile +3 -0
- data/README +11 -1
- data/README.rdoc +11 -1
- data/Rakefile +12 -0
- data/bbcloud.gemspec +10 -10
- data/bin/brightbox-accounts +7 -2
- data/bin/brightbox-cloudips +7 -2
- data/bin/brightbox-config +7 -2
- data/bin/brightbox-images +7 -2
- data/bin/brightbox-lbs +7 -2
- data/bin/brightbox-servers +7 -2
- data/bin/brightbox-types +7 -2
- data/bin/brightbox-users +7 -2
- data/bin/brightbox-zones +7 -2
- data/lib/bbcloud.rb +43 -0
- data/lib/bbcloud/accounts.rb +5 -3
- data/lib/bbcloud/command_generator.rb +50 -0
- data/lib/bbcloud/commands/accounts-list.rb +13 -11
- data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +26 -23
- data/lib/bbcloud/commands/accounts-show.rb +20 -16
- data/lib/bbcloud/commands/cloudips-create.rb +16 -14
- data/lib/bbcloud/commands/cloudips-destroy.rb +29 -26
- data/lib/bbcloud/commands/cloudips-list.rb +13 -11
- data/lib/bbcloud/commands/cloudips-map.rb +48 -46
- data/lib/bbcloud/commands/cloudips-show.rb +15 -12
- data/lib/bbcloud/commands/cloudips-unmap.rb +28 -25
- data/lib/bbcloud/commands/config-client-add.rb +33 -31
- data/lib/bbcloud/commands/config-client-default.rb +18 -16
- data/lib/bbcloud/commands/config-client-list.rb +19 -16
- data/lib/bbcloud/commands/config-client-remove.rb +18 -16
- data/lib/bbcloud/commands/images-destroy.rb +18 -16
- data/lib/bbcloud/commands/images-list.rb +20 -18
- data/lib/bbcloud/commands/images-register.rb +21 -19
- data/lib/bbcloud/commands/images-show.rb +17 -15
- data/lib/bbcloud/commands/lbs-add-nodes.rb +15 -13
- data/lib/bbcloud/commands/lbs-create.rb +65 -63
- data/lib/bbcloud/commands/lbs-destroy.rb +13 -11
- data/lib/bbcloud/commands/lbs-list.rb +13 -11
- data/lib/bbcloud/commands/lbs-remove-nodes.rb +15 -13
- data/lib/bbcloud/commands/lbs-show.rb +15 -13
- data/lib/bbcloud/commands/lbs-update.rb +59 -57
- data/lib/bbcloud/commands/servers-activate-cloud.rb +18 -16
- data/lib/bbcloud/commands/servers-create.rb +80 -77
- data/lib/bbcloud/commands/servers-destroy.rb +17 -15
- data/lib/bbcloud/commands/servers-list.rb +14 -14
- data/lib/bbcloud/commands/servers-show.rb +39 -37
- data/lib/bbcloud/commands/servers-shutdown.rb +14 -12
- data/lib/bbcloud/commands/servers-snapshot.rb +14 -12
- data/lib/bbcloud/commands/servers-start.rb +15 -13
- data/lib/bbcloud/commands/servers-stop.rb +14 -12
- data/lib/bbcloud/commands/types-list.rb +13 -11
- data/lib/bbcloud/commands/types-show.rb +18 -16
- data/lib/bbcloud/commands/users-list.rb +13 -11
- data/lib/bbcloud/commands/users-show.rb +17 -15
- data/lib/bbcloud/commands/users-update.rb +27 -25
- data/lib/bbcloud/commands/zones-list.rb +13 -11
- data/lib/bbcloud/config.rb +125 -111
- data/lib/bbcloud/error_parser.rb +34 -0
- data/lib/bbcloud/fog_extensions.rb +19 -0
- data/lib/bbcloud/gli_global_hooks.rb +56 -0
- data/lib/bbcloud/logging.rb +40 -0
- data/lib/bbcloud/ruby_core_ext.rb +9 -0
- data/lib/bbcloud/servers.rb +7 -2
- data/lib/bbcloud/tables.rb +78 -73
- data/lib/bbcloud/vendor/gli/.gitignore +10 -0
- data/lib/bbcloud/vendor/gli/.rvmrc +1 -0
- data/lib/bbcloud/vendor/gli/Gemfile +5 -0
- data/lib/bbcloud/vendor/gli/LICENSE.txt +201 -0
- data/lib/bbcloud/vendor/gli/README.rdoc +54 -0
- data/lib/bbcloud/vendor/gli/Rakefile +84 -0
- data/lib/bbcloud/vendor/gli/bin/gli +72 -0
- data/lib/bbcloud/vendor/gli/bin/report_on_rake_results +10 -0
- data/lib/bbcloud/vendor/gli/bin/test_all_rubies.sh +2 -0
- data/lib/bbcloud/vendor/gli/features/gli_executable.feature +88 -0
- data/lib/bbcloud/vendor/gli/features/gli_init.feature +122 -0
- data/lib/bbcloud/vendor/gli/features/step_definitions/gli_executable_steps.rb +12 -0
- data/lib/bbcloud/vendor/gli/features/step_definitions/gli_init_steps.rb +4 -0
- data/lib/bbcloud/vendor/gli/features/support/env.rb +21 -0
- data/lib/bbcloud/vendor/gli/gli.cheat +80 -0
- data/lib/bbcloud/vendor/gli/gli.gemspec +46 -0
- data/lib/bbcloud/vendor/gli/gli.rdoc +51 -0
- data/lib/bbcloud/vendor/gli/lib/gli.rb +560 -0
- data/lib/bbcloud/vendor/gli/lib/gli/command.rb +124 -0
- data/lib/bbcloud/vendor/gli/lib/gli/command_line_token.rb +58 -0
- data/lib/bbcloud/vendor/gli/lib/gli/copy_options_to_aliases.rb +33 -0
- data/lib/bbcloud/vendor/gli/lib/gli/exceptions.rb +45 -0
- data/lib/bbcloud/vendor/gli/lib/gli/flag.rb +67 -0
- data/lib/bbcloud/vendor/gli/lib/gli/options.rb +19 -0
- data/lib/bbcloud/vendor/gli/lib/gli/switch.rb +63 -0
- data/lib/bbcloud/vendor/gli/lib/gli/terminal.rb +79 -0
- data/lib/bbcloud/vendor/gli/lib/gli_version.rb +3 -0
- data/lib/bbcloud/vendor/gli/lib/support/help.rb +180 -0
- data/lib/bbcloud/vendor/gli/lib/support/initconfig.rb +34 -0
- data/lib/bbcloud/vendor/gli/lib/support/rdoc.rb +119 -0
- data/lib/bbcloud/vendor/gli/lib/support/scaffold.rb +284 -0
- data/lib/bbcloud/vendor/gli/test/config.yaml +9 -0
- data/lib/bbcloud/vendor/gli/test/gli.reek +116 -0
- data/lib/bbcloud/vendor/gli/test/roodi.yaml +9 -0
- data/lib/bbcloud/vendor/gli/test/tc_command.rb +329 -0
- data/lib/bbcloud/vendor/gli/test/tc_flag.rb +67 -0
- data/lib/bbcloud/vendor/gli/test/tc_gli.rb +429 -0
- data/lib/bbcloud/vendor/gli/test/tc_options.rb +31 -0
- data/lib/bbcloud/vendor/gli/test/tc_parsing.rb +279 -0
- data/lib/bbcloud/vendor/gli/test/tc_switch.rb +80 -0
- data/lib/bbcloud/vendor/gli/test/tc_terminal.rb +91 -0
- data/lib/bbcloud/version.rb +1 -1
- data/pkg/bbcloud-0.12.0.gem +0 -0
- data/spec/fixtures/vcr_cassettes/server_list.yml +117 -0
- data/spec/servers_spec.rb +36 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/common_helpers.rb +47 -0
- metadata +129 -135
- data/lib/bbcloud/cli.rb +0 -160
- data/lib/bbcloud/vendor/fog/lib/fog.rb +0 -14
- data/lib/bbcloud/vendor/fog/lib/fog/compute.rb +0 -43
- data/lib/bbcloud/vendor/fog/lib/fog/compute/brightbox.rb +0 -162
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/account.rb +0 -51
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ip.rb +0 -47
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ips.rb +0 -34
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavor.rb +0 -33
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavors.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/image.rb +0 -56
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/images.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancer.rb +0 -50
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancers.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/server.rb +0 -108
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/servers.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/user.rb +0 -39
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/users.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zone.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zones.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/activate_console_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_api_client.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_image.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_load_balancer.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_server.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_api_client.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_image.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_account.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_api_client.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_image.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_interface.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server_type.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_user.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_zone.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_api_clients.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_images.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_load_balancers.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_server_types.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_servers.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_users.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_zones.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/resize_server.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/shutdown_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/snapshot_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/start_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/stop_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_account.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_api_client.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_image.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_load_balancer.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_server.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_user.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/core.rb +0 -32
- data/lib/bbcloud/vendor/fog/lib/fog/core/attributes.rb +0 -178
- data/lib/bbcloud/vendor/fog/lib/fog/core/collection.rb +0 -127
- data/lib/bbcloud/vendor/fog/lib/fog/core/connection.rb +0 -35
- data/lib/bbcloud/vendor/fog/lib/fog/core/credentials.rb +0 -92
- data/lib/bbcloud/vendor/fog/lib/fog/core/deprecation.rb +0 -23
- data/lib/bbcloud/vendor/fog/lib/fog/core/errors.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/core/hmac.rb +0 -48
- data/lib/bbcloud/vendor/fog/lib/fog/core/mock.rb +0 -68
- data/lib/bbcloud/vendor/fog/lib/fog/core/model.rb +0 -57
- data/lib/bbcloud/vendor/fog/lib/fog/core/parser.rb +0 -99
- data/lib/bbcloud/vendor/fog/lib/fog/core/provider.rb +0 -18
- data/lib/bbcloud/vendor/fog/lib/fog/core/scp.rb +0 -67
- data/lib/bbcloud/vendor/fog/lib/fog/core/service.rb +0 -175
- data/lib/bbcloud/vendor/fog/lib/fog/core/ssh.rb +0 -120
- data/lib/bbcloud/vendor/fog/lib/fog/core/time.rb +0 -27
- data/lib/bbcloud/vendor/fog/lib/fog/core/wait_for.rb +0 -17
- data/lib/bbcloud/vendor/fog/lib/fog/providers.rb +0 -9
- data/lib/bbcloud/vendor/fog/lib/fog/providers/brightbox.rb +0 -9
@@ -1,37 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
9
|
+
c.desc "Name"
|
10
|
+
c.flag [:n, "name"]
|
10
11
|
|
11
|
-
|
12
|
+
c.action do |global_options, options, args|
|
12
13
|
|
13
|
-
|
14
|
+
raise "You must specify the user id as the first argument" if args.empty?
|
14
15
|
|
15
|
-
|
16
|
+
user = User.find args.first
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
24
|
+
if options[:n]
|
25
|
+
user.name = options[:n]
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
user.save
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
table_opts = global_options.merge({
|
31
|
+
:vertical => true,
|
32
|
+
:fields => [:id, :name, :email_address, :ssh_key ]
|
33
|
+
})
|
33
34
|
|
34
|
-
|
35
|
+
render_table([user], table_opts)
|
35
36
|
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
15
|
+
render_table(zones, global_options)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/bbcloud/config.rb
CHANGED
@@ -1,148 +1,162 @@
|
|
1
|
-
|
1
|
+
module Brightbox
|
2
|
+
class BBConfigError < StandardError ; end
|
2
3
|
|
3
|
-
class BBConfig
|
4
|
-
|
5
|
-
|
4
|
+
class BBConfig
|
5
|
+
require 'fileutils'
|
6
|
+
require 'ini'
|
6
7
|
|
7
|
-
|
8
|
+
attr_writer :client_name
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
27
|
-
@dir
|
28
|
-
|
29
|
-
@dir =
|
30
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
def config_filename
|
44
|
+
dir
|
45
|
+
@config_filename
|
46
|
+
end
|
38
47
|
|
39
|
-
|
40
|
-
|
41
|
-
|
48
|
+
def oauth_token_filename
|
49
|
+
@oauth_token_filename ||= File.join(dir, client_name + '.oauth_token')
|
50
|
+
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
67
|
+
def cache_id(cid)
|
68
|
+
FileUtils.touch(File.join(cache_path, cid)) unless cid.nil?
|
69
|
+
end
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
80
|
+
def [](k)
|
81
|
+
config[k]
|
82
|
+
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
84
|
+
def delete_section(name)
|
85
|
+
config.delete_section name
|
86
|
+
end
|
78
87
|
|
79
|
-
|
80
|
-
|
81
|
-
|
88
|
+
def save!
|
89
|
+
if @config.is_a? Ini
|
90
|
+
@config.write
|
91
|
+
end
|
82
92
|
end
|
83
|
-
end
|
84
93
|
|
85
|
-
|
86
|
-
|
87
|
-
|
94
|
+
def clients
|
95
|
+
config.sections.find_all { |s| s != 'core' }
|
96
|
+
end
|
88
97
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
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
|
-
|
152
|
+
def configured?
|
153
|
+
client_name != nil and !clients.empty?
|
154
|
+
end
|
143
155
|
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|