chef-helpers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/chef-helpers.gemspec +19 -0
- data/lib/chef-helpers.rb +3 -0
- data/lib/chef-helpers/node.rb +52 -0
- data/lib/chef-helpers/version.rb +5 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Maciej Pasternacki
|
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,34 @@
|
|
1
|
+
# Chef Helpers
|
2
|
+
|
3
|
+
This gem includes miscellaneous add-on helper methods for Opscode Chef.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To use helper methods in your Chef recipes, add `chef_gem
|
8
|
+
'chef-helpers'` and `require 'chef-helpers'` in your recipes.
|
9
|
+
|
10
|
+
To use methods locally in `knife exec` scripts or Knife plugins, add
|
11
|
+
this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'chef-helpers'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install chef-helpers
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Detailed documentation of the helper methods can be seen at
|
26
|
+
http://rdoc.info/github/3ofcoins/chef-helpers/
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/chef-helpers/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Maciej Pasternacki"]
|
6
|
+
gem.email = ["maciej@pasternacki.net"]
|
7
|
+
gem.description = "A collection of helper methods to use in Opscode Chef recipes"
|
8
|
+
gem.summary = "Helper methods for Opscode Chef"
|
9
|
+
gem.homepage = "https://github.com/3ofcoins/chef-helpers/"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "chef-helpers"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Chef::Helpers::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "chef"
|
19
|
+
end
|
data/lib/chef-helpers.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'chef/node'
|
2
|
+
|
3
|
+
class Chef::Node
|
4
|
+
|
5
|
+
# Node's "allies" are all nodes in the same environment (if the
|
6
|
+
# environment is not `_default`), and nodes specified by `allies`
|
7
|
+
# attribute. The `allies` attribute - if set - should be an array of
|
8
|
+
# node names or node search queries; the named nodes and search
|
9
|
+
# results will be added to node's allies.
|
10
|
+
#
|
11
|
+
# This is mostly useful when defining firewall or other access
|
12
|
+
# rules, to easily limit access to insides of a cluster plus a
|
13
|
+
# handful of friendly machines.
|
14
|
+
#
|
15
|
+
# @return [Array<Chef::Node>] Array of node's "allies".
|
16
|
+
def allies
|
17
|
+
@allies ||=
|
18
|
+
begin
|
19
|
+
rv = []
|
20
|
+
q = Chef::Search::Query.new
|
21
|
+
rv += q.search(:node, "chef_environment:#{self.chef_environment}").first unless self.chef_environment == '_default'
|
22
|
+
if self['allies']
|
23
|
+
self['allies'].each do |ally|
|
24
|
+
ally = "name:#{ally}" unless ally.include?(':')
|
25
|
+
rv += q.search(:node, ally).first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rv
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Find out, which IP should be used to contact with other node.
|
33
|
+
#
|
34
|
+
# If both nodes are on EC2 and in the same region, then other node's
|
35
|
+
# `ec2.local_ipv4` attribute is used. Otherwise, if other node is a
|
36
|
+
# cloud instance, its `cloud_public.ipv4` attribute is
|
37
|
+
# used. Otherwise, other node's `ipaddress` is used.
|
38
|
+
#
|
39
|
+
# @note This method may return wrong IP with non-EC2 cloud
|
40
|
+
# providers, and can use some tweaking for such cases.
|
41
|
+
# @param [Chef::Node] other_node Node, whose IP we need to know
|
42
|
+
# @return [String] IP of `other_node`
|
43
|
+
def ip_for(other_node)
|
44
|
+
if other_node['ec2'] && self['ec2'] && self['ec2']['placement_availability_zone'] == other_node['ec2']['placement_availability_zone']
|
45
|
+
other_node['ec2']['local_ipv4']
|
46
|
+
elsif other_node['cloud']
|
47
|
+
other_node['cloud']['public_ipv4']
|
48
|
+
else
|
49
|
+
other_node['ipaddress']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maciej Pasternacki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A collection of helper methods to use in Opscode Chef recipes
|
31
|
+
email:
|
32
|
+
- maciej@pasternacki.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- chef-helpers.gemspec
|
43
|
+
- lib/chef-helpers.rb
|
44
|
+
- lib/chef-helpers/node.rb
|
45
|
+
- lib/chef-helpers/version.rb
|
46
|
+
homepage: https://github.com/3ofcoins/chef-helpers/
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 795577445430498554
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 795577445430498554
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Helper methods for Opscode Chef
|
76
|
+
test_files: []
|