knife-nodefu 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -1
- data/lib/chef/knife/nodefu_base.rb +5 -1
- data/lib/chef/knife/nodefu_create.rb +41 -30
- data/lib/knife-nodefu/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -13,7 +13,14 @@ gem install knife-nodefu
|
|
13
13
|
= Definitions File Directory
|
14
14
|
|
15
15
|
This file provides all the proper definitions for nodefu to be able to easily build out servers. You can either pass in the definitions file directory with the -d option, or set the following option in your knife.rb file.
|
16
|
-
|
16
|
+
|
17
|
+
NOTE: VPC Mode is enabled when setting a Private IP
|
18
|
+
|
19
|
+
LIMITATIONS:
|
20
|
+
- Range is not supported when an Elastic IP or Private IP is set
|
21
|
+
- VPC instances require an elastic_ip_address and server_connect_attribute to be set to: public_ip_address
|
22
|
+
- VPC instances require group_ids, they don't support generated groups or aux_groups
|
23
|
+
|
17
24
|
nodefu_definitions "Path to directory"
|
18
25
|
|
19
26
|
Example definitions yml file:
|
@@ -35,6 +42,17 @@ default:
|
|
35
42
|
vm_spec: 'm1.large'
|
36
43
|
run_list:
|
37
44
|
- 'role[noodle]'
|
45
|
+
vpc_noodle:
|
46
|
+
vm_spec: 'm1.large'
|
47
|
+
run_list:
|
48
|
+
- 'role[noodle]'
|
49
|
+
subnet_id: 'subnet-00000000'
|
50
|
+
private_ip_address: ###.###.###.###
|
51
|
+
elastic_ip_address: ###.###.###.###
|
52
|
+
group_ids:
|
53
|
+
- 'sg-00000000'
|
54
|
+
- 'sg-00000000'
|
55
|
+
server_connect_attribute: public_ip_address
|
38
56
|
env:
|
39
57
|
production:
|
40
58
|
staging:
|
@@ -14,7 +14,7 @@ module NodefuBase
|
|
14
14
|
else
|
15
15
|
["node_#{env}_#{name}","default_#{env}","default"]
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
18
|
|
19
19
|
def check_args(size)
|
20
20
|
if name_args.size < 1
|
@@ -41,4 +41,8 @@ end
|
|
41
41
|
def successful_nodes(servers)
|
42
42
|
servers.select {|k,v| !v['chef_node'].nil? && v['failure'].nil? }
|
43
43
|
end
|
44
|
+
|
45
|
+
def is_vpc?(node_spec)
|
46
|
+
node_spec['subnet_id'] || node_spec['private_ip_address'] ? true : false
|
47
|
+
end
|
44
48
|
end
|
@@ -32,22 +32,23 @@ class NodefuCreate < Chef::Knife
|
|
32
32
|
|
33
33
|
option :disable_default_groups,
|
34
34
|
:short => "-g",
|
35
|
-
:long => "--
|
35
|
+
:long => "--disable-default-groups",
|
36
36
|
:boolean => true,
|
37
|
+
:description => "Disable auto generated default security groups (ignored in VPC mode)",
|
37
38
|
:default => false
|
38
39
|
|
39
40
|
option :hostname_style_groups,
|
40
41
|
:short => "-h",
|
41
42
|
:long => "--hostname-style-groups",
|
42
43
|
:boolean => true,
|
43
|
-
:description => "Use hostname style names for auto generated node security groups",
|
44
|
+
:description => "Use hostname style names for auto generated node security groups (ignored in VPC mode)",
|
44
45
|
:default => false
|
45
46
|
|
46
47
|
option :definitions_file,
|
47
48
|
:short => "-d <definitions_directory>",
|
48
49
|
:long => "--definitions_dir <definitions_directory>",
|
49
50
|
:description => "yml definitions directory",
|
50
|
-
:default => nil
|
51
|
+
:default => nil
|
51
52
|
|
52
53
|
def definitions_from_directory(dir)
|
53
54
|
definitions = Hash.new
|
@@ -66,30 +67,33 @@ class NodefuCreate < Chef::Knife
|
|
66
67
|
|
67
68
|
base_name, start_range, end_range = parse_servers(name_args[0])
|
68
69
|
|
69
|
-
env
|
70
|
-
defs_dir
|
71
|
-
yml_config
|
72
|
-
merged_config
|
73
|
-
node_spec_name
|
70
|
+
env = Chef::Config[:environment]
|
71
|
+
defs_dir = Chef::Config[:nodefu_definitions] || config[:definitions]
|
72
|
+
yml_config = definitions_from_directory defs_dir
|
73
|
+
merged_config = Chef::Mixin::DeepMerge.merge(yml_config['default'], yml_config['env'][env])
|
74
|
+
node_spec_name = config[:node_spec] || base_name
|
74
75
|
abort("I'm sorry I couldn't find any node_spec matches :(") unless (node_spec = merged_config['node_spec'][node_spec_name])
|
75
76
|
|
76
|
-
domain
|
77
|
-
vm_spec_name
|
78
|
-
vm_spec
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
77
|
+
domain = merged_config['domain']
|
78
|
+
vm_spec_name = node_spec['vm_spec']
|
79
|
+
vm_spec = merged_config['vm_spec'][vm_spec_name]
|
80
|
+
group_ids = node_spec['group_ids'] ||= []
|
81
|
+
aux_groups = node_spec['aux_groups'] ||= []
|
82
|
+
|
83
|
+
elastic_ip_address = node_spec['elastic_ip_address']
|
84
|
+
private_ip_address = node_spec['private_ip_address']
|
85
|
+
abort("Range isn't supported when a private_ip_address or an elastic_ip_address is set, please only create one instance") unless start_range == end_range
|
86
|
+
abort('private_ip_address option uses VPC mode, which requires a subnet_id in the definitions file for the node_spec]') if private_ip_address && node_spec['subnet_id'].nil?
|
84
87
|
|
85
88
|
# Present the user with some totally rad visuals!!!
|
86
89
|
ui.msg("#{ui.color('SHAZAM!',:red)} It looks like you want to launch #{ui.color((end_range - start_range + 1).to_s,:yellow)} of these:")
|
87
90
|
ui.msg("#{ui.color('Base Name',:cyan)}: #{base_name}")
|
88
91
|
ui.msg("#{ui.color('Node Spec',:cyan)}: #{node_spec_name}")
|
92
|
+
ui.msg("#{ui.color('VPC Mode',:cyan)}: #{is_vpc?(node_spec)}")
|
89
93
|
pretty_print_hash(node_spec)
|
90
94
|
pretty_print_hash(vm_spec)
|
91
95
|
|
92
|
-
unless config[:disable_default_groups]
|
96
|
+
unless config[:disable_default_groups] || is_vpc?(node_spec)
|
93
97
|
ui.msg("#{ui.color('Auto generated security groups',:cyan)}: #{generate_security_groups("#{base_name}#{start_range}-#{end_range}",env,domain)}")
|
94
98
|
end
|
95
99
|
|
@@ -106,22 +110,29 @@ class NodefuCreate < Chef::Knife
|
|
106
110
|
aux_groups
|
107
111
|
else
|
108
112
|
generate_security_groups(node_name,env,domain) + aux_groups
|
109
|
-
end
|
113
|
+
end unless is_vpc?(node_spec)
|
114
|
+
security_group_ids = group_ids
|
110
115
|
|
111
116
|
# A handfull of the Ec2ServerCreate command line options use a :proc field so I have to
|
112
117
|
# populate those by hand instead of simply passing a value to its config entry
|
113
|
-
Chef::Config[:knife][:aws_ssh_key_id]
|
114
|
-
Chef::Config[:knife][:image]
|
115
|
-
Chef::Config[:knife][:region]
|
116
|
-
ec2_server_request.config[:image]
|
117
|
-
ec2_server_request.config[:region]
|
118
|
-
ec2_server_request.config[:chef_node_name]
|
119
|
-
ec2_server_request.config[:run_list]
|
120
|
-
ec2_server_request.config[:flavor]
|
121
|
-
ec2_server_request.config[:security_groups]
|
122
|
-
ec2_server_request.config[:
|
123
|
-
ec2_server_request.config[:
|
124
|
-
ec2_server_request.config[:
|
118
|
+
Chef::Config[:knife][:aws_ssh_key_id] = vm_spec['ssh_key']
|
119
|
+
Chef::Config[:knife][:image] = vm_spec['ami']
|
120
|
+
Chef::Config[:knife][:region] = vm_spec['region']
|
121
|
+
ec2_server_request.config[:image] = vm_spec['ami']
|
122
|
+
ec2_server_request.config[:region] = vm_spec['region']
|
123
|
+
ec2_server_request.config[:chef_node_name] = full_node_name
|
124
|
+
ec2_server_request.config[:run_list] = node_spec['run_list']
|
125
|
+
ec2_server_request.config[:flavor] = vm_spec['type']
|
126
|
+
ec2_server_request.config[:security_groups] = security_groups if security_groups
|
127
|
+
ec2_server_request.config[:security_group_ids] = security_group_ids if security_group_ids
|
128
|
+
ec2_server_request.config[:associate_eip] = elastic_ip_address if elastic_ip_address
|
129
|
+
ec2_server_request.config[:subnet_id] = node_spec['subnet_id'] if node_spec['subnet_id']
|
130
|
+
ec2_server_request.config[:private_ip_address] = private_ip_address if private_ip_address
|
131
|
+
ec2_server_request.config[:ssh_user] = vm_spec['user']
|
132
|
+
ec2_server_request.config[:availability_zone] = vm_spec['az']
|
133
|
+
ec2_server_request.config[:distro] = vm_spec['bootstrap']
|
134
|
+
ec2_server_request.config[:server_connect_attribute] = node_spec['server_connect_attribute'] if node_spec['server_connect_attribute']
|
135
|
+
ec2_server_request.config[:environment] = Chef::Config[:environment]
|
125
136
|
threads << Thread.new(full_node_name,ec2_server_request) do |full_node_name,request|
|
126
137
|
e = nil
|
127
138
|
begin
|
data/lib/knife-nodefu/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-nodefu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: knife-ec2
|