Last active
March 8, 2016 18:27
-
-
Save dwallraff/5f1ca935041b9ddcd3d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env python | |
### Assumes you've added a second network | |
import yaml | |
INPUT = yaml.load(open("bosh_prod.yml")) | |
ZONE_B_RESOURCES = [] | |
IP_ADDRESS_MAP = {} | |
# Find Zone B reource pools | |
for pool in INPUT['resource_pools']: | |
for datacenter in pool['cloud_properties']['datacenters']: | |
if 'CFZB' in datacenter['clusters'][0].keys(): | |
ZONE_B_RESOURCES.append(pool['name']) | |
# Find static IPs with zone B resource pools | |
for job in INPUT['jobs']: | |
if job['resource_pool'] in ZONE_B_RESOURCES: | |
try: | |
for ip in job['networks'][0]['static_ips']: | |
IP_ADDRESS_MAP[ip] = ip.replace('<IP 1>', '<IP 2>') | |
except: | |
pass | |
# Delete updated IPs from default network, change zone B IPs in the 'jobs' section | |
with open("bosh_prod.out.yml", "wt") as fout: | |
with open("bosh_prod.yml", "rt") as fin: | |
IN_JOBS = False | |
for line in fin: | |
found_IP_match = False | |
if line == "jobs:": | |
IN_JOBS = True | |
for key in IP_ADDRESS_MAP: | |
if key in line: | |
found_IP_match = True | |
if IN_JOBS: | |
fout.write(line.replace(key, IP_ADDRESS_MAP[key])) | |
if not found_IP_match: | |
fout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment