knife-topo 0.0.11 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +60 -8
- data/knife-topo.gemspec +4 -2
- data/lib/chef/knife/topo/version.rb +1 -1
- data/lib/chef/knife/topo_cookbook_upload.rb +1 -1
- data/lib/chef/knife/topo_delete.rb +96 -0
- data/lib/chef/knife/topo_list.rb +48 -0
- data/lib/chef/knife/topo_search.rb +93 -0
- data/lib/chef/knife/topology_helper.rb +2 -0
- metadata +29 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 619e9151cea8acad0dfa7f85237ba3fd5da2c1b5
|
4
|
+
data.tar.gz: ba63cad394ff705eed82414025ba1b016de444cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14d7c03dc1fa49c70c074a1fa2e19ab35ad4e5e9369f895eccc34a5b3fd08fab574423387a4b236f6380d9292a0928735f30c6f65848caaaa0dc87fb02ea8c1e
|
7
|
+
data.tar.gz: 1ec1fc82d300e4d8973fddd3684f11f9e46808554a04751375352ffc652a62d0542d4a04d745f7b79fb17bbbdfc5944c79ae64c5153687c9a59991e222386ec1
|
data/README.md
CHANGED
@@ -22,8 +22,8 @@ topologies but differences in their configuration details.
|
|
22
22
|
[Download the latest knife-topo release](http://github.com/christinedraper/knife-topo/releases/latest),
|
23
23
|
unzip and copy `lib/chef/knife` into your plugin directory, e.g.:
|
24
24
|
|
25
|
-
$ unzip knife-topo-0.0.
|
26
|
-
$ cd ~/knife-topo-0.0.
|
25
|
+
$ unzip knife-topo-0.0.12.zip -d ~
|
26
|
+
$ cd ~/knife-topo-0.0.12
|
27
27
|
$ mkdir -p ~/.chef/plugins/knife
|
28
28
|
$ cp lib/chef/knife/* ~/.chef/plugins/knife
|
29
29
|
|
@@ -59,7 +59,7 @@ Try out this plugin using a [test-repo](test-repo) provided in the knife-topo gi
|
|
59
59
|
[Download the latest knife-topo release](http://github.com/christinedraper/knife-topo/releases/latest)
|
60
60
|
and unzip it, then follow the [Instructions](test-repo/Instructions.md) for the example.
|
61
61
|
|
62
|
-
The instructions assume you have [chefDK](
|
62
|
+
The instructions assume you have [chefDK](https://downloads.chef.io/chef-dk/)
|
63
63
|
or equivalent installed and working with Vagrant and VirtualBox, but
|
64
64
|
none of these are requirements to use the knife-topo plugin.
|
65
65
|
|
@@ -225,13 +225,14 @@ workflow:
|
|
225
225
|
* [knife topo cookbook create](#cookbook-create) - Generate the topology cookbooks
|
226
226
|
* [knife topo cookbook upload](#cookbook-upload) - Upload the topology cookbooks
|
227
227
|
* [knife export](#export) - Export data from a topology (or from nodes that you want in a topology)
|
228
|
+
* [knife topo list](#list) - List the topologies
|
229
|
+
* [knife topo search](#search) - Search for nodes that are in a topology, or in no topology
|
230
|
+
* [knife topo delete](#delete) - Delete a topology, but not the nodes in the topology
|
228
231
|
|
229
232
|
The topologies are data bag items in the 'topologies' data bag, so
|
230
233
|
you can also use knife commands such as:
|
231
234
|
|
232
|
-
* `knife data bag show topologies` -
|
233
|
-
* `knife data bag show topologies test1` - Show details of the test1 topology
|
234
|
-
* `knife data bag delete topologies test1` - Delete the test1 topology
|
235
|
+
* `knife data bag show topologies test1` - Show details of the test1 topology data bag
|
235
236
|
|
236
237
|
### Common Options:
|
237
238
|
|
@@ -338,6 +339,14 @@ or upload topology cookbooks.
|
|
338
339
|
|
339
340
|
$ knife topo create test1 --disable-upload
|
340
341
|
|
342
|
+
## knife topo delete <a name="delete"></a>
|
343
|
+
|
344
|
+
knife topo delete TOPOLOGY
|
345
|
+
|
346
|
+
Deletes the specified topology. Does not delete the nodes in the topology, but does
|
347
|
+
remove them from the topology by removing the `['topo']['name']` attribute
|
348
|
+
which is used by `knife topo search`.
|
349
|
+
|
341
350
|
## knife topo export <a name="export"></a>
|
342
351
|
|
343
352
|
knife topo export [ TOPOLOGY [ NODE ... ]
|
@@ -375,6 +384,7 @@ The following will create an outline for a new topology called 'christine_test'
|
|
375
384
|
$ knife topo export christine_test > christine_test.json
|
376
385
|
|
377
386
|
|
387
|
+
|
378
388
|
## knife topo import <a name="import"></a>
|
379
389
|
|
380
390
|
knife topo import [ TOPOLOGY_FILE [ TOPOLOGY ... ]]
|
@@ -395,6 +405,48 @@ The following will import the 'test1' topology
|
|
395
405
|
|
396
406
|
$ knife topo import topology.json test1
|
397
407
|
|
408
|
+
## knife topo list <a name="list"></a>
|
409
|
+
|
410
|
+
knife topo list
|
411
|
+
|
412
|
+
Lists the topologies that have been created on the server.
|
413
|
+
|
414
|
+
## knife topo search <a name="search"></a>
|
415
|
+
|
416
|
+
knife topo search [ QUERY ]
|
417
|
+
|
418
|
+
Searches for nodes that are in a topology and satisfy the query. With no options,
|
419
|
+
this searches for nodes in any topology. Use `--topo=topo_name` to search
|
420
|
+
within a specific topology. Use `--no-topo` to search for nodes in no topology.
|
421
|
+
|
422
|
+
`knife topo search` uses the `['topo']['name']` attribute to identify which nodes
|
423
|
+
are in which topology.
|
424
|
+
|
425
|
+
### Examples:
|
426
|
+
|
427
|
+
The following will search for nodes in any topology that have a name starting with "tst".
|
428
|
+
|
429
|
+
$ knife topo search "name:tst*"
|
430
|
+
|
431
|
+
The following will search for nodes in the "prod" chef environment that are not in a topology.
|
432
|
+
|
433
|
+
$ knife topo search "chef_environment:prod" --no-topo
|
434
|
+
|
435
|
+
The following will search for all nodes in the "systest" topology.
|
436
|
+
|
437
|
+
$ knife topo search --topo=systest
|
438
|
+
|
439
|
+
### Options:
|
440
|
+
|
441
|
+
The knife topo search subcommand supports the following additional options.
|
442
|
+
|
443
|
+
Option | Description
|
444
|
+
------------ | -----------
|
445
|
+
--topo | Search for nodes in the specified topology
|
446
|
+
--no-topo | Search for nodes that are not in any topology
|
447
|
+
See [knife search](http://docs.chef.io/knife_search.html) | Options supported by `knife search` are passed through to the search command
|
448
|
+
|
449
|
+
|
398
450
|
## knife topo update <a name="update"></a>
|
399
451
|
|
400
452
|
knife topo update [ TOPOLOGY ]
|
@@ -409,7 +461,7 @@ will be updated.
|
|
409
461
|
Option | Description
|
410
462
|
------------ | -----------
|
411
463
|
--bootstrap | Bootstrap the topology (see [topo bootstrap](#bootstrap))
|
412
|
-
See [knife bootstrap](http://docs.
|
464
|
+
See [knife bootstrap](http://docs.chef.io/knife_bootstrap.html) | Options supported by `knife bootstrap` are passed through to the bootstrap command
|
413
465
|
--disable-upload | Do not upload topology cookbooks
|
414
466
|
|
415
467
|
### Examples:
|
@@ -426,7 +478,7 @@ The following will update all topologies in the 'topologies' data bag.
|
|
426
478
|
|
427
479
|
Author:: Christine Draper (christine_draper@thirdwaveinsights.com)
|
428
480
|
|
429
|
-
Copyright:: Copyright (c) 2014 ThirdWave Insights, LLC
|
481
|
+
Copyright:: Copyright (c) 2014-2015 ThirdWave Insights, LLC
|
430
482
|
|
431
483
|
License:: Apache License, Version 2.0
|
432
484
|
|
data/knife-topo.gemspec
CHANGED
@@ -8,11 +8,13 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Knife::Topo::VERSION
|
9
9
|
spec.authors = ["Christine Draper"]
|
10
10
|
spec.email = ["christine_draper@thirdwaveinsights.com"]
|
11
|
-
spec.summary = "Knife plugin
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Knife plugin to manage topologies of nodes"
|
12
|
+
spec.description = "Knife-topo uses a JSON file to capture a topology of nodes, which can be loaded into Chef and bootstrapped"
|
13
13
|
spec.homepage = "https://github.com/christinedraper/knife-topo"
|
14
14
|
spec.license = "Apache License (2.0)"
|
15
15
|
|
16
|
+
spec.add_runtime_dependency 'chef', '>=11.8', '<13.0'
|
17
|
+
|
16
18
|
spec.files = Dir.glob("{lib}/**/*") +
|
17
19
|
['LICENSE', 'README.md', __FILE__]
|
18
20
|
spec.require_paths = ["lib"]
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 ThirdWave Insights LLC
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
require_relative 'topology_helper'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class TopoDelete < Chef::Knife
|
25
|
+
|
26
|
+
deps do
|
27
|
+
require 'chef/data_bag'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife topo delete TOPOLOGY (options)"
|
31
|
+
|
32
|
+
option :data_bag,
|
33
|
+
:short => '-D DATA_BAG',
|
34
|
+
:long => "--data-bag DATA_BAG",
|
35
|
+
:description => "The data bag the topologies are stored in"
|
36
|
+
|
37
|
+
|
38
|
+
def run
|
39
|
+
|
40
|
+
topo_bag = topo_bag_name(config[:data_bag])
|
41
|
+
@topo_name = @name_args[0]
|
42
|
+
|
43
|
+
if @name_args.length == 1
|
44
|
+
|
45
|
+
# remove each node
|
46
|
+
|
47
|
+
unless topo = load_from_server(topo_bag, @topo_name)
|
48
|
+
ui.info "Topology #{topo_bag}/#{@topo_name} does not exist on server"
|
49
|
+
exit(0)
|
50
|
+
end
|
51
|
+
|
52
|
+
confirm("Do you want to delete topology #{@topo_name} - this does not delete nodes")
|
53
|
+
|
54
|
+
topo['nodes'].each do | node |
|
55
|
+
remove_node_from_topology(node['name'])
|
56
|
+
end if topo['nodes']
|
57
|
+
|
58
|
+
# delete the data bag item
|
59
|
+
topo.destroy(topo_bag, @topo_name)
|
60
|
+
|
61
|
+
ui.info "Deleted topology #{@topo_name}"
|
62
|
+
else
|
63
|
+
show_usage
|
64
|
+
ui.fatal("You must specify a topology name")
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Remove the topo name attribute from all nodes, so topo search knows they are not in the topology
|
70
|
+
def remove_node_from_topology(node_name)
|
71
|
+
|
72
|
+
config[:disable_editing] = true
|
73
|
+
begin
|
74
|
+
|
75
|
+
# load then update and save the node
|
76
|
+
node = Chef::Node.load(node_name)
|
77
|
+
|
78
|
+
if node.normal['topo'] && node.normal['topo']['name'] == @topo_name
|
79
|
+
node.normal['topo'].delete('name')
|
80
|
+
ui.info "Removing node #{node.name} from topology"
|
81
|
+
node.save
|
82
|
+
end
|
83
|
+
|
84
|
+
rescue Net::HTTPServerException => e
|
85
|
+
raise unless e.to_s =~ /^404/
|
86
|
+
# Node has not been created
|
87
|
+
end
|
88
|
+
|
89
|
+
return node
|
90
|
+
end
|
91
|
+
|
92
|
+
include Chef::Knife::TopologyHelper
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 ThirdWave Insights LLC
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
require_relative 'topology_helper'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class TopoList < Chef::Knife
|
25
|
+
|
26
|
+
deps do
|
27
|
+
require 'chef/data_bag'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner "knife topo list (options)"
|
31
|
+
|
32
|
+
option :data_bag,
|
33
|
+
:short => '-D DATA_BAG',
|
34
|
+
:long => "--data-bag DATA_BAG",
|
35
|
+
:description => "The data bag the topologies are stored in"
|
36
|
+
|
37
|
+
|
38
|
+
def run
|
39
|
+
|
40
|
+
topo_bag = topo_bag_name(config[:data_bag])
|
41
|
+
output(format_list_for_display(Chef::DataBag.load(topo_bag)))
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
include Chef::Knife::TopologyHelper
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 ThirdWave Insights LLC
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require_relative 'topology_helper'
|
20
|
+
require 'chef/knife/search'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class TopoSearch < Chef::Knife::Search
|
25
|
+
|
26
|
+
banner "knife topo search [ QUERY ] (options)"
|
27
|
+
|
28
|
+
option :topo,
|
29
|
+
:long => "--topo TOPOLOGY",
|
30
|
+
:description => "Restrict search to nodes in the specified topology"
|
31
|
+
|
32
|
+
option :no_topo,
|
33
|
+
:long => "--no-topo",
|
34
|
+
:description => "Restrict search to nodes that are not in any topology",
|
35
|
+
:boolean => true,
|
36
|
+
:default => true
|
37
|
+
|
38
|
+
# Make the base search options available on topo search
|
39
|
+
self.options = (Chef::Knife::Search.options).merge(self.options)
|
40
|
+
|
41
|
+
def initialize (args)
|
42
|
+
super
|
43
|
+
topo_query = constrain_query(@name_args[0] || config[:query], config[:topo], !config[:no_topo].nil?)
|
44
|
+
|
45
|
+
# force a node search
|
46
|
+
@name_args[0] = "node"
|
47
|
+
|
48
|
+
# override any query
|
49
|
+
if config[:query]
|
50
|
+
config[:query] = topo_query
|
51
|
+
else
|
52
|
+
@name_args[1] = topo_query
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
begin
|
59
|
+
super
|
60
|
+
rescue Exception => e
|
61
|
+
raise if Chef::Config[:verbosity] == 2
|
62
|
+
ui.error "Topology search for \"#{@query}\" exited with error"
|
63
|
+
humanize_exception(e)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
include Chef::Knife::TopologyHelper
|
70
|
+
|
71
|
+
def constrain_query(query, topo_name, no_topo)
|
72
|
+
|
73
|
+
# group existing query
|
74
|
+
# workaround for strange behavior with NOTs and invalid query if put brackets round them
|
75
|
+
group_query = query && !query.start_with?("NOT") ? "(#{query})" : query
|
76
|
+
|
77
|
+
# search specific topologies or all/none
|
78
|
+
constraint = (topo_name) ? "topo_name:" + topo_name : "topo_name:*"
|
79
|
+
|
80
|
+
# combine the grouped query and constraint
|
81
|
+
if no_topo
|
82
|
+
result = query ? "#{group_query} NOT #{constraint}" : "NOT #{constraint}"
|
83
|
+
else
|
84
|
+
result = query ? "#{constraint} AND #{group_query}" : constraint
|
85
|
+
end
|
86
|
+
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -107,6 +107,8 @@ class Chef
|
|
107
107
|
normal_defaults = topo_hash['normal'] ? topo_hash['normal'].clone : {}
|
108
108
|
nodeprops['normal'] ||= {}
|
109
109
|
nodeprops['normal'] = prop_merge!(normal_defaults, nodeprops['normal'])
|
110
|
+
nodeprops['normal'] = prop_merge!(nodeprops['normal'], nodeprops['attributes']) if nodeprops['attributes']
|
111
|
+
nodeprops['normal'] = prop_merge!(nodeprops['normal'], { "topo" => { "name" => topo_hash['name'] }})
|
110
112
|
|
111
113
|
nodeprops['chef_environment'] ||= topo_hash['chef_environment'] if topo_hash['chef_environment']
|
112
114
|
|
metadata
CHANGED
@@ -1,16 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-topo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christine Draper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '13.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '11.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '13.0'
|
33
|
+
description: Knife-topo uses a JSON file to capture a topology of nodes, which can
|
34
|
+
be loaded into Chef and bootstrapped
|
14
35
|
email:
|
15
36
|
- christine_draper@thirdwaveinsights.com
|
16
37
|
executables: []
|
@@ -25,8 +46,11 @@ files:
|
|
25
46
|
- lib/chef/knife/topo_cookbook_create.rb
|
26
47
|
- lib/chef/knife/topo_cookbook_upload.rb
|
27
48
|
- lib/chef/knife/topo_create.rb
|
49
|
+
- lib/chef/knife/topo_delete.rb
|
28
50
|
- lib/chef/knife/topo_export.rb
|
29
51
|
- lib/chef/knife/topo_import.rb
|
52
|
+
- lib/chef/knife/topo_list.rb
|
53
|
+
- lib/chef/knife/topo_search.rb
|
30
54
|
- lib/chef/knife/topo_update.rb
|
31
55
|
- lib/chef/knife/topology_helper.rb
|
32
56
|
homepage: https://github.com/christinedraper/knife-topo
|
@@ -52,6 +76,6 @@ rubyforge_project:
|
|
52
76
|
rubygems_version: 2.4.4
|
53
77
|
signing_key:
|
54
78
|
specification_version: 4
|
55
|
-
summary: Knife plugin
|
79
|
+
summary: Knife plugin to manage topologies of nodes
|
56
80
|
test_files: []
|
57
81
|
has_rdoc:
|