knife-attribute 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -38,8 +38,46 @@ knife node attribute set foo.example.org apache.listen_ports '["80", "443"]' -t
38
38
  The above would set the `foo.example.org` node's `override` attribute
39
39
  `['apache']['listen_ports']` to the array `["80", "443"]`.
40
40
 
41
+ ### node attribute get
42
+
43
+ Getting node attributes may be achieved as follows:
44
+
45
+ ```bash
46
+ knife node attribute get foo.example.org apache.listen_ports
47
+ ```
48
+
49
+ Use the standard `-F FORMAT` flag to set the output format for complex data
50
+ structures.
51
+
52
+ Unlike other actions, by default the `get` action will return the combined
53
+ (effective) value for the attribute, if an attribute type (`-t TYPE`) is not
54
+ specified.
55
+
56
+ ```bash
57
+ knife node attribute set foo.example.org apache.listen_ports -t override -F json
58
+ ```
59
+
60
+ The above would get the `foo.example.org` node's `override` attribute
61
+ `['apache']['listen_ports']` and output it as JSON.
62
+
63
+ ### node attribute delete
64
+
65
+ Deleting node attributes may be achieved as follows:
66
+
67
+ ```bash
68
+ knife node attribute delete foo.example.org tz
69
+ ```
70
+
71
+ The above would delete the `foo.example.org` node's `normal` attribute `tz`.
72
+
73
+ ```bash
74
+ knife node attribute set foo.example.org apache.listen_ports -t override
75
+ ```
76
+
77
+ The above would delete the `foo.example.org` node's `override` attribute.
78
+ `['apache']['listen_ports']`.
79
+
41
80
 
42
81
  ## TODO
43
- - Implement attribute get/delete for nodes
44
82
  - Implement attribute get/set/delete for roles
45
83
  - Implement attribute get/set/delete for environments
@@ -5,3 +5,5 @@ require 'knife-attribute/helpers'
5
5
  require 'knife-attribute/common_options'
6
6
  require 'knife-attribute/node/helpers'
7
7
  require 'knife-attribute/node/set'
8
+ require 'knife-attribute/node/get'
9
+ require 'knife-attribute/node/delete'
@@ -0,0 +1,68 @@
1
+ module KnifeAttribute
2
+ module Node
3
+ class NodeAttributeDelete < Chef::Knife
4
+ include KnifeAttribute::CommonOptions
5
+ include KnifeAttribute::Node::Helpers
6
+
7
+ banner 'knife node attribute delete NODE PERIOD.SEPARATED.ATTRIBUTE (options)'
8
+
9
+ def run
10
+ check_arguments
11
+
12
+ case config[:attribute_type]
13
+ when 'default'
14
+ delete_attribute(node.default_attrs)
15
+ when 'override'
16
+ delete_attribute(node.override_attrs)
17
+ when 'automatic'
18
+ delete_attribute(node.automatic_attrs)
19
+ when 'normal'
20
+ delete_attribute(node.normal_attrs)
21
+ else
22
+ delete_attribute(node.normal_attrs)
23
+ end
24
+ end
25
+
26
+ private
27
+ def check_arguments
28
+ if node_name.nil?
29
+ show_usage
30
+ ui.fatal('You must specify a node name')
31
+ exit 1
32
+ end
33
+
34
+ if attribute.nil?
35
+ show_usage
36
+ ui.fatal('You must specify an attribute')
37
+ exit 1
38
+ end
39
+
40
+ check_type
41
+ end
42
+
43
+ def delete_attribute(target)
44
+ path = attribute.split('.')
45
+ key = path.pop
46
+
47
+ if path.length == 0
48
+ parent = target
49
+ else
50
+ parent = path.inject(target) { |obj, item| obj[item] || break }
51
+ end
52
+
53
+ result = false
54
+ if parent and parent.has_key?(key)
55
+ parent.delete(key)
56
+ result = node.save
57
+ end
58
+
59
+ if result
60
+ ui.info("Successfully deleted node #{ui.color(node_name, :cyan)} attribute #{ui.color(attribute, :green)}")
61
+ else
62
+ ui.fatal("Failed deleting node #{ui.color(node_name, :magenta)} attribute #{ui.color(new_attribute, :magenta)}")
63
+ exit 1
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,49 @@
1
+ module KnifeAttribute
2
+ module Node
3
+ class NodeAttributeGet < Chef::Knife
4
+ include KnifeAttribute::CommonOptions
5
+ include KnifeAttribute::Node::Helpers
6
+
7
+ banner 'knife node attribute get NODE PERIOD.SEPARATED.ATTRIBUTE (options)'
8
+
9
+ def run
10
+ check_arguments
11
+
12
+ case config[:attribute_type]
13
+ when 'default'
14
+ get_attribute(node.default_attrs)
15
+ when 'override'
16
+ get_attribute(node.override_attrs)
17
+ when 'automatic'
18
+ get_attribute(node.automatic_attrs)
19
+ when 'normal'
20
+ get_attribute(node.normal_attrs)
21
+ else
22
+ get_attribute(node.construct_attributes)
23
+ end
24
+ end
25
+
26
+ private
27
+ def check_arguments
28
+ if node_name.nil?
29
+ show_usage
30
+ ui.fatal('You must specify a node name')
31
+ exit 1
32
+ end
33
+
34
+ if attribute.nil?
35
+ show_usage
36
+ ui.fatal('You must specify an attribute')
37
+ exit 1
38
+ end
39
+
40
+ check_type
41
+ end
42
+
43
+ def get_attribute(target)
44
+ result = ui.presenter.extract_nested_value(target, attribute)
45
+ output(format_for_display(result))
46
+ end
47
+ end
48
+ end
49
+ end
@@ -4,7 +4,7 @@ module KnifeAttribute
4
4
  include KnifeAttribute::CommonOptions
5
5
  include KnifeAttribute::Node::Helpers
6
6
 
7
- banner 'knife node attribute set NODE PERIOD.SEPARATED.KEY STRING_OR_JSON_VALUE (options)'
7
+ banner 'knife node attribute set NODE PERIOD.SEPARATED.ATTRIBUTE STRING_OR_JSON_VALUE (options)'
8
8
 
9
9
  def run
10
10
  check_arguments
@@ -1,3 +1,3 @@
1
1
  module KnifeAttribute
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-06 00:00:00.000000000 Z
12
+ date: 2013-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -79,6 +79,8 @@ files:
79
79
  - lib/knife-attribute/attribute_types.rb
80
80
  - lib/knife-attribute/common_options.rb
81
81
  - lib/knife-attribute/helpers.rb
82
+ - lib/knife-attribute/node/delete.rb
83
+ - lib/knife-attribute/node/get.rb
82
84
  - lib/knife-attribute/node/helpers.rb
83
85
  - lib/knife-attribute/node/set.rb
84
86
  - lib/knife-attribute/version.rb
@@ -97,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
99
  version: '0'
98
100
  segments:
99
101
  - 0
100
- hash: -1403468226480289841
102
+ hash: 4149257689015796291
101
103
  required_rubygems_version: !ruby/object:Gem::Requirement
102
104
  none: false
103
105
  requirements:
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  version: '0'
107
109
  segments:
108
110
  - 0
109
- hash: -1403468226480289841
111
+ hash: 4149257689015796291
110
112
  requirements: []
111
113
  rubyforge_project:
112
114
  rubygems_version: 1.8.25