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. """ wp_region = args.region release_track = self.ReleaseTrack() client = cloudbuild_util.GetClientInstance(release_track, region=wp_region) messages = cloudbuild_util.GetMessagesModule(release_track) 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.locations.workerPools', api_version=cloudbuild_util. RELEASE_TRACK_TO_API_VERSION[release_track], params={ 'projectsId': parent, 'locationsId': wp_region, 'workerPoolsId': wp_name, }) # Send the Get request wp = client.projects_locations_workerPools.Get( messages.CloudbuildProjectsLocationsWorkerPoolsGetRequest( name=wp_resource.RelativeName())) # Format the workerpool name for display try: wp.name = cloudbuild_util.RegionalWorkerPoolShortName(wp.name) except ValueError: pass # Must be an old version. 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. """ wp_region = args.region release_track = self.ReleaseTrack() client = cloudbuild_util.GetClientInstance(release_track, region=wp_region) messages = cloudbuild_util.GetMessagesModule(release_track) parent = properties.VALUES.core.project.Get(required=True) # Get the parent project ref parent_resource = resources.REGISTRY.Create( collection='cloudbuild.projects.locations', projectsId=parent, locationsId=wp_region) # Send the List request wp_list = client.projects_locations_workerPools.List( messages.CloudbuildProjectsLocationsWorkerPoolsListRequest( parent=parent_resource.RelativeName())).workerPools # Format the workerpool names for display for wp in wp_list: try: wp.name = cloudbuild_util.RegionalWorkerPoolShortName(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. """ wp_region = args.region release_track = self.ReleaseTrack() client = cloudbuild_util.GetClientInstance(release_track, region=wp_region) messages = cloudbuild_util.GetMessagesModule(release_track) # 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.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 parent = properties.VALUES.core.project.Get(required=True) # Get the parent project.location ref parent_resource = resources.REGISTRY.Create( collection='cloudbuild.projects.locations', projectsId=parent, locationsId=wp_region) # Send the Create request created_op = client.projects_locations_workerPools.Create( messages.CloudbuildProjectsLocationsWorkerPoolsCreateRequest( workerPool=wp, parent=parent_resource.RelativeName(), workerPoolId=wp.name)) raw_dict = encoding.MessageToDict(created_op.response) created_wp = encoding.DictToMessage(raw_dict, messages.WorkerPool) # Get the workerpool ref wp_resource = resources.REGISTRY.Parse( None, collection='cloudbuild.projects.locations.workerPools', api_version=cloudbuild_util. RELEASE_TRACK_TO_API_VERSION[release_track], params={ 'projectsId': parent, 'locationsId': wp_region, 'workerPoolsId': created_wp.name, }) log.CreatedResource(wp_resource) # Format the workerpool name for display try: created_wp.name = cloudbuild_util.RegionalWorkerPoolShortName( created_wp.name) except ValueError: pass # Must be an old version. return created_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. """ wp_region = args.region release_track = self.ReleaseTrack() client = cloudbuild_util.GetClientInstance(release_track) messages = cloudbuild_util.GetMessagesModule(release_track) 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.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) if args.no_external_ip: worker_config.noExternalIp = True wp.workerConfig = worker_config # Get the workerpool ref wp_resource = resources.REGISTRY.Parse( None, collection='cloudbuild.projects.locations.workerPools', api_version=cloudbuild_util. RELEASE_TRACK_TO_API_VERSION[release_track], params={ 'projectsId': parent, 'locationsId': wp_region, 'workerPoolsId': wp.name, }) update_mask = cloudbuild_util.MessageToFieldPaths(wp) req = messages.CloudbuildProjectsLocationsWorkerPoolsPatchRequest( name=wp_resource.RelativeName(), workerPool=wp, updateMask=','.join(update_mask)) # Send the Update request updated_op = client.projects_locations_workerPools.Patch(req) op_resource = resources.REGISTRY.ParseRelativeName( updated_op.name, collection='cloudbuild.projects.locations.operations') updated_wp = waiter.WaitFor( waiter.CloudOperationPoller(client.projects_locations_workerPools, client.projects_locations_operations), op_resource, 'Updating worker pool') log.UpdatedResource(wp_resource) # Format the workerpool name for display try: updated_wp.name = cloudbuild_util.RegionalWorkerPoolShortName( updated_wp.name) except ValueError: pass # Must be an old version. return updated_wp
def testInvalid(self): with self.assertRaisesRegex(ValueError, '.*'): cloudbuild_util.RegionalWorkerPoolShortName('badresource')
def testValid(self): self.assertEqual( cloudbuild_util.RegionalWorkerPoolShortName( 'projects/abc/locations/def/workerPools/ghi'), 'ghi')