instance_selector 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bin
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in instance_selector.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kevin McFadden
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,80 @@
1
+ # InstanceSelector
2
+
3
+ A simple interface for querying DNS names cloud hosting environments based on searching cloud meta data. It also provides a liberal Capistrano interface for identifying deploy targets.
4
+
5
+ Currently supporting:
6
+
7
+ - AWS
8
+ - ec2 instance filtering
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'instance_selector'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install instance_selector
23
+
24
+ ## Usage
25
+
26
+ By default, only running instances will be included in the results. Overriding this restriction is in the TODO section.
27
+
28
+ ### Standalone
29
+
30
+ require 'instance_selector/connection'
31
+ conn = InstanceSelector::Connection.new(:aws)
32
+ instances = connection.instances(:tags => {"Environment" => "staging"})
33
+
34
+ ### With Capistrano
35
+
36
+ require 'instance_selector/capistrano'
37
+ instance_selector :app, :aws, :tags => {"Environment" => "staging"}
38
+
39
+ ### Filters
40
+
41
+ http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html
42
+
43
+ ## TODO
44
+
45
+ - Tests
46
+ - filters (e.g., :filters => {"instance-state-name" => nil to clear the running instance filter})
47
+ - AWS
48
+ - ELB support
49
+ - attach/detach
50
+ - selecting all instances in an ELB
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+ ## License
61
+
62
+ Copyright (c) 2013 Kevin McFadden
63
+
64
+ Permission is hereby granted, free of charge, to any person obtaining a copy
65
+ of this software and associated documentation files (the "Software"), to deal
66
+ in the Software without restriction, including without limitation the rights
67
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
68
+ copies of the Software, and to permit persons to whom the Software is
69
+ furnished to do so, subject to the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be included in all
72
+ copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
75
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
77
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
78
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
79
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
80
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'instance_selector/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "instance_selector"
8
+ spec.version = InstanceSelector::VERSION
9
+ spec.authors = ["Kevin McFadden"]
10
+ spec.email = ["kmcfadden@gmail.com"]
11
+ spec.description = %q{Retrieve cloud instance DNS names from metadata search}
12
+ spec.summary = %q{}
13
+ spec.homepage = "https://github.com/n3bulous/instance_selector"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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
+
22
+ spec.add_dependency "fog", "~> 1.4"
23
+ spec.add_dependency('capistrano', '~> 2.1')
24
+
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,7 @@
1
+ __LIB_DIR__ = File.expand_path(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift __LIB_DIR__ unless $LOAD_PATH.include?(__LIB_DIR__)
3
+
4
+ require "instance_selector/version"
5
+ require "instance_selector/connection"
6
+ require 'instance_selector/providers/aws'
7
+ require 'fog'
@@ -0,0 +1,9 @@
1
+ require 'instance_selector'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ def instance_selector(cap_role, provider, args={})
5
+ client = InstanceSelector::Connection.factory(:aws)
6
+ instances = client.instances(client.args_to_filters(args))
7
+ instances.keys.each { |instance| role(cap_role, *instances.keys) }
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module InstanceSelector
2
+ class UnsupportedProviderException < Exception; end;
3
+
4
+ class Connection
5
+ def self.factory(provider, options={})
6
+ conn = case provider
7
+ when :aws
8
+ Providers::AWS.new(options)
9
+ else
10
+ raise UnsupportedProviderException, "#{provider} is not a supported provider"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ module InstanceSelector
2
+ module Providers
3
+ class AWS
4
+ def initialize(options={})
5
+ @fog = options.delete(:fog_client)
6
+
7
+ unless @fog
8
+ @options = {
9
+ region: 'us-east-1',
10
+ }.merge(options)
11
+
12
+ connect
13
+ end
14
+ end
15
+
16
+ def instances(filters={})
17
+ instances = @fog.describe_instances({"instance-state-name" => "running"}.merge(filters))
18
+ instances.body['reservationSet'].inject({}) do |memo, i|
19
+ instance = i['instancesSet'][0]
20
+ key = instance['dnsName'].empty? ? instance['ipAddress'] : instance['dnsName']
21
+ memo[key] = instance['tagSet']['Name']
22
+ memo
23
+ end
24
+ end
25
+
26
+ def connect
27
+ begin
28
+ @fog = Fog::Compute.new(provider: 'AWS', region: @options[:region])
29
+ rescue
30
+ @fog = Fog::Compute.new(provider: 'AWS',
31
+ region: @options[:region],
32
+ aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
33
+ aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
34
+ ensure
35
+ unless @fog
36
+ abort <<-EOS
37
+ Could not authenticate with AWS.
38
+ Please create a .fog file or set AWS_ACCESS_KEY_ID and AWS_ACCESS_KEY_ID
39
+ EOS
40
+ end
41
+ end
42
+ end
43
+
44
+ def args_to_filters(args)
45
+ filters = {}
46
+ filters.merge! parse_tags(args[:tags])
47
+ end
48
+
49
+ def parse_tags(tags)
50
+ tags.inject({}) do |memo, tag|
51
+ memo["tag:#{tag[0]}"] = tag[1]
52
+ memo
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module InstanceSelector
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instance_selector
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Kevin McFadden
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fog
16
+ type: :runtime
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
22
+ none: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.4'
28
+ none: false
29
+ prerelease: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano
32
+ type: :runtime
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.1'
38
+ none: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.1'
44
+ none: false
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ type: :development
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ none: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '1.3'
60
+ none: false
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ type: :development
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ none: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ none: false
77
+ prerelease: false
78
+ description: Retrieve cloud instance DNS names from metadata search
79
+ email:
80
+ - kmcfadden@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - instance_selector.gemspec
91
+ - lib/instance_selector.rb
92
+ - lib/instance_selector/capistrano.rb
93
+ - lib/instance_selector/connection.rb
94
+ - lib/instance_selector/providers/aws.rb
95
+ - lib/instance_selector/version.rb
96
+ homepage: https://github.com/n3bulous/instance_selector
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ hash: 3938171241740158255
110
+ version: '0'
111
+ none: false
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ hash: 3938171241740158255
119
+ version: '0'
120
+ none: false
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.23
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: ''
127
+ test_files: []