kontena-plugin-aws 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ require 'shell-spinner'
2
+ require_relative 'common'
3
+
4
+ module Kontena::Machine::Aws
5
+ class NodeRestarter
6
+ include Common
7
+
8
+ attr_reader :ec2, :api_client
9
+
10
+ # @param [String] access_key_id aws_access_key_id
11
+ # @param [String] secret_key aws_secret_access_key
12
+ # @param [String] region
13
+ def initialize(access_key_id, secret_key, region)
14
+ @ec2 = ::Aws::EC2::Resource.new(
15
+ region: region, credentials: ::Aws::Credentials.new(access_key_id, secret_key)
16
+ )
17
+ end
18
+
19
+ def run!(name)
20
+ instances = ec2.instances({
21
+ filters: [
22
+ {name: 'tag:Name', values: [name]}
23
+ ]
24
+ })
25
+ abort("Cannot find AWS instance #{name}") if instances.to_a.size == 0
26
+ abort("There are multiple instances with name #{name}") if instances.to_a.size > 1
27
+ instance = instances.first
28
+ if instance
29
+ ShellSpinner "Restarting AWS instance #{name.colorize(:cyan)} " do
30
+ instance.reboot(dry_run: false)
31
+ end
32
+ else
33
+ abort "Cannot find instance #{name.colorize(:cyan)} in AWS"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Kontena
2
+ module Plugin
3
+ module Aws
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ require 'securerandom'
2
+
3
+ module Kontena::Plugin::Aws::Master
4
+ class CreateCommand < Kontena::Command
5
+ include Kontena::Cli::Common
6
+
7
+ option "--access-key", "ACCESS_KEY", "AWS access key ID", required: true
8
+ option "--secret-key", "SECRET_KEY", "AWS secret key", required: true
9
+ option "--key-pair", "KEY_PAIR", "EC2 key pair name", required: true
10
+ option "--ssl-cert", "SSL CERT", "SSL certificate file (default: generate self-signed cert)"
11
+ option "--region", "REGION", "EC2 Region", default: 'eu-west-1'
12
+ option "--zone", "ZONE", "EC2 Availability Zone", default: 'a'
13
+ option "--vpc-id", "VPC ID", "Virtual Private Cloud (VPC) ID (default: default vpc)"
14
+ option "--subnet-id", "SUBNET ID", "VPC option to specify subnet to launch instance into (default: first subnet from vpc/az)"
15
+ option "--type", "SIZE", "Instance type", default: 't2.small'
16
+ option "--storage", "STORAGE", "Storage size (GiB)", default: '30'
17
+ option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (default: generate random secret)"
18
+ option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (default: generate random iv)"
19
+ option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
20
+ option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
21
+ option "--auth-provider-url", "AUTH_PROVIDER_URL", "Define authentication provider url (optional)"
22
+ option "--associate-public-ip-address", :flag, "Whether to associated public IP in case the VPC defaults to not doing it", default: true, attribute_name: :associate_public_ip
23
+ option "--security-groups", "SECURITY_GROUPS", "Comma separated list of security groups (names) where the new instance will be attached (default: create 'kontena_master' group if not already existing)"
24
+
25
+
26
+ def execute
27
+ require 'kontena/machine/aws'
28
+
29
+ provisioner = provisioner(access_key, secret_key, region)
30
+ provisioner.run!(
31
+ type: type,
32
+ vpc: vpc_id,
33
+ zone: zone,
34
+ subnet: subnet_id,
35
+ ssl_cert: ssl_cert,
36
+ storage: storage,
37
+ version: version,
38
+ key_pair: key_pair,
39
+ auth_server: auth_provider_url,
40
+ vault_secret: vault_secret || SecureRandom.hex(24),
41
+ vault_iv: vault_iv || SecureRandom.hex(24),
42
+ mongodb_uri: mongodb_uri,
43
+ associate_public_ip: associate_public_ip?,
44
+ security_groups: security_groups
45
+ )
46
+ end
47
+
48
+ def provisioner(access_key, secret_key, region)
49
+ Kontena::Machine::Aws::MasterProvisioner.new(access_key, secret_key, region)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'master/create_command'
2
+
3
+ class Kontena::Plugin::Aws::MasterCommand < Kontena::Command
4
+
5
+ subcommand "create", "Create a new master to AWS", Kontena::Plugin::Aws::Master::CreateCommand
6
+
7
+ def execute
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'nodes/create_command'
2
+ require_relative 'nodes/restart_command'
3
+ require_relative 'nodes/terminate_command'
4
+
5
+ class Kontena::Plugin::Aws::NodeCommand < Kontena::Command
6
+
7
+ subcommand "create", "Create a new node to AWS", Kontena::Plugin::Aws::Nodes::CreateCommand
8
+ subcommand "restart", "Restart AWS node", Kontena::Plugin::Aws::Nodes::RestartCommand
9
+ subcommand "terminate", "Terminate AWS node", Kontena::Plugin::Aws::Nodes::TerminateCommand
10
+
11
+ def execute
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ module Kontena::Plugin::Aws::Nodes
2
+ class CreateCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "[NAME]", "Node name"
7
+ option "--access-key", "ACCESS_KEY", "AWS access key ID", required: true
8
+ option "--secret-key", "SECRET_KEY", "AWS secret key", required: true
9
+ option "--key-pair", "KEY_PAIR", "EC2 Key Pair", required: true
10
+ option "--region", "REGION", "EC2 Region", default: 'eu-west-1'
11
+ option "--zone", "ZONE", "EC2 Availability Zone", default: 'a'
12
+ option "--vpc-id", "VPC ID", "Virtual Private Cloud (VPC) ID (default: default vpc)"
13
+ option "--subnet-id", "SUBNET ID", "VPC option to specify subnet to launch instance into (default: first subnet in vpc/az)"
14
+ option "--type", "SIZE", "Instance type", default: 't2.small'
15
+ option "--storage", "STORAGE", "Storage size (GiB)", default: '30'
16
+ option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
17
+ option "--associate-public-ip-address", :flag, "Whether to associated public IP in case the VPC defaults to not doing it", default: true, attribute_name: :associate_public_ip
18
+ option "--security-groups", "SECURITY GROUPS", "Comma separated list of security groups (names) where the new instance will be attached (default: create grid specific group if not already existing)"
19
+
20
+ def execute
21
+ require_api_url
22
+ require_current_grid
23
+
24
+ require 'kontena/machine/aws'
25
+ grid = fetch_grid(current_grid)
26
+ provisioner = provisioner(client(require_token), access_key, secret_key, region)
27
+ provisioner.run!(
28
+ master_uri: api_url,
29
+ grid_token: grid['token'],
30
+ grid: current_grid,
31
+ name: name,
32
+ type: type,
33
+ vpc: vpc_id,
34
+ zone: zone,
35
+ subnet: subnet_id,
36
+ storage: storage,
37
+ version: version,
38
+ key_pair: key_pair,
39
+ associate_public_ip: associate_public_ip?,
40
+ security_groups: security_groups
41
+ )
42
+ end
43
+
44
+ # @param [String] id
45
+ # @return [Hash]
46
+ def fetch_grid(id)
47
+ client(require_token).get("grids/#{id}")
48
+ end
49
+
50
+ # @param [Kontena::Client] client
51
+ # @param [String] access_key
52
+ # @param [String] secret_key
53
+ # @param [String] region
54
+ # @return [Kontena::Machine::Aws::NodeProvisioner]
55
+ def provisioner(client, access_key, secret_key, region)
56
+ Kontena::Machine::Aws::NodeProvisioner.new(client, access_key, secret_key, region)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ module Kontena::Plugin::Aws::Nodes
2
+ class RestartCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--access-key", "ACCESS_KEY", "AWS access key ID", required: true
8
+ option "--secret-key", "SECRET_KEY", "AWS secret key", required: true
9
+ option "--region", "REGION", "EC2 Region", default: 'eu-west-1'
10
+
11
+ def execute
12
+ require_api_url
13
+ require_current_grid
14
+
15
+ require_relative '../../../machine/aws'
16
+
17
+ restarter = restarter(access_key, secret_key, region)
18
+ restarter.run!(name)
19
+ end
20
+
21
+ def restarter(access_key, secret_key, region)
22
+ Kontena::Machine::Aws::NodeRestarter.new(access_key, secret_key, region)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Kontena::Plugin::Aws::Nodes
2
+ class TerminateCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--access-key", "ACCESS_KEY", "AWS access key ID", required: true
8
+ option "--secret-key", "SECRET_KEY", "AWS secret key", required: true
9
+ option "--region", "REGION", "EC2 Region", default: 'eu-west-1'
10
+
11
+ def execute
12
+ require_api_url
13
+ require_current_grid
14
+
15
+ require 'kontena/machine/aws'
16
+ grid = client(require_token).get("grids/#{current_grid}")
17
+ destroyer = destroyer(client(require_token), access_key, secret_key, region)
18
+ destroyer.run!(grid, name)
19
+ end
20
+
21
+ def destroyer(client, access_key, secret_key, region)
22
+ Kontena::Machine::Aws::NodeDestroyer.new(client, access_key, secret_key, region)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'aws/master_command'
2
+ require_relative 'aws/node_command'
3
+
4
+ class Kontena::Plugin::AwsCommand < Kontena::Command
5
+
6
+ subcommand 'master', 'AWS master related commands', Kontena::Plugin::Aws::MasterCommand
7
+ subcommand 'node', 'AWS node related commands', Kontena::Plugin::Aws::NodeCommand
8
+
9
+ def execute
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'kontena_cli'
2
+ require_relative 'kontena/plugin/aws'
3
+ require_relative 'kontena/plugin/aws_command'
4
+
5
+ Kontena::MainCommand.register("aws", "AWS specific commands", Kontena::Plugin::AwsCommand)
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kontena-plugin-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kontena, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kontena-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.0.rc1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.0.rc1
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 2.3.11
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.3'
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.11
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.11'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description: Kontena Amazon Web Services plugin
76
+ email:
77
+ - info@kontena.io
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - .gitignore
83
+ - .gitmodules
84
+ - .rspec
85
+ - .travis.yml
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - kontena-plugin-aws.gemspec
90
+ - lib/kontena/machine/aws.rb
91
+ - lib/kontena/machine/aws/cloudinit.yml
92
+ - lib/kontena/machine/aws/cloudinit_master.yml
93
+ - lib/kontena/machine/aws/common.rb
94
+ - lib/kontena/machine/aws/master_provisioner.rb
95
+ - lib/kontena/machine/aws/node_destroyer.rb
96
+ - lib/kontena/machine/aws/node_provisioner.rb
97
+ - lib/kontena/machine/aws/node_restarter.rb
98
+ - lib/kontena/plugin/aws.rb
99
+ - lib/kontena/plugin/aws/master/create_command.rb
100
+ - lib/kontena/plugin/aws/master_command.rb
101
+ - lib/kontena/plugin/aws/node_command.rb
102
+ - lib/kontena/plugin/aws/nodes/create_command.rb
103
+ - lib/kontena/plugin/aws/nodes/restart_command.rb
104
+ - lib/kontena/plugin/aws/nodes/terminate_command.rb
105
+ - lib/kontena/plugin/aws_command.rb
106
+ - lib/kontena_cli_plugin.rb
107
+ homepage: https://github.com/kontena/kontena-plugin-aws
108
+ licenses:
109
+ - Apache-2.0
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Kontena AWS plugin
131
+ test_files: []