-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutit_openshift_cluster.py
More file actions
253 lines (220 loc) · 10.9 KB
/
shutit_openshift_cluster.py
File metadata and controls
253 lines (220 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import random
import string
import os
from shutit_module import ShutItModule
class shutit_openshift_cluster(ShutItModule):
def build(self, shutit):
vagrant_image = shutit.cfg[self.module_id]['vagrant_image']
vagrant_provider = shutit.cfg[self.module_id]['vagrant_provider']
gui = shutit.cfg[self.module_id]['gui']
memory = shutit.cfg[self.module_id]['memory']
home_dir = os.path.expanduser('~')
machine_names = ('master1','master2','master3','etcd1','etcd2','etcd3','node1','project1','openshiftcluster')
machines = ('master1.vagrant.test','master2.vagrant.test','master3.vagrant.test','etcd1.vagrant.test','etcd2.vagrant.test','etcd3.vagrant.test','node1.vagrant.test','project1.vagrant.test','openshiftcluster.vagrant.test')
module_name = 'shutit_openshift_cluster_' + ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(6))
# TODO: needs vagrant 1.8.6+
shutit.send('rm -rf ' + home_dir + '/' + module_name + ' && mkdir -p ' + home_dir + '/' + module_name + ' && cd ~/' + module_name)
shutit.send('vagrant plugin install landrush')
shutit.send('vagrant init ' + vagrant_image)
shutit.send_file(home_dir + '/' + module_name + '/Vagrantfile','''
Vagrant.configure("2") do |config|
config.landrush.enabled = true
config.vm.provider "virtualbox" do |vb|
vb.gui = ''' + gui + '''
vb.memory = "''' + memory + '''"
end
config.vm.define "master1" do |master1|
master1.vm.box = ''' + '"' + vagrant_image + '"' + '''
master1.vm.hostname = "master1.vagrant.test"
master1.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "4"]
end
end
config.vm.define "master2" do |master2|
master2.vm.box = ''' + '"' + vagrant_image + '"' + '''
master2.vm.hostname = "master2.vagrant.test"
master2.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", "1024"]
v.customize ["modifyvm", :id, "--cpus", "2"]
end
end
config.vm.define "master3" do |master3|
master3.vm.box = ''' + '"' + vagrant_image + '"' + '''
master3.vm.hostname = "master3.vagrant.test"
master3.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", "1024"]
v.customize ["modifyvm", :id, "--cpus", "2"]
end
end
config.vm.define "openshiftcluster" do |openshiftcluster|
openshiftcluster.vm.box = ''' + '"' + vagrant_image + '"' + '''
openshiftcluster.vm.hostname = "openshiftcluster.vagrant.test"
end
config.vm.define "etcd1" do |etcd1|
etcd1.vm.box = ''' + '"' + vagrant_image + '"' + '''
etcd1.vm.hostname = "etcd1.vagrant.test"
end
config.vm.define "etcd2" do |etcd2|
etcd2.vm.box = ''' + '"' + vagrant_image + '"' + '''
etcd2.vm.hostname = "etcd2.vagrant.test"
end
config.vm.define "etcd3" do |etcd3|
etcd3.vm.box = ''' + '"' + vagrant_image + '"' + '''
etcd3.vm.hostname = "etcd3.vagrant.test"
end
config.vm.define "node1" do |node1|
node1.vm.box = ''' + '"' + vagrant_image + '"' + '''
node1.vm.hostname = "node1.vagrant.test"
end
config.vm.define "project1" do |project1|
project1.vm.box = ''' + '"' + vagrant_image + '"' + '''
project1.vm.hostname = "project1.vagrant.test"
end
end''')
machine_names = ('master1','master2','etcd1','etcd2','etcd3','node1','project1')
machines = ('master1.vagrant.test','master2.vagrant.test','project1.vagrant.test','etcd1.vagrant.test','etcd2.vagrant.test','etcd3.vagrant.test','node1.vagrant.test')
if shutit.whoami() != 'root':
pw = shutit.get_env_pass()
else:
pw = ''
for machine in machine_names:
shutit.multisend('vagrant up ' + machine,{'assword':pw},timeout=99999)
master1_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^master1.vagrant.test | awk '{print $2}'""")
master2_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^master2.vagrant.test | awk '{print $2}'""")
master3_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^master3.vagrant.test | awk '{print $2}'""")
etcd1_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd1.vagrant.test | awk '{print $2}'""")
etcd2_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd2.vagrant.test | awk '{print $2}'""")
etcd3_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd3.vagrant.test | awk '{print $2}'""")
etcd4_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd4.vagrant.test | awk '{print $2}'""")
etcd5_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd5.vagrant.test | awk '{print $2}'""")
etcd6_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^etcd6.vagrant.test | awk '{print $2}'""")
node1_ip = shutit.send_and_get_output("""vagrant landrush ls | grep -w ^node1.vagrant.test | awk '{print $2}'""")
shutit.pause_point('machines up ok?')
for machine in machine_names:
shutit.login(command='vagrant ssh ' + machine)
shutit.login(command='sudo su - ')
# See: https://access.redhat.com/articles/1320623
shutit.send('rm -fr /var/cache/yum/*')
shutit.send('yum clean all')
shutit.send('yum update -y')
shutit.install('xterm')
shutit.install('net-tools')
shutit.send('''sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config''')
shutit.send('echo root:origin | /usr/sbin/chpasswd')
shutit.send('systemctl restart sshd')
# This is to prevent ansible from getting the 'wrong' ip address for the host from eth0.
# See: http://stackoverflow.com/questions/29495704/how-do-you-change-ansible-default-ipv4
shutit.send('route add -net 8.8.8.8 netmask 255.255.255.255 eth1')
ip_addr = shutit.send_and_get_output("""ip -4 route get 8.8.8.8 | head -1 | awk '{print $NF}'""")
shutit.send(r"""sed -i 's/127.0.0.1\t\(.*\).vagrant.test.*/""" + ip_addr + r"""\t\1.vagrant.test\t\1/' /etc/hosts""")
shutit.logout()
shutit.logout()
shutit.login(command='vagrant ssh master1')
shutit.login(command='sudo su - ')
shutit.install('epel-release')
shutit.install('git')
shutit.install('ansible')
shutit.install('pyOpenSSL')
shutit.install('etcd') # For the client
shutit.send('git clone --depth=1 https://github.com/openshift/openshift-ansible -b release-1.3')
shutit.multisend('ssh-keygen',{'Enter file':'','Enter passphrase':'','Enter same pass':''})
shutit.send_file('/etc/ansible/hosts','''# Create an OSEv3 group that contains the master, nodes, etcd, and lb groups.
# The lb group lets Ansible configure HAProxy as the load balancing solution.
# Comment lb out if your load balancer is pre-configured.
[OSEv3:children]
masters
nodes
etcd
lb
# Set variables common for all OSEv3 hosts
[OSEv3:vars]
ansible_ssh_user=root
deployment_type=origin
# Uncomment the following to enable htpasswd authentication; defaults to
# DenyAllPasswordIdentityProvider.
#openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]
# Native high availbility cluster method with optional load balancer.
# If no lb group is defined installer assumes that a load balancer has
# been preconfigured. For installation the value of
# openshift_master_cluster_hostname must resolve to the load balancer
# or to one or all of the masters defined in the inventory if no load
# balancer is present.
openshift_master_cluster_method=native
openshift_master_cluster_hostname=openshiftcluster.vagrant.test
openshift_master_cluster_public_hostname=openshiftcluster.vagrant.test
# apply updated node defaults
openshift_node_kubelet_args={'pods-per-core': ['10'], 'max-pods': ['250'], 'image-gc-high-threshold': ['90'], 'image-gc-low-threshold': ['80']}
# override the default controller lease ttl
#osm_controller_lease_ttl=30
# enable ntp on masters to ensure proper failover
openshift_clock_enabled=true
# host group for masters
[masters]
master1.vagrant.test
master2.vagrant.test
master3.vagrant.test
# host group for etcd
[etcd]
etcd1.vagrant.test
etcd2.vagrant.test
etcd3.vagrant.test
# Specify load balancer host
[lb]
openshiftcluster.vagrant.test
# host group for nodes, includes region info
[nodes]
master[1:3].vagrant.test openshift_node_labels="{'region': 'infra', 'zone': 'default'}"
node1.vagrant.test openshift_node_labels="{'region': 'primary', 'zone': 'east'}"
project1.vagrant.test openshift_node_labels="{'region': 'primary', 'zone': 'west'}"''')
for machine in machines:
# Set up ansible.
shutit.multisend('ssh-copy-id root@' + machine,{'ontinue connecting':'yes','assword':'origin'})
shutit.multisend('ssh-copy-id root@' + machine + '.vagrant.test',{'ontinue connecting':'yes','assword':'origin'})
while True:
shutit.multisend('ansible-playbook ~/openshift-ansible/playbooks/byo/config.yml',{'ontinue connecting':'yes'})
if shutit.send_and_match_output('oc get nodes','.*node1.vagrant.test Ready.*'):
break
# Need to set masters as schedulable (why? - ansible seems to un-schedule them)
shutit.send('oadm manage-node master1.vagrant.test --schedulable')
shutit.send('oadm manage-node master2.vagrant.test --schedulable')
shutit.send('oadm manage-node master3.vagrant.test --schedulable')
# List the etcd members
shutit.send('etcdctl --endpoints https://' + etcd1_ip + ':2379,https://' + etcd2_ip + ':2379,https://' + etcd3_ip + ':2379 --ca-file /etc/origin/master/master.etcd-ca.crt --cert-file /etc/origin/master/master.etcd-client.crt --key-file /etc/origin/master/master.etcd-client.key member list')
shutit.send('git clone --depth=1 https://github.com/openshift/origin')
shutit.send('cd origin/examples')
# TODO: https://github.com/openshift/origin/tree/master/examples/data-population
shutit.send('cd data-population')
shutit.send('ln -s /etc/origin openshift.local.config')
shutit.send("""sed -i 's/10.0.2.15/openshiftcluster/g' common.sh""")
#shutit.send('./populate.sh')
shutit.pause_point('Create project for node project1 and deploy')
shutit.logout()
shutit.logout()
return True
def get_config(self, shutit):
#shutit.get_config(self.module_id,'vagrant_image',default='ubuntu/trusty64')
shutit.get_config(self.module_id,'vagrant_image',default='centos/7')
shutit.get_config(self.module_id,'vagrant_provider',default='virtualbox')
shutit.get_config(self.module_id,'gui',default='false')
#shutit.get_config(self.module_id,'memory',default='1024')
shutit.get_config(self.module_id,'memory',default='512')
return True
def test(self, shutit):
return True
def finalize(self, shutit):
return True
def isinstalled(self, shutit):
return False
def start(self, shutit):
return True
def stop(self, shutit):
return True
def module():
return shutit_openshift_cluster(
'tk.shutit.shutit_openshift_cluster.shutit_openshift_cluster', 857091783.0001,
description='',
maintainer='',
delivery_methods=['bash'],
depends=['shutit.tk.setup','shutit-library.virtualization.virtualization.virtualization','tk.shutit.vagrant.vagrant.vagrant']
)