chef 0.8.16 → 0.9.0.a3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/bin/shef +1 -0
- data/distro/common/man/man1/chef-server-webui.1 +106 -0
- data/distro/common/man/man1/chef-server.1 +0 -1
- data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
- data/distro/common/man/man1/chef-solr.1 +55 -0
- data/distro/common/man/man8/chef-client.8 +4 -2
- data/distro/common/man/man8/chef-solo.8 +1 -2
- data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
- data/distro/common/man/man8/knife.8 +668 -266
- data/distro/common/man/man8/shef.8 +45 -0
- data/distro/common/markdown/README +3 -0
- data/distro/common/markdown/knife.mkd +520 -0
- data/distro/debian/etc/default/chef-client +4 -0
- data/distro/debian/etc/default/chef-server +6 -0
- data/distro/debian/etc/default/chef-server-webui +6 -0
- data/distro/debian/etc/default/chef-solr +4 -0
- data/distro/debian/etc/default/chef-solr-indexer +4 -0
- data/distro/debian/etc/init.d/chef-client +41 -41
- data/distro/debian/etc/init.d/chef-server +10 -10
- data/distro/debian/etc/init.d/chef-server-webui +121 -0
- data/distro/debian/etc/init.d/chef-solr +177 -0
- data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
- data/distro/redhat/etc/init.d/chef-client +76 -48
- data/distro/redhat/etc/init.d/chef-server +85 -51
- data/distro/redhat/etc/init.d/chef-server-webui +85 -51
- data/distro/redhat/etc/init.d/chef-solr +77 -49
- data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
- data/distro/redhat/etc/logrotate.d/chef-client +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-client +9 -4
- data/distro/redhat/etc/sysconfig/chef-server +10 -6
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
- data/distro/redhat/etc/sysconfig/chef-solr +3 -4
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
- data/lib/chef.rb +16 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -7
- data/lib/chef/cache/checksum.rb +12 -5
- data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
- data/lib/chef/checksum.rb +115 -0
- data/lib/chef/client.rb +193 -185
- data/lib/chef/config.rb +9 -1
- data/lib/chef/cookbook/cookbook_collection.rb +43 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
- data/lib/chef/cookbook/file_vendor.rb +47 -0
- data/lib/chef/cookbook/metadata.rb +34 -35
- data/lib/chef/cookbook/metadata/version.rb +1 -1
- data/lib/chef/cookbook_loader.rb +70 -45
- data/lib/chef/cookbook_version.rb +760 -0
- data/lib/chef/couchdb.rb +8 -5
- data/lib/chef/data_bag_item.rb +5 -5
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/file_access_control.rb +134 -0
- data/lib/chef/handler.rb +62 -0
- data/lib/chef/handler/json_file.rb +47 -0
- data/lib/chef/knife.rb +14 -2
- data/lib/chef/knife/bootstrap.rb +126 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_delete.rb +4 -4
- data/lib/chef/knife/cookbook_download.rb +57 -26
- data/lib/chef/knife/cookbook_metadata.rb +2 -2
- data/lib/chef/knife/cookbook_show.rb +30 -11
- data/lib/chef/knife/cookbook_upload.rb +113 -86
- data/lib/chef/knife/ec2_server_create.rb +146 -0
- data/lib/chef/knife/ec2_server_delete.rb +84 -0
- data/lib/chef/knife/ec2_server_list.rb +82 -0
- data/lib/chef/knife/status.rb +51 -0
- data/lib/chef/mixin/language_include_attribute.rb +16 -11
- data/lib/chef/mixin/language_include_recipe.rb +15 -16
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
- data/lib/chef/mixin/shell_out.rb +38 -0
- data/lib/chef/mixins.rb +1 -1
- data/lib/chef/node.rb +190 -63
- data/lib/chef/node/attribute.rb +92 -78
- data/lib/chef/platform.rb +24 -4
- data/lib/chef/provider.rb +28 -10
- data/lib/chef/provider/breakpoint.rb +2 -2
- data/lib/chef/provider/cookbook_file.rb +96 -0
- data/lib/chef/provider/cron.rb +2 -2
- data/lib/chef/provider/deploy.rb +12 -10
- data/lib/chef/provider/env.rb +152 -0
- data/lib/chef/provider/env/windows.rb +75 -0
- data/lib/chef/provider/file.rb +10 -14
- data/lib/chef/provider/group.rb +15 -2
- data/lib/chef/provider/group/dscl.rb +17 -25
- data/lib/chef/provider/group/gpasswd.rb +6 -3
- data/lib/chef/provider/group/pw.rb +3 -7
- data/lib/chef/provider/group/windows.rb +79 -0
- data/lib/chef/provider/link.rb +4 -5
- data/lib/chef/provider/mdadm.rb +25 -18
- data/lib/chef/provider/mount/mount.rb +28 -27
- data/lib/chef/provider/package.rb +35 -35
- data/lib/chef/provider/package/dpkg.rb +13 -10
- data/lib/chef/provider/package/easy_install.rb +6 -6
- data/lib/chef/provider/package/freebsd.rb +17 -51
- data/lib/chef/provider/package/rpm.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +391 -74
- data/lib/chef/provider/package/yum.rb +2 -2
- data/lib/chef/provider/package/zypper.rb +2 -1
- data/lib/chef/provider/remote_directory.rb +60 -83
- data/lib/chef/provider/remote_file.rb +17 -66
- data/lib/chef/provider/script.rb +20 -9
- data/lib/chef/provider/service.rb +23 -30
- data/lib/chef/provider/service/arch.rb +3 -3
- data/lib/chef/provider/service/debian.rb +22 -17
- data/lib/chef/provider/service/freebsd.rb +4 -4
- data/lib/chef/provider/service/init.rb +2 -2
- data/lib/chef/provider/service/redhat.rb +14 -16
- data/lib/chef/provider/service/simple.rb +7 -3
- data/lib/chef/provider/service/solaris.rb +85 -0
- data/lib/chef/provider/service/upstart.rb +12 -7
- data/lib/chef/provider/service/windows.rb +2 -2
- data/lib/chef/provider/template.rb +133 -118
- data/lib/chef/provider/user.rb +34 -17
- data/lib/chef/provider/user/dscl.rb +117 -114
- data/lib/chef/provider/user/windows.rb +124 -0
- data/lib/chef/providers.rb +7 -0
- data/lib/chef/recipe.rb +39 -20
- data/lib/chef/resource.rb +47 -52
- data/lib/chef/resource/apt_package.rb +4 -4
- data/lib/chef/resource/bash.rb +4 -4
- data/lib/chef/resource/cookbook_file.rb +45 -0
- data/lib/chef/resource/cron.rb +3 -3
- data/lib/chef/resource/csh.rb +4 -4
- data/lib/chef/resource/deploy.rb +3 -3
- data/lib/chef/resource/directory.rb +4 -4
- data/lib/chef/resource/dpkg_package.rb +4 -4
- data/lib/chef/resource/easy_install_package.rb +3 -3
- data/lib/chef/resource/env.rb +58 -0
- data/lib/chef/resource/erl_call.rb +3 -3
- data/lib/chef/resource/execute.rb +3 -3
- data/lib/chef/resource/file.rb +3 -3
- data/lib/chef/resource/freebsd_package.rb +3 -3
- data/lib/chef/resource/gem_package.rb +17 -9
- data/lib/chef/resource/git.rb +3 -3
- data/lib/chef/resource/group.rb +3 -3
- data/lib/chef/resource/http_request.rb +4 -4
- data/lib/chef/resource/ifconfig.rb +3 -3
- data/lib/chef/resource/link.rb +3 -3
- data/lib/chef/resource/log.rb +2 -2
- data/lib/chef/resource/macports_package.rb +2 -2
- data/lib/chef/resource/mdadm.rb +3 -3
- data/lib/chef/resource/mount.rb +2 -2
- data/lib/chef/resource/package.rb +4 -4
- data/lib/chef/resource/pacman_package.rb +4 -4
- data/lib/chef/resource/perl.rb +4 -4
- data/lib/chef/resource/portage_package.rb +4 -4
- data/lib/chef/resource/python.rb +4 -4
- data/lib/chef/resource/remote_directory.rb +3 -3
- data/lib/chef/resource/remote_file.rb +26 -3
- data/lib/chef/resource/route.rb +3 -3
- data/lib/chef/resource/ruby.rb +3 -3
- data/lib/chef/resource/ruby_block.rb +3 -2
- data/lib/chef/resource/scm.rb +7 -5
- data/lib/chef/resource/script.rb +4 -4
- data/lib/chef/resource/service.rb +3 -3
- data/lib/chef/resource/subversion.rb +4 -2
- data/lib/chef/resource/template.rb +3 -3
- data/lib/chef/resource/user.rb +3 -3
- data/lib/chef/resource/yum_package.rb +3 -3
- data/lib/chef/resource_collection.rb +9 -5
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +4 -0
- data/lib/chef/role.rb +2 -0
- data/lib/chef/run_context.rb +108 -0
- data/lib/chef/run_list.rb +75 -98
- data/lib/chef/run_list/run_list_expansion.rb +156 -0
- data/lib/chef/run_list/run_list_item.rb +71 -0
- data/lib/chef/runner.rb +58 -61
- data/lib/chef/sandbox.rb +147 -0
- data/lib/chef/shef.rb +4 -3
- data/lib/chef/shef/ext.rb +12 -4
- data/lib/chef/shef/shef_session.rb +27 -23
- data/lib/chef/shell_out.rb +375 -0
- data/lib/chef/util/windows.rb +56 -0
- data/lib/chef/util/windows/net_group.rb +101 -0
- data/lib/chef/util/windows/net_user.rb +198 -0
- data/lib/chef/version.rb +20 -0
- metadata +112 -22
- data/lib/chef/compile.rb +0 -158
- data/lib/chef/cookbook.rb +0 -201
- data/lib/chef/mixin/generate_url.rb +0 -58
@@ -0,0 +1,146 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
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 'json'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class Ec2ServerCreate < Knife
|
25
|
+
|
26
|
+
banner "Sub-Command: ec2 server create [RUN LIST...] (options)"
|
27
|
+
|
28
|
+
option :flavor,
|
29
|
+
:short => "-f FLAVOR",
|
30
|
+
:long => "--flavor FLAVOR",
|
31
|
+
:description => "The flavor of server (m1.small, m1.medium, etc)",
|
32
|
+
:default => "m1.small"
|
33
|
+
|
34
|
+
option :image,
|
35
|
+
:short => "-i IMAGE",
|
36
|
+
:long => "--image IMAGE",
|
37
|
+
:description => "The AMI for the server"
|
38
|
+
|
39
|
+
option :security_groups,
|
40
|
+
:short => "-G X,Y,Z",
|
41
|
+
:long => "--groups X,Y,Z",
|
42
|
+
:description => "The security groups for this server",
|
43
|
+
:default => ["default"],
|
44
|
+
:proc => Proc.new { |groups| groups.split(',') }
|
45
|
+
|
46
|
+
option :availability_zone,
|
47
|
+
:short => "-Z ZONE",
|
48
|
+
:long => "--availability-zone ZONE",
|
49
|
+
:description => "The Availability Zone",
|
50
|
+
:default => "us-east-1b"
|
51
|
+
|
52
|
+
option :ssh_key_name,
|
53
|
+
:short => "-S KEY",
|
54
|
+
:long => "--ssh-key KEY",
|
55
|
+
:description => "The SSH root key",
|
56
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_ssh_key_id] = key }
|
57
|
+
|
58
|
+
option :ssh_user,
|
59
|
+
:short => "-x USERNAME",
|
60
|
+
:long => "--ssh-user USERNAME",
|
61
|
+
:description => "The ssh username",
|
62
|
+
:default => "root"
|
63
|
+
|
64
|
+
option :aws_access_key_id,
|
65
|
+
:short => "-A ID",
|
66
|
+
:long => "--aws-access-key-id KEY",
|
67
|
+
:description => "Your AWS Access Key ID",
|
68
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
|
69
|
+
|
70
|
+
option :aws_secret_access_key,
|
71
|
+
:short => "-K SECRET",
|
72
|
+
:long => "--aws-secret-access-key SECRET",
|
73
|
+
:description => "Your AWS API Secret Access Key",
|
74
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
|
75
|
+
|
76
|
+
def h
|
77
|
+
@highline ||= HighLine.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def run
|
81
|
+
require 'fog'
|
82
|
+
require 'highline'
|
83
|
+
require 'net/ssh/multi'
|
84
|
+
require 'readline'
|
85
|
+
|
86
|
+
$stdout.sync = true
|
87
|
+
|
88
|
+
connection = Fog::AWS::EC2.new(
|
89
|
+
:aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
|
90
|
+
:aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key]
|
91
|
+
)
|
92
|
+
|
93
|
+
server = connection.servers.create(
|
94
|
+
:image_id => config[:image],
|
95
|
+
:groups => config[:security_groups],
|
96
|
+
:flavor_id => config[:flavor],
|
97
|
+
:key_name => Chef::Config[:knife][:aws_ssh_key_id],
|
98
|
+
:availability_zone => config[:availability_zone]
|
99
|
+
)
|
100
|
+
|
101
|
+
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
102
|
+
puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
|
103
|
+
puts "#{h.color("Image", :cyan)}: #{server.image_id}"
|
104
|
+
puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
|
105
|
+
puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
|
106
|
+
puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
|
107
|
+
|
108
|
+
print "\n#{h.color("Waiting for server", :magenta)}"
|
109
|
+
|
110
|
+
# wait for it to be ready to do stuff
|
111
|
+
server.wait_for { print "."; ready? }
|
112
|
+
|
113
|
+
print "\n\n"
|
114
|
+
|
115
|
+
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
116
|
+
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
117
|
+
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
118
|
+
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
119
|
+
|
120
|
+
puts "\nWaiting 15 seconds for SSH...\n"
|
121
|
+
|
122
|
+
sleep 15
|
123
|
+
|
124
|
+
bootstrap = Chef::Knife::Bootstrap.new
|
125
|
+
bootstrap.name_args = [ server.ip_address, @name_args ].flatten
|
126
|
+
bootstrap.config[:ssh_user] = config[:ssh_user]
|
127
|
+
bootstrap.config[:chef_node_name] = server.id
|
128
|
+
bootstrap.run
|
129
|
+
|
130
|
+
puts "\n"
|
131
|
+
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
132
|
+
puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
|
133
|
+
puts "#{h.color("Image", :cyan)}: #{server.image_id}"
|
134
|
+
puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
|
135
|
+
puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
|
136
|
+
puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
|
137
|
+
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
138
|
+
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
139
|
+
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
140
|
+
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
141
|
+
puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
|
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 'json'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class Ec2ServerDelete < Knife
|
25
|
+
|
26
|
+
banner "Sub-Command: ec2 server delete SERVER [SERVER] (options)"
|
27
|
+
|
28
|
+
option :aws_access_key_id,
|
29
|
+
:short => "-A ID",
|
30
|
+
:long => "--aws-access-key-id KEY",
|
31
|
+
:description => "Your AWS Access Key ID",
|
32
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
|
33
|
+
|
34
|
+
option :aws_secret_access_key,
|
35
|
+
:short => "-K SECRET",
|
36
|
+
:long => "--aws-secret-access-key SECRET",
|
37
|
+
:description => "Your AWS API Secret Access Key",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
|
39
|
+
|
40
|
+
def h
|
41
|
+
@highline ||= HighLine.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
require 'fog'
|
46
|
+
require 'highline'
|
47
|
+
require 'net/ssh/multi'
|
48
|
+
require 'readline'
|
49
|
+
|
50
|
+
connection = Fog::AWS::EC2.new(
|
51
|
+
:aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
|
52
|
+
:aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key]
|
53
|
+
)
|
54
|
+
|
55
|
+
@name_args.each do |instance_id|
|
56
|
+
server = connection.servers.get(instance_id)
|
57
|
+
|
58
|
+
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
59
|
+
puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
|
60
|
+
puts "#{h.color("Image", :cyan)}: #{server.image_id}"
|
61
|
+
puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
|
62
|
+
puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
|
63
|
+
puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
|
64
|
+
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
65
|
+
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
66
|
+
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
67
|
+
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
68
|
+
|
69
|
+
puts "\n"
|
70
|
+
confirm("Do you really want to delete this server")
|
71
|
+
|
72
|
+
server.destroy
|
73
|
+
|
74
|
+
Chef::Log.warn("Deleted server #{server.id}")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
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 'json'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class Ec2ServerList < Knife
|
25
|
+
|
26
|
+
banner "Sub-Command: ec2 server list [RUN LIST...] (options)"
|
27
|
+
|
28
|
+
option :aws_access_key_id,
|
29
|
+
:short => "-A ID",
|
30
|
+
:long => "--aws-access-key-id KEY",
|
31
|
+
:description => "Your AWS Access Key ID",
|
32
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
|
33
|
+
|
34
|
+
option :aws_secret_access_key,
|
35
|
+
:short => "-K SECRET",
|
36
|
+
:long => "--aws-secret-access-key SECRET",
|
37
|
+
:description => "Your AWS API Secret Access Key",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
|
39
|
+
|
40
|
+
def h
|
41
|
+
@highline ||= HighLine.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
require 'fog'
|
46
|
+
require 'highline'
|
47
|
+
require 'net/ssh/multi'
|
48
|
+
require 'readline'
|
49
|
+
|
50
|
+
$stdout.sync = true
|
51
|
+
|
52
|
+
connection = Fog::AWS::EC2.new(
|
53
|
+
:aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
|
54
|
+
:aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key]
|
55
|
+
)
|
56
|
+
|
57
|
+
server_list = [
|
58
|
+
h.color('Instance ID', :bold),
|
59
|
+
h.color('Public IP', :bold),
|
60
|
+
h.color('Private IP', :bold),
|
61
|
+
h.color('Flavor', :bold),
|
62
|
+
h.color('Image', :bold),
|
63
|
+
h.color('Security Groups', :bold),
|
64
|
+
h.color('State', :bold)
|
65
|
+
]
|
66
|
+
connection.servers.all.each do |server|
|
67
|
+
server_list << server.id.to_s
|
68
|
+
server_list << (server.ip_address == nil ? "" : server.ip_address)
|
69
|
+
server_list << (server.private_ip_address == nil ? "" : server.private_ip_address)
|
70
|
+
server_list << (server.flavor_id == nil ? "" : server.flavor_id)
|
71
|
+
server_list << (server.image_id == nil ? "" : server.image_id)
|
72
|
+
server_list << server.groups.join(", ")
|
73
|
+
server_list << server.state
|
74
|
+
end
|
75
|
+
puts h.list(server_list, :columns_across, 7)
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ian Meyer (<ianmmeyer@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Ian Meyer
|
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 'highline'
|
21
|
+
require 'chef/search/query'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class Status < Knife
|
26
|
+
|
27
|
+
banner "Sub-Command: status"
|
28
|
+
|
29
|
+
def highline
|
30
|
+
@h ||= HighLine.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
Chef::Search::Query.new.search(:node, '*:*') do |node|
|
35
|
+
current_time = DateTime.now
|
36
|
+
date = DateTime.parse(Time.at(node["ohai_time"]).to_s)
|
37
|
+
hours, minutes, seconds, frac = DateTime.day_fraction_to_time(current_time - date)
|
38
|
+
hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
|
39
|
+
minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"
|
40
|
+
if hours > 24
|
41
|
+
highline.say("<%= color('#{hours_text}', RED) %> ago, #{node['fqdn']} checked in as a #{node['platform']} #{node['platform_version']} node.")
|
42
|
+
elsif hours > 1
|
43
|
+
highline.say("<%= color('#{hours_text}', YELLOW) %> ago, #{node['fqdn']} checked in as a #{node['platform']} #{node['platform_version']} node.")
|
44
|
+
elsif hours == 0
|
45
|
+
highline.say("<%= color('#{minutes_text}', GREEN) %> ago, #{node['fqdn']} checked in as a #{node['platform']} #{node['platform_version']} node.")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -22,28 +22,33 @@ class Chef
|
|
22
22
|
module Mixin
|
23
23
|
module LanguageIncludeAttribute
|
24
24
|
|
25
|
-
|
25
|
+
# Loads the attribute file specified by the short name of the
|
26
|
+
# file, e.g., loads specified cookbook's
|
27
|
+
# "attributes/mailservers.rb"
|
28
|
+
# if passed
|
29
|
+
# "mailservers"
|
30
|
+
def include_attribute(*fully_qualified_attribute_short_filenames)
|
26
31
|
if self.kind_of?(Chef::Node)
|
27
32
|
node = self
|
28
33
|
else
|
29
34
|
node = @node
|
30
35
|
end
|
31
36
|
|
32
|
-
|
33
|
-
if node.run_state[:seen_attributes].has_key?(
|
34
|
-
Chef::Log.debug("I am not loading attribute file #{
|
37
|
+
fully_qualified_attribute_short_filenames.flatten.each do |fully_qualified_attribute_short_filename|
|
38
|
+
if node.run_state[:seen_attributes].has_key?(fully_qualified_attribute_short_filename)
|
39
|
+
Chef::Log.debug("I am not loading attribute file #{fully_qualified_attribute_short_filename}, because I have already seen it.")
|
35
40
|
next
|
36
41
|
end
|
37
42
|
|
38
|
-
Chef::Log.debug("Loading Attribute #{
|
39
|
-
node.run_state[:seen_attributes][
|
43
|
+
Chef::Log.debug("Loading Attribute #{fully_qualified_attribute_short_filename}")
|
44
|
+
node.run_state[:seen_attributes][fully_qualified_attribute_short_filename] = true
|
40
45
|
|
41
|
-
if amatch =
|
42
|
-
|
43
|
-
|
46
|
+
if amatch = fully_qualified_attribute_short_filename.match(/(.+?)::(.+)/)
|
47
|
+
cookbook_name = amatch[1].to_sym
|
48
|
+
node.load_attribute_by_short_filename(amatch[2], cookbook_name)
|
44
49
|
else
|
45
|
-
|
46
|
-
|
50
|
+
cookbook_name = fully_qualified_attribute_short_filename.to_sym
|
51
|
+
node.load_attribute_by_short_filename("default", cookbook_name)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
true
|
@@ -22,25 +22,24 @@ class Chef
|
|
22
22
|
module Mixin
|
23
23
|
module LanguageIncludeRecipe
|
24
24
|
|
25
|
-
def include_recipe(*
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def include_recipe(*recipe_names)
|
26
|
+
result_recipes = Array.new
|
27
|
+
recipe_names.flatten.each do |recipe_name|
|
28
|
+
if node.run_state[:seen_recipes].has_key?(recipe_name)
|
29
|
+
Chef::Log.debug("I am not loading #{recipe_name}, because I have already seen it.")
|
29
30
|
next
|
30
|
-
end
|
31
|
-
|
32
|
-
Chef::Log.debug("Loading Recipe #{recipe} via include_recipe")
|
33
|
-
@node.run_state[:seen_recipes][recipe] = true
|
34
|
-
|
35
|
-
rmatch = recipe.match(/(.+?)::(.+)/)
|
36
|
-
if rmatch
|
37
|
-
cookbook = @cookbook_loader[rmatch[1]]
|
38
|
-
cookbook.load_recipe(rmatch[2], @node, @collection, @definitions, @cookbook_loader)
|
39
|
-
else
|
40
|
-
cookbook = @cookbook_loader[recipe]
|
41
|
-
cookbook.load_recipe("default", @node, @collection, @definitions, @cookbook_loader)
|
42
31
|
end
|
32
|
+
|
33
|
+
Chef::Log.debug("Loading Recipe #{recipe_name} via include_recipe")
|
34
|
+
node.run_state[:seen_recipes][recipe_name] = true
|
35
|
+
|
36
|
+
cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name)
|
37
|
+
|
38
|
+
run_context = self.is_a?(Chef::RunContext) ? self : self.run_context
|
39
|
+
cookbook = run_context.cookbook_collection[cookbook_name]
|
40
|
+
result_recipes << cookbook.load_recipe(recipe_short_name, run_context)
|
43
41
|
end
|
42
|
+
result_recipes
|
44
43
|
end
|
45
44
|
|
46
45
|
def require_recipe(*args)
|