github.com/openshift/installer@v1.4.17/upi/azure/setup-manifests.py (about)

     1  #!/usr/bin/env python3
     2  
     3  import json
     4  import base64
     5  import sys
     6  import os
     7  import glob
     8  from dotmap import DotMap
     9  import yaml
    10  from collections import OrderedDict
    11  
    12  resource_group = sys.argv[1]
    13  infra_id = sys.argv[2]
    14  
    15  with open('openshift/99_cloud-creds-secret.yaml') as crfile:
    16      yamls = yaml.load(crfile, Loader=yaml.BaseLoader)
    17      crfile.close()
    18      yamls['data']['azure_resource_prefix'] = base64.b64encode(bytes(infra_id, 'utf-8')).decode('utf-8')
    19      yamls['data']['azure_resourcegroup'] = base64.b64encode(bytes(resource_group, 'utf-8')).decode('utf-8')
    20      with open('openshift/99_cloud-creds-secret.yaml', 'w') as crout:
    21          yaml.dump(yamls, crout, default_flow_style=False)
    22          crout.close()
    23  
    24  with open('manifests/cloud-provider-config.yaml') as file:
    25      yamlx = yaml.load(file, Loader=yaml.BaseLoader)
    26      file.close()
    27      jsondata = yamlx['data']['config']
    28      jsonx = json.loads(jsondata, object_pairs_hook=OrderedDict)
    29      config = DotMap(jsonx)
    30      config.resourceGroup = resource_group
    31      config.vnetName = infra_id + "-vnet"
    32      config.vnetResourceGroup = resource_group
    33      config.subnetName = infra_id + "-worker-subnet"
    34      config.securityGroupName = infra_id + "-nsg"
    35      config.routeTableName = ""
    36      config.cloudProviderRateLimit = False
    37      config.azure_resourcegroup = resource_group
    38      jsondata = json.dumps(dict(**config.toDict()), indent='\t')
    39      jsonstr = str(jsondata)
    40      yamlx['data']['config'] = jsonstr + '\n'
    41      yamlx['metadata']['creationTimestamp'] = None
    42      yamlstr = yaml.dump(yamlx, default_style='\"', width=4096)
    43      yamlstr = yamlstr.replace('!!null "null"', 'null')
    44      with open('manifests/cloud-provider-config.yaml', 'w') as outfile:
    45          outfile.write(yamlstr)
    46          outfile.close()
    47  
    48  with open('manifests/cluster-infrastructure-02-config.yml') as file:
    49      yamlx = yaml.load(file, Loader=yaml.BaseLoader)
    50      file.close()
    51      yamlx['status']['platformStatus']['azure']['resourceGroupName'] = resource_group
    52      yamlx['status']['platformStatus']['azure']['networkResourceGroupName'] = resource_group
    53      yamlx['status']['platformStatus']['azure']['virtualNetwork'] = infra_id + "-vnet"
    54      yamlx['status']['platformStatus']['azure']['controlPlaneSubnet'] = infra_id + "-master-subnet"
    55      yamlx['status']['platformStatus']['azure']['computeSubnet'] = infra_id + "-worker-subnet"
    56      yamlx['status']['infrastructureName'] = infra_id
    57      yamlx['metadata']['creationTimestamp'] = None
    58      with open('manifests/cluster-infrastructure-02-config.yml', 'w') as outfile:
    59          yaml.dump(yamlx, outfile, default_flow_style=False)
    60          outfile.close()