示例#1
0
  def testDisableVpcServiceControls_Success(self):
    """Test DisableVpcServiceControls returns operation when successful."""
    want = self.services_messages.Operation(
        name=self.OPERATION_NAME, done=False)
    self.ExpectDisableVpcServiceControls(self.NETWORK, self.OPERATION_NAME)

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

    self.assertEqual(got, want)
示例#2
0
  def testDisableVpcServiceControls_PermissionDenied(self):
    """Test DisableVpcServiceControls raises correctly when server returns 403 error."""
    server_error = http_error.MakeDetailedHttpError(code=403, message='Error!')
    self.ExpectDisableVpcServiceControls(self.NETWORK, None, error=server_error)

    with self.assertRaisesRegex(
        exceptions.DisableVpcServiceControlsPermissionDeniedException,
        r'Error!'):
      peering.DisableVpcServiceControls(self.PROJECT_NUMBER, self.service,
                                        self.NETWORK)
  def Run(self, args):
    """Run 'services vpc-peerings enable-vpc-service-controls'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.
    """
    project = properties.VALUES.core.project.Get(required=True)
    project_number = _GetProjectNumber(project)
    op = peering.DisableVpcServiceControls(project_number, args.service,
                                           args.network)
    if args.async_:
      cmd = OP_WAIT_CMD.format(op.name)
      log.status.Print('Asynchronous operation is in progress... '
                       'Use the following command to wait for its '
                       'completion:\n {0}'.format(cmd))
      return
    op = services_util.WaitOperation(op.name, peering.GetOperation)
    services_util.PrintOperation(op)