MCPcopy Create free account
hub / github.com/apache/cloudstack / setup_agent_config

Function setup_agent_config

python/lib/cloud_utils.py:425–484  ·  view source on GitHub ↗
(configfile, host, zone, pod, cluster, guid, pubNic, prvNic)

Source from the content-addressed store, hash-verified

423 return False
424
425def setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic):
426 stderr("Examining Agent configuration")
427 fn = configfile
428 text = open(fn).read(-1)
429 lines = [ s.strip() for s in text.splitlines() ]
430 confopts = dict([ m.split("=",1) for m in lines if "=" in m and not m.startswith("#") ])
431 confposes = dict([ (m.split("=",1)[0],n) for n,m in enumerate(lines) if "=" in m and not m.startswith("#") ])
432
433 if guid != None:
434 confopts['guid'] = guid
435 else:
436 if "guid" not in confopts:
437 stderr("Generating GUID for this Agent")
438 confopts['guid'] = uuidgen().stdout.strip()
439
440 if host == None:
441 try: host = confopts["host"]
442 except KeyError: host = "localhost"
443 stderr("Please enter the host name of the management server that this agent will connect to: (just hit ENTER to go with %s)",host)
444 print("> ", end=' ')
445 newhost = input().strip()
446 if newhost: host = newhost
447
448 confopts["host"] = host
449
450 if pubNic != None and device_exist(pubNic):
451 confopts["public.network.device"] = pubNic
452 if prvNic == None or not device_exist(prvNic):
453 confopts["private.network.device"] = pubNic
454
455 if prvNic != None and device_exist(prvNic):
456 confopts["private.network.device"] = prvNic
457 if pubNic == None or not device_exist(pubNic):
458 confopts["public.network.device"] = prvNic
459
460 stderr("Querying %s for zones and pods",host)
461
462 try:
463 if zone == None or pod == None:
464 x = list_zonespods(confopts['host'])
465 zoneandpod = prompt_for_hostpods(x)
466 if zoneandpod:
467 confopts["zone"],confopts["pod"] = zoneandpod
468 stderr("You selected zone %s pod %s",confopts["zone"],confopts["pod"])
469 else:
470 stderr("Skipped -- using the previous zone %s pod %s",confopts["zone"],confopts["pod"])
471 else:
472 confopts["zone"] = zone
473 confopts["pod"] = pod
474 confopts["cluster"] = cluster
475 except (urllib.error.URLError,urllib.error.HTTPError) as e:
476 stderr("Query failed: %s. Defaulting to zone %s pod %s",str(e),confopts["zone"],confopts["pod"])
477
478 for opt,val in list(confopts.items()):
479 line = "=".join([opt,val])
480 if opt not in confposes: lines.append(line)
481 else: lines[confposes[opt]] = line
482

Callers

nothing calls this directly

Calls 8

stderrFunction · 0.85
device_existFunction · 0.85
list_zonespodsFunction · 0.85
prompt_for_hostpodsFunction · 0.85
writeMethod · 0.65
readMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected