def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ client = cloudbuild_util.GetClientInstanceAlpha() messages = cloudbuild_util.GetMessagesModuleAlpha() parent = properties.VALUES.core.project.Get(required=True) wp_name = args.WORKER_POOL # Get the workerpool ref wp_resource = resources.REGISTRY.Parse( None, collection='cloudbuild.projects.workerPools', api_version='v1alpha1', params={ 'projectsId': parent, 'workerPoolsId': wp_name, }) # Send the Get request wp = client.projects_workerPools.Get( messages.CloudbuildProjectsWorkerPoolsGetRequest( name=wp_resource.RelativeName())) return wp
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ client = cloudbuild_util.GetClientInstanceAlpha() messages = cloudbuild_util.GetMessagesModuleAlpha() parent = properties.VALUES.core.project.Get(required=True) # Get the parent project ref parent_resource = resources.REGISTRY.Create( collection='cloudbuild.projects', projectId=parent) # Send the List request wp_list = client.projects_workerPools.List( messages.CloudbuildProjectsWorkerPoolsListRequest( parent=parent_resource.RelativeName())).workerPools # Format the workerpool names for display for wp in wp_list: try: wp.name = cloudbuild_util.WorkerPoolShortName(wp.name) except ValueError: pass # Must be an old version. return wp_list
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ client = cloudbuild_util.GetClientInstanceAlpha() messages = cloudbuild_util.GetMessagesModuleAlpha() parent = properties.VALUES.core.project.Get(required=True) # Get the parent project ref parent_resource = resources.REGISTRY.Create( collection='cloudbuild.projects', projectId=parent) # Send the List request return client.projects_workerPools.List( messages.CloudbuildProjectsWorkerPoolsListRequest( parent=parent_resource.RelativeName())).workerPools
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ client = cloudbuild_util.GetClientInstanceAlpha() messages = cloudbuild_util.GetMessagesModuleAlpha() parent = properties.VALUES.core.project.Get(required=True) # Get the workerpool proto from either the flags or the specified file. wp = messages.WorkerPool() if args.config_from_file is not None: wp = workerpool_config.LoadWorkerpoolConfigFromPath( args.config_from_file, messages) else: wp.name = args.WORKER_POOL if args.worker_count is not None: try: wp.workerCount = int(args.worker_count) except ValueError as e: raise c_exceptions.InvalidArgumentException( '--worker-count', e) if args.remove_regions is not None: regions_to_remove = set() for region_str in args.remove_regions: region = Update._region_choice_to_enum[region_str] regions_to_remove.add(region) new_regions = [] for region in wp.regions: if region not in regions_to_remove: new_regions.append(region) wp.regions[:] = new_regions if args.clear_regions: wp.regions[:] = [] if args.add_regions is not None: for region_str in args.add_regions: region = Update._region_choice_to_enum[region_str] wp.regions.append(region) worker_config = messages.WorkerConfig() if args.worker_machine_type is not None: worker_config.machineType = args.worker_machine_type if args.worker_disk_size is not None: worker_config.diskSizeGb = compute_utils.BytesToGb( args.worker_disk_size) if any([ args.worker_network_project is not None, args.worker_network_name is not None, args.worker_network_subnet is not None ]): if not all([ args.worker_network_project is not None, args.worker_network_name is not None, args.worker_network_subnet is not None ]): raise c_exceptions.RequiredArgumentException( '--worker_network_*', 'The flags --worker_network_project, --worker_network_name, and ' '--worker_network_subnet must all be set if any of them are set.' ) # At this point all network flags are set, but not necessarily truthy network = messages.Network() if args.worker_network_project: network.projectId = args.worker_network_project else: network.projectId = parent if args.worker_network_name: network.network = args.worker_network_name else: network.network = 'default' if args.worker_network_subnet: network.subnetwork = args.worker_network_subnet else: network.subnetwork = 'default' worker_config.network = network if args.worker_tag is not None: worker_config.tag = args.worker_tag wp.workerConfig = worker_config # Get the workerpool ref wp_resource = resources.REGISTRY.Parse( None, collection='cloudbuild.projects.workerPools', api_version='v1alpha1', params={ 'projectsId': parent, 'workerPoolsId': wp.name, }) # Send the Update request updated_wp = client.projects_workerPools.Patch( messages.CloudbuildProjectsWorkerPoolsPatchRequest( name=wp_resource.RelativeName(), workerPool=wp)) log.UpdatedResource(wp_resource) return updated_wp
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. """ client = cloudbuild_util.GetClientInstanceAlpha() messages = cloudbuild_util.GetMessagesModuleAlpha() parent = properties.VALUES.core.project.Get(required=True) # Get the workerpool proto from either the flags or the specified file. wp = messages.WorkerPool() if args.config_from_file is not None: wp = workerpool_config.LoadWorkerpoolConfigFromPath( args.config_from_file, messages) else: wp.name = args.WORKER_POOL if args.region is not None: wp.region = args.region if args.peered_network is not None: network_config = messages.NetworkConfig() network_config.peeredNetwork = args.peered_network wp.networkConfig = network_config worker_config = messages.WorkerConfig() if args.worker_machine_type is not None: worker_config.machineType = args.worker_machine_type if args.worker_disk_size is not None: worker_config.diskSizeGb = compute_utils.BytesToGb( args.worker_disk_size) wp.workerConfig = worker_config # Get the workerpool ref wp_resource = resources.REGISTRY.Parse( None, collection='cloudbuild.projects.workerPools', api_version='v1alpha2', params={ 'projectsId': parent, 'workerPoolsId': wp.name, }) update_mask = cloudbuild_util.MessageToFieldPaths(wp) req = messages.CloudbuildProjectsWorkerPoolsPatchRequest( name=wp_resource.RelativeName(), workerPool=wp, updateMask=','.join(update_mask)) # Send the Update request updated_wp = client.projects_workerPools.Patch(req) log.UpdatedResource(wp_resource) # Format the workerpool name for display try: updated_wp.name = cloudbuild_util.WorkerPoolShortName( updated_wp.name) except ValueError: pass # Must be an old version. return updated_wp