knife-node-attribute 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +19 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/knife-node-attribute.gemspec +17 -0
- data/lib/chef/knife/knife-node-attribute.rb +164 -0
- data/lib/knife-node-attribute.rb +4 -0
- metadata +69 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
knife-attribute (0.1.0)
|
5
|
+
chef (>= 0.10.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
chef (11.6.0)
|
11
|
+
erubis
|
12
|
+
highline (>= 1.6.9)
|
13
|
+
json (>= 1.4.4, <= 1.7.7)
|
14
|
+
mixlib-authentication (>= 1.3.0)
|
15
|
+
mixlib-cli (~> 1.3.0)
|
16
|
+
mixlib-config (>= 1.1.2)
|
17
|
+
mixlib-log (>= 1.3.0)
|
18
|
+
mixlib-shellout
|
19
|
+
net-ssh (~> 2.6)
|
20
|
+
net-ssh-multi (~> 1.1.0)
|
21
|
+
ohai (>= 0.6.0)
|
22
|
+
rest-client (>= 1.0.4, < 1.7.0)
|
23
|
+
yajl-ruby (~> 1.1)
|
24
|
+
erubis (2.7.0)
|
25
|
+
highline (1.6.19)
|
26
|
+
ipaddress (0.8.0)
|
27
|
+
json (1.7.7)
|
28
|
+
mime-types (1.25)
|
29
|
+
mixlib-authentication (1.3.0)
|
30
|
+
mixlib-log
|
31
|
+
mixlib-cli (1.3.0)
|
32
|
+
mixlib-config (1.1.2)
|
33
|
+
mixlib-log (1.6.0)
|
34
|
+
mixlib-shellout (1.2.0)
|
35
|
+
net-ssh (2.6.8)
|
36
|
+
net-ssh-gateway (1.2.0)
|
37
|
+
net-ssh (>= 2.6.5)
|
38
|
+
net-ssh-multi (1.1)
|
39
|
+
net-ssh (>= 2.1.4)
|
40
|
+
net-ssh-gateway (>= 0.99.0)
|
41
|
+
ohai (6.18.0)
|
42
|
+
ipaddress
|
43
|
+
mixlib-cli
|
44
|
+
mixlib-config
|
45
|
+
mixlib-log
|
46
|
+
mixlib-shellout
|
47
|
+
systemu
|
48
|
+
yajl-ruby
|
49
|
+
rest-client (1.6.7)
|
50
|
+
mime-types (>= 1.16)
|
51
|
+
systemu (2.5.2)
|
52
|
+
yajl-ruby (1.1.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
knife-attribute!
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2013 Daniel Schauenberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# knife-node-attribute
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
knife plugin to interact with the various attributes on a nodes.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
Show all attributes on the node (or a specific one if given):
|
8
|
+
|
9
|
+
knife node attribute show foo.example.org
|
10
|
+
knife node attribute show foo.example.org normal [foo:bar]
|
11
|
+
knife node attribute show foo.example.org default [foo:bar]
|
12
|
+
knife node attribute show foo.example.org override [foo:bar]
|
13
|
+
|
14
|
+
Delete a specific attribute on a node:
|
15
|
+
|
16
|
+
knife node attribute delete foo.example.org normal foo:bar
|
17
|
+
knife node attribute delete foo.example.org default foo:bar
|
18
|
+
knife node attribute delete foo.example.org override foo:bar
|
19
|
+
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
Just get it from rubygems:
|
23
|
+
|
24
|
+
gem install knife-node-attribute
|
25
|
+
|
26
|
+
|
27
|
+
## Contribute
|
28
|
+
- fork the project
|
29
|
+
- make your awesome changes
|
30
|
+
- send a pull request
|
31
|
+
|
32
|
+
## Thanks
|
33
|
+
[@jonlives](https://github.com/jonlives) for his plugins which I took as
|
34
|
+
examples and [@jgoulah](http://github.com/jgoulah) for the
|
35
|
+
inspiration.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'knife-node-attribute'
|
5
|
+
gem.version = '0.2.0'
|
6
|
+
gem.authors = ["Daniel Schauenberg"]
|
7
|
+
gem.email = 'd@unwiredcouch.com'
|
8
|
+
gem.homepage = 'https://github.com/mrtazz/knife-node-attribute'
|
9
|
+
gem.summary = "knife plugin to show or delete node attributes"
|
10
|
+
gem.description = "knife plugin to show or delete node attributes"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.name = "knife-node-attribute"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
|
16
|
+
gem.add_runtime_dependency 'chef', '>= 0.10.4'
|
17
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
|
4
|
+
ATTRIBUTE_CLASSES = [:normal, :default, :override]
|
5
|
+
|
6
|
+
module KnifeNodeAttribute
|
7
|
+
|
8
|
+
module Helpers
|
9
|
+
def get_node(name)
|
10
|
+
|
11
|
+
puts "Looking for an fqdn of #{name} or name of #{name}"
|
12
|
+
|
13
|
+
searcher = Chef::Search::Query.new
|
14
|
+
result = searcher.search(:node, "fqdn:#{name} OR name:#{name}")
|
15
|
+
|
16
|
+
knife_search = Chef::Knife::Search.new
|
17
|
+
node = result.first.first
|
18
|
+
if node.nil?
|
19
|
+
ui.error "Could not find a node with the fqdn of #{name} or name of #{name}"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
return node
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# helper methods to get attributes from a node
|
27
|
+
def get_all_attributes(node)
|
28
|
+
{"default" => get_default_attributes(node),
|
29
|
+
"normal" => get_normal_attributes(node),
|
30
|
+
"override" => get_override_attributes(node)}
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_default_attributes(node)
|
34
|
+
node.default_attrs
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_normal_attributes(node)
|
38
|
+
node.normal_attrs
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_override_attributes(node)
|
42
|
+
node.override_attrs
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class NodeAttributeShow < Chef::Knife
|
48
|
+
include KnifeNodeAttribute::Helpers
|
49
|
+
|
50
|
+
banner 'knife node attribute show HOSTNAME [NORMAL|DEFAULT|OVERRIDE] [colon:separated:key]'
|
51
|
+
|
52
|
+
def parse_args
|
53
|
+
unless node_name = name_args[0]
|
54
|
+
show_usage
|
55
|
+
ui.error "You need to specify a node"
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
if name_args[1].nil?
|
59
|
+
attribute_class = :all
|
60
|
+
else
|
61
|
+
attribute_class = name_args[1].downcase.to_sym
|
62
|
+
# if we passed a valid attribute class, the next one could be an
|
63
|
+
# attribute name. If it's invalid, it might be the attribute name
|
64
|
+
if ATTRIBUTE_CLASSES.include? attribute_class
|
65
|
+
attribute_name = name_args[2] || ""
|
66
|
+
else
|
67
|
+
attribute_name = attribute_class
|
68
|
+
attribute_class = :all
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
{:nodename => node_name,
|
73
|
+
:class => attribute_class,
|
74
|
+
:name => attribute_name.split(":")}
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def run
|
79
|
+
args = parse_args
|
80
|
+
method = "get_#{args[:class]}_attributes".to_sym
|
81
|
+
|
82
|
+
node = get_node(args[:nodename])
|
83
|
+
attribute_hash = self.send(method, node)
|
84
|
+
# this eval business is awful, I should probably come up with something
|
85
|
+
# smarter
|
86
|
+
getter = args[:name].empty? ? "" : "['#{args[:name].join("']['")}']"
|
87
|
+
if args[:name].nil?
|
88
|
+
pp attribute_hash
|
89
|
+
else
|
90
|
+
begin
|
91
|
+
pp eval "attribute_hash#{getter}"
|
92
|
+
rescue NoMethodError
|
93
|
+
ui.error "Key not found"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
class NodeAttributeDelete < Chef::Knife
|
101
|
+
include KnifeNodeAttribute::Helpers
|
102
|
+
|
103
|
+
banner 'knife node attribute delete HOSTNAME NORMAL|DEFAULT|OVERRIDE colon:separated:key'
|
104
|
+
|
105
|
+
def parse_args
|
106
|
+
unless node_name = name_args[0]
|
107
|
+
show_usage
|
108
|
+
ui.error "You need to specify a node"
|
109
|
+
exit 1
|
110
|
+
end
|
111
|
+
if name_args[1].nil?
|
112
|
+
show_usage
|
113
|
+
ui.error "No attribute level given. (e.g. override, normal, default)"
|
114
|
+
exit 1
|
115
|
+
else
|
116
|
+
attribute_class = name_args[1].downcase.to_sym
|
117
|
+
# if we passed a valid attribute class, the next one could be an
|
118
|
+
# attribute name. If it's invalid, it might be the attribute name
|
119
|
+
unless ATTRIBUTE_CLASSES.include? attribute_class
|
120
|
+
show_usage
|
121
|
+
ui.error "Wrong attribute level given. (e.g. override, normal, default)"
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
unless attribute_name = name_args[2]
|
127
|
+
show_usage
|
128
|
+
ui.error "No attribute name given."
|
129
|
+
exit 1
|
130
|
+
end
|
131
|
+
|
132
|
+
{:nodename => node_name,
|
133
|
+
:class => attribute_class,
|
134
|
+
:name => attribute_name.split(":")}
|
135
|
+
end
|
136
|
+
|
137
|
+
def run
|
138
|
+
args = parse_args
|
139
|
+
method = "#{args[:class]}_attrs".to_sym
|
140
|
+
|
141
|
+
node = get_node(args[:nodename])
|
142
|
+
# this eval business is awful, I should probably come up with something
|
143
|
+
# smarter
|
144
|
+
if args[:name].length == 1
|
145
|
+
delete_method = "node.#{method}.delete('#{args[:name].last}')"
|
146
|
+
else
|
147
|
+
parent_hash = args[:name][0, args[:name].length - 1]
|
148
|
+
delete_method = "node.#{method}['#{parent_hash.join("']['")}'].delete('#{args[:name].last}')"
|
149
|
+
end
|
150
|
+
begin
|
151
|
+
eval delete_method
|
152
|
+
node.save
|
153
|
+
msg = parent_hash.nil? ? "" : " from parent structure #{parent_hash.join(':')}"
|
154
|
+
puts "Key #{args[:name].last}#{msg} deleted."
|
155
|
+
rescue StandardError => e
|
156
|
+
ui.error "An error occured while trying to delete the node key:"
|
157
|
+
puts e.to_s
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-node-attribute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Schauenberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-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.10.4
|
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.10.4
|
30
|
+
description: knife plugin to show or delete node attributes
|
31
|
+
email: d@unwiredcouch.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- knife-node-attribute.gemspec
|
42
|
+
- lib/chef/knife/knife-node-attribute.rb
|
43
|
+
- lib/knife-node-attribute.rb
|
44
|
+
homepage: https://github.com/mrtazz/knife-node-attribute
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.25
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: knife plugin to show or delete node attributes
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|