### Getting Started with Intersight Python SDK Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/00-START-HERE.txt This section covers the essential steps to get started with the Intersight Python SDK, including installation, API key generation, client setup with authentication, and making your first API calls. ```APIDOC ## Getting Started ### Overview This guide provides instructions for installation, API key generation, client setup with authentication, and making your first API calls using the Intersight Python SDK. ### Key Topics Covered - Installation instructions - API key generation - Client setup with authentication - First API calls (CRUD operations) - Debugging and error handling - Troubleshooting ### Recommended Reading - **QUICK-START.md**: For hands-on setup and first API calls. ``` -------------------------------- ### Install Intersight SDK from Source Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Installs the Intersight Python SDK by cloning the repository and running the setup script. This method is useful for development or when needing the latest unreleased changes. ```bash git clone https://github.com/CiscoDevNet/intersight-python.git python intersight-python/setup.py install ``` -------------------------------- ### Basic API Client Initialization with API Key Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-client.md Demonstrates how to create an API client using basic configuration and API key authentication. This is the simplest way to get started with the Intersight API. ```python import intersight # Create configuration with API key authentication config = intersight.Configuration(host="https://intersight.com") # Create API client api_client = intersight.ApiClient(config) # Create specific API instance and make requests from intersight.api import boot_api boot_api_instance = boot_api.BootApi(api_client) ``` -------------------------------- ### List Response Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Demonstrates how to retrieve a paginated list of boot precision policies and access the results, total count, skip, and top values. ```APIDOC ## GET /boot/precision/policy/list ### Description Retrieves a paginated list of boot precision policies. ### Method GET ### Endpoint /boot/precision/policy/list ### Parameters #### Query Parameters - **top** (int) - Optional - Maximum number of items to return. - **skip** (int) - Optional - Number of items to skip from the beginning. - **count** (bool) - Optional - Whether to return the total count of items. ### Response #### Success Response (200) - **results** (list[BootPrecisionPolicy]) - List of boot precision policy objects. - **count** (int) - Total number of items available. - **skip** (int) - The skip value used in the request. - **top** (int) - The limit value used in the request. ### Response Example ```json { "results": [ { "moid": "60f1b2b3c4d5e6f7a8b9c0d1", "deviceMoId": "60f1b2b3c4d5e6f7a8b9c0d2", "dn": "org/org-name/policy/policy-name", "description": "A sample policy", "name": "SamplePolicy", "adminState": "enabled" } ], "count": 1, "skip": 0, "top": 50 } ``` ``` -------------------------------- ### Get All Resources Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Retrieves a list of resources, limited to the top 100 items, and iterates through the results. Use this pattern to fetch multiple resources of a specific type. ```python response = api_instance.get_{resource}_list(top=100, skip=0) for item in response.results: process(item) ``` -------------------------------- ### Get Boot Precision Policy List Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Retrieves a list of all Boot Precision Policy resources. This example demonstrates reading objects using the Intersight Python SDK. ```APIDOC ## GET /boot/PrecisionPolicies ### Description Retrieves a list of all Boot Precision Policy resources. ### Method GET ### Endpoint /boot/PrecisionPolicies ### Parameters #### Query Parameters - **filter** (string) - Optional - oData query string to filter results. - **orderby** (string) - Optional - oData query string to sort results. - **top** (integer) - Optional - Number of records to return. - **skip** (integer) - Optional - Number of records to skip. - **select** (string) - Optional - Selects which properties to include in the response. - **expand** (string) - Optional - Expands related resources. ### Request Example ```python from intersight.api import boot_api from pprint import pprint import intersight api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) # Create an instance of the API class api_instance = boot_api.BootApi(api_client) # example passing only required values which don't have defaults set # and optional values try: # Read a 'boot.PrecisionPolicy' resource. api_response = api_instance.get_boot_precision_policy_list() pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->get_boot_precision_policy_list: %s\n" % e) ``` ### Response #### Success Response (200) - **results** (array) - An array of BootPrecisionPolicy resources. #### Response Example ```json { "example": "[BootPrecisionPolicy object1, BootPrecisionPolicy object2, ...]" } ``` ``` -------------------------------- ### Create Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Example of creating a 'boot.PrecisionPolicy' resource. Ensure the 'boot_precision_policy' object is properly initialized before calling this function. ```python from intersight.api import boot_api from pprint import pprint import intersight # Assuming api_instance and boot_precision_policy are already initialized # api_instance = boot_api.BootApi(api_client) # boot_precision_policy = {...} try: # Create a 'boot.PrecisionPolicy' resource. api_response = api_instance.create_boot_precision_policy(boot_precision_policy) pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->create_boot_precision_policy: %s\n" % e) ``` -------------------------------- ### Manage Boot Precision Policy by Moid Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Examples for getting, updating, and deleting a Boot Precision Policy using its Managed Object ID (Moid). ```python policy = api_instance.get_boot_precision_policy_by_moid("moid-value") updated = api_instance.update_boot_precision_policy(policy, moid="moid-value") api_instance.delete_boot_precision_policy("moid-value") ``` -------------------------------- ### Install Intersight SDK using pip Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Installs the Intersight Python SDK using the pip package manager. This is the recommended method for most users. ```bash pip install intersight ``` -------------------------------- ### Create Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md This example demonstrates how to create a Boot Precision Policy by instantiating the `BootPrecisionPolicy` model, setting its attributes, and then calling the `create_boot_precision_policy` method from the `boot_api`. ```APIDOC ## Create Boot Precision Policy ### Description This endpoint creates a new Boot Precision Policy resource. It involves instantiating the `BootPrecisionPolicy` model, configuring its properties such as name, description, boot devices, and organization, and then submitting it via the API. ### Method POST ### Endpoint /boot/PrecisionPolicies ### Parameters #### Request Body - **boot_precision_policy** (BootPrecisionPolicy) - Required - The Boot Precision Policy object to create. ### Request Example ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy from intersight.model.boot_device_base import BootDeviceBase from intersight.model.organization_organization_relationship import OrganizationOrganizationRelationship from pprint import pprint import intersight api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) def create_boot_local_cdd(): boot_local_cdd = BootDeviceBase(class_id="boot.LocalCdd", object_type="boot.LocalCdd", name="local_cdd1", enabled=True) return boot_local_cdd def create_boot_local_disk(): boot_local_disk = BootDeviceBase(class_id="boot.LocalDisk", object_type="boot.LocalDisk", name="local_disk1", enabled=True) return boot_local_disk def create_organization(): organization = OrganizationOrganizationRelationship(class_id="mo.MoRef", object_type="organization.Organization") return organization api_instance = boot_api.BootApi(api_client) boot_local_cdd = create_boot_local_cdd() boot_local_disk = create_boot_local_disk() organization = create_organization() boot_devices = [ boot_local_disk, boot_local_cdd, ] boot_precision_policy = BootPrecisionPolicy() boot_precision_policy.name = "sample_boot_policy1" boot_precision_policy.description = "sample boot precision policy" boot_precision_policy.boot_devices = boot_devices boot_precision_policy.organization = organization try: api_response = api_instance.create_boot_precision_policy(boot_precision_policy) pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->create_boot_precision_policy: %s\n" % e) ``` ### Response #### Success Response (200) - **moid** (string) - The unique identifier for the created Boot Precision Policy. - **name** (string) - The name of the Boot Precision Policy. - **description** (string) - A description of the Boot Precision Policy. - **boot_devices** (list) - A list of boot devices configured for the policy. - **organization** (OrganizationOrganizationRelationship) - The organization this policy belongs to. #### Response Example ```json { "moid": "60f3b2e77070732d31313131", "name": "sample_boot_policy1", "description": "sample boot precision policy", "boot_devices": [ { "class_id": "boot.LocalDisk", "object_type": "boot.LocalDisk", "name": "local_disk1", "enabled": true }, { "class_id": "boot.LocalCdd", "object_type": "boot.LocalCdd", "name": "local_cdd1", "enabled": true } ], "organization": { "class_id": "mo.MoRef", "object_type": "organization.Organization" } } ``` ``` -------------------------------- ### Making API Calls with Examples Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/00-START-HERE.txt This section focuses on practical, real-world code examples for common operations, including CRUD operations, filtering, pagination, batch operations, and error handling. ```APIDOC ## Making API Calls ### Overview This section provides real-world code examples for common operations within the Intersight Python SDK. It covers essential patterns for interacting with the API effectively. ### Key Topics Covered - CRUD operation examples - Filtering and searching - Pagination patterns - Batch operations (multiple creates/updates) - Device management examples - Error handling and retries - JSON transformation ### Recommended Reading - **COMMON-OPERATIONS.md**: For practical code examples and usage patterns. ``` -------------------------------- ### Create Resource Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Creates a new resource by instantiating a model object and passing it to the create method. Ensure the model object is correctly populated with required attributes. ```python obj = Model(name="new", ...) created = api_instance.create_{resource}(obj) ``` -------------------------------- ### Install Intersight Python Package Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Install the Intersight Python SDK using pip or by building from source. Ensure Python 3.6 or later is installed. ```bash pip install intersight ``` ```bash pip install git+https://github.com/CiscoDevNet/intersight-python ``` ```bash python setup.py install --user ``` -------------------------------- ### Create Boot Precision Policy from JSON Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md This example shows how to create a Boot Precision Policy by loading its configuration from a JSON file. The JSON data is parsed and used to instantiate the `BootPrecisionPolicy` model. ```APIDOC ## Create Boot Precision Policy from JSON ### Description This endpoint creates a Boot Precision Policy by parsing a JSON payload. The JSON data defines the properties of the policy, including its name, description, boot devices, and organization. This method is useful for creating resources based on predefined configurations. ### Method POST ### Endpoint /boot/PrecisionPolicies ### Parameters #### Request Body - **data** (json) - Required - A JSON object containing the configuration for the Boot Precision Policy. ### Request Example `data.json`: ```json { "Name":"sample_boot_policy1", "ObjectType":"boot.PrecisionPolicy", "ClassId":"boot.PrecisionPolicy", "Description":"Create boot precision policy.", "BootDevices":[ { "ClassId":"boot.LocalCdd", "ObjectType":"boot.LocalCdd", "Enabled":true, "Name":"local_cdd" }, { "ClassId":"boot.LocalDisk", "ObjectType":"boot.LocalDisk", "Enabled":true, "Name":"local_disk" } ], "Organization":{ "ObjectType":"organization.Organization", "ClassId":"mo.MoRef" } } ``` ```python import json from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy from pprint import pprint import intersight api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) api_instance = boot_api.BootApi(api_client) data_json_file_path = "data.json" with open(data_json_file_path, "r") as json_data_file: json_data = json_data_file.read() data = json.loads(json_data) boot_precision_policy = BootPrecisionPolicy(**data, _spec_property_naming=True, _configuration=api_client.configuration) try: api_response = api_instance.create_boot_precision_policy(boot_precision_policy) pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->create_boot_precision_policy: %s\n" % e) ``` ### Response #### Success Response (200) - **moid** (string) - The unique identifier for the created Boot Precision Policy. - **name** (string) - The name of the Boot Precision Policy. - **description** (string) - A description of the Boot Precision Policy. - **boot_devices** (list) - A list of boot devices configured for the policy. - **organization** (OrganizationOrganizationRelationship) - The organization this policy belongs to. #### Response Example ```json { "moid": "60f3b2e77070732d31313131", "name": "sample_boot_policy1", "description": "Create boot precision policy.", "boot_devices": [ { "class_id": "boot.LocalCdd", "object_type": "boot.LocalCdd", "enabled": true, "name": "local_cdd" }, { "class_id": "boot.LocalDisk", "object_type": "boot.LocalDisk", "enabled": true, "name": "local_disk" } ], "organization": { "class_id": "mo.MoRef", "object_type": "organization.Organization" } } ``` ``` -------------------------------- ### Multi-Key Rotation Setup Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/authentication.md Configure multiple keys for request signing and rotation. This function creates an API client with specified signing configurations. ```python def create_api_client(key_id, private_key_path): signing_config = HttpSigningConfiguration( key_id=key_id, private_key_path=private_key_path, signing_scheme=SCHEME_HS2019, signing_algorithm=ALGORITHM_RSASSA_PKCS1v15, hash_algorithm=HASH_SHA256, signed_headers=[HEADER_REQUEST_TARGET, HEADER_HOST, HEADER_DATE, HEADER_DIGEST] ) config = intersight.Configuration( host="https://intersight.com", signing_info=signing_config ) return intersight.ApiClient(config) # Use new key new_api_client = create_api_client("new-key-id", "/path/to/new_key.pem") ``` -------------------------------- ### Get Asset Device Registration List with Filter Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-classes-detailed.md Retrieve a list of registered devices, with the ability to filter results. This example shows how to list connected devices and print their serial numbers and IP addresses. ```python response = api_instance.get_asset_device_registration_list( filter="ConnectionStatus eq 'Connected'" ) for device in response.results: print(f"{device.serial_number}: {device.device_ip_address}") ``` -------------------------------- ### RSA Private Key Format Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/authentication.md Example format for an RSA private key PEM file. ```text -----BEGIN RSA PRIVATE KEY----- ...base64_content... -----END RSA PRIVATE KEY----- ``` -------------------------------- ### Claiming an Appliance Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md This example demonstrates how to claim an appliance using the Intersight Python SDK. It involves creating an ApplianceDeviceClaim object with username, password, hostname, and platform type, and then posting it to claim the appliance. ```APIDOC ## Claiming an Appliance ### Description This operation claims an appliance by providing its credentials and platform details. ### Method POST ### Endpoint `/appliance/DeviceClaims` ### Request Body - **username** (string) - Required - The username for the appliance. - **password** (string) - Required - The password for the appliance. - **hostname** (string) - Required - The hostname of the appliance. - **platform_type** (string) - Required - The platform type of the appliance (e.g., "UCSD"). ### Request Example ```json { "username": "user1", "password": "ChangeMe", "hostname": "host1", "platform_type": "UCSD" } ``` ### Response #### Success Response (200) - **moid** (string) - The unique identifier for the claimed appliance. - **status** (string) - The status of the claim operation. ``` -------------------------------- ### Configuration Constructor Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/configuration.md Initializes the Configuration object with various parameters for API client setup. Use this to set authentication credentials, host, and other connection details. ```python def __init__(self, host=None, api_key=None, api_key_prefix=None, access_token=None, username=None, password=None, discard_unknown_keys=False, disabled_client_side_validations="", signing_info=None, server_index=None, server_variables=None, server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None) ``` -------------------------------- ### Paginate Boot Precision Policy List Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Example of retrieving a paginated list of Boot Precision Policies, specifying the number of results to return ('top') and the number to skip ('skip'). It also shows how to access the total count and the results. ```python response = api_instance.get_boot_precision_policy_list(top=50, skip=100) print(response.count) # Total count print(response.results) # 50 results starting at position 100 ``` -------------------------------- ### Create Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Creates a new Boot Precision Policy resource using the Intersight Python SDK. This example shows how to pass only the required values. ```APIDOC ## POST /boot/PrecisionPolicies ### Description Creates a new Boot Precision Policy resource. ### Method POST ### Endpoint /boot/PrecisionPolicies ### Request Body - **body** (BootPrecisionPolicy) - Required - The payload to create a BootPrecisionPolicy resource. ### Request Example ```python from intersight.api import boot_api from pprint import pprint import intersight api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) # Create an instance of the API class api_instance = boot_api.BootApi(api_client) # boot_precision_policy is a model object # boot_precision_policy = BootPrecisionPolicy() # example passing only required values which don't have defaults set try: # Create a 'boot.PrecisionPolicy' resource. api_response = api_instance.create_boot_precision_policy(boot_precision_policy) pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->create_boot_precision_policy: %s\n" % e) ``` ### Response #### Success Response (200) - **body** (BootPrecisionPolicy) - Returns the created BootPrecisionPolicy resource. #### Response Example ```json { "example": "BootPrecisionPolicy object" } ``` ``` -------------------------------- ### AssetDeviceRegistration Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Fetches device registration information using its MOID and accesses properties like IP address, serial number, and connection status. ```APIDOC ## GET /asset/device/registration/{moid} ### Description Retrieves detailed information about a specific device registration using its Managed Object ID (MOID). ### Method GET ### Endpoint /asset/device/registration/{moid} ### Parameters #### Path Parameters - **moid** (string) - Required - The Managed Object ID of the device registration. ### Response #### Success Response (200) - **device_ip_address** (list[string]) - List of IP addresses associated with the device. - **serial_number** (string) - The serial number of the device. - **connection_status** (string) - The current connection status of the device (e.g., "Connected", "Disconnected"). ### Response Example ```json { "device_ip_address": [ "192.168.1.100", "192.168.1.101" ], "serial_number": "QOG23456789", "connection_status": "Connected" } ``` ``` -------------------------------- ### Read Boot Precision Policy List Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Example of reading a list of 'boot.PrecisionPolicy' resources. This function retrieves all available precision policies. Ensure API client and necessary imports are set up. ```python from intersight.api import boot_api from pprint import pprint import intersight # Assuming api_client is already initialized # api_client = get_api_client(api_key, api_key_file) # Create an instance of the API class api_instance = boot_api.BootApi(api_client) try: # Read a 'boot.PrecisionPolicy' resource. api_response = api_instance.get_boot_precision_policy_list() pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->get_boot_precision_policy_list: %s\n" % e) ``` -------------------------------- ### Get Boot Precision Policy List Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Retrieves a paginated list of boot precision policies. Use this to fetch multiple policies with options for limiting results and counting total items. ```python response = boot_api_instance.get_boot_precision_policy_list( top=50, skip=0, count=True ) print(response.results) # list[BootPrecisionPolicy] print(response.count) # Total count print(response.skip) # Skip value used print(response.top) # Limit value used ``` -------------------------------- ### Read List Boot Precision Policies Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/common-operations.md Retrieves a paginated list of all Boot Precision Policies using a GET request. Supports filtering with `top` and `skip` parameters. ```APIDOC ## Read List Boot Precision Policies ### Description Retrieves a collection of Boot Precision Policies, supporting pagination. ### Method GET ### Endpoint `/boot/PrecisionPolicies` ### Parameters #### Query Parameters - **top** (integer) - Optional - The maximum number of policies to return. - **skip** (integer) - Optional - The number of policies to skip from the beginning of the list. ### Response #### Success Response (200 OK) - **results** (array) - A list of Boot Precision Policy objects. - Each object contains properties like **name** (string) and **moid** (string). #### Response Example ```json { "results": [ { "name": "policy1", "moid": "moid1" }, { "name": "policy2", "moid": "moid2" } ] } ``` ``` -------------------------------- ### Update Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Updates an existing Boot Precision Policy resource. This example demonstrates fetching a policy, modifying its attributes, and then updating it. ```APIDOC ## PATCH /boot/PrecisionPolicies/{moid} ### Description Updates an existing Boot Precision Policy resource. ### Method PATCH ### Endpoint /boot/PrecisionPolicies/{moid} ### Parameters #### Path Parameters - **moid** (string) - Required - The Moid of the Boot Precision Policy to update. ### Request Body - **body** (BootPrecisionPolicy) - Required - The updated BootPrecisionPolicy object. ### Request Example ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy from intersight.model.boot_device_base import BootDeviceBase from intersight.model.organization_organization_relationship import OrganizationOrganizationRelationship from pprint import pprint import intersight api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) def create_boot_sdcard(): # Creating an instance of boot_hdd_device boot_sdcard = BootDeviceBase(class_id="boot.SdCard", object_type="boot.SdCard", name="sdcard1", enabled=True) return boot_sdcard def create_boot_iscsi(): # Creating an instance of boot_iscsi boot_iscsi = BootDeviceBase(class_id="boot.Iscsi", object_type="boot.Iscsi", name="iscsi1", enabled=True) return boot_iscsi def create_boot_pxe(): # Creating an instance of boot_pxe boot_pxe = BootDeviceBase(class_id="boot.Pxe", object_type="boot.Pxe", name="pxe1", enabled=True, interface_name="pxe1") return boot_pxe def get_boot_precision_policy(api_client): # Enter a context with an instance of the API client with api_client: # Create an instance of the API class api_instance = boot_api.BootApi(api_client) # example passing only required values which don't have defaults set # and optional values try: # Read a 'boot.PrecisionPolicy' resource. api_response = api_instance.get_boot_precision_policy_list() except intersight.ApiException as e: print("Exception when calling BootApi->get_boot_precision_policy_list: %s\n" % e) return api_response def create_organization(moid): # Creating an instance of organization organization = OrganizationOrganizationRelationship(class_id="mo.MoRef", object_type="organization.Organization", moid=moid) return organization # Assuming api_client is already initialized and a policy exists # First, get the policy to be updated policy_list = get_boot_precision_policy(api_client) if policy_list and policy_list.results: policy_to_update = policy_list.results[0] # Get the first policy policy_moid = policy_to_update.moid # Create an instance of the API class for update api_instance = boot_api.BootApi(api_client) # Modify attributes of the policy object # For example, let's add a new boot device (sdcard) new_sdcard = create_boot_sdcard() policy_to_update.sd_card_boot_devices.append(new_sdcard) # Update the policy try: api_response = api_instance.patch_boot_precision_policy(policy_moid, policy_to_update) pprint(api_response) except intersight.ApiException as e: print("Exception when calling BootApi->patch_boot_precision_policy: %s\n" % e) else: print("No Boot Precision Policies found to update.") ``` ### Response #### Success Response (200) - **body** (BootPrecisionPolicy) - Returns the updated BootPrecisionPolicy resource. #### Response Example ```json { "example": "Updated BootPrecisionPolicy object" } ``` ``` -------------------------------- ### Authentication Methods Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/00-START-HERE.txt This section provides a comprehensive explanation of all four authentication methods supported by the SDK, including HTTP signature setup, key management, and security best practices. ```APIDOC ## Authentication Details ### Overview This section covers all authentication methods supported by the Intersight Python SDK, ensuring secure and reliable access to the API. ### Key Topics Covered - All 4 authentication methods - HTTP signature setup (RSA and ECDSA) - Key management and rotation - Security best practices - Environment configuration - Troubleshooting auth failures ### Recommended Reading - **AUTHENTICATION.md**: For a complete guide to authentication methods. ``` -------------------------------- ### Get Boot Precision Policy List with Filtering Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-classes-detailed.md Retrieves a list of boot precision policies. Supports filtering, pagination (top, skip), sorting (orderby), and selecting specific properties. Use 'count=True' to include the total number of matching policies. ```python response = api_instance.get_boot_precision_policy_list( filter="Status eq 'Active'", top=50, skip=0, count=True ) print(f"Total: {response.count}") for policy in response.results: print(policy.name) ``` -------------------------------- ### Update Resource Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Updates an existing resource by first retrieving it, modifying its attributes, and then calling the update method with the MOID. Note that the MOID must be provided for the update operation. ```python obj = api_instance.get_{resource}_by_moid("moid") obj.name = "updated" updated = api_instance.update_{resource}(obj, moid="moid") ``` -------------------------------- ### HTTP Methods Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/rest-client.md Demonstrates how to perform various HTTP requests (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) using the REST client. Ensure the URL and appropriate headers/body are provided. ```python # GET request response = rest_client.GET(url, headers={...}) # POST request response = rest_client.POST(url, headers={...}, body=body) # PUT request response = rest_client.PUT(url, headers={...}, body=body) # DELETE request response = rest_client.DELETE(url, headers={...}) # PATCH request response = rest_client.PATCH(url, headers={...}, body=body) # HEAD request response = rest_client.HEAD(url, headers={...}) # OPTIONS request response = rest_client.OPTIONS(url, headers={...}) ``` -------------------------------- ### Claiming a Target Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md This example demonstrates how to claim a target device using the Intersight Python SDK. It involves creating an AssetDeviceClaim object with security token and serial number, and then posting it to claim the target. ```APIDOC ## Claiming a Target ### Description This operation claims a target device by providing its security token and serial number. ### Method POST ### Endpoint `/asset/Targets` ### Request Body - **security_token** (string) - Required - The security token for the device. - **serial_number** (string) - Required - The serial number of the device. ### Request Example ```json { "security_token": "2Nxxx-int", "serial_number": "WZPxxxxxFMx" } ``` ### Response #### Success Response (200) - **moid** (string) - The unique identifier for the claimed target. - **status** (string) - The status of the claim operation. ``` -------------------------------- ### Create API Instance and List Boot Policies Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/quick-start.md Instantiate the Boot API client and retrieve a list of all boot precision policies. Requires an initialized ApiClient. ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy boot_api_instance = boot_api.BootApi(api_client) # List boot policies response = boot_api_instance.get_boot_precision_policy_list() for policy in response.results: print(f"Policy: {policy.name} (moid: {policy.moid})") ``` -------------------------------- ### Create a Resource Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/quick-start.md Demonstrates how to create a new boot precision policy. It includes fetching an organization Moid, defining boot devices, and setting up the organization relationship before creating the policy. ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy from intersight.model.boot_device_base import BootDeviceBase from intersight.model.organization_organization_relationship import OrganizationOrganizationRelationship # Get organization moid (adjust filter as needed) org_response = boot_api_instance.get_boot_precision_policy_list(top=1) org_moid = org_response.results[0].organization['moid'] if org_response.results else "org-default" # Create boot devices boot_device = BootDeviceBase( class_id="boot.LocalDisk", object_type="boot.LocalDisk", name="local_disk1", enabled=True ) # Create organization relationship organization = OrganizationOrganizationRelationship( class_id="mo.MoRef", object_type="organization.Organization", moid=org_moid ) # Create policy policy = BootPrecisionPolicy( name="my-boot-policy", description="Test boot policy", boot_devices=[boot_device], organization=organization ) # POST to create created_policy = boot_api_instance.create_boot_precision_policy(policy) print(f"Created policy with moid: {created_policy.moid}") ``` -------------------------------- ### Get Single Resource by MOID Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Fetches a single resource using its Managed Object ID (MOID). This is useful when you need to retrieve a specific, known resource. ```python item = api_instance.get_{resource}_by_moid("moid-value") ``` -------------------------------- ### Creating an API Client with Proxy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Shows how to create an API client with a specified proxy server and then use it to create a Boot Precision Policy. ```APIDOC ## create_boot_precision_policy_with_proxy ### Description Creates a Boot Precision Policy using an API client configured with a proxy server. ### Method POST ### Endpoint /boot/PrecisionPolicies ### Parameters #### Path Parameters - **api_key_id** (string) - Required - The ID of the API key. - **api_secret_file** (string) - Required - The file path to the API secret. - **proxy** (string) - Required - The proxy server to use for the connection. #### Request Body - **boot_precision_policy** (BootPrecisionPolicy) - Required - An object representing the Boot Precision Policy to be created. ### Request Example ```json { "example": "BootPrecisionPolicy object" } ``` ### Response #### Success Response (200 or 201) - **(object)** - The created Boot Precision Policy object. #### Response Example ```json { "example": "Created BootPrecisionPolicy object details" } ``` ``` -------------------------------- ### Unclaiming a Target Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md This example shows how to unclaim a target device. It first retrieves a list of registered targets, filters for the target to be unclaimed (identified by its IP address), and then deletes the claim using its MOID. ```APIDOC ## Unclaiming a Target ### Description This operation unclaims a target device by deleting its claim entry. It requires identifying the target, typically by its IP address, and then using its MOID to perform the deletion. ### Method DELETE ### Endpoint `/asset/Targets/{moid}` ### Parameters #### Path Parameters - **moid** (string) - Required - The Managed Object ID (MOID) of the device claim to delete. ### Request Example (No request body is typically sent for a DELETE operation, the MOID is in the URL) ### Response #### Success Response (200) Indicates that the claim was successfully removed. ``` -------------------------------- ### Get Asset Device Registration List with Filter Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Retrieves a filtered list of Asset Device Registration objects. This example demonstrates using oData filters for querying resources. ```APIDOC ## GET /asset/DeviceRegistrations ### Description Retrieves a filtered list of Asset Device Registration objects. ### Method GET ### Endpoint /asset/DeviceRegistrations ### Parameters #### Query Parameters - **filter** (string) - Required - oData query string to filter results. Example: "ConnectionStatus eq 'Connected'" ### Request Example ```python from intersight.api import asset_api api_key = "api_key" api_key_file = "~/api_key_file_path" api_client = get_api_client(api_key, api_key_file) asset_api = asset_api.AssetApi(api_client) kwargs = dict(filter="ConnectionStatus eq 'Connected'") # Get all device registration objects that are in connected state api_result= asset_api.get_asset_device_registration_list(**kwargs) for device in api_result.results: print(device.device_ip_address[0]) ``` ### Response #### Success Response (200) - **results** (array) - An array of AssetDeviceRegistration resources matching the filter. #### Response Example ```json { "example": "[AssetDeviceRegistration object1, AssetDeviceRegistration object2, ...]" } ``` ``` -------------------------------- ### Creating a Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Demonstrates how to create an API client, instantiate a BootApi, create a BootPrecisionPolicy object, and then create this object on the Intersight server. ```APIDOC ## create_boot_precision_policy ### Description Creates a new Boot Precision Policy on the Intersight server. ### Method POST ### Endpoint /boot/PrecisionPolicies ### Parameters #### Request Body - **boot_precision_policy** (BootPrecisionPolicy) - Required - An object representing the Boot Precision Policy to be created. ### Request Example ```json { "example": "BootPrecisionPolicy object" } ``` ### Response #### Success Response (200 or 201) - **(object)** - The created Boot Precision Policy object. #### Response Example ```json { "example": "Created BootPrecisionPolicy object details" } ``` ``` -------------------------------- ### Create Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Demonstrates creating a Boot Precision Policy object and then creating it on the Intersight server using an API client. Ensure the API client is initialized before use. ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy api_client = get_api_client("api_key", "~/api_secret_file_path") # Create an api instance of the correct API type api_instance = boot_api.BootApi(api_client) # Create an object locally and populate the object properties boot_precision_policy = BootPrecisionPolicy() # Create an object in Intersight api_response = api_instance.create_boot_precision_policy(boot_precision_policy) ``` -------------------------------- ### Get Resource by MOID Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-overview.md Retrieves a single resource using its unique identifier (MOID). ```python resource = api_instance.get_{resource_type}_by_moid(moid, **kwargs) ``` ```python policy = boot_api_instance.get_boot_precision_policy_by_moid("moid-123") ``` -------------------------------- ### ECDSA Private Key Format Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/authentication.md Example format for an ECDSA private key PEM file. ```text -----BEGIN EC PRIVATE KEY----- ...base64_content... -----END EC PRIVATE KEY----- ``` -------------------------------- ### BootUefiShellDevice Configuration Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Configure UEFI shell boot. Set 'enabled' to True to make this a selectable boot option. ```python BootUefiShellDevice( class_id="boot.UefiShellDevice", object_type="boot.UefiShellDevice", name="uefi_shell", enabled=True ) ``` -------------------------------- ### Create Boot Precision Policy with Proxy Source: https://github.com/ciscodevnet/intersight-python/blob/main/README.md Shows how to create a Boot Precision Policy using an API client configured with proxy settings. This is useful for environments requiring a proxy to access external services. ```python from intersight.api import boot_api from intersight.model.boot_precision_policy import BootPrecisionPolicy api_key_id = "your api_key_id" api_secret_file = "path to your api secret file" proxy = "your proxy" # Creating API Client with proxy api_client = get_api_client(api_key_id, api_secret_file = api_secret_file proxy = proxy) # Create an api instance of the correct API type api_instance = boot_api.BootApi(api_client) # Create an object locally and populate the object properties boot_precision_policy = BootPrecisionPolicy() # Create an object in Intersight api_response = api_instance.create_boot_precision_policy(boot_precision_policy) ``` -------------------------------- ### Get BIOS Policy by MOID Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-classes-detailed.md Retrieve a specific BIOS policy using its unique Moid. ```python def get_bios_policy_by_moid(self, moid, **kwargs) -> BiosPolicy ``` -------------------------------- ### BootVmediaDevice Configuration Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Configure virtual media boot. Ensure 'enabled' is True for this option to be active. ```python BootVmediaDevice( class_id="boot.VMedia", object_type="boot.VMedia", name="vmedia1", enabled=True ) ``` -------------------------------- ### BootSdDevice Configuration Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Configure an SD card as a boot device. Set 'enabled' to True to activate this boot option. ```python BootDeviceBase( class_id="boot.SdCard", object_type="boot.SdCard", name="sdcard1", enabled=True ) ``` -------------------------------- ### Host Property Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/configuration.md Get or set the base URL for API requests. The default is 'https://intersight.com'. ```python @property def host(self) -> str @host.setter def host(self, value: str) -> None ``` -------------------------------- ### Filter by Status Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-overview.md Filter resources based on their 'Status' property. This example retrieves resources with the status 'Active'. ```python filter="Status eq 'Active'" ``` -------------------------------- ### Create Boot Precision Policy Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/common-operations.md Demonstrates how to create a new Boot Precision Policy using the Intersight SDK. It includes defining boot devices, organization relationships, and the policy object itself, followed by a POST request to the API. ```APIDOC ## Create Boot Precision Policy ### Description Creates a new Boot Precision Policy by sending a POST request with the policy definition. ### Method POST ### Endpoint `/boot/PrecisionPolicies` ### Parameters #### Request Body - **policy** (BootPrecisionPolicy) - Required - The BootPrecisionPolicy object to create. ### Request Example ```json { "name": "new-boot-policy", "description": "Boot policy created via SDK", "boot_devices": [ { "class_id": "boot.LocalDisk", "object_type": "boot.LocalDisk", "name": "local_disk1", "enabled": true } ], "organization": { "class_id": "mo.MoRef", "object_type": "organization.Organization", "moid": "org-moid" } } ``` ### Response #### Success Response (200 OK) - **moid** (string) - The unique identifier of the created policy. #### Response Example ```json { "moid": "created-policy-moid" } ``` ``` -------------------------------- ### Get BIOS Unit by MOID Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-classes-detailed.md Retrieve detailed information about a specific BIOS unit using its Moid. ```python def get_bios_unit_by_moid(self, moid, **kwargs) -> BiosUnit ``` -------------------------------- ### AssetDeviceClaim Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Creates a device claim request to claim an unregistered device using its security token and serial number. ```APIDOC ## POST /asset/device/claim ### Description Initiates a claim request for an unregistered device, providing the necessary security token and serial number. ### Method POST ### Endpoint /asset/device/claim ### Parameters #### Request Body - **security_token** (string) - Required - The security token obtained from the device. - **serial_number** (string) - Required - The serial number of the device to be claimed. ### Request Example ```json { "security_token": "token-from-device", "serial_number": "device-serial-number" } ``` ### Response #### Success Response (200) (Response details not explicitly provided in source, typically returns confirmation or status of the claim operation.) ``` -------------------------------- ### Delete Resource Example Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/README.md Deletes a resource using its Managed Object ID (MOID). This action is irreversible and should be used with caution. ```python api_instance.delete_{resource}("moid") ``` -------------------------------- ### BootPxeDevice Configuration Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Configure PXE (network) boot. Specify the interface name (e.g., 'eth0') and ensure 'enabled' is True. ```python BootPxeDevice( class_id="boot.Pxe", object_type="boot.Pxe", name="pxe1", enabled=True, interface_name="eth0" ) ``` -------------------------------- ### Get Compute Physical Summary by MOID Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-classes-detailed.md Retrieve detailed physical summary information for a specific server using its Moid. ```python def get_compute_physical_summary_by_moid(self, moid, **kwargs) -> ComputePhysicalSummary ``` -------------------------------- ### Configuration with Proxy and Custom SSL Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/configuration.md Set up the SDK to use a proxy server and specify a custom CA certificate for SSL verification. ```python config = intersight.Configuration( host="https://intersight.com", signing_info=signing_config, proxy="http://proxy.corp.com:8080", no_proxy="localhost,127.0.0.1", ssl_ca_cert="/etc/ssl/certs/ca-bundle.crt", verify_ssl=True ) ``` -------------------------------- ### Get Default Organization Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/common-operations.md Retrieves the default organization from the Intersight API. This is useful for setting a default context for subsequent operations. ```python from intersight.api import organization_api org_api = organization_api.OrganizationApi(api_client) # Get all organizations response = org_api.get_organization_organization_list(top=1) if response.results: default_org = response.results[0] org_moid = default_org.moid print(f"Organization: {default_org.name} (moid: {org_moid})") ``` -------------------------------- ### BootSanDevice Configuration Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/models.md Configure Storage Area Network (SAN) boot. Requires specifying LUN and WWPN, along with 'enabled' set to True. ```python BootSanDevice( class_id="boot.San", object_type="boot.San", name="san1", enabled=True, lun=0, wwpn="50:00:09:72:00:00:00:00" ) ``` -------------------------------- ### Get List Source: https://github.com/ciscodevnet/intersight-python/blob/main/_autodocs/api-overview.md Fetches a paginated list of resources. Supports filtering and limiting results using `top` and `skip` parameters. ```APIDOC ## Get List ### Description Returns paginated list of resources. ### Method GET (implied) ### Endpoint `/resources/{resource_type}` (implied) ### Parameters #### Path Parameters None. #### Query Parameters - **top** (integer) - Optional - The maximum number of resources to return. - **skip** (integer) - Optional - The number of resources to skip from the beginning of the list. #### Request Body None. ### Request Example ```python response = boot_api_instance.get_boot_precision_policy_list(top=50, skip=0) for policy in response.results: print(policy.name) ``` ### Response #### Success Response (200) - **results** (list) - List of resource objects. - **count** (integer) - Total number of results available. - **skip** (integer) - The skip value used in the request. - **top** (integer) - The limit value used in the request. #### Response Example (Example not provided in source) ```