### Python IPAddress Usage Examples from netaddr Source: https://github.com/intel/mfd-typing/blob/main/README.md Demonstrates the usage of the `IPAddress` class from the netaddr library for manipulating and inspecting IPv4 and IPv6 addresses. Includes examples of version checking, string representation, integer conversion, and bit manipulation. ```python # Assuming IPAddress is imported from netaddr # from netaddr import IPAddress # Usage examples # ip = IPAddress('192.0.2.1') # ip.version -> 4 # str(ip) -> '192.0.2.1' # int(ip) -> 3221225985 # hex(ip) -> '0xc0000201' # ip.bin -> '0b11000000000000000000001000000001' # ip.bits() -> '11000000.00000000.00000010.00000001' # ip.words() -> (192, 0, 2, 1) # ip.is_multicast() # ip.is_reserved() # IPAddress(ip1) == IPAddress(ip2) ``` -------------------------------- ### Python IPNetwork Usage Examples from netaddr Source: https://github.com/intel/mfd-typing/blob/main/README.md Illustrates the usage of the `IPNetwork` class from the netaddr library for representing and manipulating IPv4 and IPv6 networks and subnets. Examples cover network instantiation, accessing broadcast addresses, network size, and prefix length. ```python # Assuming IPNetwork is imported from netaddr # from netaddr import IPNetwork # Usage examples # ip = IPNetwork('192.0.2.1/0') # broadcast_ip = IPNetwork('192.0.2.0/24').broadcast # IPNetwork('192.0.2.0/24').size # ip = IPNetwork('fe80::dead:beef/64') # netmask = IPNetwork('192.0.2.1/16').prefixlen ``` -------------------------------- ### PCIAddress: Formatting and Conversion Examples Source: https://github.com/intel/mfd-typing/blob/main/README.md Demonstrates various formatting and conversion capabilities of the PCIAddress structure, including converting to BDF, lspci, and handling hexadecimal to decimal conversions. ```python # PCIAddress(0, 94, 0, 1).sbdf == "00:094:00:01" # PCIAddress(0, 26, 10, 1).lspci == "0000:1a:0a.1" # PCIAddress(0xFFFF, 0xFF, 0x1F, 0x7).sbdf == "65535:255:31:07" # PCIAddress(0, 26, 10, 1).lspci == "0000:1a:0a.1" # PCIAddress(0, 0xFF, 0x1F, 0x7).lspci_short == "ff:1f.7" ``` -------------------------------- ### Python Base Dataclass for Network Interface Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `InterfaceInfo` dataclass as a base structure for network interface details. It includes common attributes like PCI address, device name, interface type, MAC address, and installation status. ```python from dataclasses import dataclass from typing import Optional # Assuming PCIAddress, PCIDevice, InterfaceType, MACAddress are defined elsewhere @dataclass class InterfaceInfo: """ Structure for network interface info. All possible fields that can be helpful, while creating network interface. """ pci_address: Optional[PCIAddress] = None pci_device: Optional[PCIDevice] = None name: Optional[str] = None interface_type: InterfaceType = InterfaceType.GENERIC mac_address: Optional[MACAddress] = None installed: Optional[bool] = None branding_string: Optional[str] = None vlan_info: Optional[VlanInterfaceInfo] = None ``` -------------------------------- ### PCIDevice: Initialization Source: https://github.com/intel/mfd-typing/blob/main/README.md The PCIDevice structure can be initialized with individual ID components (VendorID, DeviceID, SubVendorID, SubDeviceID) or by providing a colon-separated string of these IDs. It also supports default values for sub-system IDs when only vendor and device IDs are provided. ```python # PCIDevice(vendor_id: VendorID, device_id: DeviceID, sub_vendor_id: SubVendorID, sub_device_id: SubDeviceID) # PCIDevice(data="vendor_id:device_id:sub_vendor_id:sub_device_id") # PCIDevice(data="vendor_id:device_id") ``` -------------------------------- ### Execute Documentation Generation Script (Shell) Source: https://github.com/intel/mfd-typing/blob/main/sphinx-doc/README.md This command executes the Python script responsible for generating the Sphinx documentation. Ensure you are in the activated virtual environment and the correct directory before running this command. No specific inputs are required, and the output is the generation of HTML documentation files. ```shell $ python generate_docs.py ``` -------------------------------- ### Utils: Generate SED Inline Command Source: https://github.com/intel/mfd-typing/blob/main/README.md Constructs a complete `sed` command string for in-place file editing. It takes the current line, the new line, the filename, and an optional line index to prepare the `sed` command with all necessary parameters. ```python from mfd_typing.utils import get_sed_inline # Assume act_line = 'old content', new_line = 'new content', filename = 'my_file.txt', line_idx = 5 sed_command = get_sed_inline('old content', 'new content', 'my_file.txt', 5) # sed_command will be something like: sed -i "5cnew content" my_file.txt ``` -------------------------------- ### Utils: Kernel Version to Windows Flavor Mapping Source: https://github.com/intel/mfd-typing/blob/main/README.md Maps a given kernel version string to a specific Windows flavor enumeration. This is useful for identifying the exact Windows version based on its kernel identifier. ```python from mfd_typing.utils import get_windows_version_from_kernel windows_flavour = get_windows_version_from_kernel("10.0.19041") # windows_flavour will be a WindowsFlavour enum member ``` -------------------------------- ### PCIAddress: Create from various inputs Source: https://github.com/intel/mfd-typing/blob/main/README.md The PCIAddress structure can be initialized with individual integer components (domain, bus, slot, func) or by converting string/double representations of these components. It also supports initialization from string formats like BDF or full lspci output. ```python from mfd_typing.pci_address import PCIAddress pci = PCIAddress('0', 0.0, '0', 0.0) # PCIAddress(0,0,0,0) print(pci.domain) print(pci.bus) print(pci.slot) print(pci.func) ``` ```python from mfd_typing.pci_address import PCIAddress pci = PCIAddress("0000:00:00.0") # equivalent of PCIAddress(0,0,0,0) pci = PCIAddress("00:00.0") # equivalent of PCIAddress(0,0,0,0) because `domain` default will be se on `0` ``` -------------------------------- ### Define SystemInfo Dataclass - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines a dataclass for generic system information about the System Under Test. It includes fields for hostname, OS details, kernel version, boot time, manufacturer, model, bitness, BIOS version, memory, and architecture. ```python @dataclass class SystemInfo: """Generic Information about the System Under Test.""" host_name: str | None = None # WINDOWS-2019 os_name: str | None = None # Microsoft Windows Server 2019 Standard os_version: str | None = None # 10.0.17763 N/A Build 17763 kernel_version: str | None = None # 17763 system_boot_time: str | None = None # 4/4/2023, 2:40:55 PM system_manufacturer: str | None = None # Intel Corporation system_model: str | None = None # S2600BPB system_bitness: OSBitness | None = None # x64-based PC -> OSBitness.OS_64BIT bios_version: str | None = None # Intel Corporation SE5C620.86B.02.01.0012.070720200218, 7/7/2020 total_memory: str | None = None # 130,771 MB architecture_info: str | None = None # x86_64 ``` -------------------------------- ### Utils: Prepare SED Command String Source: https://github.com/intel/mfd-typing/blob/main/README.md Prepares a string to be used as a literal pattern within a `sed` command, ensuring that special characters within the input string are properly escaped to avoid misinterpretation by `sed`. ```python from mfd_typing.utils import prepare_sed_string original_string = "file.txt (new)" prepared_string = prepare_sed_string(original_string, r"[()]?") # prepared_string will be "file\.txt \(new\)" ``` -------------------------------- ### Signing Git Commits Automatically Source: https://github.com/intel/mfd-typing/blob/main/CONTRIBUTING.md Demonstrates how to automatically sign your Git commits using your configured user name and email. This ensures compliance with the project's contribution policy by appending the 'Signed-off-by' line to your commit messages. ```git git config --global user.name "Your Name" git config --global user.email "your.email@example.com" git commit -s -m "Your commit message" ``` -------------------------------- ### Utils: MAC String Canonical Formatting Source: https://github.com/intel/mfd-typing/blob/main/README.md Takes a MAC address string in any common format and standardizes it into a canonical format, typically colon-separated uppercase hexadecimal pairs. ```python from mfd_typing.utils import format_mac_string_to_canonical canonical_mac = format_mac_string_to_canonical("00:1a:2b:3c:4d:5e") # canonical_mac will be "00:1A:2B:3C:4D:5E" canonical_mac_dash = format_mac_string_to_canonical("00-1a-2b-3c-4d-5e") # canonical_mac_dash will be "00:1A:2B:3C:4D:5E" ``` -------------------------------- ### Utils: Non-conforming Version Comparison Source: https://github.com/intel/mfd-typing/blob/main/README.md Compares two version strings that may not conform to standard versioning schemes (e.g., not strictly semantic versioning), returning an integer indicating their relative order. ```python from mfd_typing.utils import compare_non_conforming_versions comparison_result = compare_non_conforming_versions("1.0.beta", "1.0.alpha") # comparison_result will indicate that "1.0.beta" is greater than "1.0.alpha" ``` -------------------------------- ### Utils: MAC String to HEX Conversion Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts a MAC address string, regardless of its input format, into its canonical hexadecimal string representation. ```python from mfd_typing.utils import convert_mac_string_to_hex mac_hex = convert_mac_string_to_hex("00:1A:2B:3C:4D:5E") # mac_hex will be "001a2b3c4d5e" mac_hex_alt = convert_mac_string_to_hex("00-1a-2b-3c-4d-5e") # mac_hex_alt will be "001a2b3c4d5e" ``` -------------------------------- ### Python Dataclass for Linux Network Interface Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `LinuxInterfaceInfo` dataclass, inheriting from `InterfaceInfo`, to store Linux-specific network interface attributes. Includes namespace and VSI information. ```python from dataclasses import dataclass from typing import Optional # Assuming InterfaceInfo, VsiInfo are defined elsewhere @dataclass class LinuxInterfaceInfo(InterfaceInfo): """ Structure for Linux network interface info. All possible fields that can be helpful, while creating network interface. """ namespace: Optional[str] = None vsi_info: Optional[VsiInfo] = None ``` -------------------------------- ### Python Dataclass for Windows Network Interface Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `WindowsInterfaceInfo` dataclass, inheriting from `InterfaceInfo`, for Windows-specific network interface details. Includes various Windows-specific properties and cluster information. ```python from dataclasses import dataclass from typing import Optional # Assuming InterfaceInfo, ClusterInfo are defined elsewhere @dataclass class WindowsInterfaceInfo(InterfaceInfo): """ Structure for Windows network interface info. All possible fields that can be helpful, while creating network interface. """ description: Optional[str] = None index: Optional[str] = None manufacturer: Optional[str] = None net_connection_status: Optional[str] = None pnp_device_id: Optional[str] = None product_name: Optional[str] = None service_name: Optional[str] = None guid: Optional[str] = None speed: Optional[str] = None cluster_info: Optional[ClusterInfo] = None ``` -------------------------------- ### MACAddress Structure and Methods - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines a structure for representing MAC addresses in standard IEEE format. It includes methods for generating random MAC addresses (multicast, unicast, prefixed) and parsing MAC strings into a specific format. ```python class MACAddress(str, Enum): """Structure for representing mac address""" # Usage Examples: # * mac = MACAddress("00-1B-77-49-54-FD") # * int(mac) -> 117965411581 # * hex(mac) -> '0x1b774954fd' # * oct(mac) -> '01556722252375' # * mac.bits() -> '00000000-00011011-01110111-01001001-01010100-11111101' # * mac.bin -> '0b1101101110111010010010101010011111101' # * str(MACAddress(mac1)) -> '00:1b:77:49:54:fd' # * MACAddress(mac1) == MACAddress(mac2) # * MACAddress(mac1) > MACAddress(mac2) # * MACAddress(mac1) < MACAddress(mac2) # Implemented methods # `get_random_mac() -> MACAddress` : Generate a random MAC address. # `get_random_multicast_mac() -> MACAddress` : Generate multicast MAC starting from '01:00:5e:xx:xx:xx', with the last 3 octets randomize. # `get_random_unicast_mac() -> MACAddress` : Generate unicast MAC starting from 'fa:xx:xx:xx:xx:xx' # `get_random_mac_using_prefix(prefix: str = None) -> MACAddress` : Generate a random MAC address from the range prefix:xx:xx:xx - prefix:xx:xx:xx. If prefix is not passed the MAC address generated will be fa:11:11:xx:xx:xx. # `parse_mac(mac: MACAddress) -> str`: Parse mac in special way to get i.e. from `3c:fd:fe:bc:b7:68` -> `{0xffff,0xffff,0xffff}`. The function creates a list from string and chops it to 3x 2 byte, and reverses bytes order for each couple. ``` -------------------------------- ### Utils: Decimal to Binary Conversion Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts a decimal value, provided as a string or integer, into its binary string representation. ```python from mfd_typing.utils import decimal_to_bin bin_value = decimal_to_bin("10") # bin_value will be "0b1010" bin_value_int = decimal_to_bin(15) # bin_value_int will be "0b1111" ``` -------------------------------- ### OSNames for Switches: Mellanox OS Regexes Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines regular expressions used to identify Mellanox operating systems. This dictionary maps the `OSName.MELLANOX` enum to a list of regex patterns that match various Mellanox OS names like 'Onyx', 'SX_PPC_M460EX', and 'MLNX-OS'. ```python from mfd_typing.os_names import OSName SWITCHES_OS_NAME_REGEXES = { OSName.MELLANOX: [r"Onyx", r"SX_PPC_M460EX", r"MLNX-OS"] } ``` -------------------------------- ### Python Dataclass for Virtual Station Interface (VSI) Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `VsiInfo` dataclass for storing details about a Virtual Station Interface (VSI). This includes identifiers like function ID, host ID, VSI ID, and vPort ID, along with flags indicating creation and enablement status. ```python from dataclasses import dataclass @dataclass class VsiInfo: """Structure for VSI Info.""" fn_id: int host_id: int is_vf: bool vsi_id: int vport_id: int is_created: bool is_enabled: bool ``` -------------------------------- ### Utils: IP Address to HEX Value Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts IPv4Address, IPv6Address, IPv4Interface, or IPv6Interface objects into their raw hexadecimal string representation. ```python from ipaddress import IPv4Address from mfd_typing.utils import convert_ip_to_hex_value ipv4 = IPv4Address("127.0.0.1") hex_val = convert_ip_to_hex_value(ipv4) # hex_val will be "7f000001" ``` -------------------------------- ### Utils: IP Address to Special Bracket-Colon Format Source: https://github.com/intel/mfd-typing/blob/main/README.md Parses an IP address (IPv4 or IPv6) and formats it into a specific string representation involving curly braces, hexadecimal values, and reversed byte order for each 2-byte segment. ```python from ipaddress import ip_address from mfd_typing.utils import convert_ip_to_brackets_colon_format ipv4 = ip_address("1.2.1.1") formatted_ipv4 = convert_ip_to_brackets_colon_format(ipv4) # formatted_ipv4 will be "{0x0201,0x0101}" ipv6 = ip_address("fe80::3efd:feff:febc:b4c9") formatted_ipv6 = convert_ip_to_brackets_colon_format(ipv6) # formatted_ipv6 will be "{0x80fe,0x0000,0x0000,0x0000,0xfd3e,0xfffe,0xbcfe,0xc9b4}" ``` -------------------------------- ### Utils: IP Address to Hexadecimal String Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts various IP address types (IPv4, IPv6, interfaces) into a comma-separated hexadecimal string representation. Optionally, it can pad IPv6 addresses to a specific length. ```python from ipaddress import IPv4Address from mfd_typing.utils import convert_ip_dc_to_ip_hex ipv4 = IPv4Address("192.168.1.1") hex_ip = convert_ip_dc_to_ip_hex(ipv4) # hex_ip will be "0xc0a80101" ``` -------------------------------- ### Python Dataclass for Driver Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `DriverInfo` dataclass for storing essential driver details, specifically the driver name and version. This structure is used to represent information about a software driver. ```python from dataclasses import dataclass @dataclass class DriverInfo: """Structure for information about driver.""" driver_name: str driver_version: str ``` -------------------------------- ### Python Dataclass for VLAN Interface Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `VlanInterfaceInfo` dataclass for storing VLAN ID and parent interface details. This is used to represent virtual network interfaces assigned to a specific 802.1Q VLAN. ```python from dataclasses import dataclass from typing import Optional @dataclass class VlanInterfaceInfo: """Structure for vlan interface info.""" vlan_id: int parent: Optional[str] = None ``` -------------------------------- ### Utils: Port Number Conversion to Hex Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts a port number, given as an integer or string, into a comma-separated hexadecimal string format. ```python from mfd_typing.utils import convert_port_dc_to_port_hex hex_port = convert_port_dc_to_port_hex(80) # hex_port will be "0x50" hex_ports = convert_port_dc_to_port_hex("80,443") # hex_ports will be "0x50,0x1bb" ``` -------------------------------- ### Define OSName Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for supported operating system names, compatible with os.name. This provides a standardized way to refer to different OS names. ```python class OSName(str, Enum): """Available os names.""" WINDOWS = "Windows" LINUX = "Linux" FREEBSD = "FreeBSD" ESXI = "VMkernel" EFISHELL = "EFIShell" ``` -------------------------------- ### Dataclass Utils: Field Type and Value Conversion Source: https://github.com/intel/mfd-typing/blob/main/README.md Provides helper methods for dataclasses, including `get_field_type` to retrieve the type hint of a specific field and `convert_value_field_to_typehint_type` to convert a field's value to the type specified in its type hint. ```python # get_field_type(model, field_name: str) -> type # convert_value_field_to_typehint_type(model, field_name: str, value: any) -> any ``` -------------------------------- ### Define OSBitness Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for supported operating system bitness (32-bit or 64-bit). This is useful for system compatibility checks. ```python class OSBitness(str, Enum): """Available OS bitnesses.""" OS_32BIT = "32bit" OS_64BIT = "64bit" ``` -------------------------------- ### Define CPUArchitecture Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for available CPU architectures such as x86, x86-64, ARM, and ARM64. This is essential for cross-platform development and deployment. ```python class CPUArchitecture(str, Enum): """Available CPU architectures.""" X86 = "x86" X86_64 = "x86-64" ARM = "ARM" ARM64 = "ARM64" ``` -------------------------------- ### Define WindowsFlavour Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for supported Windows OS versions, including server and Azure Stack HCI editions. This aids in specifying and validating Windows versions. ```python class WindowsFlavour(Enum): """Available Windows System Flavours.""" WindowsServer2012R2 = "Microsoft Windows Server 2012 R2" WindowsServer2016 = "Microsoft Windows Server 2016" # Windows-10.0.14393 WindowsServer2019 = "Microsoft Windows Server 2019" # Windows-10.0.17763 WindowsServer2022 = "Microsoft Windows Server 2022" # Windows-10.0.20348 WindowsServer2025 = "Microsoft Windows Server 2025" # Windows-10.0.26100 WindowsServer2022H2 = "Microsoft Windows Server 2022 H2" # Windows-10.0.22621 AzureStackHCI22H2 = "Microsoft Azure Stack HCI 22H2" # Windows-10.0.20349 AzureStackHCI23H2 = "Microsoft Azure Stack HCI 23H2" # Windows-10.0.25398 AzureStackHCI24H2 = "Microsoft Azure Stack HCI 24H2" # Windows-10.0.26100 ``` -------------------------------- ### Utils: Unsigned Integer Comparison Source: https://github.com/intel/mfd-typing/blob/main/README.md Compares two integers as if they were unsigned, correctly handling potential overflows that can occur with negative values when treated as signed integers. ```python from mfd_typing.utils import compare_numbers_as_unsigned result = compare_numbers_as_unsigned(-1, 1) # result will be False because -1 treated as unsigned is larger than 1 ``` -------------------------------- ### Define OSType Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for supported operating system types, compatible with platform.system. This helps in standardizing OS identification across different platforms. ```python class OSType(str, Enum): """Available OS types.""" WINDOWS = "nt" POSIX = "posix" EFISHELL = "efishell" ``` -------------------------------- ### Utils: Decimal to Hexadecimal Conversion Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts a decimal value, provided as a string or integer, into its hexadecimal string representation. ```python from mfd_typing.utils import decimal_to_hex hex_value = decimal_to_hex("255") # hex_value will be "0xff" hex_value_int = decimal_to_hex(4095) # hex_value_int will be "0xfff" ``` -------------------------------- ### Utils: String to Boolean Conversion Source: https://github.com/intel/mfd-typing/blob/main/README.md Converts various string representations of boolean values (case-insensitive) into Python's True or False. Supported positive values include 'true', 'yes', '1', 'y', 't', 'on', and negative values include 'false', 'no', '0', 'n', 'f', 'off'. ```python from mfd_typing.utils import strtobool print(strtobool("True")) # Output: True print(strtobool("no")) # Output: False print(strtobool("1")) # Output: True ``` -------------------------------- ### Utils: String to Number Calculation Source: https://github.com/intel/mfd-typing/blob/main/README.md Calculates an integer based on a provided input string, constrained within a specified range. This function is useful for deriving deterministic numerical identifiers from arbitrary strings. ```python from mfd_typing.utils import get_number_based_on_string number = get_number_based_on_string("example_string", 1000) # number will be an integer between 0 and 999 ``` -------------------------------- ### Define CPUBitness Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for available CPU bitness (32-bit or 64-bit). This is crucial for software compatibility and performance considerations. ```python class CPUBitness(str, Enum): """Available CPU bitnesses.""" CPU_32BIT = "32bit" CPU_64BIT = "64bit" ``` -------------------------------- ### Python Dataclass for Cluster Network Information Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines the `ClusterInfo` dataclass for storing cluster-related network information, such as the node name and network identifier. This is typically used for network interfaces within a cluster environment. ```python from dataclasses import dataclass from typing import Optional @dataclass class ClusterInfo: """Structure for cluster info.""" node: Optional[str] = None network: Optional[str] = None ``` -------------------------------- ### Define InterfaceType Enum - Python Source: https://github.com/intel/mfd-typing/blob/main/README.md Defines an enumeration for different types of network interfaces. This structure helps in categorizing and managing network interface configurations. ```python class InterfaceType(str, Enum): """Structure for network interface types.""" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.