cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
s003_install_services.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
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 # @COPYRIGHT_end
19 
20 from settings import SERVICES_TMP, BASIC_IMAGE, SSH_KEY, SYSTEM_VERSION, DEB_REPO
21 import os
22 import time
23 
24 try:
25  os.mkdir(SERVICES_TMP)
26 except Exception:
27  pass
28 
29 # Save ssh key in file
30 ssh_key = open('%s/id_test' % SERVICES_TMP, 'w')
31 ssh_key.write(SSH_KEY)
32 ssh_key.close()
33 os.chmod('%s/id_test' % SERVICES_TMP, 0600)
34 
35 # Define ip addresses
36 wi_net_wi_clm = ''
37 clm_net_wi_clm = ''
38 clm_net_clm_cm = ''
39 cm_net_clm_cm = ''
40 cm_net_cm_cluster = ''
41 rm = ''
42 node04 = ''
43 node05 = ''
44 
45 # Wait until Libvirt leases are not ready
46 while wi_net_wi_clm == '' or clm_net_clm_cm == '' or clm_net_wi_clm == '' or cm_net_clm_cm == '' or cm_net_cm_cluster == '' or rm == '' or node04 == '' or node05 == '':
47  try:
48  # Read hosts file
49  wi_clm_leases = open('/var/lib/libvirt/dnsmasq/wi_clm.hostsfile', 'r').readlines()
50  clm_cm_leases = open('/var/lib/libvirt/dnsmasq/clm_cm.hostsfile', 'r').readlines()
51  cm_cluster_leases = open('/var/lib/libvirt/dnsmasq/cm_cluster.hostsfile', 'r').readlines()
52  for line in wi_clm_leases:
53  if '01:02' in line:
54  wi_net_wi_clm = line.split(',')[1]
55  elif '01:03' in line:
56  clm_net_wi_clm = line.split(',')[1]
57 
58  for line in clm_cm_leases:
59  if '02:02' in line:
60  clm_net_clm_cm = line.split(',')[1]
61  elif '02:03' in line:
62  cm_net_clm_cm = line.split(',')[1]
63 
64  for line in cm_cluster_leases:
65  if '03:02' in line:
66  cm_net_cm_cluster = line.split(',')[1]
67  elif '03:03' in line:
68  rm = line.split(',')[1]
69  elif '03:04' in line:
70  node04 = line.split(',')[1]
71  elif '03:05' in line:
72  node05 = line.split(',')[1]
73  except Exception:
74  # Otherwise, try to read leases
75  wi_clm_leases = open('/var/lib/libvirt/dnsmasq/wi_clm.leases', 'r').readlines()
76  clm_cm_leases = open('/var/lib/libvirt/dnsmasq/clm_cm.leases', 'r').readlines()
77  cm_cluster_leases = open('/var/lib/libvirt/dnsmasq/cm_cluster.leases', 'r').readlines()
78  for line in wi_clm_leases:
79  if '01:02' in line:
80  wi_net_wi_clm = line.split(' ')[2]
81  elif '01:03' in line:
82  clm_net_wi_clm = line.split(' ')[2]
83 
84  for line in clm_cm_leases:
85  if '02:02' in line:
86  clm_net_clm_cm = line.split(' ')[2]
87  elif '02:03' in line:
88  cm_net_clm_cm = line.split(' ')[2]
89 
90  for line in cm_cluster_leases:
91  if '03:02' in line:
92  cm_net_cm_cluster = line.split(' ')[2]
93  elif '03:03' in line:
94  rm = line.split(' ')[2]
95  elif '03:04' in line:
96  node04 = line.split(' ')[2]
97  elif '03:05' in line:
98  node05 = line.split(' ')[2]
99  print "wi: " + wi_net_wi_clm
100  print "clm: " + clm_net_wi_clm + ", " + clm_net_clm_cm
101  print "cm: " + cm_net_clm_cm + ", " + cm_net_cm_cluster
102  print "rm: " + rm
103  print "node04: " + node04
104  print "node05: " + node05
105  print ""
106  time.sleep(1)
107 
108 actions = []
109 
110 # Install WI
111 actions.append({'type': 'exec',
112  'command': 'ssh',
113  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % wi_net_wi_clm, 'echo deb %s wheezy main >> /etc/apt/sources.list' % DEB_REPO],
114  'wait_response': 'r == 0',
115  'wait_max': 120})
116 
117 actions.append({'type': 'exec',
118  'command': 'ssh',
119  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % wi_net_wi_clm, 'apt-get update'],
120  'wait_response': 'r == 0',
121  'wait_max': 40})
122 
123 actions.append({'type': 'exec',
124  'command': 'ssh',
125  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % wi_net_wi_clm,
126  '''export wi_configure=True
127  apt-get --yes --force-yes install cc1-system-wi-%s''' % SYSTEM_VERSION],})
128 
129 # Install CLM
130 
131 
132 actions.append({'type': 'exec',
133  'command': 'ssh',
134  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % clm_net_wi_clm, 'echo deb %s wheezy main >> /etc/apt/sources.list' % DEB_REPO],
135  'wait_response': 'r == 0',
136  'wait_max': 120})
137 
138 actions.append({'type': 'exec',
139  'command': 'ssh',
140  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % clm_net_wi_clm, 'apt-get update'],
141  'wait_response': 'r == 0',
142  'wait_max': 40})
143 
144 actions.append({'type': 'exec',
145  'command': 'ssh',
146  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % clm_net_wi_clm,
147  '''export clm_clm_connection_string="mysql://cc1:cc14321@localhost/clm" ;
148  export clm_db_input_again=false
149  export clm_configure=true
150  export clm_changed=true
151  apt-get --yes --force-yes install cc1-system-clm-%s''' % SYSTEM_VERSION],})
152 
153 # Install CM
154 actions.append({'type': 'exec',
155  'command': 'ssh',
156  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % cm_net_clm_cm, 'echo deb %s wheezy main >> /etc/apt/sources.list' % DEB_REPO],
157  'wait_response': 'r == 0',
158  'wait_max': 120})
159 
160 actions.append({'type': 'exec',
161  'command': 'ssh',
162  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % cm_net_clm_cm, 'apt-get update'],
163  'wait_response': 'r == 0',
164  'wait_max': 40})
165 
166 actions.append({'type': 'exec',
167  'command': 'ssh',
168  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % cm_net_clm_cm,
169  '''export cm_cm_connection_string="mysql://cc1:cc14321@localhost/cm"
170  export cm_db_input_again=false
171  export cm_cmh_connection_string="mysql://cc1:cc14321@localhost/cm_history"
172  export cm_history_db_input_again=false
173  export cm_changed=true
174  apt-get --yes --force-yes install cc1-system-cm-%s''' % SYSTEM_VERSION],})
175 
176 # Install RM
177 actions.append({'type': 'exec',
178  'command': 'ssh',
179  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % rm, 'echo deb %s wheezy main >> /etc/apt/sources.list' % DEB_REPO],
180  'wait_response': 'r == 0',
181  'wait_max': 120})
182 
183 actions.append({'type': 'exec',
184  'command': 'ssh',
185  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % rm, 'apt-get update'],
186  'wait_response': 'r == 0',
187  'wait_max': 40})
188 
189 actions.append({'type': 'exec',
190  'command': 'ssh',
191  'args': ['-i', '%s/id_test' % SERVICES_TMP, 'root@%s' % rm,
192  '''export cm_cm_connection_string="mysql://cc1:cc14321@localhost/cm"
193  export cm_db_input_again=false
194  export cm_cmh_connection_string="mysql://cc1:cc14321@localhost/cm_history"
195  export cm_history_db_input_again=false
196  export cm_changed=true
197  apt-get --yes --force-yes install cc1-system-rm-%s''' % SYSTEM_VERSION],})
198