Exemplo n.º 1
0
def ValidateInstanceLocation(args):
    """Construct a Cloud SQL instance from command line args.

  Args:
    args: argparse.Namespace, The CLI arg namespace.

  Raises:
    RequiredArgumentException: Zone is required.
    ConflictingArgumentsException: Zones in arguments belong to different
    regions.
  """

    if args.IsSpecified('secondary_zone') and not args.IsSpecified('zone'):
        raise exceptions.RequiredArgumentException(
            '--zone', '`--zone` is required if --secondary-zone is used '
            'while creating an instance.')

    if args.IsSpecified('secondary_zone') and args.IsSpecified('zone'):
        if args.zone == args.secondary_zone:
            raise exceptions.ConflictingArgumentsException(
                'Zones in arguments --zone and --secondary-zone are identical.'
            )

        region_from_zone = api_util.GetRegionFromZone(args.zone)
        region_from_secondary_zone = api_util.GetRegionFromZone(
            args.secondary_zone)
        if region_from_zone != region_from_secondary_zone:
            raise exceptions.ConflictingArgumentsException(
                'Zones in arguments --zone and --secondary-zone '
                'belong to different regions.')
def Region(specified_region, gce_zone, secondary_zone=None):
    """Generates the region string for the instance.

  Args:
    specified_region: string, the GCE region to create the instance in.
    gce_zone: string, the GCE zone to create the instance in.
    secondary_zone: string, the GCE zone to create the standby instance in.

  Returns:
    string, the region to create the instance in.
  """
    if gce_zone and secondary_zone:
        region_from_zone = api_util.GetRegionFromZone(gce_zone)
        region_from_secondary_zone = api_util.GetRegionFromZone(secondary_zone)
        if region_from_zone != region_from_secondary_zone:
            raise exceptions.ConflictingArgumentsException(
                'Zones in arguments --zone and --secondary-zone '
                'belong to different regions.')
    if gce_zone:
        derived_region = api_util.GetRegionFromZone(gce_zone)
        return derived_region
    return specified_region
def Region(specified_region, gce_zone):
    """Generates the region string for the instance.

  Args:
    specified_region: string, the GCE region to create the instance in.
    gce_zone: string, the GCE zone to create the instance in.

  Returns:
    string, the region to create the instance in.
  """
    if gce_zone:
        derived_region = api_util.GetRegionFromZone(gce_zone)
        return derived_region
    return specified_region
Exemplo n.º 4
0
 def testGetRegionFromZone(self, zone, derived_region):
     self.assertEqual(instances_util.GetRegionFromZone(zone),
                      derived_region)