(configfile, host, zone, pod, cluster, guid, pubNic, prvNic)
| 423 | return False |
| 424 | |
| 425 | def 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 |
nothing calls this directly
no test coverage detected