def test_patch_job(self): project_id = os.environ["PROJECT_ID"] client = OsConfigServiceClient() # ExecutePatchJob request = patch_jobs.ExecutePatchJobRequest( parent=f"projects/{project_id}", description="Python Client Library System Test", instance_filter=patch_jobs.PatchInstanceFilter(all=True), ) patch_job = client.execute_patch_job(request) assert patch_job is not None # GetPatchJob request = patch_jobs.GetPatchJobRequest(name=patch_job.name) patch_job = client.get_patch_job(request) assert patch_job.description == "Python Client Library System Test" # ListPatchJobInstanceDetails request = patch_jobs.ListPatchJobInstanceDetailsRequest(parent=patch_job.name) response = client.list_patch_job_instance_details(request) assert len(response.patch_job_instance_details) >= 0 # CancelPatchJob request = patch_jobs.CancelPatchJobRequest(name=patch_job.name) patch_job = client.cancel_patch_job(request) assert patch_job.state == patch_jobs.PatchJob.State.CANCELED # ListPatchJobs request = patch_jobs.ListPatchJobsRequest(parent=f"projects/{project_id}") response = client.list_patch_jobs(request) assert response.patch_jobs
def execute_patch_job( self, request: patch_jobs.ExecutePatchJobRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> patch_jobs.PatchJob: r"""Patch VM instances by creating and running a patch job. Args: request (:class:`~.patch_jobs.ExecutePatchJobRequest`): The request object. A request message to initiate patching across Compute Engine instances. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.patch_jobs.PatchJob: A high level representation of a patch job that is either in progress or has completed. Instances details are not included in the job. To paginate through instance details, use ListPatchJobInstanceDetails. For more information about patch jobs, see `Creating patch jobs <https://cloud.google.com/compute/docs/os-patch-management/create-patch-job>`__. """ # Create or coerce a protobuf request object. request = patch_jobs.ExecutePatchJobRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.execute_patch_job, default_timeout=None, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) # Done; return the response. return response
def execute_patch_job( self, request: patch_jobs.ExecutePatchJobRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> patch_jobs.PatchJob: r"""Patch VM instances by creating and running a patch job. Args: request (google.cloud.osconfig_v1.types.ExecutePatchJobRequest): The request object. A request message to initiate patching across Compute Engine instances. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.osconfig_v1.types.PatchJob: A high level representation of a patch job that is either in progress or has completed. Instance details are not included in the job. To paginate through instance details, use ListPatchJobInstanceDetails. For more information about patch jobs, see [Creating patch jobs](\ https://cloud.google.com/compute/docs/os-patch-management/create-patch-job). """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a patch_jobs.ExecutePatchJobRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, patch_jobs.ExecutePatchJobRequest): request = patch_jobs.ExecutePatchJobRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ self._transport.execute_patch_job] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response