Ejemplo n.º 1
0
def GenerateBackends(context):
  """Generates dictionary of IGMs connected to a backeend service."""
  name = context.env['name']
  prop = context.properties
  replicas = prop[REPLICAS]
  backends = []
  for zone_dict in replicas:
    short_abbrv = common.ShortenZoneName(zone_dict[default.ZONE])
    ig_name = common.AutoName(name, default.IGM, short_abbrv)
    zone_dict[GEN_NAME] = ig_name
    backend = {'name': ig_name, 'group': common.RefGroup(ig_name)}
    backends.append(backend)
  prop[GENERATED_PROP][REPLICAS] = copy.deepcopy(replicas)
  return backends
Ejemplo n.º 2
0
def generate_config(context):
    # This method will:
    # 1. Create a instance template for a security GW
    # (with a tag for the managing security server)
    # 2. Create a managed instance group
    # (based on the instance template and zones list provided by the user)
    # 3. Configure autoscaling
    # (based on min, max & policy settings provided by the user)
    prop = context.properties
    prop['deployment'] = context.env['deployment']
    prop['project'] = context.env['project']
    prop['templateName'] = TEMPLATE_NAME
    prop['templateVersion'] = TEMPLATE_VERSION
    prop['allowUploadDownload'] = str(prop['allowUploadDownload']).lower()
    prop['hasInternet'] = 'true'  # via Google Private Access
    prop['installationType'] = 'AutoScale'
    prop['resources'] = []
    prop['outputs'] = []
    prop['gw_dependencies'] = []
    prop['computed_sic_key'] = password.GeneratePassword(12, False)
    prop['gatewayExternalIP'] = (
        prop['mgmtNIC'] == 'Ephemeral Public IP (eth0)')

    version_chosen = prop['autoscalingVersion'].split(' ')[0] + "-GW"
    nics = create_nics(context)
    gw_template = create_instance_template(context,
                                           prop['deployment'],
                                           nics,
                                           depends_on=prop['gw_dependencies'],
                                           gw_version=VERSIONS[version_chosen])
    prop['resources'] += [gw_template]
    prop['igm_dependencies'] = [gw_template['name']]
    igm = GenerateAutscaledGroup(context, prop['deployment'],
                                 gw_template['name'], prop['igm_dependencies'])
    prop['resources'] += [igm]

    prop['autoscaler_dependencies'] = [igm['name']]
    cpu_usage = prop.get("cpuUsage")
    autoscaler = CreateAutscaler(context, prop['deployment'], igm['name'],
                                 cpu_usage, prop['autoscaler_dependencies'])
    prop['resources'] += [autoscaler]

    prop['outputs'] += [
        {
            'name': 'deployment',
            'value': prop['deployment']
        },
        {
            'name': 'project',
            'value': prop['project']
        },
        {
            'name': 'instanceTemplateName',
            'value': gw_template['name']
        },
        {
            'name': 'InstanceTemplateLink',
            'value': common.Ref(gw_template['name'])
        },
        {
            'name': 'IGMname',
            'value': igm['name']
        },
        {
            'name': 'IGMLink',
            'value': common.RefGroup(igm['name'])
        },
        {
            'name': 'cpuUsagePercentage',
            'value': str(int(prop['cpuUsage'])) + '%'
        },
        {
            'name': 'minInstancesInt',
            'value': str(int(prop['minInstances']))
        },
        {
            'name': 'maxInstancesInt',
            'value': str(int(prop['maxInstances']))
        },
    ]

    return common.MakeResource(prop['resources'], prop['outputs'])