def testEnableVpcServiceControls_Success(self): """Test EnableVpcServiceControls returns operation when successful.""" want = self.services_messages.Operation( name=self.OPERATION_NAME, done=False) self.ExpectEnableVpcServiceControls(self.NETWORK, self.OPERATION_NAME) got = peering.EnableVpcServiceControls(self.PROJECT_NUMBER, self.service, self.NETWORK) self.assertEqual(got, want)
def testEnableVpcServiceControls_PermissionDenied(self): """Test EnableVpcServiceControls raises correctly when server returns 403 error.""" server_error = http_error.MakeDetailedHttpError(code=403, message='Error!') self.ExpectEnableVpcServiceControls(self.NETWORK, None, error=server_error) with self.assertRaisesRegex( exceptions.EnableVpcServiceControlsPermissionDeniedException, r'Error!'): peering.EnableVpcServiceControls(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.EnableVpcServiceControls(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)