{"library":"python-libmaas","title":"MAAS Client Library","description":"A client API library for interacting with MAAS (Metal as a Service). It provides a programmatic interface to manage MAAS resources like machines, networks, and storage. Currently at version 0.6.8, it has a release cadence of a few releases per year, primarily for bug fixes and minor enhancements.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install python-libmaas"],"cli":null},"imports":["from maas.client import MaasClient","from maas.client.enum import LinkMode"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom maas.client import MaasClient\nfrom maas.client.enum import LinkMode # Example: for network configuration\n\n# Configure MAAS connection from environment variables or provide directly\nMAAS_URL = os.environ.get(\"MAAS_URL\", \"https://your.maas.server:5240/MAAS\")\nMAAS_API_KEY = os.environ.get(\"MAAS_API_KEY\", \"your-maas-api-key\")\n\nif \"your-maas-api-key\" in MAAS_API_KEY:\n    print(\"Warning: Please set the MAAS_API_KEY environment variable or replace 'your-maas-api-key'.\")\nif \"your.maas.server\" in MAAS_URL:\n    print(\"Warning: Please set the MAAS_URL environment variable or replace 'your.maas.server'.\")\n\ntry:\n    # Initialize the client\n    client = MaasClient(MAAS_URL, api_key=MAAS_API_KEY)\n    \n    # Connect to the MAAS API\n    maas = client.connect()\n\n    # Example: List all machines\n    print(\"Fetching machines...\")\n    machines = maas.machines.list()\n    if machines:\n        print(f\"Found {len(machines)} machines:\")\n        for machine in machines[:3]: # Print details for up to 3 machines\n            print(f\"  - Hostname: {machine.hostname}, Status: {machine.status}, ID: {machine.system_id}\")\n            if machine.ip_addresses:\n                print(f\"    IPs: {[ip.ip for ip in machine.ip_addresses]}\")\n            else:\n                print(\"    No IP addresses found.\")\n    else:\n        print(\"No machines found in MAAS.\")\n\n    # Example: Get a specific machine (uncomment and replace with a known system_id)\n    # machine_id = \"your_machine_system_id\" \n    # if machine_id != \"your_machine_system_id\":\n    #     try:\n    #         specific_machine = maas.machines.get(system_id=machine_id)\n    #         print(f\"\\nDetails for machine {machine_id}: {specific_machine.hostname}, {specific_machine.status}\")\n    #     except Exception as e:\n    #         print(f\"\\nCould not fetch machine {machine_id}: {e}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"Demonstrates connecting to a MAAS server using an API key and listing available machines. Uses environment variables for sensitive connection details and provides basic error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}