def SetUp(self): self.name_generator = e2e_utils.GetResourceNameGenerator('sdk-e2e') project_name = next(self.name_generator) self.project_id = command_lib_util.IdFromName(project_name) self.project_ref = command_lib_util.ParseProject(self.project_id) create_op = projects_api.Create( self.project_ref, parent=projects_api.ParentNameToResourceId( CLOUD_SDK_TESTING_FOLDER_ID)) log.CreatedResource(self.project_ref, is_async=True) operations.WaitForOperation(create_op) log.debug('Enabling cloudapis.googleapis.com') services_enable_api.EnableService(self.project_ref.Name(), 'cloudapis.googleapis.com') self.Run('services enable cloudbilling') self.Run(('alpha billing accounts projects link {project} ' '--account-id={billing}').format(project=self.project_id, billing=self.BillingId())) self.Run('projects add-iam-policy-binding {project} ' '--member="group:[email protected]" ' '--role="roles/owner"'.format(project=self.project_id)) properties.VALUES.core.disable_prompts.Set(True) # This is set to false by sdk_test_base.SdkBase. properties.VALUES.core.should_prompt_to_enable_api.Set(True) # The api enablement check will prompt, and this will inject a yes into that self.StartPatch( 'googlecloudsdk.core.console.console_io.PromptContinue', return_value=True)
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): 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)