(context)
return Resources()
Generate template config based on python objects.
Generate template config based on python objects.
Generate template config based on python objects .
def GenerateConfig(context):
  """Generate template config based on python objects."""
  compute_resource_util.SetContext(context)
  properties = context.properties
  disk_name = context.env['deployment'] + '-' + 'disk'
  image = 'projects/debian-cloud/global/images/debian-7-wheezy-v20140619'
  default_network = 'global/networks/default'
  assert ('region' in properties) ^ ('zone' in properties), (
      'Need to specify exactly only one from zone or region')
  template = ComputeResource(
      'template', compute_constants.INSTANCETEMPLATES, {
          'properties': {
              'machineType':
                  'f1-micro',
              'disks': [{
                  'deviceName': 'boot',
                  'boot': True,
                  'autoDelete': True,
                  'mode': 'READ_WRITE',
                  'initializeParams': {
                      'diskName': disk_name,
                      'sourceImage': image
                  },
                  'type': 'PERSISTENT'
              }],
              'networkInterfaces': [{
                  'network': default_network
              }]
          }
      })
  if 'region' in properties:
    igm = ComputeResource(
        'igm', compute_constants.REGIONINSTANCEGROUPMANAGERS, {
            'region': properties['region'],
            'size': properties['size'],
            'baseInstanceName': context.env['deployment'] + '-instance',
            'instanceTemplate': template.SelfLink(),
            'targetSize': 1
        })
    ComputeResource(
        'autoscaler', compute_constants.REGIONAUTOSCALERS, {
            'region':
                properties['region'],
            'autoscalingPolicy': {
                'coolDownPeriodSec': 60,
                'cpuUtilization': {
                    'utilizationTarget': 0.8
                },
                'maxNumReplicas': 3,
                'minNumReplicas': 1
            },
            'description':
                'Autoscaler created for cloud config testing purposes',
            'target':
                igm.SelfLink()
        })
  else:
    igm = ComputeResource(
        'igm', compute_constants.INSTANCEGROUPMANAGERS, {
            'zone': properties['zone'],
            'size': properties['size'],
            'baseInstanceName': context.env['deployment'] + '-instance',
            'instanceTemplate': template.SelfLink(),
            'targetSize': 1
        })
    ComputeResource(
        'autoscaler', compute_constants.AUTOSCALERS, {
            'zone':
                properties['zone'],
            'autoscalingPolicy': {
                'coolDownPeriodSec': 60,
                'cpuUtilization': {
                    'utilizationTarget': 0.8
                },
                'maxNumReplicas': 3,
                'minNumReplicas': 1
            },
            'description':
                'Autoscaler created for cloud config testing purposes',
            'target':
                igm.SelfLink()
        })
  return Resources()
def GenerateConfig ( context ) : compute_resource_util . SetContext ( context ) properties = context . properties disk_name = context . env [ 'deployment' ] + '-' + 'disk' image = 'projects/debian-cloud/global/images/debian-7-wheezy-v20140619' default_network = 'global/networks/default' assert ( 'region' in properties ) ^ ( 'zone' in properties ) , ( 'Need to specify exactly only one from zone or region' ) template = ComputeResource ( 'template' , compute_constants . INSTANCETEMPLATES , { 'properties' : { 'machineType' : 'f1-micro' , 'disks' : [ { 'deviceName' : 'boot' , 'boot' : True , 'autoDelete' : True , 'mode' : 'READ_WRITE' , 'initializeParams' : { 'diskName' : disk_name , 'sourceImage' : image } , 'type' : 'PERSISTENT' } ] , 'networkInterfaces' : [ { 'network' : default_network } ] } } ) if 'region' in properties : igm = ComputeResource ( 'igm' , compute_constants . REGIONINSTANCEGROUPMANAGERS , { 'region' : properties [ 'region' ] , 'size' : properties [ 'size' ] , 'baseInstanceName' : context . env [ 'deployment' ] + '-instance' , 'instanceTemplate' : template . SelfLink ( ) , 'targetSize' : 1 } ) ComputeResource ( 'autoscaler' , compute_constants . REGIONAUTOSCALERS , { 'region' : properties [ 'region' ] , 'autoscalingPolicy' : { 'coolDownPeriodSec' : 60 , 'cpuUtilization' : { 'utilizationTarget' : 0.8 } , 'maxNumReplicas' : 3 , 'minNumReplicas' : 1 } , 'description' : 'Autoscaler created for cloud config testing purposes' , 'target' : igm . SelfLink ( ) } ) else : igm = ComputeResource ( 'igm' , compute_constants . INSTANCEGROUPMANAGERS , { 'zone' : properties [ 'zone' ] , 'size' : properties [ 'size' ] , 'baseInstanceName' : context . env [ 'deployment' ] + '-instance' , 'instanceTemplate' : template . SelfLink ( ) , 'targetSize' : 1 } ) ComputeResource ( 'autoscaler' , compute_constants . AUTOSCALERS , { 'zone' : properties [ 'zone' ] , 'autoscalingPolicy' : { 'coolDownPeriodSec' : 60 , 'cpuUtilization' : { 'utilizationTarget' : 0.8 } , 'maxNumReplicas' : 3 , 'minNumReplicas' : 1 } , 'description' : 'Autoscaler created for cloud config testing purposes' , 'target' : igm . SelfLink ( ) } ) return Resources ( )