chef-vpc-toolkit 2.1.0 → 2.2.0
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.
- data/CHANGELOG +14 -0
- data/COPYING +1 -1
- data/README.rdoc +29 -7
- data/VERSION +1 -1
- data/config/server_group.json +2 -2
- data/lib/chef-vpc-toolkit.rb +7 -2
- data/lib/chef-vpc-toolkit/chef-0.9.bash +1 -0
- data/lib/chef-vpc-toolkit/chef_bootstrap/fedora.bash +3 -3
- data/lib/chef-vpc-toolkit/chef_bootstrap/ubuntu.bash +1 -0
- data/lib/chef-vpc-toolkit/chef_installer.rb +8 -1
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/client.rb +186 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/connection.rb +146 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/server.rb +113 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/server_group.rb +387 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/ssh_public_key.rb +25 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/vpn_network_interface.rb +29 -0
- data/lib/chef-vpc-toolkit/util.rb +20 -16
- data/lib/chef-vpc-toolkit/vpn_network_manager.rb +16 -16
- data/lib/chef-vpc-toolkit/xml_util.rb +15 -0
- data/rake/chef_vpc_toolkit.rake +194 -155
- data/test/client_test.rb +108 -0
- data/test/server_group_test.rb +259 -0
- data/test/server_test.rb +66 -0
- data/test/test_helper.rb +21 -0
- data/test/util_test.rb +7 -0
- data/test/vpn_network_manager_test.rb +7 -5
- metadata +17 -8
- data/lib/chef-vpc-toolkit/cloud_servers_vpc.rb +0 -393
- data/lib/chef-vpc-toolkit/http_util.rb +0 -118
- data/test/cloud_servers_vpc_test.rb +0 -129
@@ -0,0 +1,25 @@
|
|
1
|
+
module ChefVPCToolkit
|
2
|
+
|
3
|
+
module CloudServersVPC
|
4
|
+
|
5
|
+
class SshPublicKey
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :description
|
9
|
+
attr_accessor :public_key
|
10
|
+
attr_accessor :server_group_id
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
|
14
|
+
@id=options[:id]
|
15
|
+
@description=options[:description]
|
16
|
+
@public_key=options[:public_key]
|
17
|
+
@server_group_id=options[:server_group_id]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ChefVPCToolkit
|
2
|
+
|
3
|
+
module CloudServersVPC
|
4
|
+
|
5
|
+
class VpnNetworkInterface
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :vpn_ip_addr
|
9
|
+
attr_accessor :ptp_ip_addr
|
10
|
+
attr_accessor :client_key
|
11
|
+
attr_accessor :client_cert
|
12
|
+
attr_accessor :ca_cert
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
|
16
|
+
@id=options[:id].to_i
|
17
|
+
@vpn_ip_addr=options[:vpn_ip_addr]
|
18
|
+
@ptp_ip_addr=options[:ptp_ip_addr]
|
19
|
+
@client_key=options[:client_key]
|
20
|
+
@client_cert=options[:client_cert]
|
21
|
+
@ca_cert=options[:ca_cert]
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -5,12 +5,16 @@ module ChefVPCToolkit
|
|
5
5
|
|
6
6
|
module Util
|
7
7
|
|
8
|
+
@@configs=nil
|
9
|
+
|
8
10
|
def self.hostname
|
9
11
|
Socket.gethostname
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.load_configs
|
13
15
|
|
16
|
+
return @@configs if not @@configs.nil?
|
17
|
+
|
14
18
|
config_file=ENV['CHEF_VPC_TOOLKIT_CONF']
|
15
19
|
if config_file.nil? then
|
16
20
|
|
@@ -26,36 +30,36 @@ module Util
|
|
26
30
|
raise_if_nil_or_empty(configs, "cloud_servers_vpc_url")
|
27
31
|
raise_if_nil_or_empty(configs, "cloud_servers_vpc_username")
|
28
32
|
raise_if_nil_or_empty(configs, "cloud_servers_vpc_password")
|
29
|
-
|
33
|
+
@@configs=configs
|
30
34
|
else
|
31
35
|
raise "Failed to load cloud toolkit config file. Please configure /etc/chef_vpc_toolkit.conf or create a .chef_vpc_toolkit.conf config file in your HOME directory."
|
32
36
|
end
|
33
37
|
|
34
|
-
|
38
|
+
@@configs
|
35
39
|
|
36
|
-
def self.raise_if_nil_or_empty(options, key)
|
37
|
-
if options[key].nil? || options[key].empty? then
|
38
|
-
raise "Please specify a valid #{key.to_s} parameter."
|
39
|
-
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def self.
|
42
|
+
def self.load_public_key
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
ssh_dir=ENV['HOME']+File::SEPARATOR+".ssh"+File::SEPARATOR
|
45
|
+
if File.exists?(ssh_dir+"id_rsa.pub")
|
46
|
+
pubkey=IO.read(ssh_dir+"id_rsa.pub")
|
47
|
+
elsif File.exists?(ssh_dir+"id_dsa.pub")
|
48
|
+
pubkey=IO.read(ssh_dir+"id_dsa.pub")
|
49
49
|
else
|
50
|
-
|
51
|
-
hash = CloudServersVPC.server_group_hash(IO.read(file))
|
50
|
+
raise "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
|
52
51
|
end
|
53
|
-
raise "Create a cloud before running this command." if hash.nil?
|
54
52
|
|
55
|
-
|
53
|
+
pubkey.chomp
|
56
54
|
|
57
55
|
end
|
58
56
|
|
57
|
+
def self.raise_if_nil_or_empty(options, key)
|
58
|
+
if not options or options[key].nil? or options[key].empty? then
|
59
|
+
raise "Please specify a valid #{key.to_s} parameter."
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
59
63
|
end
|
60
64
|
|
61
65
|
end
|
@@ -13,28 +13,28 @@ module VpnNetworkManager
|
|
13
13
|
|
14
14
|
CERT_DIR=File.join(ENV['HOME'], '.pki', 'openvpn')
|
15
15
|
|
16
|
-
def self.configure_gconf(
|
16
|
+
def self.configure_gconf(group, client)
|
17
17
|
|
18
|
-
ca_cert=File.join(CERT_DIR,
|
19
|
-
client_cert=File.join(CERT_DIR,
|
20
|
-
client_key=File.join(CERT_DIR,
|
18
|
+
ca_cert=File.join(CERT_DIR, group.id.to_s, 'ca.crt')
|
19
|
+
client_cert=File.join(CERT_DIR, group.id.to_s, 'client.crt')
|
20
|
+
client_key=File.join(CERT_DIR, group.id.to_s, 'client.key')
|
21
21
|
|
22
|
-
vpn_interface=
|
22
|
+
vpn_interface=client.vpn_network_interfaces[0]
|
23
23
|
|
24
|
-
FileUtils.mkdir_p(File.join(CERT_DIR,
|
24
|
+
FileUtils.mkdir_p(File.join(CERT_DIR, group.id.to_s))
|
25
25
|
File::chmod(0700, File.join(ENV['HOME'], '.pki'))
|
26
26
|
File::chmod(0700, CERT_DIR)
|
27
27
|
|
28
|
-
File.open(ca_cert, 'w') { |f| f.write(vpn_interface
|
29
|
-
File.open(client_cert, 'w') { |f| f.write(vpn_interface
|
28
|
+
File.open(ca_cert, 'w') { |f| f.write(vpn_interface.ca_cert) }
|
29
|
+
File.open(client_cert, 'w') { |f| f.write(vpn_interface.client_cert) }
|
30
30
|
File.open(client_key, 'w') do |f|
|
31
|
-
f.write(vpn_interface
|
31
|
+
f.write(vpn_interface.client_key)
|
32
32
|
f.chmod(0600)
|
33
33
|
end
|
34
34
|
|
35
35
|
xml = Builder::XmlMarkup.new
|
36
36
|
xml.gconfentryfile do |file|
|
37
|
-
file.entrylist({ "base" => "/system/networking/connections/vpc_#{
|
37
|
+
file.entrylist({ "base" => "/system/networking/connections/vpc_#{group.id}"}) do |entrylist|
|
38
38
|
|
39
39
|
entrylist.entry do |entry|
|
40
40
|
entry.key("connection/autoconnect")
|
@@ -45,7 +45,7 @@ module VpnNetworkManager
|
|
45
45
|
entrylist.entry do |entry|
|
46
46
|
entry.key("connection/id")
|
47
47
|
entry.value do |value|
|
48
|
-
value.string("VPC Group: #{
|
48
|
+
value.string("VPC Group: #{group.id}")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
entrylist.entry do |entry|
|
@@ -83,7 +83,7 @@ module VpnNetworkManager
|
|
83
83
|
entry.key("ipv4/dns")
|
84
84
|
entry.value do |value|
|
85
85
|
value.list("type" => "int") do |list|
|
86
|
-
ip=IPAddr.new(
|
86
|
+
ip=IPAddr.new(group.vpn_network.chomp("0")+"1")
|
87
87
|
list.value do |lv|
|
88
88
|
lv.int(ip_to_integer(ip.to_s))
|
89
89
|
end
|
@@ -95,7 +95,7 @@ module VpnNetworkManager
|
|
95
95
|
entry.value do |value|
|
96
96
|
value.list("type" => "string") do |list|
|
97
97
|
list.value do |lv|
|
98
|
-
lv.string(
|
98
|
+
lv.string(group.domain_name)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -170,7 +170,7 @@ module VpnNetworkManager
|
|
170
170
|
entrylist.entry do |entry|
|
171
171
|
entry.key("vpn/remote")
|
172
172
|
entry.value do |value|
|
173
|
-
value.string(
|
173
|
+
value.string(group.vpn_gateway_ip)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
entrylist.entry do |entry|
|
@@ -198,7 +198,7 @@ module VpnNetworkManager
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def self.delete_certs(server_group_id)
|
201
|
-
FileUtils.rm_rf(File.join(CERT_DIR, server_group_id))
|
201
|
+
FileUtils.rm_rf(File.join(CERT_DIR, server_group_id.to_s))
|
202
202
|
end
|
203
203
|
|
204
204
|
def self.connect(server_group_id)
|
@@ -211,7 +211,7 @@ module VpnNetworkManager
|
|
211
211
|
|
212
212
|
def self.ip_to_integer(ip_string)
|
213
213
|
return 0 if ip_string.nil?
|
214
|
-
ip_arr=ip_string.
|
214
|
+
ip_arr=ip_string.split(".").collect{ |s| s.to_i }
|
215
215
|
return ip_arr[0] + ip_arr[1]*2**8 + ip_arr[2]*2**16 + ip_arr[3]*2**24
|
216
216
|
end
|
217
217
|
|
data/rake/chef_vpc_toolkit.rake
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#require 'chef-cloud-toolkit'
|
2
|
+
include ChefVPCToolkit::CloudServersVPC
|
2
3
|
|
3
4
|
namespace :group do
|
4
5
|
TMP_SG=File.join(CHEF_VPC_PROJECT, 'tmp', 'server_groups')
|
@@ -7,41 +8,31 @@ namespace :group do
|
|
7
8
|
directory TMP_SG
|
8
9
|
directory TMP_CLIENTS
|
9
10
|
|
10
|
-
|
11
|
-
task :create => [ TMP_SG, "chef:validate_json" ] do
|
12
|
-
|
13
|
-
request=CloudServersVPC.server_group_xml
|
14
|
-
configs=Util.load_configs
|
11
|
+
task :init => [TMP_SG, TMP_CLIENTS]
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
request,
|
19
|
-
configs["cloud_servers_vpc_username"],
|
20
|
-
configs["cloud_servers_vpc_password"]
|
21
|
-
)
|
13
|
+
desc "Create a new group of cloud servers"
|
14
|
+
task :create => [ "init", "chef:validate_json" ] do
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
f.chmod(0600)
|
27
|
-
f.write(resp)
|
28
|
-
end
|
29
|
-
puts "Cloud server group ID #{hash['id']} created."
|
16
|
+
sg=ServerGroup.from_json_config(IO.read(ServerGroup::CONFIG_FILE))
|
17
|
+
sg=ServerGroup.create(sg)
|
18
|
+
puts "Server group ID #{sg.id} created."
|
30
19
|
|
31
20
|
end
|
32
21
|
|
33
|
-
desc "List existing cloud server groups"
|
34
|
-
task :list =>
|
22
|
+
desc "List existing cloud server groups."
|
23
|
+
task :list => "init" do
|
35
24
|
|
36
|
-
server_groups=
|
37
|
-
|
38
|
-
server_groups
|
25
|
+
server_groups=nil
|
26
|
+
if ENV['REMOTE']
|
27
|
+
server_groups=ServerGroup.list(:source => "remote")
|
28
|
+
else
|
29
|
+
server_groups=ServerGroup.list(:source => "cache")
|
39
30
|
end
|
40
31
|
if server_groups.size > 0
|
41
|
-
puts "
|
42
|
-
server_groups.sort { |a,b| b
|
43
|
-
gw=sg
|
44
|
-
puts "\t#{sg
|
32
|
+
puts "Server groups:"
|
33
|
+
server_groups.sort { |a,b| b.id <=> a.id }.each do |sg|
|
34
|
+
gw=sg.vpn_gateway_ip.nil? ? "" : " (#{sg.vpn_gateway_ip})"
|
35
|
+
puts "\t :id => #{sg.id}, :name => #{sg.name}, :owner => #{sg.owner_name}#{gw}"
|
45
36
|
end
|
46
37
|
else
|
47
38
|
puts "No server groups."
|
@@ -49,37 +40,39 @@ namespace :group do
|
|
49
40
|
|
50
41
|
end
|
51
42
|
|
52
|
-
desc "
|
53
|
-
task :
|
54
|
-
id=ENV['GROUP_ID']
|
55
|
-
configs=Util.load_configs
|
56
|
-
xml=CloudServersVPC.server_group_xml_for_id(configs, File.join(TMP_SG, '*.xml'), id)
|
43
|
+
desc "Join a group by caching the server group data to disk."
|
44
|
+
task :join => [ "init" ] do
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
id=ENV['GROUP_ID']
|
47
|
+
if id.nil?
|
48
|
+
ENV['REMOTE']="true"
|
49
|
+
Rake::Task['group:list'].invoke
|
50
|
+
puts "Enter ID of group to join:"
|
51
|
+
id=STDIN.gets.chomp
|
62
52
|
end
|
63
|
-
|
53
|
+
|
54
|
+
sg=ServerGroup.fetch(:id => id, :source => "remote")
|
55
|
+
sg.cache_to_disk
|
56
|
+
sg.pretty_print
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Print information for a cloud server group"
|
61
|
+
task :show => [ "init" ] do
|
62
|
+
|
63
|
+
sg=ServerGroup.fetch
|
64
|
+
sg.cache_to_disk
|
65
|
+
sg.pretty_print
|
64
66
|
|
65
67
|
end
|
66
68
|
|
67
69
|
desc "Delete a cloud server group"
|
68
|
-
task :delete => "vpn:delete" do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
SshUtil.remove_known_hosts_ip(hash["vpn-gateway"])
|
76
|
-
puts "Deleting cloud server group ID: #{id}."
|
77
|
-
HttpUtil.delete(
|
78
|
-
configs["cloud_servers_vpc_url"]+"/server_groups/#{id}.xml",
|
79
|
-
configs["cloud_servers_vpc_username"],
|
80
|
-
configs["cloud_servers_vpc_password"]
|
81
|
-
)
|
82
|
-
File.delete(File.join(TMP_SG, "#{id}.xml"))
|
70
|
+
task :delete => ["init", "vpn:delete"] do
|
71
|
+
|
72
|
+
sg=ServerGroup.fetch(:source => "cache")
|
73
|
+
SshUtil.remove_known_hosts_ip(sg.vpn_gateway_ip)
|
74
|
+
puts "Deleting cloud server group ID: #{sg.id}."
|
75
|
+
sg.delete
|
83
76
|
|
84
77
|
end
|
85
78
|
|
@@ -90,28 +83,58 @@ namespace :group do
|
|
90
83
|
end
|
91
84
|
|
92
85
|
desc "Poll/loop until a server group is online"
|
93
|
-
task :poll do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
hash=Util.hash_for_group
|
86
|
+
task :poll => ["init"] do
|
87
|
+
|
88
|
+
sg=ServerGroup.fetch
|
89
|
+
|
99
90
|
puts "Polling for server(s) to come online (this may take a couple minutes)..."
|
100
|
-
|
91
|
+
old_group_xml=nil
|
101
92
|
vpn_gateway=nil
|
102
|
-
|
103
|
-
if
|
104
|
-
|
105
|
-
vpn_gateway =
|
93
|
+
sg.poll_until_online do |server_group|
|
94
|
+
if old_group_xml != server_group.to_xml then
|
95
|
+
old_group_xml = server_group.to_xml
|
96
|
+
vpn_gateway = server_group.vpn_gateway_ip if server_group.vpn_gateway_ip
|
106
97
|
if not vpn_gateway.nil? and not vpn_gateway.empty? then
|
107
98
|
SshUtil.remove_known_hosts_ip(vpn_gateway)
|
108
99
|
end
|
109
|
-
|
110
|
-
CloudServersVPC.print_server_group(server_group_hash)
|
100
|
+
server_group.pretty_print
|
111
101
|
end
|
112
102
|
end
|
113
103
|
Rake::Task['group:show'].invoke
|
114
|
-
puts "
|
104
|
+
puts "Server group online."
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "Add a single server to the server group."
|
108
|
+
task :add_server do
|
109
|
+
server_name=ENV['SERVER_NAME']
|
110
|
+
image_id=ENV['IMAGE_ID']
|
111
|
+
flavor_id=ENV['FLAVOR_ID']
|
112
|
+
raise "Please specify a SERVER_NAME." if server_name.nil?
|
113
|
+
raise "Please specify a IMAGE_ID." if image_id.nil?
|
114
|
+
raise "Please specify a FLAVOR_ID." if flavor_id.nil?
|
115
|
+
group=ServerGroup.fetch(:source => "cache")
|
116
|
+
server=Server.new(
|
117
|
+
:name => server_name,
|
118
|
+
:description => server_name,
|
119
|
+
:image_id => image_id,
|
120
|
+
:flavor_id => flavor_id,
|
121
|
+
:server_group_id => group.id
|
122
|
+
)
|
123
|
+
server=Server.create(server)
|
124
|
+
group=ServerGroup.fetch
|
125
|
+
group.cache_to_disk
|
126
|
+
puts "Server ID #{server.id} created."
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "Delete a single server from the server group."
|
130
|
+
task :delete_server do
|
131
|
+
server_name=ENV['SERVER_NAME']
|
132
|
+
raise "Please specify a SERVER_NAME." if server_name.nil?
|
133
|
+
group=ServerGroup.fetch(:source => "cache")
|
134
|
+
server=group.server(server_name)
|
135
|
+
raise "Server with name '#{server_name}' does not exist." if server.nil?
|
136
|
+
server.delete
|
137
|
+
puts "Server '#{server_name}' deleted."
|
115
138
|
end
|
116
139
|
|
117
140
|
end
|
@@ -119,16 +142,13 @@ end
|
|
119
142
|
namespace :server do
|
120
143
|
|
121
144
|
desc "Rebuild a server in a server group."
|
122
|
-
task :rebuild
|
123
|
-
id=ENV['GROUP_ID']
|
145
|
+
task :rebuild do
|
124
146
|
server_name=ENV['SERVER_NAME']
|
125
147
|
raise "Please specify a SERVER_NAME." if server_name.nil?
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
CloudServersVPC.rebuild(hash, server_name)
|
131
|
-
|
148
|
+
group=ServerGroup.fetch
|
149
|
+
server=group.server(server_name)
|
150
|
+
raise "Server with name '#{server_name}' does not exist." if server.nil?
|
151
|
+
server.rebuild
|
132
152
|
end
|
133
153
|
|
134
154
|
end
|
@@ -148,12 +168,19 @@ namespace :chef do
|
|
148
168
|
|
149
169
|
configs=ChefInstaller.load_configs
|
150
170
|
configs.merge!(Util.load_configs)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
171
|
+
group=ServerGroup.fetch(:source => "cache")
|
172
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
173
|
+
|
174
|
+
server_name=ENV['SERVER_NAME']
|
175
|
+
if server_name.nil? then
|
176
|
+
client_validation_key=ChefInstaller.install_chef_server(configs, group.os_types)
|
177
|
+
ChefInstaller.create_databags(configs)
|
178
|
+
ChefInstaller.install_chef_clients(configs, client_validation_key, group.os_types)
|
179
|
+
else
|
180
|
+
raise "Server with name '#{server_name}' does not exist." if group.server(server_name).nil?
|
181
|
+
client_validation_key=ChefInstaller.client_validation_key(configs)
|
182
|
+
ChefInstaller.install_chef_client(configs, server_name, client_validation_key, group.os_types[server_name])
|
183
|
+
end
|
157
184
|
|
158
185
|
end
|
159
186
|
|
@@ -161,35 +188,56 @@ namespace :chef do
|
|
161
188
|
task :tail_logs do
|
162
189
|
|
163
190
|
lines=ENV['LINES']
|
191
|
+
server=ENV['SERVER_NAME']
|
192
|
+
if server && server.empty?
|
193
|
+
server=nil
|
194
|
+
end
|
164
195
|
if lines.nil? or lines.empty? then
|
165
196
|
lines=100
|
166
197
|
end
|
167
198
|
configs=ChefInstaller.load_configs
|
168
|
-
|
169
|
-
|
199
|
+
group=ServerGroup.fetch(:source => "cache")
|
200
|
+
group.server_names do |name|
|
201
|
+
if server && server != name
|
202
|
+
next
|
203
|
+
end
|
204
|
+
|
170
205
|
puts "================================================================================"
|
171
206
|
puts "SERVER NAME: #{name}"
|
172
|
-
puts ChefInstaller.tail_log(
|
207
|
+
puts ChefInstaller.tail_log(group.vpn_gateway_ip, name, "/var/log/chef/client.log", lines)
|
173
208
|
end
|
174
209
|
|
175
210
|
end
|
176
211
|
|
177
|
-
|
178
|
-
task :sync_repos
|
212
|
+
#Deprecated
|
213
|
+
task :sync_repos => "chef:push_repos"
|
214
|
+
|
215
|
+
desc "Push/Extract cookbook repos to the server group."
|
216
|
+
task :push_repos do
|
179
217
|
|
180
218
|
configs=ChefInstaller.load_configs
|
181
|
-
|
182
|
-
configs["ssh_gateway_ip"]=
|
219
|
+
group=ServerGroup.fetch(:source => "cache")
|
220
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
183
221
|
ChefInstaller.rsync_cookbook_repos(configs)
|
184
222
|
|
185
223
|
end
|
186
224
|
|
225
|
+
desc "Pull cookbook repos from the server group to the local project."
|
226
|
+
task :pull_repos do
|
227
|
+
|
228
|
+
configs=ChefInstaller.load_configs
|
229
|
+
group=ServerGroup.fetch(:source => "cache")
|
230
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
231
|
+
ChefInstaller.pull_cookbook_repos(configs)
|
232
|
+
|
233
|
+
end
|
234
|
+
|
187
235
|
desc "Create/Update databags on the Chef server."
|
188
236
|
task :databags do
|
189
237
|
|
190
238
|
configs=ChefInstaller.load_configs
|
191
|
-
|
192
|
-
configs["ssh_gateway_ip"]=
|
239
|
+
group=ServerGroup.fetch(:source => "cache")
|
240
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
193
241
|
ChefInstaller.create_databags(configs)
|
194
242
|
|
195
243
|
end
|
@@ -203,9 +251,8 @@ namespace :share do
|
|
203
251
|
|
204
252
|
if File.exists?("#{CHEF_VPC_PROJECT}/share/") then
|
205
253
|
puts "Syncing share data."
|
206
|
-
|
207
|
-
|
208
|
-
system("rsync -azL '#{CHEF_VPC_PROJECT}/share/' root@#{hash['vpn-gateway']}:/mnt/share/")
|
254
|
+
group=ServerGroup.fetch(:source => "cache")
|
255
|
+
system("rsync -azL '#{CHEF_VPC_PROJECT}/share/' root@#{group.vpn_gateway_ip}:/mnt/share/")
|
209
256
|
end
|
210
257
|
|
211
258
|
end
|
@@ -218,90 +265,71 @@ namespace :vpn do
|
|
218
265
|
task :connect do
|
219
266
|
|
220
267
|
puts "Creating VPN Connection..."
|
221
|
-
|
222
|
-
|
223
|
-
if not File.exists?(File.join(TMP_CLIENTS, group_hash['id']+'.xml')) then
|
268
|
+
group=ServerGroup.fetch(:source => "cache")
|
269
|
+
if not File.exists?(File.join(TMP_CLIENTS, "#{group.id}.xml")) then
|
224
270
|
Rake::Task['vpn:create_client'].invoke
|
225
271
|
Rake::Task['vpn:poll_client'].invoke
|
226
272
|
end
|
227
|
-
|
228
|
-
ChefVPCToolkit::VpnNetworkManager.configure_gconf(
|
229
|
-
ChefVPCToolkit::VpnNetworkManager.connect(
|
273
|
+
client=Client.fetch(:id => group.id, :source => "cache")
|
274
|
+
ChefVPCToolkit::VpnNetworkManager.configure_gconf(group, client)
|
275
|
+
ChefVPCToolkit::VpnNetworkManager.connect(group.id)
|
230
276
|
|
231
277
|
end
|
232
278
|
|
233
279
|
desc "Disconnect from a server group as a VPN client."
|
234
280
|
task :disconnect do
|
235
281
|
|
236
|
-
|
237
|
-
|
238
|
-
ChefVPCToolkit::VpnNetworkManager.disconnect(group_hash['id'])
|
282
|
+
group=ServerGroup.fetch(:source => "cache")
|
283
|
+
ChefVPCToolkit::VpnNetworkManager.disconnect(group.id)
|
239
284
|
|
240
|
-
vpn_server_ip=
|
285
|
+
vpn_server_ip=group.vpn_network.chomp("0")+"1"
|
241
286
|
SshUtil.remove_known_hosts_ip(vpn_server_ip)
|
242
|
-
SshUtil.remove_known_hosts_ip("#{
|
287
|
+
SshUtil.remove_known_hosts_ip("#{group.vpn_gateway_name},#{vpn_server_ip}")
|
243
288
|
|
244
289
|
end
|
245
290
|
|
246
291
|
desc "Delete VPN config information."
|
247
292
|
task :delete do
|
248
293
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
ChefVPCToolkit::VpnNetworkManager.unset_gconf_config(group_id)
|
253
|
-
ChefVPCToolkit::VpnNetworkManager.delete_certs(group_id)
|
254
|
-
client_file=File.join(TMP_CLIENTS, "#{group_id}.xml")
|
294
|
+
group=ServerGroup.fetch(:source => "cache")
|
295
|
+
ChefVPCToolkit::VpnNetworkManager.unset_gconf_config(group.id)
|
296
|
+
ChefVPCToolkit::VpnNetworkManager.delete_certs(group.id)
|
255
297
|
|
256
|
-
vpn_server_ip=
|
298
|
+
vpn_server_ip=group.vpn_network.chomp("0")+"1"
|
257
299
|
SshUtil.remove_known_hosts_ip(vpn_server_ip)
|
258
|
-
SshUtil.remove_known_hosts_ip("#{
|
259
|
-
|
260
|
-
|
261
|
-
|
300
|
+
SshUtil.remove_known_hosts_ip("#{group.vpn_gateway_name},#{vpn_server_ip}")
|
301
|
+
begin
|
302
|
+
client=Client.fetch(:id => group.id, :source => "cache")
|
303
|
+
client.delete if client
|
304
|
+
rescue
|
262
305
|
end
|
263
306
|
|
264
307
|
end
|
265
308
|
|
266
309
|
desc "Create a new VPN client."
|
267
|
-
task :create_client
|
268
|
-
|
269
|
-
configs=Util.load_configs
|
270
|
-
group_hash=Util.hash_for_group(configs)
|
310
|
+
task :create_client do
|
271
311
|
|
312
|
+
group=ServerGroup.fetch(:source => "cache")
|
272
313
|
vpn_client_name=Util.hostname
|
314
|
+
configs=Util.load_configs
|
273
315
|
if not configs['vpn_client_name'].nil? then
|
274
316
|
vpn_client_name=configs['vpn_client_name']
|
275
317
|
end
|
276
318
|
|
277
|
-
|
278
|
-
|
279
|
-
out_file=group_hash["id"]+".xml"
|
280
|
-
File.open(File.join(TMP_CLIENTS, out_file), 'w') do |f|
|
281
|
-
f.chmod(0600)
|
282
|
-
f.write(xml)
|
283
|
-
end
|
284
|
-
puts "Client ID #{client_hash['id']} created."
|
319
|
+
client=Client.create(group, vpn_client_name)
|
320
|
+
puts "Client ID #{client.id} created."
|
285
321
|
|
286
322
|
end
|
287
323
|
|
288
324
|
desc "Poll until a client is online"
|
289
|
-
task :poll_client
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
end
|
294
|
-
configs=Util.load_configs
|
295
|
-
group_hash=Util.hash_for_group
|
296
|
-
client_hash=CloudServersVPC.client_hash(IO.read(File.join(TMP_CLIENTS, group_hash['id']+'.xml')))
|
325
|
+
task :poll_client do
|
326
|
+
|
327
|
+
group=ServerGroup.fetch(:source => "cache")
|
328
|
+
client=Client.fetch(:id => group.id, :source => "cache")
|
297
329
|
puts "Polling for client VPN cert to be created (this may take a minute)...."
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
File.open(File.join(TMP_CLIENTS, out_file), 'w') do |f|
|
302
|
-
f.chmod(0600)
|
303
|
-
f.write(xml)
|
304
|
-
end
|
330
|
+
client.poll_until_online
|
331
|
+
client=Client.fetch(:id => client.id, :remote => "cache")
|
332
|
+
client.cache_to_disk
|
305
333
|
puts "Client VPN certs are ready to use."
|
306
334
|
|
307
335
|
end
|
@@ -309,9 +337,14 @@ namespace :vpn do
|
|
309
337
|
end
|
310
338
|
|
311
339
|
desc "SSH into the most recently created VPN gateway server."
|
312
|
-
task :ssh do
|
313
|
-
|
314
|
-
|
340
|
+
task :ssh => 'group:init' do
|
341
|
+
|
342
|
+
sg=ServerGroup.fetch(:source => "cache")
|
343
|
+
args=ARGV[1, ARGV.length].join(" ")
|
344
|
+
if ARGV[1] and ARGV[1].start_with?('GROUP_ID=')
|
345
|
+
args=ARGV[2, ARGV.length].join(" ")
|
346
|
+
end
|
347
|
+
exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.vpn_gateway_ip} #{args}")
|
315
348
|
end
|
316
349
|
|
317
350
|
desc "Create a server group, install chef, sync share data and cookbooks."
|
@@ -319,7 +352,7 @@ task :create do
|
|
319
352
|
|
320
353
|
Rake::Task['group:create'].invoke
|
321
354
|
Rake::Task['group:poll'].invoke
|
322
|
-
Rake::Task['chef:
|
355
|
+
Rake::Task['chef:push_repos'].invoke
|
323
356
|
Rake::Task['chef:install'].invoke
|
324
357
|
#Rake::Task['share:sync'].invoke
|
325
358
|
|
@@ -332,9 +365,9 @@ task :rechef => [ "server:rebuild", "group:poll" ] do
|
|
332
365
|
|
333
366
|
configs=ChefInstaller.load_configs
|
334
367
|
configs.merge!(Util.load_configs)
|
335
|
-
|
336
|
-
os_types=
|
337
|
-
configs["ssh_gateway_ip"]=
|
368
|
+
group=ServerGroup.fetch
|
369
|
+
os_types=group.os_types
|
370
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
338
371
|
ChefInstaller.knife_readd_node(configs, server_name)
|
339
372
|
client_validation_key=ChefInstaller.client_validation_key(configs)
|
340
373
|
ChefInstaller.install_chef_client(configs, server_name, client_validation_key, os_types[server_name])
|
@@ -349,7 +382,7 @@ desc "Print help and usage information"
|
|
349
382
|
task :usage do
|
350
383
|
|
351
384
|
puts ""
|
352
|
-
puts "
|
385
|
+
puts "Chef VPC Toolkit Version: #{ChefVPCToolkit::Version::VERSION}"
|
353
386
|
puts ""
|
354
387
|
puts "The following tasks are available:"
|
355
388
|
|
@@ -357,32 +390,38 @@ task :usage do
|
|
357
390
|
puts "----"
|
358
391
|
puts "Example commands:"
|
359
392
|
puts ""
|
360
|
-
puts "\t- Create a new
|
393
|
+
puts "\t- Create a new server group, upload cookbooks, install chef\n\ton all the nodes, sync share data and cookbooks."
|
361
394
|
puts ""
|
362
395
|
puts "\t\t$ rake create"
|
363
396
|
|
364
397
|
puts ""
|
365
|
-
puts "\t- List your currently running
|
398
|
+
puts "\t- List your currently running server groups."
|
366
399
|
puts ""
|
367
400
|
puts "\t\t$ rake group:list"
|
368
401
|
|
369
402
|
puts ""
|
370
|
-
puts "\t-
|
403
|
+
puts "\t- List all remote groups using a common Cloud Servers VPC account."
|
404
|
+
puts ""
|
405
|
+
puts "\t\t$ rake group:list REMOTE=true"
|
406
|
+
|
407
|
+
|
408
|
+
puts ""
|
409
|
+
puts "\t- SSH into the current (most recently created) server group."
|
371
410
|
puts ""
|
372
411
|
puts "\t\t$ rake ssh"
|
373
412
|
|
374
413
|
puts ""
|
375
|
-
puts "\t- SSH into a
|
414
|
+
puts "\t- SSH into a server group with an ID of 3."
|
376
415
|
puts ""
|
377
416
|
puts "\t\t$ rake ssh GROUP_ID=3"
|
378
417
|
|
379
418
|
puts ""
|
380
|
-
puts "\t- Delete the
|
419
|
+
puts "\t- Delete the server group with an ID of 3."
|
381
420
|
puts ""
|
382
421
|
puts "\t\t$ rake group:delete GROUP_ID=3"
|
383
422
|
|
384
423
|
puts ""
|
385
|
-
puts "\t- Rebuild/Re-Chef a server in the most recently created
|
424
|
+
puts "\t- Rebuild/Re-Chef a server in the most recently created server group."
|
386
425
|
puts ""
|
387
426
|
puts "\t\t$ rake rechef SERVER_NAME=db1"
|
388
427
|
|