Google Cloud OS Config Client Library

1.24.0 · active · verified Sun Apr 12

The Google Cloud OS Config client library for Python provides tools to manage operating systems on virtual machine instances, offering functionalities for patch management, patch compliance reporting, and configuration management. Currently at version 1.24.0, it is actively maintained as part of the broader google-cloud-python monorepo, with frequent updates and releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the OS Config client and list patch jobs within a specified Google Cloud project. Ensure your `GCP_PROJECT_ID` environment variable is set and the OS Config API is enabled.

import os
from google.cloud import osconfig_v1

def list_patch_jobs():
    # Set your Google Cloud Project ID as an environment variable or replace 'your-project-id'
    project_id = os.environ.get('GCP_PROJECT_ID', 'your-project-id')
    if project_id == 'your-project-id':
        print("Please set the 'GCP_PROJECT_ID' environment variable or replace 'your-project-id'.")
        return

    client = osconfig_v1.OsConfigServiceClient()
    parent_path = f"projects/{project_id}"

    request = osconfig_v1.ListPatchJobsRequest(
        parent=parent_path,
    )

    try:
        page_result = client.list_patch_jobs(request=request)
        print(f"Patch jobs for project {project_id}:")
        for response in page_result:
            print(f"  - {response.name} (State: {response.state.name})")
    except Exception as e:
        print(f"An error occurred: {e}")
        print("Ensure the OS Config API is enabled for your project and your credentials are set up correctly.")

if __name__ == "__main__":
    list_patch_jobs()

view raw JSON →