def Run(self, args):
   """Runs the command."""
   messages = privateca_base.GetMessagesModule('v1')
   return [
       messages.Location(locationId=location)
       for location in locations.GetSupportedLocations('v1')
   ]
示例#2
0
def ValidateResourceLocation(resource_ref, arg_name):
    """Raises an exception if the given resource is in an unsupported location."""
    supported_locations = locations.GetSupportedLocations()
    if resource_ref.locationsId not in supported_locations:
        raise exceptions.InvalidArgumentException(
            arg_name,
            'Resource is in an unsupported location. Supported locations are: {}.'
            .format(', '.join(sorted(supported_locations))))
示例#3
0
def ValidateKmsKeyVersionLocation(version_ref):
    """Raises an exception if the key version is in an unsupported location."""
    supported_locations = locations.GetSupportedLocations()
    if version_ref.locationsId not in supported_locations:
        raise exceptions.InvalidArgumentException(
            '--kms-key-version',
            'Resource is in an unsupported location. Supported locations are: {}.'
            .format(', '.join(sorted(supported_locations))))
  def testGetLocationsReturnsFallbackListOnApiFailure(self):
    properties.VALUES.core.project.Set('p1')
    self.client.projects_locations.List.Expect(
        request=self.messages.PrivatecaProjectsLocationsListRequest(
            name='projects/p1'),
        exception=http_error.MakeHttpError(code=500))

    result = locations.GetSupportedLocations()
    self.assertCountEqual(locations._FallbackLocations, result)
示例#5
0
  def testGetLocationsReturnsLocationIds(self):
    properties.VALUES.core.project.Set('p1')
    self.client.projects_locations.List.Expect(
        request=self.messages.PrivatecaProjectsLocationsListRequest(
            name='projects/p1'),
        response=self.messages.ListLocationsResponse(
            locations=[
                self.messages.Location(locationId='us-west1'),
                self.messages.Location(locationId='europe-west1'),
            ]))

    result = locations.GetSupportedLocations()
    self.assertCountEqual(['us-west1', 'europe-west1'], result)
示例#6
0
 def Args(parser):
     concept_parsers.ConceptParser.ForResource(
         'REUSABLE_CONFIG',
         resource_args.CreateReusableConfigResourceSpec(
             location_fallthrough=deps.Fallthrough(
                 function=lambda: locations.GetSupportedLocations()[0],
                 hint=(
                     'location will default to the first location supported '
                     'by the service'),
                 active=False,
                 plural=False)),
         'The reusable config to describe.',
         required=True).AddToParser(parser)
  def Run(self, args):
    """Runs the command."""
    self.client = privateca_base.GetClientInstance(api_version='v1')
    self.messages = privateca_base.GetMessagesModule(api_version='v1')

    template_ref = args.CONCEPTS.certificate_template.Parse()
    template = self.client.projects_locations_certificateTemplates.Get(
        self.messages.PrivatecaProjectsLocationsCertificateTemplatesGetRequest(
            name=template_ref.RelativeName()))

    # Name is output-only and will be different for each location.
    template.name = ''

    success_count = 0
    target_locations = args.target_locations
    if args.all_locations:
      target_locations = [
          location for location in locations.GetSupportedLocations('v1')
          if location != template_ref.locationsId
      ]
    for location in target_locations:
      location = location.strip()
      if location == template_ref.locationsId:
        log.warning(
            'Skipping location [{}] since it is the source location.'.format(
                location))
        continue

      try:
        operation = self._CreateOrUpdateTemplate(template_ref.projectsId,
                                                 location, template_ref.Name(),
                                                 template, args.overwrite)
        operations.Await(
            operation,
            'Replicating template to [{}]'.format(location),
            api_version='v1')
        success_count += 1
      except ReplicationError as e:
        if args.continue_on_error:
          log.warning(six.text_type(e))
          continue
        raise e

    log.status.Print(
        'Replicated template [{}] to {} out of {} locations.'.format(
            template_ref.RelativeName(), success_count, len(target_locations)))
示例#8
0
def _GetLocation(args):
    if args.IsSpecified('location'):
        return args.location

    # During alpha, we replicate the same set of resources across all locations.
    return locations.GetSupportedLocations()[0]