knife-spork 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +35 -35
- data/lib/chef/knife/spork-bump.rb +100 -100
- data/lib/chef/knife/spork-check.rb +165 -161
- data/lib/chef/knife/spork-databag-create.rb +54 -54
- data/lib/chef/knife/spork-databag-delete.rb +51 -51
- data/lib/chef/knife/spork-databag-edit.rb +54 -54
- data/lib/chef/knife/spork-databag-fromfile.rb +88 -88
- data/lib/chef/knife/spork-delete.rb +132 -132
- data/lib/chef/knife/spork-environment-check.rb +90 -90
- data/lib/chef/knife/spork-environment-create.rb +63 -63
- data/lib/chef/knife/spork-environment-delete.rb +38 -38
- data/lib/chef/knife/spork-environment-edit.rb +40 -40
- data/lib/chef/knife/spork-environment-fromfile.rb +46 -46
- data/lib/chef/knife/spork-info.rb +34 -34
- data/lib/chef/knife/spork-node-create.rb +41 -41
- data/lib/chef/knife/spork-node-delete.rb +41 -41
- data/lib/chef/knife/spork-node-edit.rb +48 -48
- data/lib/chef/knife/spork-node-fromfile.rb +46 -46
- data/lib/chef/knife/spork-node-runlistadd.rb +51 -51
- data/lib/chef/knife/spork-node-runlistremove.rb +44 -44
- data/lib/chef/knife/spork-node-runlistset.rb +44 -44
- data/lib/chef/knife/spork-omni.rb +112 -112
- data/lib/chef/knife/spork-promote.rb +197 -197
- data/lib/chef/knife/spork-role-create.rb +46 -46
- data/lib/chef/knife/spork-role-delete.rb +50 -50
- data/lib/chef/knife/spork-role-edit.rb +40 -40
- data/lib/chef/knife/spork-role-fromfile.rb +65 -65
- data/lib/chef/knife/spork-upload.rb +151 -151
- data/lib/chef/knife/spork-version.rb +12 -12
- data/lib/knife-spork.rb +3 -3
- data/lib/knife-spork/plugins.rb +27 -27
- data/lib/knife-spork/plugins/campfire.rb +219 -219
- data/lib/knife-spork/plugins/eventinator.rb +329 -329
- data/lib/knife-spork/plugins/foodcritic.rb +46 -46
- data/lib/knife-spork/plugins/git.rb +393 -399
- data/lib/knife-spork/plugins/graphite.rb +25 -25
- data/lib/knife-spork/plugins/grove.rb +167 -167
- data/lib/knife-spork/plugins/hipchat.rb +171 -171
- data/lib/knife-spork/plugins/influxdb.rb +28 -28
- data/lib/knife-spork/plugins/irccat.rb +332 -332
- data/lib/knife-spork/plugins/jabber.rb +133 -133
- data/lib/knife-spork/plugins/plugin.rb +117 -117
- data/lib/knife-spork/plugins/rubocop.rb +56 -56
- data/lib/knife-spork/plugins/slack.rb +125 -125
- data/lib/knife-spork/plugins/statusnet.rb +122 -122
- data/lib/knife-spork/runner.rb +342 -342
- data/lib/knife-spork/version.rb +5 -5
- metadata +4 -51
- data/.gitignore +0 -21
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -3
- data/CHANGELOG.md +0 -445
- data/Gemfile +0 -3
- data/README.md +0 -544
- data/Rakefile +0 -35
- data/knife-spork.gemspec +0 -28
- data/plugins/Campfire.md +0 -43
- data/plugins/Eventinator.md +0 -30
- data/plugins/Foodcritic.md +0 -53
- data/plugins/Git.md +0 -53
- data/plugins/Graphite.md +0 -30
- data/plugins/Grove.md +0 -31
- data/plugins/HipChat.md +0 -69
- data/plugins/Influxdb.md +0 -25
- data/plugins/Irccat.md +0 -50
- data/plugins/Jabber.md +0 -61
- data/plugins/README.md +0 -70
- data/plugins/Rubocop.md +0 -110
- data/plugins/Slack.md +0 -48
- data/plugins/StatusNet.md +0 -41
- data/plugins/Template.md +0 -34
- data/spec/spec_helper.rb +0 -10
- data/spec/test_helpers.rb +0 -46
- data/spec/unit/fixtures/config/spork-config.yml +0 -1
- data/spec/unit/fixtures/cookbooks/example/metadata.rb +0 -8
- data/spec/unit/fixtures/environments/example.json +0 -12
- data/spec/unit/fixtures/knife.rb +0 -6
- data/spec/unit/fixtures/test_client.pem +0 -27
- data/spec/unit/spork_bump_spec.rb +0 -75
- data/spec/unit/spork_info_spec.rb +0 -40
- data/spec/unit/spork_promote_spec.rb +0 -77
- data/spec/unit/spork_upload_spec.rb +0 -46
@@ -1,132 +1,132 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkDelete < Chef::Knife
|
5
|
-
deps do
|
6
|
-
require 'chef/exceptions'
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
require 'socket'
|
9
|
-
end
|
10
|
-
|
11
|
-
ALL_NO_CONF = 'all_no_conf'.freeze
|
12
|
-
ALL_CONF = 'all_conf'.freeze
|
13
|
-
ONE_NO_CONF = 'one_no_conf'.freeze
|
14
|
-
ONE_CONF = 'one_conf'.freeze
|
15
|
-
|
16
|
-
banner 'knife spork delete [COOKBOOKS...] (options)'
|
17
|
-
|
18
|
-
option :cookbook_path,
|
19
|
-
:short => '-o PATH:PATH',
|
20
|
-
:long => '--cookbook-path PATH:PATH',
|
21
|
-
:description => 'A colon-separated path to look for cookbooks in',
|
22
|
-
:proc => lambda { |o| o.split(':') }
|
23
|
-
|
24
|
-
option :yes,
|
25
|
-
:short => '-y',
|
26
|
-
:long => '--yes',
|
27
|
-
:description => 'Say yes to all prompts for confirmation'
|
28
|
-
|
29
|
-
option :all,
|
30
|
-
:short => '-a',
|
31
|
-
:long => '--all',
|
32
|
-
:description => 'Delete all versions of the specified cookbooks'
|
33
|
-
|
34
|
-
|
35
|
-
def run
|
36
|
-
self.class.send(:include, KnifeSpork::Runner)
|
37
|
-
self.config = Chef::Config.merge!(config)
|
38
|
-
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
39
|
-
|
40
|
-
if @name_args.empty?
|
41
|
-
show_usage
|
42
|
-
ui.error("You must specify the --all flag or at least one cookbook name")
|
43
|
-
exit 1
|
44
|
-
end
|
45
|
-
|
46
|
-
delete
|
47
|
-
@misc_output = @deleted_cookbook_string
|
48
|
-
run_plugins(:after_delete)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def printable_version_string(version)
|
54
|
-
# The version variable might be a string or an array. The array might even be empty.
|
55
|
-
# Based on what it is, we will return a string that says something like "versions 1, 2" or "version 1" or "ALL versions"
|
56
|
-
# for more human-readable output.
|
57
|
-
if (version.class == Array and version.size == 0) or version == "ALL"
|
58
|
-
return "ALL versions"
|
59
|
-
elsif version.class == Array
|
60
|
-
if version.size > 1
|
61
|
-
return "versions #{version.join(', ')}"
|
62
|
-
else
|
63
|
-
return "version #{version.join(', ')}"
|
64
|
-
end
|
65
|
-
else
|
66
|
-
return "version #{version}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def run_knife_command(cookbook_name, command, version = [])
|
71
|
-
begin
|
72
|
-
ui.warn("Deleting cookbook #{cookbook_name}...")
|
73
|
-
case command
|
74
|
-
when ALL_NO_CONF
|
75
|
-
@knife.delete_all_without_confirmation
|
76
|
-
when ALL_CONF
|
77
|
-
@knife.delete_all_versions
|
78
|
-
when ONE_NO_CONF
|
79
|
-
@knife.delete_versions_without_confirmation(version)
|
80
|
-
when ONE_CONF
|
81
|
-
@knife.version = version
|
82
|
-
@knife.delete_explicit_version
|
83
|
-
end
|
84
|
-
ui.msg("Successfully deleted cookbook #{cookbook_name} #{printable_version_string(version)} from the Chef server")
|
85
|
-
true
|
86
|
-
rescue SystemExit
|
87
|
-
# The user said no at a confirmation prompt, just continue. But return false since we
|
88
|
-
# didn't actually delete anything.
|
89
|
-
false
|
90
|
-
rescue Exception => e
|
91
|
-
ui.error("Error deleting cookbook #{cookbook_name}: #{e}")
|
92
|
-
false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def delete
|
97
|
-
@deleted_cookbooks = []
|
98
|
-
name_args.each do |cookbook_name|
|
99
|
-
@knife = Chef::Knife::CookbookDelete.new
|
100
|
-
@knife.name_args = cookbook_name
|
101
|
-
@knife.cookbook_name = cookbook_name
|
102
|
-
if config[:all]
|
103
|
-
@knife.config[:all] = true
|
104
|
-
if config[:yes]
|
105
|
-
@deleted_cookbooks.push([cookbook_name, "ALL"]) if run_knife_command(cookbook_name, ALL_NO_CONF)
|
106
|
-
else
|
107
|
-
@deleted_cookbooks.push([cookbook_name, "ALL"]) if run_knife_command(cookbook_name, ALL_CONF)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
begin
|
111
|
-
versions_to_delete = @knife.ask_which_versions_to_delete
|
112
|
-
rescue NoMethodError
|
113
|
-
# Rescuing this means the output from knife itself already gets printed, no need to duplicate that.
|
114
|
-
exit 1
|
115
|
-
end
|
116
|
-
if config[:yes]
|
117
|
-
@deleted_cookbooks.push([cookbook_name, versions_to_delete]) if run_knife_command(cookbook_name, ONE_NO_CONF, versions_to_delete)
|
118
|
-
else
|
119
|
-
versions_to_delete.each do |version|
|
120
|
-
@deleted_cookbooks.push([cookbook_name, version]) if run_knife_command(cookbook_name, ONE_CONF, version)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
# This is the formatted string that the plugins will use to print.
|
126
|
-
@deleted_cookbook_string = ""
|
127
|
-
@deleted_cookbooks.each {|cookbook, version| @deleted_cookbook_string << "#{cookbook}: #{printable_version_string(version)}, " }
|
128
|
-
@deleted_cookbook_string.chop!.chop! # Get rid of the trailing , chop chop!
|
129
|
-
ui.msg("Cookbooks deleted from chef server: #{@deleted_cookbook_string}")
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkDelete < Chef::Knife
|
5
|
+
deps do
|
6
|
+
require 'chef/exceptions'
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
require 'socket'
|
9
|
+
end
|
10
|
+
|
11
|
+
ALL_NO_CONF = 'all_no_conf'.freeze
|
12
|
+
ALL_CONF = 'all_conf'.freeze
|
13
|
+
ONE_NO_CONF = 'one_no_conf'.freeze
|
14
|
+
ONE_CONF = 'one_conf'.freeze
|
15
|
+
|
16
|
+
banner 'knife spork delete [COOKBOOKS...] (options)'
|
17
|
+
|
18
|
+
option :cookbook_path,
|
19
|
+
:short => '-o PATH:PATH',
|
20
|
+
:long => '--cookbook-path PATH:PATH',
|
21
|
+
:description => 'A colon-separated path to look for cookbooks in',
|
22
|
+
:proc => lambda { |o| o.split(':') }
|
23
|
+
|
24
|
+
option :yes,
|
25
|
+
:short => '-y',
|
26
|
+
:long => '--yes',
|
27
|
+
:description => 'Say yes to all prompts for confirmation'
|
28
|
+
|
29
|
+
option :all,
|
30
|
+
:short => '-a',
|
31
|
+
:long => '--all',
|
32
|
+
:description => 'Delete all versions of the specified cookbooks'
|
33
|
+
|
34
|
+
|
35
|
+
def run
|
36
|
+
self.class.send(:include, KnifeSpork::Runner)
|
37
|
+
self.config = Chef::Config.merge!(config)
|
38
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
39
|
+
|
40
|
+
if @name_args.empty?
|
41
|
+
show_usage
|
42
|
+
ui.error("You must specify the --all flag or at least one cookbook name")
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
delete
|
47
|
+
@misc_output = @deleted_cookbook_string
|
48
|
+
run_plugins(:after_delete)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def printable_version_string(version)
|
54
|
+
# The version variable might be a string or an array. The array might even be empty.
|
55
|
+
# Based on what it is, we will return a string that says something like "versions 1, 2" or "version 1" or "ALL versions"
|
56
|
+
# for more human-readable output.
|
57
|
+
if (version.class == Array and version.size == 0) or version == "ALL"
|
58
|
+
return "ALL versions"
|
59
|
+
elsif version.class == Array
|
60
|
+
if version.size > 1
|
61
|
+
return "versions #{version.join(', ')}"
|
62
|
+
else
|
63
|
+
return "version #{version.join(', ')}"
|
64
|
+
end
|
65
|
+
else
|
66
|
+
return "version #{version}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def run_knife_command(cookbook_name, command, version = [])
|
71
|
+
begin
|
72
|
+
ui.warn("Deleting cookbook #{cookbook_name}...")
|
73
|
+
case command
|
74
|
+
when ALL_NO_CONF
|
75
|
+
@knife.delete_all_without_confirmation
|
76
|
+
when ALL_CONF
|
77
|
+
@knife.delete_all_versions
|
78
|
+
when ONE_NO_CONF
|
79
|
+
@knife.delete_versions_without_confirmation(version)
|
80
|
+
when ONE_CONF
|
81
|
+
@knife.version = version
|
82
|
+
@knife.delete_explicit_version
|
83
|
+
end
|
84
|
+
ui.msg("Successfully deleted cookbook #{cookbook_name} #{printable_version_string(version)} from the Chef server")
|
85
|
+
true
|
86
|
+
rescue SystemExit
|
87
|
+
# The user said no at a confirmation prompt, just continue. But return false since we
|
88
|
+
# didn't actually delete anything.
|
89
|
+
false
|
90
|
+
rescue Exception => e
|
91
|
+
ui.error("Error deleting cookbook #{cookbook_name}: #{e}")
|
92
|
+
false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def delete
|
97
|
+
@deleted_cookbooks = []
|
98
|
+
name_args.each do |cookbook_name|
|
99
|
+
@knife = Chef::Knife::CookbookDelete.new
|
100
|
+
@knife.name_args = cookbook_name
|
101
|
+
@knife.cookbook_name = cookbook_name
|
102
|
+
if config[:all]
|
103
|
+
@knife.config[:all] = true
|
104
|
+
if config[:yes]
|
105
|
+
@deleted_cookbooks.push([cookbook_name, "ALL"]) if run_knife_command(cookbook_name, ALL_NO_CONF)
|
106
|
+
else
|
107
|
+
@deleted_cookbooks.push([cookbook_name, "ALL"]) if run_knife_command(cookbook_name, ALL_CONF)
|
108
|
+
end
|
109
|
+
else
|
110
|
+
begin
|
111
|
+
versions_to_delete = @knife.ask_which_versions_to_delete
|
112
|
+
rescue NoMethodError
|
113
|
+
# Rescuing this means the output from knife itself already gets printed, no need to duplicate that.
|
114
|
+
exit 1
|
115
|
+
end
|
116
|
+
if config[:yes]
|
117
|
+
@deleted_cookbooks.push([cookbook_name, versions_to_delete]) if run_knife_command(cookbook_name, ONE_NO_CONF, versions_to_delete)
|
118
|
+
else
|
119
|
+
versions_to_delete.each do |version|
|
120
|
+
@deleted_cookbooks.push([cookbook_name, version]) if run_knife_command(cookbook_name, ONE_CONF, version)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
# This is the formatted string that the plugins will use to print.
|
126
|
+
@deleted_cookbook_string = ""
|
127
|
+
@deleted_cookbooks.each {|cookbook, version| @deleted_cookbook_string << "#{cookbook}: #{printable_version_string(version)}, " }
|
128
|
+
@deleted_cookbook_string.chop!.chop! # Get rid of the trailing , chop chop!
|
129
|
+
ui.msg("Cookbooks deleted from chef server: #{@deleted_cookbook_string}")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -1,90 +1,90 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkEnvironmentCheck < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
require 'chef/exceptions'
|
9
|
-
end
|
10
|
-
|
11
|
-
banner 'knife spork environment check ENVIRONMENT (options)'
|
12
|
-
|
13
|
-
option :fatal,
|
14
|
-
:short => '-f',
|
15
|
-
:long => '--fatal',
|
16
|
-
:description => 'Quit on first invalid constraint located'
|
17
|
-
|
18
|
-
def run
|
19
|
-
self.class.send(:include, KnifeSpork::Runner)
|
20
|
-
self.config = Chef::Config.merge!(config)
|
21
|
-
|
22
|
-
#First load so plugins etc know what to work with
|
23
|
-
@environments = verify_and_load_environments
|
24
|
-
|
25
|
-
run_plugins(:before_environmentcheck)
|
26
|
-
|
27
|
-
#Reload cookbook and env in case a VCS plugin found updates
|
28
|
-
@environments = verify_and_load_environments
|
29
|
-
|
30
|
-
check_environments
|
31
|
-
run_plugins(:after_environmentcheck)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def check_environments
|
37
|
-
@environments.each do |e|
|
38
|
-
env_status = true
|
39
|
-
ui.info "\nChecking constraints for environment: #{e}\n"
|
40
|
-
environment = load_environment_from_file(e)
|
41
|
-
cookbook_versions = environment.cookbook_versions
|
42
|
-
|
43
|
-
cookbook_versions.each do |cookbook, version_constraint|
|
44
|
-
vc = Chef::VersionConstraint.new(version_constraint)
|
45
|
-
status = check_cookbook_uploaded(cookbook, vc.version)
|
46
|
-
if !status
|
47
|
-
fail_and_exit(cookbook, vc.version)
|
48
|
-
env_status = status
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
if env_status
|
53
|
-
ui.msg "Environment #{e} looks good"
|
54
|
-
else
|
55
|
-
ui.fatal "Environment #{e} has constraints that point to non existent cookbook versions."
|
56
|
-
exit 1
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def check_cookbook_uploaded(cookbook_name, version)
|
62
|
-
api_endpoint = "cookbooks/#{cookbook_name}"
|
63
|
-
|
64
|
-
begin
|
65
|
-
cookbook = rest.get_rest(api_endpoint)
|
66
|
-
results = cookbook[cookbook_name]['versions'].any? do |cv|
|
67
|
-
cv['version'] == version.to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
if results
|
71
|
-
return true
|
72
|
-
else
|
73
|
-
return false
|
74
|
-
end
|
75
|
-
rescue Net::HTTPServerException
|
76
|
-
false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def fail_and_exit(cookbook_name, version)
|
81
|
-
message = "#{cookbook_name}@#{version} does not exist on Chef Server! Upload the cookbook first by running:\n\n\tknife spork upload #{cookbook_name}\n\n"
|
82
|
-
if config[:fatal]
|
83
|
-
ui.fatal message
|
84
|
-
exit 1
|
85
|
-
else
|
86
|
-
ui.error message
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkEnvironmentCheck < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
require 'chef/exceptions'
|
9
|
+
end
|
10
|
+
|
11
|
+
banner 'knife spork environment check ENVIRONMENT (options)'
|
12
|
+
|
13
|
+
option :fatal,
|
14
|
+
:short => '-f',
|
15
|
+
:long => '--fatal',
|
16
|
+
:description => 'Quit on first invalid constraint located'
|
17
|
+
|
18
|
+
def run
|
19
|
+
self.class.send(:include, KnifeSpork::Runner)
|
20
|
+
self.config = Chef::Config.merge!(config)
|
21
|
+
|
22
|
+
#First load so plugins etc know what to work with
|
23
|
+
@environments = verify_and_load_environments
|
24
|
+
|
25
|
+
run_plugins(:before_environmentcheck)
|
26
|
+
|
27
|
+
#Reload cookbook and env in case a VCS plugin found updates
|
28
|
+
@environments = verify_and_load_environments
|
29
|
+
|
30
|
+
check_environments
|
31
|
+
run_plugins(:after_environmentcheck)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def check_environments
|
37
|
+
@environments.each do |e|
|
38
|
+
env_status = true
|
39
|
+
ui.info "\nChecking constraints for environment: #{e}\n"
|
40
|
+
environment = load_environment_from_file(e)
|
41
|
+
cookbook_versions = environment.cookbook_versions
|
42
|
+
|
43
|
+
cookbook_versions.each do |cookbook, version_constraint|
|
44
|
+
vc = Chef::VersionConstraint.new(version_constraint)
|
45
|
+
status = check_cookbook_uploaded(cookbook, vc.version)
|
46
|
+
if !status
|
47
|
+
fail_and_exit(cookbook, vc.version)
|
48
|
+
env_status = status
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if env_status
|
53
|
+
ui.msg "Environment #{e} looks good"
|
54
|
+
else
|
55
|
+
ui.fatal "Environment #{e} has constraints that point to non existent cookbook versions."
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_cookbook_uploaded(cookbook_name, version)
|
62
|
+
api_endpoint = "cookbooks/#{cookbook_name}"
|
63
|
+
|
64
|
+
begin
|
65
|
+
cookbook = rest.get_rest(api_endpoint)
|
66
|
+
results = cookbook[cookbook_name]['versions'].any? do |cv|
|
67
|
+
cv['version'] == version.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
if results
|
71
|
+
return true
|
72
|
+
else
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
rescue Net::HTTPServerException
|
76
|
+
false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def fail_and_exit(cookbook_name, version)
|
81
|
+
message = "#{cookbook_name}@#{version} does not exist on Chef Server! Upload the cookbook first by running:\n\n\tknife spork upload #{cookbook_name}\n\n"
|
82
|
+
if config[:fatal]
|
83
|
+
ui.fatal message
|
84
|
+
exit 1
|
85
|
+
else
|
86
|
+
ui.error message
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -1,63 +1,63 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkEnvironmentCreate < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
end
|
9
|
-
|
10
|
-
banner 'knife spork environment create ENVIRONMENT (options)'
|
11
|
-
|
12
|
-
option :description,
|
13
|
-
:short => "-d DESC",
|
14
|
-
:long => "--description DESC",
|
15
|
-
:description => "The environment description"
|
16
|
-
|
17
|
-
def run
|
18
|
-
self.class.send(:include, KnifeSpork::Runner)
|
19
|
-
self.config = Chef::Config.merge!(config)
|
20
|
-
|
21
|
-
if @name_args.empty?
|
22
|
-
show_usage
|
23
|
-
ui.error("You must specify a environment name")
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
@object_name = @name_args.first
|
28
|
-
|
29
|
-
run_plugins(:before_environmentcreate)
|
30
|
-
|
31
|
-
# Check if environment already exists
|
32
|
-
begin
|
33
|
-
check_environment = load_environment(@object_name)
|
34
|
-
if check_environment
|
35
|
-
ui.confirm("It looks like the environment #{@object_name} already exists. Are you sure you want to overwrite it")
|
36
|
-
end
|
37
|
-
rescue Net::HTTPServerException
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
pre_environment = {}
|
42
|
-
environment_create
|
43
|
-
post_environment = load_environment(@object_name)
|
44
|
-
|
45
|
-
if spork_config[:save_environment_locally_on_create]
|
46
|
-
ui.msg "Saving environment changes to #{@object_name}.json"
|
47
|
-
save_environment_changes(@object_name, pretty_print_json(post_environment))
|
48
|
-
end
|
49
|
-
|
50
|
-
@object_difference = json_diff(pre_environment,post_environment).to_s
|
51
|
-
run_plugins(:after_environmentcreate)
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
def environment_create
|
56
|
-
rc = Chef::Knife::EnvironmentCreate.new
|
57
|
-
rc.name_args = @name_args
|
58
|
-
rc.config[:editor] = config[:editor]
|
59
|
-
rc.config[:description] = config[:description]
|
60
|
-
rc.run
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkEnvironmentCreate < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
end
|
9
|
+
|
10
|
+
banner 'knife spork environment create ENVIRONMENT (options)'
|
11
|
+
|
12
|
+
option :description,
|
13
|
+
:short => "-d DESC",
|
14
|
+
:long => "--description DESC",
|
15
|
+
:description => "The environment description"
|
16
|
+
|
17
|
+
def run
|
18
|
+
self.class.send(:include, KnifeSpork::Runner)
|
19
|
+
self.config = Chef::Config.merge!(config)
|
20
|
+
|
21
|
+
if @name_args.empty?
|
22
|
+
show_usage
|
23
|
+
ui.error("You must specify a environment name")
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
@object_name = @name_args.first
|
28
|
+
|
29
|
+
run_plugins(:before_environmentcreate)
|
30
|
+
|
31
|
+
# Check if environment already exists
|
32
|
+
begin
|
33
|
+
check_environment = load_environment(@object_name)
|
34
|
+
if check_environment
|
35
|
+
ui.confirm("It looks like the environment #{@object_name} already exists. Are you sure you want to overwrite it")
|
36
|
+
end
|
37
|
+
rescue Net::HTTPServerException
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
pre_environment = {}
|
42
|
+
environment_create
|
43
|
+
post_environment = load_environment(@object_name)
|
44
|
+
|
45
|
+
if spork_config[:save_environment_locally_on_create]
|
46
|
+
ui.msg "Saving environment changes to #{@object_name}.json"
|
47
|
+
save_environment_changes(@object_name, pretty_print_json(post_environment))
|
48
|
+
end
|
49
|
+
|
50
|
+
@object_difference = json_diff(pre_environment,post_environment).to_s
|
51
|
+
run_plugins(:after_environmentcreate)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def environment_create
|
56
|
+
rc = Chef::Knife::EnvironmentCreate.new
|
57
|
+
rc.name_args = @name_args
|
58
|
+
rc.config[:editor] = config[:editor]
|
59
|
+
rc.config[:description] = config[:description]
|
60
|
+
rc.run
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|