tugboat 1.3.1 → 2.0.0.RC1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +12 -8
- data/lib/tugboat/cli.rb +8 -7
- data/lib/tugboat/config.rb +8 -12
- data/lib/tugboat/middleware/add_key.rb +9 -6
- data/lib/tugboat/middleware/ask_for_credentials.rb +7 -8
- data/lib/tugboat/middleware/check_configuration.rb +1 -1
- data/lib/tugboat/middleware/check_credentials.rb +4 -2
- data/lib/tugboat/middleware/config.rb +3 -4
- data/lib/tugboat/middleware/create_droplet.rb +32 -26
- data/lib/tugboat/middleware/destroy_droplet.rb +6 -6
- data/lib/tugboat/middleware/destroy_image.rb +6 -6
- data/lib/tugboat/middleware/find_droplet.rb +20 -16
- data/lib/tugboat/middleware/find_image.rb +17 -10
- data/lib/tugboat/middleware/halt_droplet.rb +8 -8
- data/lib/tugboat/middleware/info_droplet.rb +38 -25
- data/lib/tugboat/middleware/info_image.rb +5 -5
- data/lib/tugboat/middleware/inject_client.rb +3 -9
- data/lib/tugboat/middleware/list_droplets.rb +6 -4
- data/lib/tugboat/middleware/list_images.rb +28 -23
- data/lib/tugboat/middleware/list_regions.rb +3 -3
- data/lib/tugboat/middleware/list_sizes.rb +3 -3
- data/lib/tugboat/middleware/list_ssh_keys.rb +5 -4
- data/lib/tugboat/middleware/password_reset.rb +7 -7
- data/lib/tugboat/middleware/rebuild_droplet.rb +8 -8
- data/lib/tugboat/middleware/resize_droplet.rb +7 -7
- data/lib/tugboat/middleware/restart_droplet.rb +8 -8
- data/lib/tugboat/middleware/snapshot_droplet.rb +6 -6
- data/lib/tugboat/middleware/ssh_droplet.rb +3 -1
- data/lib/tugboat/middleware/start_droplet.rb +6 -6
- data/lib/tugboat/middleware/wait_for_state.rb +6 -6
- data/lib/tugboat/version.rb +1 -1
- data/spec/cli/add_key_spec.rb +16 -9
- data/spec/cli/authorize_cli_spec.rb +24 -29
- data/spec/cli/config_cli_spec.rb +57 -0
- data/spec/cli/create_cli_spec.rb +18 -28
- data/spec/cli/debug_cli_spec.rb +8 -14
- data/spec/cli/destroy_cli_spec.rb +39 -50
- data/spec/cli/destroy_image_cli_spec.rb +33 -39
- data/spec/cli/droplets_cli_spec.rb +15 -12
- data/spec/cli/halt_cli_spec.rb +50 -46
- data/spec/cli/images_cli_spec.rb +134 -58
- data/spec/cli/info_cli_spec.rb +139 -139
- data/spec/cli/info_image_cli_spec.rb +113 -26
- data/spec/cli/keys_cli_spec.rb +7 -5
- data/spec/cli/password_reset_cli_spec.rb +46 -44
- data/spec/cli/rebuild_cli_spec.rb +187 -101
- data/spec/cli/regions_cli_spec.rb +13 -6
- data/spec/cli/resize_cli_spec.rb +51 -48
- data/spec/cli/restart_cli_spec.rb +41 -39
- data/spec/cli/sizes_cli_spec.rb +13 -8
- data/spec/cli/snapshot_cli_spec.rb +36 -37
- data/spec/cli/ssh_cli_spec.rb +7 -15
- data/spec/cli/start_cli_spec.rb +39 -35
- data/spec/cli/verify_cli_spec.rb +20 -12
- data/spec/cli/wait_cli_spec.rb +43 -27
- data/spec/config_spec.rb +19 -25
- data/spec/fixtures/create_droplet.json +44 -0
- data/spec/fixtures/create_ssh_key.json +4 -4
- data/spec/fixtures/create_ssh_key_from_file.json +8 -0
- data/spec/fixtures/droplet_start_response.json +13 -0
- data/spec/fixtures/not_found.json +4 -0
- data/spec/fixtures/password_reset_response.json +13 -0
- data/spec/fixtures/power_cycle_response.json +13 -0
- data/spec/fixtures/resize_droplet.json +13 -0
- data/spec/fixtures/restart_response.json +13 -0
- data/spec/fixtures/show_coreos_image.json +23 -0
- data/spec/fixtures/show_droplet.json +90 -11
- data/spec/fixtures/show_droplet_inactive.json +90 -11
- data/spec/fixtures/show_droplets.json +249 -30
- data/spec/fixtures/show_droplets_empty.json +5 -2
- data/spec/fixtures/show_image.json +14 -7
- data/spec/fixtures/show_images.json +1075 -13
- data/spec/fixtures/show_images_global.json +25 -16
- data/spec/fixtures/show_keys.json +15 -7
- data/spec/fixtures/show_redmine_image.json +24 -0
- data/spec/fixtures/show_regions.json +181 -12
- data/spec/fixtures/show_sizes.json +178 -9
- data/spec/fixtures/shutdown_response.json +13 -0
- data/spec/fixtures/snapshot_response.json +13 -0
- data/spec/fixtures/ubuntu_image_9801951.json +24 -0
- data/spec/middleware/check_credentials_spec.rb +4 -3
- data/spec/middleware/inject_client_spec.rb +2 -2
- data/spec/shared/environment.rb +6 -7
- data/spec/spec_helper.rb +1 -1
- data/tugboat.gemspec +39 -19
- metadata +50 -14
- data/spec/fixtures/show_droplet_fuzzy.json +0 -13
- data/spec/fixtures/show_droplets_fuzzy.json +0 -35
- data/spec/fixtures/show_droplets_inactive.json +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4a6516497a6285190e53a1e6209f4c3bc7ff38e
|
4
|
+
data.tar.gz: 1deee8b54ce280230929f27e920fef46b6d471ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f275a9150a93971d9a8e0067c09d51727162c2b97bd52c6acd42faead78c8fbcd713212343ace0c296fa347976ada8e9d5d99c2d7b0268d2f53108fe23ac424
|
7
|
+
data.tar.gz: 4a77d1bd1b256ba368d04c722e13b85802f5344d80f69979ce0887517577dcf95a66507730bb350cd7f54a205c43a66e8b04004393b17784407663c5b6d0bc3a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.3.1](https://github.com/pearkes/tugboat/tree/v1.3.1) (2015-08-02)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/pearkes/tugboat/compare/v1.3.0...v1.3.1)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Bad documentation string [\#174](https://github.com/pearkes/tugboat/issues/174)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Removes wrong help messages for `images`. [\#173](https://github.com/pearkes/tugboat/pull/173) ([haihappen](https://github.com/haihappen))
|
14
|
+
|
3
15
|
## [v1.3.0](https://github.com/pearkes/tugboat/tree/v1.3.0) (2015-07-19)
|
4
16
|
|
5
17
|
[Full Changelog](https://github.com/pearkes/tugboat/compare/v1.2.0...v1.3.0)
|
@@ -36,14 +48,6 @@
|
|
36
48
|
|
37
49
|
- Update ssh to private ip [\#172](https://github.com/pearkes/tugboat/pull/172) ([petems](https://github.com/petems))
|
38
50
|
|
39
|
-
## [v2.0.0.ALPHA](https://github.com/pearkes/tugboat/tree/v2.0.0.ALPHA) (2015-07-18)
|
40
|
-
|
41
|
-
[Full Changelog](https://github.com/pearkes/tugboat/compare/v1.0.0...v2.0.0.ALPHA)
|
42
|
-
|
43
|
-
**Closed issues:**
|
44
|
-
|
45
|
-
- 1.0.0 Release [\#125](https://github.com/pearkes/tugboat/issues/125)
|
46
|
-
|
47
51
|
## [v1.0.0](https://github.com/pearkes/tugboat/tree/v1.0.0) (2015-05-26)
|
48
52
|
|
49
53
|
[Full Changelog](https://github.com/pearkes/tugboat/compare/v0.2.0...v1.0.0)
|
data/lib/tugboat/cli.rb
CHANGED
@@ -73,15 +73,15 @@ module Tugboat
|
|
73
73
|
})
|
74
74
|
end
|
75
75
|
|
76
|
-
desc "images [OPTIONS]", "Retrieve a list of
|
77
|
-
method_option "
|
76
|
+
desc "images [OPTIONS]", "Retrieve a list of images"
|
77
|
+
method_option "show_just_private_images",
|
78
78
|
:type => :boolean,
|
79
79
|
:default => false,
|
80
|
-
:aliases => "-
|
81
|
-
:desc => "Show
|
80
|
+
:aliases => "-p",
|
81
|
+
:desc => "Show just private images"
|
82
82
|
def images
|
83
83
|
Middleware.sequence_list_images.call({
|
84
|
-
"
|
84
|
+
"user_show_just_private_images" => options[:show_just_private_images],
|
85
85
|
"user_quiet" => options[:quiet]
|
86
86
|
})
|
87
87
|
end
|
@@ -102,7 +102,8 @@ module Tugboat
|
|
102
102
|
method_option "use_private_ip",
|
103
103
|
:type => :boolean,
|
104
104
|
:aliases => "-t",
|
105
|
-
:desc => "Use Private IP while private IP is present"
|
105
|
+
:desc => "Use Private IP while private IP is present",
|
106
|
+
:default => false
|
106
107
|
method_option "ssh_user",
|
107
108
|
:type => :string,
|
108
109
|
:aliases => "-u",
|
@@ -122,7 +123,7 @@ module Tugboat
|
|
122
123
|
"user_droplet_fuzzy_name" => name,
|
123
124
|
"user_droplet_ssh_port" => options[:ssh_port],
|
124
125
|
"user_droplet_ssh_user" => options[:ssh_user],
|
125
|
-
"user_droplet_use_private_ip" => options[:
|
126
|
+
"user_droplet_use_private_ip" => options[:use_private_ip],
|
126
127
|
"user_droplet_ssh_opts" => options[:ssh_opts],
|
127
128
|
"user_droplet_ssh_command" => options[:ssh_command],
|
128
129
|
"user_quiet" => options[:quiet]
|
data/lib/tugboat/config.rb
CHANGED
@@ -12,9 +12,9 @@ module Tugboat
|
|
12
12
|
FILE_NAME = '.tugboat'
|
13
13
|
DEFAULT_SSH_KEY_PATH = '.ssh/id_rsa'
|
14
14
|
DEFAULT_SSH_PORT = '22'
|
15
|
-
DEFAULT_REGION = '
|
16
|
-
DEFAULT_IMAGE = '
|
17
|
-
DEFAULT_SIZE = '
|
15
|
+
DEFAULT_REGION = 'nyc2'
|
16
|
+
DEFAULT_IMAGE = 'ubuntu-14-04-x64'
|
17
|
+
DEFAULT_SIZE = '512mb'
|
18
18
|
DEFAULT_SSH_KEY = ''
|
19
19
|
DEFAULT_PRIVATE_NETWORKING = 'false'
|
20
20
|
DEFAULT_BACKUPS_ENABLED = 'false'
|
@@ -37,12 +37,8 @@ module Tugboat
|
|
37
37
|
return
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
@data['authentication']['
|
42
|
-
end
|
43
|
-
|
44
|
-
def api_key
|
45
|
-
@data['authentication']['api_key']
|
40
|
+
def access_token
|
41
|
+
@data['authentication']['access_token']
|
46
42
|
end
|
47
43
|
|
48
44
|
def ssh_key_path
|
@@ -96,7 +92,7 @@ module Tugboat
|
|
96
92
|
end
|
97
93
|
|
98
94
|
# Writes a config file
|
99
|
-
def create_config_file(
|
95
|
+
def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled)
|
100
96
|
# Default SSH Key path
|
101
97
|
if ssh_key_path.empty?
|
102
98
|
ssh_key_path = File.join("~", DEFAULT_SSH_KEY_PATH)
|
@@ -138,8 +134,8 @@ module Tugboat
|
|
138
134
|
File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
|
139
135
|
data = {
|
140
136
|
"authentication" => {
|
141
|
-
"
|
142
|
-
|
137
|
+
"access_token" => access_token
|
138
|
+
},
|
143
139
|
"ssh" => {
|
144
140
|
"ssh_user" => ssh_user,
|
145
141
|
"ssh_key_path" => ssh_key_path ,
|
@@ -2,7 +2,7 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class AddKey < Base
|
4
4
|
def call(env)
|
5
|
-
ocean = env[
|
5
|
+
ocean = env['barge']
|
6
6
|
|
7
7
|
if env["add_key_pub_key"]
|
8
8
|
pub_key_string = env["add_key_pub_key"]
|
@@ -29,15 +29,18 @@ module Tugboat
|
|
29
29
|
|
30
30
|
say "Queueing upload of SSH key '#{env["add_key_name"]}'...", nil, false
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
response = ocean.key.create :name => env["add_key_name"],
|
33
|
+
:public_key => pub_key_string
|
34
34
|
|
35
|
-
|
36
|
-
say
|
35
|
+
unless response.success?
|
36
|
+
say "Failed to create key: #{response.message}", :red
|
37
37
|
exit 1
|
38
38
|
end
|
39
39
|
|
40
|
-
say "
|
40
|
+
say "SSH Key uploaded", :green
|
41
|
+
say
|
42
|
+
say "Name: #{response.ssh_key.name}"
|
43
|
+
say "ID: #{response.ssh_key.id}"
|
41
44
|
|
42
45
|
@app.call(env)
|
43
46
|
end
|
@@ -3,11 +3,10 @@ module Tugboat
|
|
3
3
|
# Ask for user credentials from the command line, then write them out.
|
4
4
|
class AskForCredentials < Base
|
5
5
|
def call(env)
|
6
|
-
say "Note: You can get
|
7
|
-
say "Also Note: Tugboat is setup to work with v1 of the Digital Ocean API (https://developers.digitalocean.com/v1/)", :yellow
|
6
|
+
say "Note: You can get your Access Token from https://cloud.digitalocean.com/settings/tokens/new", :yellow
|
8
7
|
say
|
9
|
-
|
10
|
-
|
8
|
+
access_token = ask "Enter your access token:"
|
9
|
+
access_token.strip!
|
11
10
|
ssh_key_path = ask "Enter your SSH key path (optional, defaults to ~/.ssh/id_rsa):"
|
12
11
|
ssh_user = ask "Enter your SSH user (optional, defaults to root):"
|
13
12
|
ssh_port = ask "Enter your SSH port number (optional, defaults to 22):"
|
@@ -15,15 +14,15 @@ module Tugboat
|
|
15
14
|
say "To retrieve region, image, size and key ID's, you can use the corresponding tugboat command, such as `tugboat images`."
|
16
15
|
say "Defaults can be changed at any time in your ~/.tugboat configuration file."
|
17
16
|
say
|
18
|
-
region = ask "Enter your default region
|
19
|
-
image = ask "Enter your default image ID (optional, defaults to
|
20
|
-
size = ask "Enter your default size
|
17
|
+
region = ask "Enter your default region (optional, defaults to nyc1):"
|
18
|
+
image = ask "Enter your default image ID or image slug (optional, defaults to ubuntu-14-04-x64):"
|
19
|
+
size = ask "Enter your default size (optional, defaults to 512mb)):"
|
21
20
|
ssh_key = ask "Enter your default ssh key ID (optional, defaults to none):"
|
22
21
|
private_networking = ask "Enter your default for private networking (optional, defaults to false):"
|
23
22
|
backups_enabled = ask "Enter your default for enabling backups (optional, defaults to false):"
|
24
23
|
|
25
24
|
# Write the config file.
|
26
|
-
env['config'].create_config_file(
|
25
|
+
env['config'].create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled)
|
27
26
|
env['config'].reload!
|
28
27
|
|
29
28
|
@app.call(env)
|
@@ -5,7 +5,7 @@ module Tugboat
|
|
5
5
|
def call(env)
|
6
6
|
config = env["config"]
|
7
7
|
|
8
|
-
if !config || !config.data || !config.
|
8
|
+
if !config || !config.data || !config.access_token
|
9
9
|
say "You must run `tugboat authorize` in order to connect to DigitalOcean", :red
|
10
10
|
exit 1
|
11
11
|
end
|
@@ -8,9 +8,11 @@ module Tugboat
|
|
8
8
|
# We use a harmless API call to check if the authentication will
|
9
9
|
# work.
|
10
10
|
begin
|
11
|
-
env[
|
11
|
+
env['barge'].droplet.all.list
|
12
12
|
rescue Faraday::Error::ClientError => e
|
13
|
-
say "Authentication with DigitalOcean failed.
|
13
|
+
say "Authentication with DigitalOcean failed."
|
14
|
+
say "Error was: #{e}"
|
15
|
+
say "Try re-running `tugboat authorize`", :red
|
14
16
|
exit 1
|
15
17
|
end
|
16
18
|
|
@@ -8,15 +8,14 @@ module Tugboat
|
|
8
8
|
|
9
9
|
keys_retracted = ''
|
10
10
|
|
11
|
-
config_data = config.data.to_yaml
|
11
|
+
config_data = config.data.to_yaml.gsub(/"/,'')
|
12
12
|
|
13
13
|
if env["user_hide_keys"]
|
14
14
|
keys_retracted = '(Keys Redacted)'
|
15
|
-
config_data = config_data.gsub(/(
|
16
|
-
config_data = config_data.gsub(/(api_key: )([a-zA-Z0-9]+)/,'\1 [REDACTED]')
|
15
|
+
config_data = config_data.gsub(/(access_token: )([a-zA-Z0-9]+)/,'\1 [REDACTED]')
|
17
16
|
end
|
18
17
|
|
19
|
-
say "Current Config #{keys_retracted}", :green
|
18
|
+
say "Current Config #{keys_retracted}\n", :green
|
20
19
|
|
21
20
|
say "Path: #{config.path}"
|
22
21
|
say config_data
|
@@ -2,49 +2,55 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class CreateDroplet < Base
|
4
4
|
def call(env)
|
5
|
-
ocean = env[
|
5
|
+
ocean = env['barge']
|
6
6
|
|
7
7
|
say "Queueing creation of droplet '#{env["create_droplet_name"]}'...", nil, false
|
8
8
|
|
9
9
|
env["create_droplet_region_id"] ?
|
10
|
-
|
11
|
-
|
10
|
+
droplet_region_id = env["create_droplet_region_id"] :
|
11
|
+
droplet_region_id = env["config"].default_region
|
12
12
|
|
13
13
|
env["create_droplet_image_id"] ?
|
14
|
-
|
15
|
-
|
14
|
+
droplet_image_id = env["create_droplet_image_id"] :
|
15
|
+
droplet_image_id = env["config"].default_image
|
16
16
|
|
17
17
|
env["create_droplet_size_id"] ?
|
18
|
-
|
19
|
-
|
18
|
+
droplet_size_id = env["create_droplet_size_id"] :
|
19
|
+
droplet_size_id = env["config"].default_size
|
20
20
|
|
21
21
|
env["create_droplet_ssh_key_ids"] ?
|
22
|
-
|
23
|
-
|
22
|
+
droplet_ssh_key_id = env["create_droplet_ssh_key_ids"] :
|
23
|
+
droplet_ssh_key_id = env["config"].default_ssh_key
|
24
24
|
|
25
25
|
env["create_droplet_private_networking"] ?
|
26
|
-
|
27
|
-
|
26
|
+
droplet_private_networking = env["create_droplet_private_networking"] :
|
27
|
+
droplet_private_networking = env["config"].default_private_networking
|
28
28
|
|
29
29
|
env["create_droplet_backups_enabled"] ?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
droplet_backups_enabled = env["create_droplet_backups_enabled"] :
|
31
|
+
droplet_backups_enabled = env["config"].default_backups_enabled
|
32
|
+
|
33
|
+
droplet_ssh_key_id = nil if droplet_ssh_key_id.empty?
|
34
|
+
|
35
|
+
create_opts = {
|
36
|
+
:name => env["create_droplet_name"],
|
37
|
+
:size => droplet_size_id,
|
38
|
+
:image => "#{droplet_image_id}",
|
39
|
+
:region => droplet_region_id,
|
40
|
+
:ssh_keys => [droplet_ssh_key_id],
|
41
|
+
:private_networking => droplet_private_networking,
|
42
|
+
:backups_enabled => droplet_backups_enabled,
|
43
|
+
:ipv6 => nil,
|
44
|
+
}
|
45
|
+
|
46
|
+
response = ocean.droplet.create(create_opts)
|
47
|
+
|
48
|
+
unless response.success?
|
49
|
+
say "Failed to create Droplet: #{response.message}", :red
|
44
50
|
exit 1
|
45
51
|
end
|
46
52
|
|
47
|
-
say "
|
53
|
+
say "Droplet created!"
|
48
54
|
|
49
55
|
@app.call(env)
|
50
56
|
end
|
@@ -2,19 +2,19 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class DestroyDroplet < Base
|
4
4
|
def call(env)
|
5
|
-
ocean = env[
|
5
|
+
ocean = env['barge']
|
6
6
|
|
7
7
|
say "Queuing destroy for #{env["droplet_id"]} #{env["droplet_name"]}...", nil, false
|
8
8
|
|
9
|
-
|
9
|
+
response = ocean.droplet.destroy env["droplet_id"]
|
10
10
|
|
11
|
-
|
12
|
-
say "
|
11
|
+
unless response.success?
|
12
|
+
say "Failed to destroy Droplet: #{response.message}", :red
|
13
13
|
exit 1
|
14
|
+
else
|
15
|
+
say "Deletion Successful!", :green
|
14
16
|
end
|
15
17
|
|
16
|
-
say "done", :green
|
17
|
-
|
18
18
|
@app.call(env)
|
19
19
|
end
|
20
20
|
end
|
@@ -2,19 +2,19 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class DestroyImage < Base
|
4
4
|
def call(env)
|
5
|
-
ocean = env[
|
5
|
+
ocean = env['barge']
|
6
6
|
|
7
7
|
say "Queuing destroy image for #{env["image_id"]} #{env["image_name"]}...", nil, false
|
8
8
|
|
9
|
-
|
9
|
+
response = ocean.image.destroy env["image_id"]
|
10
10
|
|
11
|
-
|
12
|
-
say "
|
11
|
+
unless response.success?
|
12
|
+
say "Failed to destroy image: #{response.message}", :red
|
13
13
|
exit 1
|
14
|
+
else
|
15
|
+
say 'Image deletion successful!', :green
|
14
16
|
end
|
15
17
|
|
16
|
-
say "done", :green
|
17
|
-
|
18
18
|
@app.call(env)
|
19
19
|
end
|
20
20
|
end
|
@@ -3,7 +3,7 @@ module Tugboat
|
|
3
3
|
# Check if the client has set-up configuration yet.
|
4
4
|
class FindDroplet < Base
|
5
5
|
def call(env)
|
6
|
-
ocean = env[
|
6
|
+
ocean = env['barge']
|
7
7
|
user_fuzzy_name = env['user_droplet_fuzzy_name']
|
8
8
|
user_droplet_name = env['user_droplet_name']
|
9
9
|
user_droplet_id = env['user_droplet_id']
|
@@ -28,21 +28,22 @@ module Tugboat
|
|
28
28
|
|
29
29
|
# Easy for us if they provide an id. Just set it to the droplet_id
|
30
30
|
if user_droplet_id
|
31
|
+
|
31
32
|
if !porcelain
|
32
33
|
say "Droplet id provided. Finding Droplet...", nil, false
|
33
34
|
end
|
34
|
-
|
35
|
+
response = ocean.droplet.show user_droplet_id
|
35
36
|
|
36
|
-
|
37
|
-
say "
|
37
|
+
unless response.success?
|
38
|
+
say "Failed to find Droplet: #{response.message}", :red
|
38
39
|
exit 1
|
39
40
|
end
|
40
41
|
|
41
|
-
env["droplet_id"] =
|
42
|
-
env["droplet_name"] = "(#{
|
43
|
-
env["droplet_ip"] =
|
44
|
-
env["droplet_ip_private"] =
|
45
|
-
env["droplet_status"] =
|
42
|
+
env["droplet_id"] = response.droplet.id
|
43
|
+
env["droplet_name"] = "(#{response.droplet.name})"
|
44
|
+
env["droplet_ip"] = response.droplet.ip_address
|
45
|
+
env["droplet_ip_private"] = response.droplet.private_ip_address
|
46
|
+
env["droplet_status"] = response.droplet.status
|
46
47
|
end
|
47
48
|
|
48
49
|
# If they provide a name, we need to get the ID for it.
|
@@ -53,7 +54,7 @@ module Tugboat
|
|
53
54
|
end
|
54
55
|
|
55
56
|
# Look for the droplet by an exact name match.
|
56
|
-
ocean.
|
57
|
+
ocean.droplet.all.droplets.each do |d|
|
57
58
|
if d.name == user_droplet_name
|
58
59
|
env["droplet_id"] = d.id
|
59
60
|
env["droplet_name"] = "(#{d.name})"
|
@@ -82,7 +83,7 @@ module Tugboat
|
|
82
83
|
found_droplets = []
|
83
84
|
choices = []
|
84
85
|
|
85
|
-
ocean.
|
86
|
+
ocean.droplet.all.droplets.each_with_index do |d, i|
|
86
87
|
# Check to see if one of the droplet names have the fuzzy string.
|
87
88
|
if d.name.upcase.include? user_fuzzy_name.upcase
|
88
89
|
found_droplets << d
|
@@ -92,11 +93,14 @@ module Tugboat
|
|
92
93
|
# Check to see if we have more then one droplet, and prompt
|
93
94
|
# a user to choose otherwise.
|
94
95
|
if found_droplets.length == 1
|
95
|
-
|
96
|
-
|
97
|
-
env["
|
98
|
-
env["
|
99
|
-
env["
|
96
|
+
droplet_return = found_droplets.first
|
97
|
+
|
98
|
+
env["droplet_id"] = droplet_return.id
|
99
|
+
env["droplet_name"] = "(#{droplet_return.name})"
|
100
|
+
env["droplet_ip"] = droplet_return.networks.v4.detect { |address| address.type == 'public' }.ip_address
|
101
|
+
check_private_ip = droplet_return.networks.v4.detect { |address| address.type == 'private' }
|
102
|
+
env["droplet_ip_private"] = check_private_ip.ip_address if check_private_ip
|
103
|
+
env["droplet_status"] = droplet_return.status
|
100
104
|
elsif found_droplets.length > 1
|
101
105
|
# Did we run the multiple questionairre?
|
102
106
|
did_run_multiple = true
|
@@ -3,7 +3,7 @@ module Tugboat
|
|
3
3
|
# Check if the client has set-up configuration yet.
|
4
4
|
class FindImage < Base
|
5
5
|
def call(env)
|
6
|
-
ocean = env[
|
6
|
+
ocean = env['barge']
|
7
7
|
user_fuzzy_name = env['user_image_fuzzy_name']
|
8
8
|
user_image_name = env['user_image_name']
|
9
9
|
user_image_id = env['user_image_id']
|
@@ -23,24 +23,24 @@ module Tugboat
|
|
23
23
|
# Easy for us if they provide an id. Just set it to the image_id
|
24
24
|
if user_image_id
|
25
25
|
say "Image id provided. Finding Image...", nil, false
|
26
|
-
|
26
|
+
response = ocean.image.show user_image_id
|
27
27
|
|
28
|
-
|
29
|
-
say "
|
28
|
+
unless response.success?
|
29
|
+
say "Failed to find Image: #{response.message}", :red
|
30
30
|
exit 1
|
31
31
|
end
|
32
32
|
|
33
|
-
env["image_id"] =
|
34
|
-
env["image_name"] = "(#{
|
33
|
+
env["image_id"] = response.image.id
|
34
|
+
env["image_name"] = "(#{response.image.name})"
|
35
35
|
end
|
36
36
|
|
37
37
|
# If they provide a name, we need to get the ID for it.
|
38
38
|
# This requires a lookup.
|
39
39
|
if user_image_name && !env["image_id"]
|
40
|
-
say "Image name provided. Finding
|
40
|
+
say "Image name provided. Finding Image...", nil, false
|
41
41
|
|
42
42
|
# Look for the image by an exact name match.
|
43
|
-
ocean.
|
43
|
+
ocean.image.all['images'].each do |d|
|
44
44
|
if d.name == user_image_name
|
45
45
|
env["image_id"] = d.id
|
46
46
|
env["image_name"] = "(#{d.name})"
|
@@ -50,7 +50,7 @@ module Tugboat
|
|
50
50
|
# If we coulnd't find it, tell the user and drop out of the
|
51
51
|
# sequence.
|
52
52
|
if !env["image_id"]
|
53
|
-
say "error\nUnable to find
|
53
|
+
say "error\nUnable to find an image named '#{user_image_name}'.", :red
|
54
54
|
exit 1
|
55
55
|
end
|
56
56
|
end
|
@@ -66,11 +66,18 @@ module Tugboat
|
|
66
66
|
found_images = []
|
67
67
|
choices = []
|
68
68
|
|
69
|
-
ocean.
|
69
|
+
ocean.image.all['images'].each_with_index do |d, i|
|
70
|
+
|
70
71
|
# Check to see if one of the image names have the fuzzy string.
|
71
72
|
if d.name.upcase.include? user_fuzzy_name.upcase
|
72
73
|
found_images << d
|
73
74
|
end
|
75
|
+
|
76
|
+
unless d.slug.nil?
|
77
|
+
if d.slug.upcase.include? user_fuzzy_name.upcase
|
78
|
+
found_images << d
|
79
|
+
end
|
80
|
+
end
|
74
81
|
end
|
75
82
|
|
76
83
|
# Check to see if we have more then one image, and prompt
|
@@ -2,23 +2,23 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class HaltDroplet < Base
|
4
4
|
def call(env)
|
5
|
-
ocean = env[
|
5
|
+
ocean = env['barge']
|
6
6
|
|
7
|
-
|
7
|
+
response = if env["user_droplet_hard"]
|
8
8
|
say "Queuing hard shutdown for #{env["droplet_id"]} #{env["droplet_name"]}...", nil, false
|
9
|
-
ocean.
|
9
|
+
ocean.droplet.power_off env["droplet_id"]
|
10
10
|
else
|
11
11
|
say "Queuing shutdown for #{env["droplet_id"]} #{env["droplet_name"]}...", nil, false
|
12
|
-
ocean.
|
12
|
+
ocean.droplet.shutdown env["droplet_id"]
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
say
|
15
|
+
unless response.success?
|
16
|
+
say "Failed to halt on Droplet: #{response.message}", :red
|
17
17
|
exit 1
|
18
|
+
else
|
19
|
+
say "Halt successful!", :green
|
18
20
|
end
|
19
21
|
|
20
|
-
say "done", :green
|
21
|
-
|
22
22
|
@app.call(env)
|
23
23
|
end
|
24
24
|
end
|