### Install naapi from GitHub Source: https://github.com/netactuate/naapi/blob/master/README.md Clone the naapi repository from GitHub and install it locally. ```bash git clone git@github.com:netactuate/naapi cd naapi python setup.py install ``` -------------------------------- ### Install naapi using pip Source: https://github.com/netactuate/naapi/blob/master/README.md Install the naapi package from PyPI using pip. ```bash pip install naapi ``` -------------------------------- ### Fetch Servers using Standard API Source: https://github.com/netactuate/naapi/blob/master/README.md Example demonstrating how to fetch server information using the synchronous naapi.api client. Ensure the NETACTUATE_API_KEY environment variable is set. ```python #!/usr/bin/env python import os import sys import pprint as pp import naapi.api as api API_KEY = os.getenv('NETACTUATE_API_KEY') def main(): """Basic main""" conn = api.NetActuateNodeDriver(API_KEY) servers = conn.servers().json() pp.pprint(servers) if __name__ == '__main__': main() ``` -------------------------------- ### Fetch Servers using Asyncio API Source: https://github.com/netactuate/naapi/blob/master/README.md Example demonstrating how to fetch server information using the asynchronous naapi.aioapi client. Ensure the NETACTUATE_API_KEY environment variable is set. ```python #!/usr/bin/env python import os import sys import asyncio import naapi.aioapi as api API_KEY = os.getenv('NETACTUATE_API_KEY') async def main(): """Basic Main""" conn = api.NetActuateNodeDriver(API_KEY) servers = await conn.servers() print(servers) asyncio.run(main()) ``` -------------------------------- ### Get Server Summary and Status Source: https://context7.com/netactuate/naapi/llms.txt Retrieves detailed summary information and current operational status for a specific server. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Get server summary summary = conn.summary(mbpkgid).json() # Returns: {"mbpkgid": 12345, "hostname": "server1", "ram": 1024, "cpu": 1, ...} # Get server status status = conn.status(mbpkgid).json() # Returns: {"status": "running", "uptime": 86400, ...} ``` -------------------------------- ### Server Power Operations API Source: https://context7.com/netactuate/naapi/llms.txt Provides functionality to start, gracefully shut down, or reboot server instances. A force parameter can be used for shutdown. ```APIDOC ## Server Power Operations Start, shutdown, and reboot server instances with optional force parameter. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Start a server result = conn.start(mbpkgid).json() # Returns: {"success": true, "job_id": 67890, ...} # Graceful shutdown result = conn.shutdown(mbpkgid).json() ``` ``` -------------------------------- ### Get Bandwidth Report Source: https://context7.com/netactuate/naapi/llms.txt Retrieves the monthly bandwidth usage report for a specific server. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 bw_report = conn.bandwidth_report(mbpkgid).json() # Returns: {"total_in": 1073741824, "total_out": 2147483648, "month": "2024-01", ...} ``` -------------------------------- ### Server Power Operations Source: https://context7.com/netactuate/naapi/llms.txt Controls server power states: start, graceful shutdown, and reboot. An optional force parameter can be used for shutdown. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Start a server result = conn.start(mbpkgid).json() # Returns: {"success": true, "job_id": 67890, ...} # Graceful shutdown result = conn.shutdown(mbpkgid).json() ``` -------------------------------- ### Get IP Addresses Source: https://context7.com/netactuate/naapi/llms.txt Retrieves IPv4, IPv6, or all network IP addresses assigned to a specific server. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Get IPv4 addresses ipv4_list = conn.ipv4(mbpkgid).json() # Returns: [{"ip": "192.168.1.1", "netmask": "255.255.255.0", ...}, ...] # Get IPv6 addresses ipv6_list = conn.ipv6(mbpkgid).json() # Returns: [{"ip": "2001:db8::1", "prefix": 64, ...}, ...] # Get all network IPs all_ips = conn.networkips(mbpkgid).json() ``` -------------------------------- ### Get IP Addresses API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves IPv4 and IPv6 addresses assigned to a specific server, or all network IP addresses for the server. ```APIDOC ## Get IP Addresses Retrieves IPv4 and IPv6 addresses assigned to a specific server, or all network IPs. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Get IPv4 addresses ipv4_list = conn.ipv4(mbpkgid).json() # Returns: [{"ip": "192.168.1.1", "netmask": "255.255.255.0", ...}, ...] # Get IPv6 addresses ipv6_list = conn.ipv6(mbpkgid).json() # Returns: [{"ip": "2001:db8::1", "prefix": 64, ...}, ...] # Get all network IPs all_ips = conn.networkips(mbpkgid).json() ``` ``` -------------------------------- ### Purchase and Build Server Source: https://context7.com/netactuate/naapi/llms.txt Buy a new plan and provision a server in one operation. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # Buy a plan result = conn.buy(plan='small').json() # Returns: {"success": true, "mbpkgid": 12346, ...} # Buy and build in one operation params = { 'plan': 'small', 'location': 1, 'image': 'ubuntu-20.04', 'fqdn': 'newserver.example.com', 'password': 'SecurePassword123!' } result = conn.buy_build(params).json() # Returns: {"success": true, "mbpkgid": 12346, "job_id": 67891, ...} ``` -------------------------------- ### Provision New Server Source: https://context7.com/netactuate/naapi/llms.txt Deploy a new server instance by specifying the image, hostname, and location. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) result = conn.build( site=1, # Location ID image='ubuntu-20.04', # OS image identifier fqdn='myserver.example.com', # Fully qualified domain name passwd='SecurePassword123!', # Root password mbpkgid=12345 # Package ID to build on ).json() # Returns: {"success": true, "job_id": 67890, "mbpkgid": 12345, ...} ``` -------------------------------- ### List OS Images Source: https://context7.com/netactuate/naapi/llms.txt Retrieves all available operating system images for server creation. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) images = conn.os_list().json() # Returns: {"centos-7": {"name": "CentOS 7", ...}, "ubuntu-20.04": {"name": "Ubuntu 20.04", ...}, ...} ``` -------------------------------- ### List Plans (Sizes) Source: https://context7.com/netactuate/naapi/llms.txt Retrieves available server plans or sizes, with an option to filter by location ID. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # Get all plans all_plans = conn.plans().json() # Get plans for a specific location location_plans = conn.plans(location=1).json() # Returns: [{"id": "small", "ram": 1024, "cpu": 1, "disk": 20, ...}, ...] ``` -------------------------------- ### List Plans (Sizes) API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves available server plans or sizes, with an option to filter by location. ```APIDOC ## List Plans (Sizes) Retrieves available server plans/sizes, optionally filtered by location. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # Get all plans all_plans = conn.plans().json() # Get plans for a specific location location_plans = conn.plans(location=1).json() # Returns: [{"id": "small", "ram": 1024, "cpu": 1, "disk": 20, ...}, ...] ``` ``` -------------------------------- ### List OS Images API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves a list of all available operating system images that can be used for creating new servers. ```APIDOC ## List OS Images Retrieves all available operating system images that can be used when building new servers. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) images = conn.os_list().json() # Returns: {"centos-7": {"name": "CentOS 7", ...}, "ubuntu-20.04": {"name": "Ubuntu 20.04", ...}, ...} ``` ``` -------------------------------- ### List Servers Source: https://context7.com/netactuate/naapi/llms.txt Retrieves all cloud servers or details for a specific server using its package ID (mbpkgid). ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # List all servers servers = conn.servers().json() # Returns: [{"mbpkgid": 12345, "hostname": "server1.example.com", "status": "running", ...}, ...] # Get specific server details server = conn.servers(mbpkgid=12345).json() # Returns: {"mbpkgid": 12345, "hostname": "server1.example.com", "ip": "192.168.1.1", ...} ``` -------------------------------- ### Configure Rescue Mode Source: https://context7.com/netactuate/naapi/llms.txt Toggle rescue mode for system recovery using a temporary password. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Start rescue mode with password result = conn.rescue(mbpkgid, password='TempRescuePass123').json() # Returns: {"success": true, "rescue_ip": "192.168.1.100", ...} # Stop rescue mode and boot normally result = conn.rescue_stop(mbpkgid).json() ``` -------------------------------- ### Manage Server Power States Source: https://context7.com/netactuate/naapi/llms.txt Perform power operations such as shutdown and reboot on a server instance. ```python # Force shutdown result = conn.shutdown(mbpkgid, force=True).json() # Graceful reboot result = conn.reboot(mbpkgid).json() # Force reboot result = conn.reboot(mbpkgid, force=True).json() ``` -------------------------------- ### List Packages Source: https://context7.com/netactuate/naapi/llms.txt Retrieves cloud packages (billing units) associated with the account, or details for a specific package. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # List all packages packages = conn.packages().json() # Get specific package details package = conn.packages(mbpkgid=12345).json() # Returns: {"mbpkgid": 12345, "plan": "small", "status": "active", ...} ``` -------------------------------- ### Initialize NetActuateNodeDriver Source: https://context7.com/netactuate/naapi/llms.txt Initializes the driver for interacting with the NetActuate API. Requires an API key and optionally accepts an API version. ```python import os import naapi.api as api API_KEY = os.getenv('NETACTUATE_API_KEY') # Initialize the driver with default API version (v1) conn = api.NetActuateNodeDriver(API_KEY) # Initialize with specific API version conn = api.NetActuateNodeDriver(API_KEY, api_version='v1') ``` -------------------------------- ### NetActuateNodeDriver Initialization Source: https://context7.com/netactuate/naapi/llms.txt Initializes the NetActuateNodeDriver for interacting with the NetActuate API. Requires an API key and optionally accepts an API version. ```APIDOC ## NetActuateNodeDriver Initialization The main driver class that establishes a connection to the NetActuate API. Requires an API key for authentication and optionally accepts an API version parameter (defaults to 'v1'). ```python import os import naapi.api as api API_KEY = os.getenv('NETACTUATE_API_KEY') # Initialize the driver with default API version (v1) conn = api.NetActuateNodeDriver(API_KEY) # Initialize with specific API version conn = api.NetActuateNodeDriver(API_KEY, api_version='v1') ``` ``` -------------------------------- ### Delete and Cancel Server Billing Source: https://context7.com/netactuate/naapi/llms.txt Remove server instances and manage associated billing packages. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Delete server (keeps billing active) result = conn.delete(mbpkgid).json() # Delete server and cancel billing result = conn.delete(mbpkgid, extra_params={'cancel_billing': True}).json() # Unlink server from package result = conn.unlink(mbpkgid).json() # Cancel package billing result = conn.cancel(mbpkgid).json() ``` -------------------------------- ### List Locations Source: https://context7.com/netactuate/naapi/llms.txt Retrieves all available data center locations, parsing country information from the location name. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) locations = conn.locations().json() # Returns: [{"id": 1, "name": "Los Angeles, US", "country": "US", ...}, ...] for loc in locations: print(f"Location: {loc['name']} - Country: {loc['country']}") ``` -------------------------------- ### List Servers API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves a list of all cloud servers associated with the account or details for a specific server using its package ID (mbpkgid). ```APIDOC ## List Servers Retrieves all cloud servers associated with your account, or details for a specific server when providing an mbpkgid (server package ID). ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # List all servers servers = conn.servers().json() # Returns: [{"mbpkgid": 12345, "hostname": "server1.example.com", "status": "running", ...}, ...] # Get specific server details server = conn.servers(mbpkgid=12345).json() # Returns: {"mbpkgid": 12345, "hostname": "server1.example.com", "ip": "192.168.1.1", ...} ``` ``` -------------------------------- ### List Packages API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves cloud packages (billing/subscription units) associated with the user's account, or details for a specific package by its ID. ```APIDOC ## List Packages Retrieves cloud packages (billing/subscription units) associated with your account. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) # List all packages packages = conn.packages().json() # Get specific package details package = conn.packages(mbpkgid=12345).json() # Returns: {"mbpkgid": 12345, "plan": "small", "status": "active", ...} ``` ``` -------------------------------- ### Manage BGP Sessions Source: https://context7.com/netactuate/naapi/llms.txt Configure and retrieve BGP session information for networking. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Get all BGP sessions sessions = conn.bgp_sessions().json() # Get specific BGP session session = conn.bgp_sessions(session_id=100).json() # Returns: {"id": 100, "asn": 65000, "status": "established", ...} # Get BGP summary summary = conn.bgp_summary().json() # Returns: {"total_sessions": 5, "established": 4, "idle": 1, ...} # Create BGP sessions for a server result = conn.bgp_create_sessions( mbpkgid=mbpkgid, group_id=10, ipv6=True, redundant=True ).json() # Returns: {"success": true, "sessions": [{"id": 101, ...}, {"id": 102, ...}], ...} ``` -------------------------------- ### Server Summary and Status API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves detailed summary information and the current operational status for a specific server. ```APIDOC ## Server Summary and Status Retrieves detailed summary information and current status for a server. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 # Get server summary summary = conn.summary(mbpkgid).json() # Returns: {"mbpkgid": 12345, "hostname": "server1", "ram": 1024, "cpu": 1, ...} # Get server status status = conn.status(mbpkgid).json() # Returns: {"status": "running", "uptime": 86400, ...} ``` ``` -------------------------------- ### Bandwidth Report API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves the monthly bandwidth usage report for a specified server. ```APIDOC ## Bandwidth Report Retrieves monthly bandwidth usage report for a specific server. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 bw_report = conn.bandwidth_report(mbpkgid).json() # Returns: {"total_in": 1073741824, "total_out": 2147483648, "month": "2024-01", ...} ``` ``` -------------------------------- ### List Locations API Source: https://context7.com/netactuate/naapi/llms.txt Retrieves a list of all available data center locations, including country information parsed from the location name. ```APIDOC ## List Locations Retrieves all available data center locations with country information automatically parsed from the location name. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) locations = conn.locations().json() # Returns: [{"id": 1, "name": "Los Angeles, US", "country": "US", ...}, ...] for loc in locations: print(f"Location: {loc['name']} - Country: {loc['country']}") ``` ``` -------------------------------- ### Asynchronous API Usage Source: https://context7.com/netactuate/naapi/llms.txt Utilize the asyncio module for non-blocking API requests and concurrent operations. ```python import os import json import asyncio from naapi.aioapi import NetActuateNodeDriver API_KEY = os.getenv('NETACTUATE_API_KEY') async def main(): conn = NetActuateNodeDriver(API_KEY) # List servers asynchronously servers = json.loads(await conn.servers()) print(f"Found {len(servers)} servers") if servers: server = servers[0] mbpkgid = server['mbpkgid'] # Get server details concurrently locations_task = conn.locations() summary_task = conn.summary(mbpkgid) bw_task = conn.bandwidth_report(mbpkgid) locations, summary, bw_report = await asyncio.gather( locations_task, summary_task, bw_task ) print(f"Locations: {json.loads(locations)}") print(f"Summary: {json.loads(summary)}") print(f"Bandwidth: {json.loads(bw_report)}") asyncio.run(main()) ``` -------------------------------- ### Track Asynchronous Job Status Source: https://context7.com/netactuate/naapi/llms.txt Uses HVJobStatus to poll for the completion of a build operation. Requires an active connection and a valid job ID from the initial request. ```python import asyncio import json from naapi.aioapi import NetActuateNodeDriver, HVJobStatus async def build_and_wait(conn, mbpkgid, build_params): # Start a build operation result = json.loads(await conn.build(**build_params)) # Create job status tracker job_status = HVJobStatus( conn=conn, node_id=mbpkgid, job_result={'id': result['job_id']} ) # Poll until job completes while await job_status.is_working(): print(f"Job {await job_status.job_id()} status: {await job_status.status()}") await asyncio.sleep(10) await job_status.refresh() if await job_status.is_success(): print("Build completed successfully!") elif await job_status.is_failure(): print("Build failed!") return job_status asyncio.run(build_and_wait(conn, 12345, { 'site': 1, 'image': 'ubuntu-20.04', 'fqdn': 'myserver.example.com', 'passwd': 'SecurePassword123!', 'mbpkgid': 12345 })) ``` -------------------------------- ### Track Job Status Source: https://context7.com/netactuate/naapi/llms.txt Monitor the progress of asynchronous operations using job identifiers. ```python import naapi.api as api conn = api.NetActuateNodeDriver(API_KEY) mbpkgid = 12345 job_id = 67890 # Get specific job status job = conn.get_job(mbpkgid, job_id).json() # Returns: {"id": 67890, "status": 5, "command": "build", "ts_insert": "2024-01-01 12:00:00", ...} # Status codes: 1-3 = working, 5 = success, 6 = failure # Get all jobs for a server jobs = conn.get_jobs(mbpkgid).json() # Returns: [{"id": 67890, "status": 5, ...}, {"id": 67889, "status": 5, ...}, ...] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.