### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Install Intersight Python SDK using SetupTools Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Installs the Intersight Python SDK by cloning the repository and using the setup.py script. This method allows for installation for a specific user or all users. ```Bash $ python setup.py install --user # or $ sudo python setup.py install ``` -------------------------------- ### Install Intersight Python SDK using pip Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Installs the Intersight Python SDK on the control node. Multiple methods are provided, including direct installation from PyPI or from GitHub. ```Bash $ pip install intersight ``` ```Bash $ pip install git+https://github.com/CiscoDevNet/intersight-python ``` -------------------------------- ### Execute Intersight API example script Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/README.md Runs an example Python script, such as 'alarms_example.py', to interact with the Intersight API. This script will perform operations like retrieving alarm details and displaying them in a formatted table. Assumes prior authentication setup. ```bash python alarms_example.py ``` -------------------------------- ### Example Log File Snippet (Bash) Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md This snippet is an excerpt from an example log file, showing timestamps, server identifiers, and the detailed OS inventory collection in JSON format. It demonstrates the structure and content of the discovery tool's output. ```Bash [2021-10-08 08:14:25.220036]------------------------START-TIMESTAMP-------------------------- [2021-10-08 08:15:40.237309][ubuntu-server]: Intersight MO Identifier: 5bce7116683663343218ed92 [2021-10-08 08:15:40.237327][ubuntu-server]: Building OS Inventory Collection... [ { "Key": "intersight.server.os.updateTimestamp", "Value": "2021-10-08T08:14:52.802Z" }, { "Key": "intersight.server.os.updateVersionString", "Value": "" }, { "Key": "intersight.server.os.kernelVersionString", "Value": "Ubuntu Server 16.04.5 LTS" }, { "Key": "intersight.server.os.releaseVersionString", "Value": "4.4.0-140-generic" } ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Install Intersight Python SDK using pip Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/README.md Installs the Cisco Intersight Python SDK from the Python Package Index using pip. It's important to ensure only one version of the Intersight SDK is active to avoid conflicts. This command assumes pip is installed and configured. ```bash sudo pip install intersight ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Intersight Discovery Configuration (discovery_config_linux.json) Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Example JSON configuration file for the OS discovery tool. It specifies paths for the hosts file, Intersight URL, API keys, and log files. ```JSON { "config": { "hosts_file_path": "/home/odt-user/hosts", "intersight_url": "https://intersight.com", "intersight_api_key": "59552af60b1905000195be54/59552aec0b1905000195bde5/5becc002673738387ab2cc1b", "intersight_secret_file": "/home/odt-user/Downloads/SecretKey.txt", "logfile_path": "/tmp" } } ``` -------------------------------- ### Untitled No description -------------------------------- ### Run get_linux_inv_to_intersight.py Script Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Example command to run the get_linux_inv_to_intersight.py script with logging enabled and a specified configuration file. This pushes OS inventory to Intersight. ```Bash ./get_linux_inv_to_intersight.py --log-inventory --configfile=discovery_config_linux.json ``` -------------------------------- ### Get Linux Inventory Script Help Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Displays the usage and available options for the get_linux_inv_to_intersight.py script. It shows mandatory and optional arguments. ```Bash ./get_linux_inv_to_intersight.py --help ``` -------------------------------- ### Untitled No description -------------------------------- ### Install Enum Module using pip Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md Installs the Enum module, a dependency for the Intersight Python SDK. This is typically done using pip on the control node. ```Bash $ pip install enum34 ``` -------------------------------- ### Untitled No description -------------------------------- ### Process OS and Driver Inventory (Bash) Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md This snippet illustrates the steps involved in extracting OS and driver inventory from a server. It also indicates whether changes are detected, which determines if the inventory needs to be pushed to Intersight. ```Bash [ubuntu-server]: Extracting OS Inventory... [ubuntu-server]: Extracting driver Inventory... [ubuntu-server]: No Changes detected in OS Inventory, skipping... ``` ```Bash [centos-server]: Extracting OS Inventory... [centos-server]: Extracting driver Inventory... [centos-server]: Changes detected in OS Inventory, pushing to intersight... [centos-server]: Patching Server MO with OS Inventory... ``` ```Bash [suse-server]: Extracting OS Inventory... [suse-server]: Extracting driver Inventory... [suse-server]: Changes detected in OS Inventory, pushing to intersight... [suse-server]: Patching Server MO with OS Inventory... ``` -------------------------------- ### Example host-inv.yaml Structure Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-agent-linux/README.md This snippet illustrates the expected YAML structure for the host inventory file that will be generated and sent to Intersight. It includes annotations for OS type, version, kernel, architecture, and details about network and storage drivers. ```yaml annotations: -kv: key: os.updateTimestamp value: 2023-04-09T20:42:58-0400 -kv: key: os.kernelVersionString value: Red Hat Enterprise Linux 7.9 -kv: key: os.releaseVersionString value: 3.10.0-1160.88.1.el7.x86_64 -kv: key: os.type value: Linux -kv: key: os.vendor value: Red Hat -kv: key: os.name value: Red Hat Enterprise Linux 7.9 -kv: key: os.arch value: x86_64 -kv: key: os.driver.0.name value: enic -kv: key: os.driver.1.name value: enic -kv: key: os.driver.0.version value: 2.3.0.53 -kv: key: os.driver.1.version value: 2.3.0.53 -kv: key: os.driver.0.description value: Cisco Systems Inc VIC 1440 Mezzanine Ethernet NIC -kv: key: os.driver.1.description value: Cisco Systems Inc VIC 1440 Mezzanine Ethernet NIC -kv: key: os.driver.2.name value: fnic -kv: key: os.driver.2.version value: 2.0.0.89-243.0 -kv: key: os.driver.2.description value: Cisco MQ FNIC FC -kv: key: os.driver.3.name value: ahci -kv: key: os.driver.4.name value: megaraid_sas -kv: key: os.driver.3.version value: 3.0 -kv: key: os.driver.4.version value: 07.719.02.00 -kv: key: os.driver.3.description value: Cisco Systems Inc Device 0101 -kv: key: os.driver.4.description value: Cisco Systems Inc Device 0124 ``` -------------------------------- ### Configure Intersight API authentication using environment variables Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/README.md Sets environment variables for API key ID and the private key file path to authenticate with the Intersight API. This is a common method for providing credentials to scripts without hardcoding them. ```bash export INTERSIGHT_API_PRIVATE_KEY=/Users/guest/Downloads/v3_SecretKey.txt export INTERSIGHT_API_KEY_ID=596cc... ``` -------------------------------- ### Configure Intersight API authentication using command-line arguments Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/README.md Provides Intersight API authentication details, including API key ID and the path to the API key file, directly through command-line arguments when running a Python script. The '--api-key-legacy' flag may be used for specific authentication modes. ```bash python users_example.py --api-key-id 596cc --api-key-file ~/Downloads/devSecretKey.txt --api-key-legacy ``` -------------------------------- ### Untitled No description -------------------------------- ### Send Inventory to Intersight via IPMI Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-agent-linux/README.md This script reads the 'host-inv.yaml' file and transmits its content to Intersight using IPMI commands. It involves deleting any existing file, opening a file descriptor, writing the inventory data, and then closing the file descriptor. Ensure 'ipmitool' is installed and configured. ```shell #!/bin/bash HOST_INV_FILE="host-inv.yaml" # Convert filename to hex hex_filename=$(echo -n "$HOST_INV_FILE" | xxd -p | tr -d '\n') # Delete existing file if it exists # echo "Deleting existing $HOST_INV_FILE..." # ipmitool raw 0x36 0x77 0x03 $hex_filename # Open and retrieve file descriptor # echo "Opening $HOST_INV_FILE to get file descriptor..." # file_descriptor_hex=$(ipmitool raw 0x36 0x77 0x00 $hex_filename | sed 's/ //g') # For simplicity, assuming file descriptor 0x08 if not obtained dynamically # In a real scenario, you would parse the output of the previous command file_descriptor_hex="08" # Read inventory content inventory_content=$(<"$HOST_INV_FILE") # Convert content to hex payload hex_payload=$(echo -n "$inventory_content" | xxd -p | tr -d '\n') # Write data to file (simplified - real implementation needs chunking for large files) # echo "Writing inventory data..." # ipmitool raw 0x36 0x77 0x02 $file_descriptor_hex $(printf %02x $(($(echo -n "$inventory_content" | wc -c)))) $(printf %08x 0) $hex_payload # Close file descriptor # echo "Closing file descriptor..." # ipmitool raw 0x36 0x77 0x01 $file_descriptor_hex # echo "Inventory sent to Intersight via IPMI." # --- Simplified example of IPMI commands for demonstration --- # Note: The actual implementation requires dynamic file descriptor handling and potential chunking for large files. # Example: Delete file command structure # echo "Delete File - 0x36 0x77 0x03 [hex-filename]" # echo " Example Delete host-inv.yaml - ipmitool raw 0x36 0x77 0x03 0x68 0x6f 0x73 0x74 0x2d 0x69 0x6e 0x76 0x2e 0x79 0x61 0x6d 0x6c" # Example: Open and Retrieve File Descriptor command structure # echo "Open and Retrieve File Descriptor - 0x36 0x77 0x00 [hex-filename]" # echo " Example Get host-inv.yaml file descriptor - ipmitool raw 0x36 0x77 0x00 0x68 0x6f 0x73 0x74 0x2d 0x69 0x6e 0x76 0x2e 0x79 0x61 0x6d 0x6c" # echo " IPMI will return file descriptor eg 0x08" # Example: Write Data to File command structure # echo "Write Data to File - 0x36 0x77 0x02 [hex-filedescriptor] [hex-payload length] [hex-litle endian starting point in file] [hex-payload]" # echo " Example write 1's (0x31) and 2's (0x32) starting at byte 40 in the host-inv.yaml file - ipmitool raw 0x36 0x77 0x02 0x03 0x14 0x28 0x00 0x00 0x00 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x0A" # Example: Close File Descriptor command structure # echo "Close File Descriptor - 0x36 0x77 0x01 [hex-filedescriptor]" # echo " Example close file ipmitool raw 0x36 0x77 0x01 0x08" exit 0 ``` -------------------------------- ### Uninstall conflicting Intersight SDKs Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/README.md Removes older or conflicting versions of the Intersight SDK, such as 'Intersight-OpenAPI', to ensure the correct SDK version is used. This is a prerequisite for a clean installation and to avoid potential runtime errors. ```bash pip uninstall Intersight-OpenAPI ``` -------------------------------- ### Schedule OS Discovery Tool with CRON Job Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md This snippet shows an example crontab entry for scheduling the `get_linux_inv_to_intersight.py` script. It is configured to run daily at 23:55, logging output to `/tmp/odt_out.log`. Recommended frequency is daily to hourly. ```bash $ crontab -l 55 23 * * * /home/odt-user/intersight-python-utils/os-discovery-tool/get_linux_inv_to_intersight.py --log-inventory --configfile=/home/odt-user/Documents/discovery_config_linux.json >> /tmp/odt_out.log $ ``` -------------------------------- ### Create and Configure Server Profile in Python Source: https://context7.com/ciscodevnet/intersight-python-utils/llms.txt This Python script demonstrates how to create a server profile, assign it to a physical server, attach policies (like firmware), and initiate deployment using the Intersight API. It requires the 'intersight' and 'credentials' modules for API interaction and authentication. The script handles profile creation, server assignment, policy attachment, and deployment actions, with error handling for API exceptions. ```python import intersight import credentials from intersight.api import server_api from intersight.model.server_profile import ServerProfile from intersight.model.compute_blade_relationship import ComputeBladeRelationship from intersight.model.organization_organization_relationship import OrganizationOrganizationRelationship from intersight.model.policy_abstract_policy_relationship import PolicyAbstractPolicyRelationship api_client = credentials.config_credentials() server_instance = server_api.ServerApi(api_client) try: # Create server profile profile = ServerProfile() profile.name = "Web-Server-Profile-01" profile.target_platform = "FIAttached" profile.organization = OrganizationOrganizationRelationship( moid="6418bfd46972652d30a596ef", object_type="organization.Organization", class_id="mo.MoRef" ) create_response = server_instance.create_server_profile(profile) print(f"Profile created: {create_response.name} (MOID: {create_response.moid})") # Assign server to profile profile_update = ServerProfile() profile_update.assigned_server = ComputeBladeRelationship( moid="641c9af36176753501b70f63", object_type="compute.Blade", class_id="mo.MoRef" ) profile_update.server_assignment_mode = "Static" server_instance.update_server_profile(create_response.moid, profile_update) print("Server assigned to profile") # Attach firmware policy current_profile = server_instance.get_server_profile_list( filter=f"Moid eq '{create_response.moid}'" ).results[0] policy_update = ServerProfile() policy_update.policy_bucket = current_profile.policy_bucket or [] policy_update.policy_bucket.append(PolicyAbstractPolicyRelationship( moid="64bedfd57068613101e8aa28", object_type="firmware.Policy", class_id="mo.MoRef" )) server_instance.patch_server_profile(create_response.moid, policy_update) print("Policy attached to profile") # Deploy configuration deploy_update = ServerProfile() deploy_update.action = "Deploy" server_instance.update_server_profile(create_response.moid, deploy_update) print("Profile deployment initiated") except intersight.ApiException as e: print(f"Error managing server profile: {e}") ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Extract Server MO Identity from Intersight (Bash) Source: https://github.com/ciscodevnet/intersight-python-utils/blob/main/os-discovery-tool/README.md This snippet shows the process of retrieving the Managed Object (MO) identity for a server from the Intersight platform. This unique identifier is crucial for associating server data with its representation in Intersight. ```Bash [ubuntu-server]: Extracting Server MO Identity from Intersight... [ubuntu-server]: Server MO Identity: 5bce7116683663343218ed92 ``` ```Bash [centos-server]: Extracting Server MO Identity from Intersight... [centos-server]: Server MO Identity: 5bce7116683663343218ed96 ``` ```Bash [suse-server]: Extracting Server MO Identity from Intersight... [suse-server]: Server MO Identity: 5c8ae0426176752d31a99718 ``` -------------------------------- ### Initiate Firmware Direct Download Update for Blade Server Source: https://context7.com/ciscodevnet/intersight-python-utils/llms.txt This script initiates a direct firmware upgrade on a specified blade server. It first performs an impact assessment to understand potential consequences before proceeding with the upgrade. It requires the Intersight SDK, credentials configuration, and specific MOIDs for the firmware distributable and the target server. ```python import intersight import credentials from intersight.model.firmware_distributable_relationship import FirmwareDistributableRelationship from intersight.model.compute_blade_relationship import ComputeBladeRelationship from intersight.model.firmware_upgrade_impact import FirmwareUpgradeImpact from intersight.model.firmware_direct_download import FirmwareDirectDownload from intersight.model.firmware_upgrade import FirmwareUpgrade from intersight.api import firmware_api api_client = credentials.config_credentials() firmware_instance = firmware_api.FirmwareApi(api_client) try: # Define firmware distributable reference firmware_dist = FirmwareDistributableRelationship( class_id="mo.MoRef", moid="621505896567612d31eb0fbf", object_type="firmware.Distributable" ) # Define target server target_server = ComputeBladeRelationship( moid="5fa5b87f6176752d37b73b26", object_type="compute.Blade", class_id="mo.MoRef" ) # Create impact assessment impact_assessment = FirmwareUpgradeImpact() impact_assessment.distributable = firmware_dist impact_assessment.server = [target_server] impact_response = firmware_instance.create_firmware_upgrade_impact(impact_assessment) print(f"Impact assessment created: {impact_response.moid}") # Create firmware upgrade firmware_upgrade = FirmwareUpgrade() firmware_upgrade.distributable = firmware_dist firmware_upgrade.server = target_server firmware_upgrade.upgrade_type = "direct_upgrade" firmware_upgrade.direct_download = FirmwareDirectDownload( upgradeoption="upgrade_mount_only", object_type="firmware.DirectDownload", class_id="firmware.DirectDownload" ) upgrade_response = firmware_instance.create_firmware_upgrade(firmware_upgrade) print(f"Firmware upgrade initiated: {upgrade_response.moid}") except intersight.ApiException as e: print(f"Error performing firmware upgrade: {e}") ``` -------------------------------- ### Power Cycle Server by Name with Python Source: https://context7.com/ciscodevnet/intersight-python-utils/llms.txt Powers cycles a specified server by its name using the Intersight Python SDK. It first locates the server by name and then initiates the power cycle action. Includes error handling for cases where the server is not found or API errors occur. ```python import sys import intersight from intersight.api import compute_api from intersight.model import compute_server_setting as compute import credentials def power_cycle_server(api_client, server_name): compute_instance = compute_api.ComputeApi(api_client) try: # Find server by name api_response = compute_instance.get_compute_server_setting_list( filter=f"Name eq '{server_name}'" ) if len(api_response.results) == 0: print(f"No servers found with name: {server_name}") return None # Power cycle the server update_response = compute_instance.update_compute_server_setting( api_response.results[0].moid, compute.ComputeServerSetting(admin_power_state="PowerCycle") ) print(f"Power cycle initiated for {server_name}") return update_response except intersight.ApiException as e: print(f"Error power cycling server: {e}") return None # Usage api_client = credentials.config_credentials() power_cycle_server(api_client, "server-01") ```