knife-attribute 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/knife-attribute.gemspec +24 -0
- data/lib/chef/knife/attribute.rb +1 -0
- data/lib/knife-attribute.rb +7 -0
- data/lib/knife-attribute/attribute_types.rb +4 -0
- data/lib/knife-attribute/common_options.rb +20 -0
- data/lib/knife-attribute/helpers.rb +7 -0
- data/lib/knife-attribute/node/helpers.rb +32 -0
- data/lib/knife-attribute/node/set.rb +65 -0
- data/lib/knife-attribute/version.rb +3 -0
- metadata +116 -0
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Peter Fern
|
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,45 @@
|
|
1
|
+
# knife-attribute
|
2
|
+
|
3
|
+
Manipulate Chef attributes via Knife
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install via rubygems:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install knife-attribute
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
In this initial release, only `node attribute set` is implemented, more to
|
16
|
+
follow in the near future.
|
17
|
+
|
18
|
+
To work with attributes of type `default`, `normal`, `override` or `automatic`,
|
19
|
+
use the `-t TYPE` flag (default if unspecified is `normal`).
|
20
|
+
|
21
|
+
### node attribute set
|
22
|
+
|
23
|
+
Setting node attributes may be achieved as follows:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
knife node attribute set foo.example.org tz 'Australia/Melbourne'
|
27
|
+
```
|
28
|
+
|
29
|
+
The above would set the `foo.example.org` node's `normal` attribute `tz` to the
|
30
|
+
string `Austraila/Melbourne`.
|
31
|
+
|
32
|
+
You may specify either a regular string, or a JSON structure, ie:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
knife node attribute set foo.example.org apache.listen_ports '["80", "443"]' -t override
|
36
|
+
```
|
37
|
+
|
38
|
+
The above would set the `foo.example.org` node's `override` attribute
|
39
|
+
`['apache']['listen_ports']` to the array `["80", "443"]`.
|
40
|
+
|
41
|
+
|
42
|
+
## TODO
|
43
|
+
- Implement attribute get/delete for nodes
|
44
|
+
- Implement attribute get/set/delete for roles
|
45
|
+
- Implement attribute get/set/delete for environments
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knife-attribute/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'knife-attribute'
|
8
|
+
spec.version = KnifeAttribute::VERSION
|
9
|
+
spec.authors = ['Peter Fern']
|
10
|
+
spec.email = ['ruby@0xc0dedbad.com']
|
11
|
+
spec.description = %q{Manipulate (currently only set) Chef attributes (currently only for nodes) via Knife}
|
12
|
+
spec.summary = %q{Manipulate Chef attributes via Knife}
|
13
|
+
spec.homepage = 'https://github.com/pdf/knife-attribute'
|
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
|
+
spec.add_dependency 'chef', '>= 0.11'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'knife-attribute'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module KnifeAttribute
|
2
|
+
module CommonOptions
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
option :attribute_type,
|
6
|
+
short: '-t TYPE',
|
7
|
+
long: '--type TYPE',
|
8
|
+
default: 'normal',
|
9
|
+
description: "Attribute type to set, one of: #{KnifeAttribute::ATTRIBUTE_TYPES} (default: 'normal')"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_type
|
14
|
+
if config[:attribute_type] and !KnifeAttribute::ATTRIBUTE_TYPES.include?(config[:attribute_type])
|
15
|
+
show_usage
|
16
|
+
ui.fatal("Invalid attribute type: '#{config[:attribute_type]}'")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module KnifeAttribute
|
2
|
+
module Node
|
3
|
+
module Helpers
|
4
|
+
include KnifeAttribute::Helpers
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
deps do
|
9
|
+
require 'chef/node'
|
10
|
+
require 'chef/json_compat'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def node_name
|
16
|
+
@node_name ||= @name_args[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
def attribute
|
20
|
+
@attribute ||= @name_args[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def value
|
24
|
+
@value ||= @name_args[2]
|
25
|
+
end
|
26
|
+
|
27
|
+
def node
|
28
|
+
@node ||= Chef::Node.load(node_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module KnifeAttribute
|
2
|
+
module Node
|
3
|
+
class NodeAttributeSet < Chef::Knife
|
4
|
+
include KnifeAttribute::CommonOptions
|
5
|
+
include KnifeAttribute::Node::Helpers
|
6
|
+
|
7
|
+
banner 'knife node attribute set NODE PERIOD.SEPARATED.KEY STRING_OR_JSON_VALUE (options)'
|
8
|
+
|
9
|
+
def run
|
10
|
+
check_arguments
|
11
|
+
|
12
|
+
case config[:attribute_type]
|
13
|
+
when 'default'
|
14
|
+
set_attribute(node.default_attrs)
|
15
|
+
when 'override'
|
16
|
+
set_attribute(node.override_attrs)
|
17
|
+
when 'automatic'
|
18
|
+
set_attribute(node.automatic_attrs)
|
19
|
+
when 'normal', nil
|
20
|
+
set_attribute(node.normal_attrs)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def check_arguments
|
26
|
+
if node_name.nil?
|
27
|
+
show_usage
|
28
|
+
ui.fatal('You must specify a node name')
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
if attribute.nil?
|
33
|
+
show_usage
|
34
|
+
ui.fatal('You must specify an attribute')
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
38
|
+
if value.nil?
|
39
|
+
show_usage
|
40
|
+
ui.fatal('You must specify a value')
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
check_type
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_attribute(target)
|
48
|
+
begin
|
49
|
+
new_value = Chef::JSONCompat.from_json(value)
|
50
|
+
rescue JSON::ParserError, Yajl::ParseError
|
51
|
+
new_value = value
|
52
|
+
end
|
53
|
+
new_attribute = attribute.split('.').reverse.inject(new_value) { |result, key| { key => result } }
|
54
|
+
target.merge!(new_attribute)
|
55
|
+
|
56
|
+
if node.save
|
57
|
+
ui.info("Successfully set node #{ui.color(node_name, :cyan)} attribute #{ui.color(attribute, :cyan)} to: #{ui.color(new_value.inspect, :green)}")
|
58
|
+
else
|
59
|
+
ui.fatal("Failed updating node #{ui.color(node_name, :magenta)} attribute #{ui.color(new_attribute, :magenta)}")
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-attribute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Fern
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-06 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.11'
|
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.11'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Manipulate (currently only set) Chef attributes (currently only for nodes)
|
63
|
+
via Knife
|
64
|
+
email:
|
65
|
+
- ruby@0xc0dedbad.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- CONTRIBUTING.md
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- knife-attribute.gemspec
|
77
|
+
- lib/chef/knife/attribute.rb
|
78
|
+
- lib/knife-attribute.rb
|
79
|
+
- lib/knife-attribute/attribute_types.rb
|
80
|
+
- lib/knife-attribute/common_options.rb
|
81
|
+
- lib/knife-attribute/helpers.rb
|
82
|
+
- lib/knife-attribute/node/helpers.rb
|
83
|
+
- lib/knife-attribute/node/set.rb
|
84
|
+
- lib/knife-attribute/version.rb
|
85
|
+
homepage: https://github.com/pdf/knife-attribute
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -1403468226480289841
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -1403468226480289841
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.25
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Manipulate Chef attributes via Knife
|
116
|
+
test_files: []
|