def Run(self, args): folder_flags.CheckParentFlags(args) project_ref = command_lib_util.ParseProject(args.id) result = projects_api.Update( project_ref, parent=projects_api.ParentNameToResourceId( folder_flags.GetParentFromFlags(args))) log.UpdatedResource(project_ref) return result
def Run(self, args): """Default Run method implementation.""" flags.CheckParentFlags(args, parent_required=False) project_id = args.id if not project_id and args.name: candidate = command_lib_util.IdFromName(args.name) if candidate and console_io.PromptContinue( 'No project id provided.', 'Use [{}] as project id'.format(candidate), throw_if_unattended=True): project_id = candidate if not project_id: raise exceptions.RequiredArgumentException( 'PROJECT_ID', 'an id must be provided for the new project') project_ref = command_lib_util.ParseProject(project_id) labels = labels_util.ParseCreateArgs( args, projects_util.GetMessages().Project.LabelsValue) try: create_op = projects_api.Create( project_ref, display_name=args.name, parent=projects_api.ParentNameToResourceId( flags.GetParentFromFlags(args)), labels=labels) except apitools_exceptions.HttpConflictError: msg = ( 'Project creation failed. The project ID you specified is ' 'already in use by another project. Please try an alternative ' 'ID.') core_exceptions.reraise(exceptions.HttpException(msg)) log.CreatedResource(project_ref, is_async=True) create_op = operations.WaitForOperation(create_op) # Enable cloudapis.googleapis.com if args.enable_cloud_apis: log.debug('Enabling cloudapis.googleapis.com') services_client = apis.GetClientInstance('servicemanagement', 'v1') enable_operation = services_enable_api.EnableServiceApiCall( project_ref.Name(), 'cloudapis.googleapis.com') enable_operation_ref = resources.REGISTRY.Parse( enable_operation.name, collection='servicemanagement.operations') services_util.WaitForOperation(enable_operation_ref, services_client) if args.set_as_default: project_property = properties.FromString('core/project') properties.PersistProperty(project_property, project_id) log.status.Print( 'Updated property [core/project] to [{0}].'.format(project_id)) return operations.ExtractOperationResponse( create_op, apis.GetMessagesModule('cloudresourcemanager', 'v1').Project)
def Run(self, args): """Run the list command.""" flags.CheckParentFlags(args) return list_pager.YieldFromList( folders.FoldersService(), folders.FoldersMessages().CloudresourcemanagerFoldersListRequest( parent=flags.GetParentFromFlags(args)), limit=args.limit, batch_size_attribute='pageSize', batch_size=args.page_size, field='folders')
def Run(self, args): flags.CheckParentFlags(args) messages = folders.FoldersMessages() operation = folders.FoldersService().Create( messages.CloudresourcemanagerFoldersCreateRequest( parent=flags.GetParentFromFlags(args), folder=messages.Folder(displayName=args.display_name))) if args. async: return operation else: finished_operation = operations.WaitForOperation(operation) result = operations.ExtractOperationResponse( finished_operation, messages.Folder) log.CreatedResource(result)
def Run(self, args): flags.CheckParentFlags(args) messages = folders.FoldersMessages() move_request = messages.CloudresourcemanagerFoldersMoveRequest( foldersId=args.id, moveFolderRequest=messages.MoveFolderRequest( destinationParent=flags.GetParentFromFlags(args))) operation = folders.FoldersService().Move(move_request) if args. async: return operation else: finished_op = operations.WaitForOperation(operation) result = operations.ExtractOperationResponse( finished_op, messages.Folder) log.UpdatedResource(result)
def Run(self, args): folder_flags.CheckParentFlags(args) project_ref = command_lib_util.ParseProject(args.id) if not console_io.PromptContinue( 'Your project will be moved. This may alter the policies enforced on ' 'your Project, either exposing your Project to more security risk ' 'through looser polices or cause an outage through stricter polices. ' 'See these public notes on policy implications for more information: ' 'https://cloud.google.com/resource-manager/docs/' 'creating-managing-folders#moving-folders-policy-considerations and ' 'https://cloud.google.com/resource-manager/docs/' 'migrating-projects-billing#note_on_policy_implications. ' 'Once moved, you can move the Project again so long as you have the ' 'appropriate permissions. See our public documentation for more ' 'information: https://cloud.google.com/resource-manager/docs/' 'creating-managing-folders#moving_a_project_into_a_folder'): return None result = projects_api.Update( project_ref, parent=projects_api.ParentNameToResourceId( folder_flags.GetParentFromFlags(args))) log.UpdatedResource(project_ref) return result
def Run(self, args): flags.CheckParentFlags(args, parent_required=False) project_ref = command_lib_util.ParseProject(args.id) try: create_op = projects_api.Create( project_ref, display_name=args.name, parent=projects_api.ParentNameToResourceId( flags.GetParentFromFlags(args)), update_labels=labels_util.GetUpdateLabelsDictFromArgs(args)) except apitools_exceptions.HttpError as error: if error.status_code == httplib.CONFLICT: msg = ( 'Project creation failed. The project ID you specified is ' 'already in use by another project. Please try an alternative ' 'ID.') unused_type, unused_value, traceback = sys.exc_info() raise exceptions.HttpException, msg, traceback raise log.CreatedResource(project_ref, async=True) create_op = operations.WaitForOperation(create_op) # Enable cloudapis.googleapis.com if args.enable_cloud_apis: log.debug('Enabling cloudapis.googleapis.com') services_client = apis.GetClientInstance('servicemanagement', 'v1') enable_operation = services_enable_api.EnableServiceApiCall( project_ref.Name(), 'cloudapis.googleapis.com') services_util.WaitForOperation(enable_operation.name, services_client) # TODO(user): Retry in case it failed? return operations.ExtractOperationResponse( create_op, apis.GetMessagesModule('cloudresourcemanager', 'v1').Project)