56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/chef/knife/terremark_server_create.rb', line 56
def run
server_name = @name_args[0]
= Fog::.new(
:terremark_username => Chef::Config[:knife][:terremark_username],
:terremark_password => Chef::Config[:knife][:terremark_password],
:terremark_service => Chef::Config[:knife][:terremark_service] || :vcloud
)
$stdout.sync = true
puts "Instantiating vApp #{h.color(server_name, :bold)}"
vapp_id = .instantiate_vapp_template(server_name).body['href'].split('/').last
deploy_task_id = .deploy_vapp(vapp_id).body['href'].split('/').last
print "Waiting for deploy task [#{h.color(deploy_task_id, :bold)}]"
.tasks.get(deploy_task_id).wait_for { print "."; ready? }
print "\n"
power_on_task_id = .power_on(vapp_id).body['href'].split('/').last
print "Waiting for power on task [#{h.color(power_on_task_id, :bold)}]"
.tasks.get(power_on_task_id).wait_for { print "."; ready? }
print "\n"
private_ip = .get_vapp(vapp_id).body['IpAddress']
ssh_internet_service = .create_internet_service(.default_vdc_id, 'SSH', 'TCP', 22).body
ssh_internet_service_id = ssh_internet_service['Id']
public_ip = ssh_internet_service['PublicIpAddress']['Name']
public_ip_id = ssh_internet_service['PublicIpAddress']['Id']
ssh_node_service_id = .add_node_service(ssh_internet_service_id, private_ip, 'SSH', 22).body['Id']
puts "\nBootstrapping #{h.color(server_name, :bold)}..."
password = .get_vapp_template(12).body['Description'].scan(/\npassword: (.*)\n/).first.first
command = "bash -c '\necho nameserver 208.67.222.222 > /etc/resolv.conf\necho nameserver 208.67.220.220 >> /etc/resolv.conf\n\nif [ ! -f /usr/bin/chef-client ]; then\n apt-get update\n apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras\n cd /tmp\n wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz\n tar xvf rubygems-1.3.6.tgz\n cd rubygems-1.3.6\n ruby setup.rb\n cp /usr/bin/gem1.8 /usr/bin/gem\n gem install chef ohai --no-rdoc --no-ri --verbose\nfi\n\nmkdir -p /etc/chef\n\n(\ncat <<'EOP'\n\#{IO.read(Chef::Config[:validation_key])}\nEOP\n) > /etc/chef/validation.pem\n\n(\ncat <<'EOP'\nlog_level :info\nlog_location STDOUT\nchef_server_url \"\#{Chef::Config[:chef_server_url]}\" \nvalidation_client_name \"\#{Chef::Config[:validation_client_name]}\"\nEOP\n) > /etc/chef/client.rb\n\n(\ncat <<'EOP'\n\#{{ \"run_list\" => @name_args[1..-1] }.to_json}\nEOP\n) > /etc/chef/first-boot.json\n\n/usr/bin/chef-client -j /etc/chef/first-boot.json'\n"
begin
ssh = Chef::Knife::Ssh.new
ssh.name_args = [ public_ip, "sudo #{command}" ]
ssh.config[:ssh_user] = "vcloud"
ssh.config[:manual] = true
ssh.config[:password] = password
ssh.password = password
ssh.run
rescue Errno::ETIMEDOUT
puts "Timed out on bootstrap, re-trying. Hit CTRL-C to abort."
puts "You probably need to log in to Terremark and powercycle #{h.color(@name_args[0], :bold)}"
retry
end
end
|