fleetctl-setup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +1 -0
- data/bin/fleetctl-setup +11 -0
- data/fleetctl-setup.gemspec +25 -0
- data/lib/fleetctl/setup/aws/cloud_formation_search.rb +62 -0
- data/lib/fleetctl/setup/aws/search.rb +33 -0
- data/lib/fleetctl/setup/cli.rb +72 -0
- data/lib/fleetctl/setup/version.rb +5 -0
- data/lib/fleetctl/setup.rb +6 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b11ccb97ecf00fb9a6d8a63e587da980ad6d5220
|
4
|
+
data.tar.gz: 36eab04e98702a95ccc206c99197b37c9ff125d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e9c07775947af698dad1a5a22fd382548223af2dc94292fe3cd70396fe8fc2df3488ffdaca7c0f2993ac26f2da7776011c6f9d15fd944db1cf9a5827856e8b1
|
7
|
+
data.tar.gz: 9e67f5db032811e7731027303d2e9b81f52421b128cb554d14522ed60af62e204956f2ad5401144bb8cf92c9bb2673b6fa183c945d54d453c2f89486eeb8e9ef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryan Taylor Long
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# fleetctl-setup
|
2
|
+
|
3
|
+
This tool assists you in using `fleetctl` to control a remote CoreOS cluster. Doing so requires an IP address to one of the nodes on the Cluster. Rather than logging in to AWS and finding that IP manually (which would have to happen everytime, as the IP could change, especialy if you're using the recommended CloudFormation approach with an Auto-Scaling Group), this tool helps by picking a node in a cluster which you specify by a search term.
|
4
|
+
|
5
|
+
At the moment, it only uses the Search term for finding a CloudFormation stack based on its `stack_name`. It should be rather trivial to expand the search to other services.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ gem install fleetctl-setup
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
It uses the `aws-core-api` gem to talk to AWS. This requires authentication with
|
14
|
+
IAM credentials, and a region, to be configured.
|
15
|
+
|
16
|
+
```shell
|
17
|
+
export AWS_ACCESS_KEY_ID="..."
|
18
|
+
export AWS_SECRET_ACCESS_KEY="..."
|
19
|
+
export AWS_REGION=us-east-1
|
20
|
+
```
|
21
|
+
|
22
|
+
Then, run `fleetctl-setup [search]`.
|
23
|
+
|
24
|
+
Assuming you have a CloudFormation stack called 'internal-tools', a search for
|
25
|
+
"tools" may result in this:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ fleetctl-setup tools
|
29
|
+
Looking up instances for CloudFormation Stack: internal-tools
|
30
|
+
Picking randomly from <ip_addr1>, <ip_addr2>, <ip_addr3>, <ip_addr4>.
|
31
|
+
export FLEETCTL_TUNNEL=<ip_addr3>
|
32
|
+
```
|
33
|
+
|
34
|
+
The last line is the variable you need to set in your shell to use `fleetctl`.
|
35
|
+
|
36
|
+
All the output of this tool is on STDERR, save for that last line, so you can eval
|
37
|
+
the output for easier use:
|
38
|
+
|
39
|
+
```
|
40
|
+
$ eval `fleetctl-setup tools`
|
41
|
+
Looking up instances for CloudFormation Stack: internal-tools
|
42
|
+
Picking randomly from <ip_addr1>, <ip_addr2>, <ip_addr3>, <ip_addr4>.
|
43
|
+
|
44
|
+
$ echo $FLEETCTL_TUNNEL
|
45
|
+
<ip_addr4>
|
46
|
+
|
47
|
+
$ fleetctl list-machines
|
48
|
+
MACHINE IP METADATA
|
49
|
+
3f5399cd... <ip_addr1> -
|
50
|
+
b7ff2469... <ip_addr2> -
|
51
|
+
cd411b1d... <ip_addr3> -
|
52
|
+
aa07c493... <ip_addr4> -
|
53
|
+
```
|
54
|
+
|
55
|
+
If you use an ambiguous search term, it will prompt you to choose among the
|
56
|
+
results, before it grabs any info about instances.
|
57
|
+
|
58
|
+
## fleetctl Setup
|
59
|
+
|
60
|
+
To get `fleetctl` installed on your system, refer to the following resources:
|
61
|
+
|
62
|
+
- [CoreOS: Controlling the cluster with fleetctl](https://coreos.com/docs/launching-containers/launching/fleet-using-the-client/)
|
63
|
+
- [fleet: Remote fleet Access](https://github.com/coreos/fleet/blob/master/Documentation/remote-access.md)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/fleetctl-setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fleetctl/setup/cli'
|
4
|
+
|
5
|
+
cli = Fleetctl::Setup::CLI.new(ARGV)
|
6
|
+
cli.parse_opts!
|
7
|
+
|
8
|
+
warn "Picking randomly from #{cli.instance_ips.join(', ')}."
|
9
|
+
ip_address = cli.instance_ips.sample
|
10
|
+
|
11
|
+
puts "export FLEETCTL_TUNNEL=#{ip_address}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fleetctl/setup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fleetctl-setup"
|
8
|
+
spec.version = Fleetctl::Setup::VERSION
|
9
|
+
spec.authors = ["Ryan Taylor Long"]
|
10
|
+
spec.email = ["ryan@rtlong.com"]
|
11
|
+
spec.summary = %q{Determines the endpoint for a CoreOS node in a cluster running on Amazon Web Services}
|
12
|
+
spec.description = %q{Finds the public IP of a random node on a CodeOS cluster running in AWS, and sets the FLEETCTL_TUNNEL variable to allow dev-ops engineers a simple workflow of controlling CoreOS cluster without delving into the AWS console each time}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "pry"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_dependency "aws-sdk-core", ">= 2.0.0.rc6"
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'aws-sdk-core'
|
2
|
+
require 'fleetctl/setup'
|
3
|
+
|
4
|
+
module Fleetctl::Setup
|
5
|
+
module AWS
|
6
|
+
class CloudFormationSearch
|
7
|
+
class Result
|
8
|
+
def initialize(resource)
|
9
|
+
@resource = resource
|
10
|
+
end
|
11
|
+
|
12
|
+
def description
|
13
|
+
"CloudFormation Stack: #{@resource.stack_name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def instances
|
17
|
+
[].tap do |instances|
|
18
|
+
Aws.ec2.describe_instances(filters: [filter]).each do |response|
|
19
|
+
response.reservations.each do |res|
|
20
|
+
instances.concat res.instances
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def filter
|
29
|
+
{ name: 'tag:aws:cloudformation:stack-id', values: [@resource.stack_id] }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class <<self
|
34
|
+
def search(search_term)
|
35
|
+
new(search_term).results
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(search_term)
|
40
|
+
@search_term = search_term
|
41
|
+
end
|
42
|
+
|
43
|
+
def results
|
44
|
+
filtered_resources.map { |r| Result.new(r) }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def filtered_resources
|
50
|
+
all_resources.select do |stack|
|
51
|
+
/#{@search_term}/.match(stack.stack_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def all_resources
|
56
|
+
@all_resources ||= Aws::CloudFormation.new.describe_stacks.stacks
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'fleetctl/setup'
|
2
|
+
require 'fleetctl/setup/aws/cloud_formation_search'
|
3
|
+
|
4
|
+
module Fleetctl::Setup
|
5
|
+
module AWS
|
6
|
+
class Search
|
7
|
+
class <<self
|
8
|
+
def search(search_term)
|
9
|
+
new(search_term).results
|
10
|
+
end
|
11
|
+
|
12
|
+
def service_classes
|
13
|
+
{
|
14
|
+
cloud_formation: CloudFormationSearch
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(search_term)
|
20
|
+
@search_term = search_term
|
21
|
+
end
|
22
|
+
|
23
|
+
def results
|
24
|
+
[].tap do |results|
|
25
|
+
self.class.service_classes.values.each do |klass|
|
26
|
+
results.concat klass.search(@search_term)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'fleetctl/setup'
|
3
|
+
require 'fleetctl/setup/aws/search'
|
4
|
+
|
5
|
+
module Fleetctl::Setup
|
6
|
+
class CLI
|
7
|
+
def initialize(argv=ARGV)
|
8
|
+
@options = {}
|
9
|
+
@argv = argv
|
10
|
+
end
|
11
|
+
attr_reader :options
|
12
|
+
|
13
|
+
def parse_opts!
|
14
|
+
opt_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: fleetctl-setup [search-term]"
|
16
|
+
|
17
|
+
opts.on_tail '-h', '--help', 'show this message' do
|
18
|
+
warn opts
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
opt_parser.parse!(@argv)
|
23
|
+
|
24
|
+
if @argv.empty?
|
25
|
+
warn "ERROR: You must supply a keyword or ID to pick a cluster.\n\n"
|
26
|
+
puts opt_parser
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
options[:search_term] = @argv.join(' ')
|
30
|
+
options.freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
def instance_ips
|
34
|
+
return @instance_ips if @instance_ips
|
35
|
+
|
36
|
+
results = AWS::Search.search(options[:search_term])
|
37
|
+
raise "No results found" if results.empty?
|
38
|
+
|
39
|
+
choice = user_choice(results)
|
40
|
+
warn "Looking up instances for #{choice.description}"
|
41
|
+
|
42
|
+
@instance_ips = choice.instances.map(&:public_ip_address)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def user_choice(choices)
|
48
|
+
return nil if choices.empty?
|
49
|
+
return choices.first if choices.length == 1
|
50
|
+
choices.each_with_index do |choice, i|
|
51
|
+
$stderr.puts "#{i+1}. #{choice.description}"
|
52
|
+
end
|
53
|
+
choice_index = prompt_int('Please enter a number to select an option: ', 1..choices.length)
|
54
|
+
choices[choice_index - 1]
|
55
|
+
end
|
56
|
+
|
57
|
+
def prompt(message, format=nil)
|
58
|
+
begin
|
59
|
+
$stderr.print message
|
60
|
+
response = $stdin.gets.chomp
|
61
|
+
end while format && !format.match(response)
|
62
|
+
response
|
63
|
+
end
|
64
|
+
|
65
|
+
def prompt_int(message, range=nil)
|
66
|
+
begin
|
67
|
+
int = Integer(prompt(message, /\A\d+\z/))
|
68
|
+
end while range && !range.include?(int)
|
69
|
+
int
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fleetctl-setup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Taylor Long
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk-core
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.0.rc6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.0.rc6
|
69
|
+
description: Finds the public IP of a random node on a CodeOS cluster running in AWS,
|
70
|
+
and sets the FLEETCTL_TUNNEL variable to allow dev-ops engineers a simple workflow
|
71
|
+
of controlling CoreOS cluster without delving into the AWS console each time
|
72
|
+
email:
|
73
|
+
- ryan@rtlong.com
|
74
|
+
executables:
|
75
|
+
- fleetctl-setup
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/fleetctl-setup
|
85
|
+
- fleetctl-setup.gemspec
|
86
|
+
- lib/fleetctl/setup.rb
|
87
|
+
- lib/fleetctl/setup/aws/cloud_formation_search.rb
|
88
|
+
- lib/fleetctl/setup/aws/search.rb
|
89
|
+
- lib/fleetctl/setup/cli.rb
|
90
|
+
- lib/fleetctl/setup/version.rb
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.0
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Determines the endpoint for a CoreOS node in a cluster running on Amazon
|
115
|
+
Web Services
|
116
|
+
test_files: []
|
117
|
+
has_rdoc:
|