Exemple #1
0
  def testListConnections_PermissionDenied(self):
    """Test ListConnection raises correctly when server returns 403 error."""
    server_error = http_error.MakeDetailedHttpError(code=403, message='Error!')
    self.ExpectListConnections(self.NETWORK, None, error=server_error)

    with self.assertRaisesRegex(
        exceptions.ListConnectionsPermissionDeniedException, r'Error!'):
      peering.ListConnections(self.PROJECT_NUMBER, self.service, self.NETWORK)
Exemple #2
0
  def Run(self, args):
    """Run 'services vpc-peerings list'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The list of connections.
    """
    project = properties.VALUES.core.project.Get(required=True)
    project_number = projects_util.GetProjectNumber(project)
    conns = peering.ListConnections(project_number, args.service, args.network)
    return iter(conns)
Exemple #3
0
  def testListConnections_Success(self):
    """Test ListConnection returns connections when successful."""
    want = [
        self.services_messages.Connection(
            network='projects/%s/global/networks/%s' % (self.PROJECT_NUMBER,
                                                        self.NETWORK),
            peering='servicenetworking-googleapis-com',
            reservedPeeringRanges=['google1', 'google2'])
    ]
    self.ExpectListConnections(self.NETWORK, want)

    got = peering.ListConnections(self.PROJECT_NUMBER, self.service,
                                  self.NETWORK)

    self.assertEqual(got, want)
Exemple #4
0
def CreateValidateVPCHook(ref, args, request):
    """Validates that supplied network has been peered to a GoogleOrganization.

     Uses the Service Networking API to check if the network specified via
     --network flag has been peered to Google Organization. If it has, proceeds
     with TPU create operation otherwise will raise ServiceNetworking exception.
     Check is only valid if --use-service-networking has been specified
     otherwise check will return immediately.

  Args:
    ref: Reference to the TPU Node resource to be created.
    args: Argument namespace.
    request: TPU Create requests message.

  Returns:
    request: Passes requests through if args pass validation

  Raises:
    ServiceNetworkingException: if network is not properly peered
  """
    del ref
    service_networking_enabled = args.use_service_networking
    if service_networking_enabled:
        project = args.project or properties.VALUES.core.project.Get(
            required=True)
        try:
            network_project_number = _ParseProjectNumberFromNetwork(
                args.network, project)

            lookup_result = peering.ListConnections(
                network_project_number, 'servicenetworking.googleapis.com',
                args.network)
        except (exceptions.ListConnectionsPermissionDeniedException,
                apitools_exceptions.HttpError) as e:
            raise ServiceNetworkingException(
                _PROJECT_LOOKUP_ERROR.format(args.network, project, e))

        if not lookup_result:
            raise ServiceNetworkingException(
                _PEERING_VALIDATION_ERROR.format(args.network))

    return request