knife-topo 0.0.8 → 0.0.9
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 +7 -0
- data/README.md +39 -6
- data/lib/chef/knife/topo/version.rb +1 -1
- data/lib/chef/knife/topo_bootstrap.rb +2 -2
- data/lib/chef/knife/topo_cookbook_create.rb +2 -1
- data/lib/chef/knife/topo_cookbook_upload.rb +1 -1
- data/lib/chef/knife/topo_create.rb +5 -3
- data/lib/chef/knife/topo_export.rb +31 -4
- data/lib/chef/knife/topo_import.rb +1 -1
- data/lib/chef/knife/topo_update.rb +5 -2
- data/lib/chef/knife/topology_helper.rb +9 -2
- metadata +14 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 567dce9e707b529d85df97a58de7c9a180ef57d4
|
4
|
+
data.tar.gz: 0550b76dc324cd4966d013d41f0efe34fd2264ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bbc66a61636b8d1563cfe271ef6772839b875cbf1fe56c0f23e031b278f4a7a76dd9f4bf1007ae60c13a97ddd31165618c0acb2f34f725391991b4b19c54a53
|
7
|
+
data.tar.gz: 66260591db0aa228aab5e4a5648012d313f9ff7df9b78ed671d7d37af9004682391b600c3f41b4a33d8d364d6c571925092ca0220a6f531dbed10bef0a2ea105
|
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.9.zip -d ~
|
26
|
+
$ cd ~/knife-topo-0.0.9
|
27
27
|
$ mkdir -p ~/.chef/plugins/knife
|
28
28
|
$ cp lib/chef/knife/* ~/.chef/plugins/knife
|
29
29
|
|
@@ -33,7 +33,7 @@ or install knife-topo as a gem
|
|
33
33
|
|
34
34
|
You may need to use `sudo gem install knife-topo`, depending on your setup.
|
35
35
|
|
36
|
-
This plugin has been tested with Chef Version 11.12 on Ubuntu 14.04 LTS.
|
36
|
+
This plugin has been tested with Chef Version 11.12 on Ubuntu 14.04 LTS, and run on Windows and Mac.
|
37
37
|
|
38
38
|
Note: I've encountered a case (on a Mac) where knife was not configured to use
|
39
39
|
gems on the gem path. If the gem install succeeds but `knife topo`
|
@@ -59,6 +59,25 @@ and unzip it, then follow the [Instructions](test-repo/Instructions.md) for the
|
|
59
59
|
The instructions assume you have [chefDK](http://www.getchef.com/downloads/chef-dk/)
|
60
60
|
or equivalent installed and working with Vagrant and VirtualBox, but
|
61
61
|
none of these are requirements to use the knife-topo plugin.
|
62
|
+
|
63
|
+
If you're the sort of person who just wants to jump in and try it, here's some hints.
|
64
|
+
|
65
|
+
Generate a topology file for a topology called test1 from existing nodes node1 and node2:
|
66
|
+
|
67
|
+
knife topo export test1 node1 node2 > topology.json
|
68
|
+
|
69
|
+
Import a topology json file, generating all of the necessary artifacts in your workspace:
|
70
|
+
|
71
|
+
knife topo import topology1.json
|
72
|
+
|
73
|
+
Create the topology using existing nodes:
|
74
|
+
|
75
|
+
knife topo create test1
|
76
|
+
|
77
|
+
Create the topology bootstrapping new nodes in vagrant (you will need to add the
|
78
|
+
host details for bootstrap to the file before importing):
|
79
|
+
|
80
|
+
knife topo create test1 --bootstrap -xvagrant -Pvagrant --sudo
|
62
81
|
|
63
82
|
# Topology File <a name="topology-file"></a>#
|
64
83
|
|
@@ -240,7 +259,7 @@ See [knife bootstrap](http://docs.opscode.com/knife_bootstrap.html) | Options s
|
|
240
259
|
The following will bootstrap nodes in the test1 topology, using a
|
241
260
|
user name of vagrant, password of vagrant, and running using sudo.
|
242
261
|
|
243
|
-
$ knife topo bootstrap
|
262
|
+
$ knife topo bootstrap test1 -x vagrant -P vagrant --sudo
|
244
263
|
|
245
264
|
## knife topo cookbook create <a name="cookbook-create"></a>
|
246
265
|
|
@@ -329,10 +348,24 @@ to any nodes that are in the topology.
|
|
329
348
|
|
330
349
|
If no topology is specified, all defined topologies will be exported.
|
331
350
|
|
351
|
+
### Options:
|
352
|
+
|
353
|
+
The knife topo export subcommand supports the following additional options.
|
354
|
+
|
355
|
+
Option | Description
|
356
|
+
------------ | -----------
|
357
|
+
--min-priority | Only export attributes with a priority equal or above this priority.
|
358
|
+
|
332
359
|
### Examples:
|
333
|
-
The following will export all topologies to a file called 'sys1_test.json'.
|
334
360
|
|
335
|
-
|
361
|
+
The following will export the data for nodes n1 and n2 as part of a topology called 'new_topo':
|
362
|
+
|
363
|
+
$ knife topo export new_topo n1 n2 > new_topo.json
|
364
|
+
|
365
|
+
|
366
|
+
The following will export all topologies to a file called 'all_topos.json'.
|
367
|
+
|
368
|
+
$ knife topo export > all_topos.json
|
336
369
|
|
337
370
|
The following will create an outline for a new topology called 'christine_test':
|
338
371
|
|
@@ -79,10 +79,10 @@ class Chef
|
|
79
79
|
end
|
80
80
|
|
81
81
|
end
|
82
|
-
ui.info "Bootstrapped #{nodes.length - (@failed.length + skipped)} nodes and skipped #{skipped} nodes of #{nodes.length} in topology #{
|
82
|
+
ui.info "Bootstrapped #{nodes.length - (@failed.length + skipped)} nodes and skipped #{skipped} nodes of #{nodes.length} in topology #{display_name(topo)}"
|
83
83
|
ui.warn "#{@failed.length} nodes [ #{@failed.join(', ')} ] failed to bootstrap" if @failed.length > 0
|
84
84
|
else
|
85
|
-
ui.info "No nodes found for topology #{
|
85
|
+
ui.info "No nodes found for topology #{display_name(topo)}"
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -132,7 +132,8 @@ class Chef
|
|
132
132
|
print_attr(file, "#{lhs}['#{key}']", value2)
|
133
133
|
end
|
134
134
|
else
|
135
|
-
|
135
|
+
rubyString = (value1 == nil) ? "nil" : Chef::JSONCompat.to_json(value1);
|
136
|
+
file.write "#{lhs} = " + rubyString + " \n"
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
@@ -84,7 +84,9 @@ class Chef
|
|
84
84
|
topo.create
|
85
85
|
rescue Net::HTTPServerException => e
|
86
86
|
raise unless e.to_s =~ /^409/
|
87
|
-
|
87
|
+
msg = "Topology already exists - do you want to update it";
|
88
|
+
msg + " to version " + topo['version'] if topo['version']
|
89
|
+
ui.confirm(msg, true, false)
|
88
90
|
topo.save
|
89
91
|
end
|
90
92
|
|
@@ -105,10 +107,10 @@ class Chef
|
|
105
107
|
# if bootstrap is specified, run the bootstrap command
|
106
108
|
run_cmd(Chef::Knife::TopoBootstrap, @topo_bootstrap_args) if config[:bootstrap]
|
107
109
|
else
|
108
|
-
ui.info "No nodes found for topology #{topo_hash
|
110
|
+
ui.info "No nodes found for topology #{display_name(topo_hash)}"
|
109
111
|
end
|
110
112
|
|
111
|
-
ui.info("Topology created")
|
113
|
+
ui.info("Topology #{display_name(topo_hash)} created")
|
112
114
|
|
113
115
|
end
|
114
116
|
|
@@ -20,7 +20,7 @@ require 'chef/knife'
|
|
20
20
|
|
21
21
|
require_relative 'topology_helper'
|
22
22
|
|
23
|
-
# NOTE: This command exports to stdout
|
23
|
+
# NOTE: This command exports to stdout
|
24
24
|
|
25
25
|
class Chef
|
26
26
|
class Knife
|
@@ -35,7 +35,18 @@ class Chef
|
|
35
35
|
:short => '-D DATA_BAG',
|
36
36
|
:long => "--data-bag DATA_BAG",
|
37
37
|
:description => "The data bag the topologies are stored in"
|
38
|
-
|
38
|
+
|
39
|
+
option :min_priority,
|
40
|
+
:long => "--min-priority PRIORITY",
|
41
|
+
:default => "default",
|
42
|
+
:description => "Export attributes with this priority or above"
|
43
|
+
|
44
|
+
def most_common (vals)
|
45
|
+
vals.group_by do |val|
|
46
|
+
val
|
47
|
+
end.values.max_by(&:size).first
|
48
|
+
end
|
49
|
+
|
39
50
|
def run
|
40
51
|
|
41
52
|
@bag_name = topo_bag_name(config[:data_bag])
|
@@ -43,6 +54,10 @@ class Chef
|
|
43
54
|
@topo_name = @name_args[0]
|
44
55
|
@node_names = @name_args[1..-1]
|
45
56
|
|
57
|
+
unless ['default', 'normal', 'override'].include?(config[:min_priority])
|
58
|
+
ui.warn("--min-priority should be one of 'default', 'normal' or 'override'")
|
59
|
+
end
|
60
|
+
|
46
61
|
if @topo_name
|
47
62
|
if topo = load_from_server(@bag_name, @topo_name)
|
48
63
|
export = topo.raw_data
|
@@ -55,6 +70,15 @@ class Chef
|
|
55
70
|
@node_names.each do |node_name|
|
56
71
|
merge_node_properties!(export['nodes'], node_name)
|
57
72
|
end
|
73
|
+
|
74
|
+
# if a new topo, pick an topo environment based on the nodes
|
75
|
+
if !topo && @node_names.length != 0
|
76
|
+
envs = []
|
77
|
+
export['nodes'].each do |node|
|
78
|
+
envs << node['chef_environment'] if node['chef_environment']
|
79
|
+
end
|
80
|
+
export['chef_environment'] = most_common(envs) if envs.length > 0
|
81
|
+
end
|
58
82
|
|
59
83
|
else
|
60
84
|
# export all topologies
|
@@ -78,7 +102,6 @@ class Chef
|
|
78
102
|
"name" => @topo_name || "topo1",
|
79
103
|
"chef_environment" => "_default",
|
80
104
|
"tags" => [ ],
|
81
|
-
"normal" => { },
|
82
105
|
"nodes" => [ ],
|
83
106
|
"cookbook_attributes" => [{
|
84
107
|
"cookbook" => @topo_name || "topo1",
|
@@ -109,8 +132,12 @@ class Chef
|
|
109
132
|
node_data['name'] = node.name
|
110
133
|
node_data['tags'] = node.tags
|
111
134
|
node_data['chef_environment'] = node.chef_environment
|
112
|
-
node_data['normal'] = node.normal
|
113
135
|
node_data['run_list'] = node.run_list
|
136
|
+
|
137
|
+
pri = config[:min_priority]
|
138
|
+
node_data['default'] = node.default if pri == "default"
|
139
|
+
node_data['normal'] = node.normal if pri == "default" || pri == "normal"
|
140
|
+
node_data['override'] = node.override
|
114
141
|
|
115
142
|
rescue Net::HTTPServerException => e
|
116
143
|
raise unless e.to_s =~ /^404/
|
@@ -83,7 +83,7 @@ class Chef
|
|
83
83
|
File.open(path,"w") do |f|
|
84
84
|
f.write(Chef::JSONCompat.to_json_pretty(topo_data))
|
85
85
|
f.close()
|
86
|
-
ui.info "Imported topology #{
|
86
|
+
ui.info "Imported topology #{display_name(topo_data)} into #{path}"
|
87
87
|
end
|
88
88
|
|
89
89
|
# run topo cookbook to generate the cookbooks for this topology
|
@@ -62,7 +62,6 @@ class Chef
|
|
62
62
|
|
63
63
|
if topo_name
|
64
64
|
# update a specific topo
|
65
|
-
ui.info "Updating topology: #{topo_name} in data bag: #{bag_name}"
|
66
65
|
|
67
66
|
unless current_topo = load_from_server(bag_name, topo_name)
|
68
67
|
ui.fatal "Topology #{bag_name}/#{topo_name} does not exist on server - use 'knife topo create' first"
|
@@ -73,6 +72,10 @@ class Chef
|
|
73
72
|
ui.info "No topology found in #{topologies_path}/#{bag_name}/#{topo_name}.json - exiting without action"
|
74
73
|
exit(0)
|
75
74
|
end
|
75
|
+
|
76
|
+
msg = "Updating topology #{display_name(current_topo)}"
|
77
|
+
msg = msg + " to version " + topo['version'] if topo['version']
|
78
|
+
ui.info msg
|
76
79
|
|
77
80
|
update_topo(topo)
|
78
81
|
|
@@ -92,7 +95,7 @@ class Chef
|
|
92
95
|
# do not update topologies that are not in the local workspace
|
93
96
|
ui.info("No topology file found in #{topologies_path}/#{bag_name}/#{topo_name}.json - skipping")
|
94
97
|
else
|
95
|
-
ui.info("Updating topology #{
|
98
|
+
ui.info("Updating topology #{display_name(topo)}")
|
96
99
|
update_topo(topo)
|
97
100
|
end
|
98
101
|
end
|
@@ -18,6 +18,7 @@
|
|
18
18
|
|
19
19
|
require 'chef/data_bag'
|
20
20
|
require 'chef/encrypted_data_bag_item'
|
21
|
+
require 'chef/environment'
|
21
22
|
require 'chef/knife/core/object_loader'
|
22
23
|
|
23
24
|
class Chef
|
@@ -191,8 +192,10 @@ class Chef
|
|
191
192
|
|
192
193
|
# Load a topology from local data bag item file
|
193
194
|
def load_from_file(bag_name, topo_name)
|
194
|
-
|
195
|
-
|
195
|
+
|
196
|
+
topo_file = File.join(Dir.pwd, "#{topologies_path}", bag_name, topo_name + '.json')
|
197
|
+
return unless (loader.file_exists_and_is_readable?(topo_file))
|
198
|
+
|
196
199
|
item_data = loader.object_from_file(topo_file)
|
197
200
|
item_data = if use_encryption
|
198
201
|
secret = read_secret
|
@@ -288,6 +291,10 @@ class Chef
|
|
288
291
|
raise if Chef::Config[:verbosity] == 2
|
289
292
|
end
|
290
293
|
end
|
294
|
+
|
295
|
+
def display_name (topo)
|
296
|
+
topo['name'] + ((topo['version']) ? " version " + topo['version'] : "")
|
297
|
+
end
|
291
298
|
|
292
299
|
end
|
293
300
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-topo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Christine Draper
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-09-27 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Knife plugin that to manage topologies of nodes
|
15
14
|
email:
|
@@ -18,42 +17,41 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
-
|
22
|
-
-
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- knife-topo.gemspec
|
23
23
|
- lib/chef/knife/topo/version.rb
|
24
|
+
- lib/chef/knife/topo_bootstrap.rb
|
24
25
|
- lib/chef/knife/topo_cookbook_create.rb
|
26
|
+
- lib/chef/knife/topo_cookbook_upload.rb
|
25
27
|
- lib/chef/knife/topo_create.rb
|
26
|
-
- lib/chef/knife/
|
28
|
+
- lib/chef/knife/topo_export.rb
|
27
29
|
- lib/chef/knife/topo_import.rb
|
30
|
+
- lib/chef/knife/topo_update.rb
|
28
31
|
- lib/chef/knife/topology_helper.rb
|
29
|
-
- lib/chef/knife/topo_cookbook_upload.rb
|
30
|
-
- LICENSE
|
31
|
-
- README.md
|
32
|
-
- knife-topo.gemspec
|
33
32
|
homepage: https://github.com/christinedraper/knife-topo
|
34
33
|
licenses:
|
35
34
|
- Apache License (2.0)
|
35
|
+
metadata: {}
|
36
36
|
post_install_message:
|
37
37
|
rdoc_options: []
|
38
38
|
require_paths:
|
39
39
|
- lib
|
40
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
|
-
- -
|
42
|
+
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '0'
|
46
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
46
|
requirements:
|
49
|
-
- -
|
47
|
+
- - ">="
|
50
48
|
- !ruby/object:Gem::Version
|
51
49
|
version: '0'
|
52
50
|
requirements: []
|
53
51
|
rubyforge_project:
|
54
|
-
rubygems_version:
|
52
|
+
rubygems_version: 2.2.1
|
55
53
|
signing_key:
|
56
|
-
specification_version:
|
54
|
+
specification_version: 4
|
57
55
|
summary: Knife plugin that to manage topologies of nodes
|
58
56
|
test_files: []
|
59
57
|
has_rdoc:
|