Revision debac808 lib/bootstrap.py
b/lib/bootstrap.py | ||
---|---|---|
160 | 160 |
""" |
161 | 161 |
# TODO: complete the docstring |
162 | 162 |
if config.ConfigWriter.IsCluster(): |
163 |
raise errors.OpPrereqError("Cluster is already initialised") |
|
163 |
raise errors.OpPrereqError("Cluster is already initialised", |
|
164 |
errors.ECODE_STATE) |
|
164 | 165 |
|
165 | 166 |
if not enabled_hypervisors: |
166 | 167 |
raise errors.OpPrereqError("Enabled hypervisors list must contain at" |
167 |
" least one member") |
|
168 |
" least one member", errors.ECODE_INVAL)
|
|
168 | 169 |
invalid_hvs = set(enabled_hypervisors) - constants.HYPER_TYPES |
169 | 170 |
if invalid_hvs: |
170 | 171 |
raise errors.OpPrereqError("Enabled hypervisors contains invalid" |
171 |
" entries: %s" % invalid_hvs) |
|
172 |
" entries: %s" % invalid_hvs, |
|
173 |
errors.ECODE_INVAL) |
|
172 | 174 |
|
173 | 175 |
hostname = utils.HostInfo() |
174 | 176 |
|
175 | 177 |
if hostname.ip.startswith("127."): |
176 | 178 |
raise errors.OpPrereqError("This host's IP resolves to the private" |
177 | 179 |
" range (%s). Please fix DNS or %s." % |
178 |
(hostname.ip, constants.ETC_HOSTS)) |
|
180 |
(hostname.ip, constants.ETC_HOSTS), |
|
181 |
errors.ECODE_ENVIRON) |
|
179 | 182 |
|
180 | 183 |
if not utils.OwnIpAddress(hostname.ip): |
181 | 184 |
raise errors.OpPrereqError("Inconsistency: this host's name resolves" |
182 | 185 |
" to %s,\nbut this ip address does not" |
183 |
" belong to this host."
|
|
184 |
" Aborting." % hostname.ip)
|
|
186 |
" belong to this host. Aborting." %
|
|
187 |
hostname.ip, errors.ECODE_ENVIRON)
|
|
185 | 188 |
|
186 | 189 |
clustername = utils.HostInfo(cluster_name) |
187 | 190 |
|
188 | 191 |
if utils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT, |
189 | 192 |
timeout=5): |
190 |
raise errors.OpPrereqError("Cluster IP already active. Aborting.") |
|
193 |
raise errors.OpPrereqError("Cluster IP already active. Aborting.", |
|
194 |
errors.ECODE_NOTUNIQUE) |
|
191 | 195 |
|
192 | 196 |
if secondary_ip: |
193 | 197 |
if not utils.IsValidIP(secondary_ip): |
194 |
raise errors.OpPrereqError("Invalid secondary ip given") |
|
198 |
raise errors.OpPrereqError("Invalid secondary ip given", |
|
199 |
errors.ECODE_INVAL) |
|
195 | 200 |
if (secondary_ip != hostname.ip and |
196 | 201 |
not utils.OwnIpAddress(secondary_ip)): |
197 | 202 |
raise errors.OpPrereqError("You gave %s as secondary IP," |
198 | 203 |
" but it does not belong to this host." % |
199 |
secondary_ip) |
|
204 |
secondary_ip, errors.ECODE_ENVIRON)
|
|
200 | 205 |
else: |
201 | 206 |
secondary_ip = hostname.ip |
202 | 207 |
|
... | ... | |
206 | 211 |
constants.MIN_VG_SIZE) |
207 | 212 |
if vgstatus: |
208 | 213 |
raise errors.OpPrereqError("Error: %s\nspecify --no-lvm-storage if" |
209 |
" you are not using lvm" % vgstatus) |
|
214 |
" you are not using lvm" % vgstatus, |
|
215 |
errors.ECODE_INVAL) |
|
210 | 216 |
|
211 | 217 |
file_storage_dir = os.path.normpath(file_storage_dir) |
212 | 218 |
|
213 | 219 |
if not os.path.isabs(file_storage_dir): |
214 | 220 |
raise errors.OpPrereqError("The file storage directory you passed is" |
215 |
" not an absolute path.") |
|
221 |
" not an absolute path.", errors.ECODE_INVAL)
|
|
216 | 222 |
|
217 | 223 |
if not os.path.exists(file_storage_dir): |
218 | 224 |
try: |
219 | 225 |
os.makedirs(file_storage_dir, 0750) |
220 | 226 |
except OSError, err: |
221 | 227 |
raise errors.OpPrereqError("Cannot create file storage directory" |
222 |
" '%s': %s" % |
|
223 |
(file_storage_dir, err))
|
|
228 |
" '%s': %s" % (file_storage_dir, err),
|
|
229 |
errors.ECODE_ENVIRON)
|
|
224 | 230 |
|
225 | 231 |
if not os.path.isdir(file_storage_dir): |
226 | 232 |
raise errors.OpPrereqError("The file storage directory '%s' is not" |
227 |
" a directory." % file_storage_dir) |
|
233 |
" a directory." % file_storage_dir, |
|
234 |
errors.ECODE_ENVIRON) |
|
228 | 235 |
|
229 | 236 |
if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix): |
230 |
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix) |
|
237 |
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix, |
|
238 |
errors.ECODE_INVAL) |
|
231 | 239 |
|
232 | 240 |
result = utils.RunCmd(["ip", "link", "show", "dev", master_netdev]) |
233 | 241 |
if result.failed: |
234 | 242 |
raise errors.OpPrereqError("Invalid master netdev given (%s): '%s'" % |
235 | 243 |
(master_netdev, |
236 |
result.output.strip())) |
|
244 |
result.output.strip()), errors.ECODE_INVAL)
|
|
237 | 245 |
|
238 | 246 |
if not (os.path.isfile(constants.NODE_INITD_SCRIPT) and |
239 | 247 |
os.access(constants.NODE_INITD_SCRIPT, os.X_OK)): |
240 | 248 |
raise errors.OpPrereqError("Init.d script '%s' missing or not" |
241 |
" executable." % constants.NODE_INITD_SCRIPT) |
|
249 |
" executable." % constants.NODE_INITD_SCRIPT, |
|
250 |
errors.ECODE_ENVIRON) |
|
242 | 251 |
|
243 | 252 |
dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE)] |
244 | 253 |
utils.EnsureDirs(dirs) |
... | ... | |
449 | 458 |
raise errors.OpPrereqError("This commands must be run on the node" |
450 | 459 |
" where you want the new master to be." |
451 | 460 |
" %s is already the master" % |
452 |
old_master) |
|
461 |
old_master, errors.ECODE_INVAL)
|
|
453 | 462 |
|
454 | 463 |
if new_master not in mc_list: |
455 | 464 |
mc_no_master = [name for name in mc_list if name != old_master] |
... | ... | |
457 | 466 |
" as master candidates. Only these nodes" |
458 | 467 |
" can become masters. Current list of" |
459 | 468 |
" master candidates is:\n" |
460 |
"%s" % ('\n'.join(mc_no_master))) |
|
469 |
"%s" % ('\n'.join(mc_no_master)), |
|
470 |
errors.ECODE_STATE) |
|
461 | 471 |
|
462 | 472 |
if not no_voting: |
463 | 473 |
vote_list = GatherMasterVotes(node_list) |
... | ... | |
466 | 476 |
voted_master = vote_list[0][0] |
467 | 477 |
if voted_master is None: |
468 | 478 |
raise errors.OpPrereqError("Cluster is inconsistent, most nodes did" |
469 |
" not respond.") |
|
479 |
" not respond.", errors.ECODE_ENVIRON)
|
|
470 | 480 |
elif voted_master != old_master: |
471 | 481 |
raise errors.OpPrereqError("I have a wrong configuration, I believe" |
472 | 482 |
" the master is %s but the other nodes" |
473 | 483 |
" voted %s. Please resync the configuration" |
474 | 484 |
" of this node." % |
475 |
(old_master, voted_master)) |
|
485 |
(old_master, voted_master), |
|
486 |
errors.ECODE_STATE) |
|
476 | 487 |
# end checks |
477 | 488 |
|
478 | 489 |
rcode = 0 |
Also available in: Unified diff