From 31f93dc29dfbf8accaf1ac98c6c1a7b5e493685c Mon Sep 17 00:00:00 2001 From: Alphaeus Mote Date: Wed, 7 May 2025 10:47:38 -0400 Subject: [PATCH] Add SMBIOS functionality with manufacturer profiles --- Documentation/cmdlets/Get-ProxmoxVMSMBIOS.md | 140 ++++++++ Documentation/cmdlets/Set-ProxmoxVMSMBIOS.md | 310 ++++++++++++++++++ Documentation/examples/SMBIOS-Examples.ps1 | 66 ++++ Module/PSProxmox.psd1 | 4 +- Module/README.md | 259 +++++++++++++-- PSProxmox/Cmdlets/GetProxmoxVMSMBIOSCmdlet.cs | 82 +++++ .../Cmdlets/NewProxmoxVMBuilderCmdlet.cs | 90 +++++ PSProxmox/Cmdlets/NewProxmoxVMCmdlet.cs | 25 ++ PSProxmox/Cmdlets/SetProxmoxVMSMBIOSCmdlet.cs | 177 ++++++++++ PSProxmox/Models/ProxmoxVMBuilder.cs | 100 ++++++ PSProxmox/Models/ProxmoxVMSMBIOS.cs | 124 +++++++ PSProxmox/Models/ProxmoxVMSMBIOSProfile.cs | 207 ++++++++++++ 12 files changed, 1561 insertions(+), 23 deletions(-) create mode 100644 Documentation/cmdlets/Get-ProxmoxVMSMBIOS.md create mode 100644 Documentation/cmdlets/Set-ProxmoxVMSMBIOS.md create mode 100644 Documentation/examples/SMBIOS-Examples.ps1 create mode 100644 PSProxmox/Cmdlets/GetProxmoxVMSMBIOSCmdlet.cs create mode 100644 PSProxmox/Cmdlets/SetProxmoxVMSMBIOSCmdlet.cs create mode 100644 PSProxmox/Models/ProxmoxVMSMBIOS.cs create mode 100644 PSProxmox/Models/ProxmoxVMSMBIOSProfile.cs diff --git a/Documentation/cmdlets/Get-ProxmoxVMSMBIOS.md b/Documentation/cmdlets/Get-ProxmoxVMSMBIOS.md new file mode 100644 index 0000000..e1d24e5 --- /dev/null +++ b/Documentation/cmdlets/Get-ProxmoxVMSMBIOS.md @@ -0,0 +1,140 @@ +# Get-ProxmoxVMSMBIOS + +Gets the SMBIOS settings for a Proxmox VM. + +## Syntax + +```powershell +Get-ProxmoxVMSMBIOS + -Connection + -Node + -VMID + [-RawJson] + [] +``` + +## Description + +The `Get-ProxmoxVMSMBIOS` cmdlet retrieves the SMBIOS (System Management BIOS) settings for a virtual machine in Proxmox VE. SMBIOS settings allow you to customize hardware identification information that's presented to the guest operating system. + +## Parameters + +### -Connection + +The connection to the Proxmox VE server. + +```yaml +Type: ProxmoxConnection +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Node + +The node where the VM is located. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VMID + +The ID of the VM. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RawJson + +Return the raw JSON response from the Proxmox API instead of a PowerShell object. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### None + +## Outputs + +### PSProxmox.Models.ProxmoxVMSMBIOS + +Returns a ProxmoxVMSMBIOS object containing the SMBIOS settings for the VM. + +## Notes + +- SMBIOS settings can be useful for software licensing that's tied to hardware identifiers +- These settings can also help with VM migration between different hypervisors +- Some applications may require specific hardware information to function properly + +## Examples + +### Example 1: Get SMBIOS settings for a VM + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 +``` + +This example retrieves the SMBIOS settings for VM 100 on node pve1. + +### Example 2: Get SMBIOS settings and display specific properties + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 +$smbios | Select-Object Manufacturer, Product, Serial +``` + +This example retrieves the SMBIOS settings for VM 100 and displays only the manufacturer, product, and serial number. + +### Example 3: Get SMBIOS settings as raw JSON + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -RawJson +``` + +This example retrieves the SMBIOS settings for VM 100 as raw JSON. + +## Related Links + +- [Set-ProxmoxVMSMBIOS](Set-ProxmoxVMSMBIOS.md) +- [New-ProxmoxVMBuilder](New-ProxmoxVMBuilder.md) +- [New-ProxmoxVM](New-ProxmoxVM.md) diff --git a/Documentation/cmdlets/Set-ProxmoxVMSMBIOS.md b/Documentation/cmdlets/Set-ProxmoxVMSMBIOS.md new file mode 100644 index 0000000..81fda54 --- /dev/null +++ b/Documentation/cmdlets/Set-ProxmoxVMSMBIOS.md @@ -0,0 +1,310 @@ +# Set-ProxmoxVMSMBIOS + +Sets the SMBIOS settings for a Proxmox VM. + +## Syntax + +```powershell +Set-ProxmoxVMSMBIOS + -Connection + -Node + -VMID + -SMBIOS + [-PassThru] + [-WhatIf] + [-Confirm] + [] +``` + +```powershell +Set-ProxmoxVMSMBIOS + -Connection + -Node + -VMID + [-Manufacturer ] + [-Product ] + [-Version ] + [-Serial ] + [-Family ] + [-UUID ] + [-PassThru] + [-WhatIf] + [-Confirm] + [] +``` + +## Description + +The `Set-ProxmoxVMSMBIOS` cmdlet sets the SMBIOS (System Management BIOS) settings for a virtual machine in Proxmox VE. SMBIOS settings allow you to customize hardware identification information that's presented to the guest operating system. + +## Parameters + +### -Connection + +The connection to the Proxmox VE server. + +```yaml +Type: ProxmoxConnection +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Node + +The node where the VM is located. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -VMID + +The ID of the VM. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SMBIOS + +The SMBIOS settings object. + +```yaml +Type: ProxmoxVMSMBIOS +Parameter Sets: SMBIOSObject +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Manufacturer + +The manufacturer information. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Product + +The product information. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Version + +The version information. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Serial + +The serial number. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Family + +The system family. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UUID + +The system UUID. + +```yaml +Type: String +Parameter Sets: Individual +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru + +Return the updated SMBIOS settings. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf + +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm + +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### None + +## Outputs + +### PSProxmox.Models.ProxmoxVMSMBIOS + +Returns a ProxmoxVMSMBIOS object if -PassThru is specified. + +## Notes + +- SMBIOS settings can be useful for software licensing that's tied to hardware identifiers +- These settings can also help with VM migration between different hypervisors +- Some applications may require specific hardware information to function properly + +## Examples + +### Example 1: Set individual SMBIOS settings for a VM + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Dell Inc." -Product "PowerEdge R740" -Serial "ABC123" +``` + +This example sets the manufacturer, product, and serial number SMBIOS settings for VM 100 on node pve1. + +### Example 2: Set SMBIOS settings using an object + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +$smbios = New-Object PSProxmox.Models.ProxmoxVMSMBIOS +$smbios.Manufacturer = "Dell Inc." +$smbios.Product = "PowerEdge R740" +$smbios.Serial = "ABC123" +Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios +``` + +This example creates a ProxmoxVMSMBIOS object and uses it to set the SMBIOS settings for VM 100. + +### Example 3: Get current SMBIOS settings, modify them, and update + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 +$smbios.Manufacturer = "Dell Inc." +$smbios.Product = "PowerEdge R740" +Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios -PassThru +``` + +This example retrieves the current SMBIOS settings for VM 100, modifies them, and then updates the VM with the new settings. + +## Related Links + +- [Get-ProxmoxVMSMBIOS](Get-ProxmoxVMSMBIOS.md) +- [New-ProxmoxVMBuilder](New-ProxmoxVMBuilder.md) +- [New-ProxmoxVM](New-ProxmoxVM.md) diff --git a/Documentation/examples/SMBIOS-Examples.ps1 b/Documentation/examples/SMBIOS-Examples.ps1 new file mode 100644 index 0000000..36ea1cb --- /dev/null +++ b/Documentation/examples/SMBIOS-Examples.ps1 @@ -0,0 +1,66 @@ +# SMBIOS-Examples.ps1 +# This script demonstrates how to use SMBIOS settings with the PSProxmox module. + +# Import the PSProxmox module +Import-Module PSProxmox + +# Connect to the Proxmox VE server +$credential = Get-Credential -Message "Enter your Proxmox VE credentials" +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam" + +# Example 1: Create a VM with automatic SMBIOS settings using a specific manufacturer profile +$vm1 = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "dell-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Dell" + +# Example 2: Create a VM with automatic SMBIOS settings using a random manufacturer profile +$vm2 = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "random-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Random" + +# Example 3: Create a VM using the builder pattern with automatic SMBIOS settings +$builder = New-ProxmoxVMBuilder -Name "hp-server" -AutomaticSMBIOS -SMBIOSProfile "HP" +$builder.WithMemory(4096) + .WithCores(2) + .WithDisk(50, "local-lvm") + .WithNetwork("virtio", "vmbr0") + .WithStart($true) +$vm3 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder + +# Example 4: Create a VM using the builder pattern with manual SMBIOS settings +$builder = New-ProxmoxVMBuilder -Name "custom-server" +$builder.WithMemory(4096) + .WithCores(2) + .WithDisk(50, "local-lvm") + .WithNetwork("virtio", "vmbr0") + .WithSMBIOSManufacturer("Custom Manufacturer") + .WithSMBIOSProduct("Custom Product") + .WithSMBIOSVersion("1.0") + .WithSMBIOSSerial("CUSTOM123") + .WithStart($true) +$vm4 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder + +# Example 5: Get SMBIOS settings for an existing VM +$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 +Write-Host "Current SMBIOS settings for VM 100:" +Write-Host "Manufacturer: $($smbios.Manufacturer)" +Write-Host "Product: $($smbios.Product)" +Write-Host "Version: $($smbios.Version)" +Write-Host "Serial: $($smbios.Serial)" +Write-Host "Family: $($smbios.Family)" +Write-Host "UUID: $($smbios.UUID)" + +# Example 6: Update SMBIOS settings for an existing VM using individual parameters +Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Lenovo" -Product "ThinkSystem SR650" -Serial "LENOVO123" + +# Example 7: Update SMBIOS settings for an existing VM using a manufacturer profile +$smbios = ProxmoxVMSMBIOSProfile.GetProfile("VMware") +Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 101 -SMBIOS $smbios + +# Example 8: Create a VM with SMBIOS settings that mimic a physical server for licensing purposes +$builder = New-ProxmoxVMBuilder -Name "license-server" -AutomaticSMBIOS -SMBIOSProfile "Dell" +$builder.WithMemory(8192) + .WithCores(4) + .WithDisk(100, "local-lvm") + .WithNetwork("virtio", "vmbr0") + .WithStart($true) +$vm5 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder + +# Disconnect from the server when done +Disconnect-ProxmoxServer -Connection $connection diff --git a/Module/PSProxmox.psd1 b/Module/PSProxmox.psd1 index 83cd836..a184db3 100644 --- a/Module/PSProxmox.psd1 +++ b/Module/PSProxmox.psd1 @@ -1,7 +1,7 @@ @{ RootModule = 'PSProxmox.psm1' NestedModules = @('bin\PSProxmox.dll') - ModuleVersion = '2025.04.28.2035' + ModuleVersion = '2025.05.07.1046' GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad' Author = 'PSProxmox Team' CompanyName = 'PSProxmox' @@ -98,3 +98,5 @@ + + diff --git a/Module/README.md b/Module/README.md index 390c4ed..4988250 100644 --- a/Module/README.md +++ b/Module/README.md @@ -1,48 +1,263 @@ -# PSProxmox Module +# PSProxmox -This directory contains the PowerShell module files for PSProxmox. +PSProxmox is a C#-based PowerShell module for managing Proxmox VE clusters. It provides a comprehensive set of cmdlets for interacting with Proxmox VE API, featuring structured return objects, mass deployment tools, automatic IP management, and more. -## Structure +## Features -- **PSProxmox.psd1**: The module manifest file -- **bin/**: Contains the compiled DLL +- **Session Management**: Authenticate and persist sessions with Proxmox VE clusters +- **Core CRUD Operations**: Manage VMs, Storage, Network, Users, Roles, SDN, and Clusters +- **Templates**: Create and use VM deployment templates +- **Mass Creation**: Bulk create VMs with prefix/counter +- **IP Management**: CIDR parsing, subnetting, FIFO IP queue assignment +- **Structured Objects**: All outputs are typed C# classes (PowerShell-native) +- **Pipeline Support**: Cmdlets support pipeline input where appropriate -## Building the Module +## Project Structure -The module is built using the build script in the Scripts directory: +- **Module/**: Contains the PowerShell module files +- **PSProxmox/**: Contains the C# source code for the module +- **Documentation/**: Contains detailed documentation and examples +- **Scripts/**: Contains build and installation scripts +- **Release/**: Contains built releases (created by build script) + +## Installation + +### From PowerShell Gallery (Recommended) ```powershell -.\Scripts\build.ps1 +# Install from PowerShell Gallery +Install-Module -Name PSProxmox -Scope CurrentUser ``` -This will compile the C# code from the PSProxmox directory and place the DLL in the bin directory. - -## Installing the Module - -You can install the module using the installation script in the Scripts directory: +### Manual Installation ```powershell +# Clone the repository +git clone https://github.com/freedbygrace/PSProxmox.git +cd PSProxmox + +# Build the module +.\Scripts\build.ps1 + +# Install the module .\Scripts\Install-PSProxmox.ps1 ``` -This will copy the module files to your PowerShell modules directory. +## Getting Started -## Manual Installation +### Connecting to a Proxmox VE Server -You can manually install the module by copying the files to your PowerShell modules directory: - -For Windows PowerShell: ```powershell -Copy-Item -Path .\Module\* -Destination "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\PSProxmox" -Recurse -Force +# Connect using username and password +$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam" + +# Connect using a credential object +$credential = Get-Credential +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam" ``` -For PowerShell Core: +### Managing Virtual Machines + ```powershell -Copy-Item -Path .\Module\* -Destination "$env:USERPROFILE\Documents\PowerShell\Modules\PSProxmox" -Recurse -Force +# Get all VMs +$vms = Get-ProxmoxVM -Connection $connection + +# Get a specific VM +$vm = Get-ProxmoxVM -Connection $connection -VMID 100 + +# Create a new VM +$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "test-vm" -Memory 2048 -Cores 2 -DiskSize 32 -Start + +# Create a new VM using the builder pattern +$builder = New-ProxmoxVMBuilder -Name "web-server" +$builder.WithMemory(4096) + .WithCores(2) + .WithDisk(50, "local-lvm") + .WithNetwork("virtio", "vmbr0") + .WithIPConfig("192.168.1.10/24", "192.168.1.1") + .WithStart($true) + +$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder + +# Start, stop, and restart VMs +Start-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 +Stop-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 +Restart-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 + +# Remove a VM +Remove-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 -Confirm:$false ``` +### Managing Templates + +```powershell +# Create a template from an existing VM +$template = New-ProxmoxVMTemplate -Connection $connection -VMID 100 -Name "Ubuntu-Template" -Description "Ubuntu 20.04 Template" + +# Get all templates +$templates = Get-ProxmoxVMTemplate + +# Create a VM from a template +$vm = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" -Name "web01" -Start + +# Create multiple VMs from a template +$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" -Prefix "web" -Count 3 -Start +``` + +### Managing Storage + +```powershell +# Get all storage +$storage = Get-ProxmoxStorage -Connection $connection + +# Get storage on a specific node +$storage = Get-ProxmoxStorage -Connection $connection -Node "pve1" + +# Create a new storage +$storage = New-ProxmoxStorage -Connection $connection -Name "backup" -Type "dir" -Path "/mnt/backup" -Content "backup,iso" + +# Remove a storage +Remove-ProxmoxStorage -Connection $connection -Name "backup" -Confirm:$false +``` + +### Managing Networks + +```powershell +# Get all network interfaces on a node +$networks = Get-ProxmoxNetwork -Connection $connection -Node "pve1" + +# Create a new bridge interface +$network = New-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" -Type "bridge" -BridgePorts "eth1" -Method "static" -Address "192.168.2.1" -Netmask "255.255.255.0" -Autostart + +# Remove a network interface +Remove-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" -Confirm:$false +``` + +### Managing Users and Roles + +```powershell +# Get all users +$users = Get-ProxmoxUser -Connection $connection + +# Create a new user +$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force +$user = New-ProxmoxUser -Connection $connection -Username "john" -Realm "pam" -Password $securePassword -FirstName "John" -LastName "Doe" -Email "john.doe@example.com" + +# Remove a user +Remove-ProxmoxUser -Connection $connection -UserID "john@pam" -Confirm:$false + +# Get all roles +$roles = Get-ProxmoxRole -Connection $connection + +# Create a new role +$role = New-ProxmoxRole -Connection $connection -RoleID "Developer" -Privileges "VM.Allocate", "VM.Config.Disk", "VM.Config.CPU", "VM.PowerMgmt" + +# Remove a role +Remove-ProxmoxRole -Connection $connection -RoleID "Developer" -Confirm:$false +``` + +### Managing SDN + +```powershell +# Get all SDN zones +$zones = Get-ProxmoxSDNZone -Connection $connection + +# Create a new SDN zone +$zone = New-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Type "vlan" -Bridge "vmbr0" + +# Remove an SDN zone +Remove-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Confirm:$false + +# Get all SDN VNets +$vnets = Get-ProxmoxSDNVnet -Connection $connection + +# Create a new SDN VNet +$vnet = New-ProxmoxSDNVnet -Connection $connection -VNet "vnet1" -Zone "zone1" -IPv4 "192.168.1.0/24" -Gateway "192.168.1.1" + +# Remove an SDN VNet +Remove-ProxmoxSDNVnet -Connection $connection -VNet "vnet1" -Confirm:$false +``` + +### Managing Clusters + +```powershell +# Get cluster information +$cluster = Get-ProxmoxCluster -Connection $connection + +# Join a node to a cluster +$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force +Join-ProxmoxCluster -Connection $connection -ClusterName "cluster1" -HostName "pve1" -Password $securePassword + +# Leave a cluster +Leave-ProxmoxCluster -Connection $connection -Force + +# Create a cluster backup +$backup = New-ProxmoxClusterBackup -Connection $connection -Compress -Wait + +# Restore a cluster backup +Restore-ProxmoxClusterBackup -Connection $connection -BackupID "vzdump-cluster-2023_04_28-12_00_00.vma.lzo" -Force -Wait +``` + +### Managing IP Addresses + +```powershell +# Create a new IP pool +$pool = New-ProxmoxIPPool -Name "Production" -CIDR "192.168.1.0/24" -ExcludeIPs "192.168.1.1", "192.168.1.254" + +# Get all IP pools +$pools = Get-ProxmoxIPPool + +# Get a specific IP pool +$pool = Get-ProxmoxIPPool -Name "Production" + +# Clear an IP pool +Clear-ProxmoxIPPool -Name "Production" +``` + +## Disconnecting + +```powershell +# Disconnect from the server +Disconnect-ProxmoxServer -Connection $connection +``` + +## Development + +### Building the Module + +To build the module from source: + +```powershell +# Run the build script +.\Scripts\build.ps1 +``` + +This will: +1. Compile the C# code +2. Create a versioned release in the Release folder +3. Update the Module folder with the latest build +4. Create a ZIP package for distribution + +### Project Organization + +- **C# Source Code**: All C# source code is in the PSProxmox folder +- **PowerShell Module**: The PowerShell module files are in the Module folder +- **Documentation**: Comprehensive documentation is in the Documentation folder +- **Scripts**: Build and installation scripts are in the Scripts folder + ## Documentation -For detailed documentation, see the [Documentation](../Documentation) directory. +For detailed documentation, see the [Documentation](Documentation) directory. The documentation includes: +- [Cmdlet Reference](Documentation/cmdlets/README.md) +- [Examples](Documentation/examples/README.md) +- [Guides](Documentation/guides/README.md) +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/PSProxmox/Cmdlets/GetProxmoxVMSMBIOSCmdlet.cs b/PSProxmox/Cmdlets/GetProxmoxVMSMBIOSCmdlet.cs new file mode 100644 index 0000000..b5b226c --- /dev/null +++ b/PSProxmox/Cmdlets/GetProxmoxVMSMBIOSCmdlet.cs @@ -0,0 +1,82 @@ +using System; +using System.Management.Automation; +using Newtonsoft.Json.Linq; +using PSProxmox.Models; +using PSProxmox.Session; + +namespace PSProxmox.Cmdlets +{ + /// + /// Gets the SMBIOS settings for a Proxmox VM. + /// The Get-ProxmoxVMSMBIOS cmdlet retrieves the SMBIOS settings for a Proxmox VM. + /// + /// Get SMBIOS settings for a VM + /// Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 + /// + /// + [Cmdlet(VerbsCommon.Get, "ProxmoxVMSMBIOS")] + [OutputType(typeof(ProxmoxVMSMBIOS))] + public class GetProxmoxVMSMBIOSCmdlet : PSCmdlet + { + /// + /// The connection to the Proxmox VE server. + /// + [Parameter(Mandatory = true, Position = 0)] + public ProxmoxConnection Connection { get; set; } + + /// + /// The node where the VM is located. + /// + [Parameter(Mandatory = true, Position = 1)] + public string Node { get; set; } + + /// + /// The ID of the VM. + /// + [Parameter(Mandatory = true, Position = 2)] + public int VMID { get; set; } + + /// + /// Return the raw JSON response. + /// + [Parameter(Mandatory = false)] + public SwitchParameter RawJson { get; set; } + + /// + /// Processes the cmdlet. + /// + protected override void ProcessRecord() + { + try + { + var client = new ProxmoxApiClient(Connection, this); + + // Get the VM configuration + string response = client.Get($"nodes/{Node}/qemu/{VMID}/config"); + var configData = JsonUtility.DeserializeResponse(response); + + if (RawJson.IsPresent) + { + WriteObject(response); + return; + } + + // Extract SMBIOS settings + var smbios = new ProxmoxVMSMBIOS(); + if (configData.TryGetValue("data", out JToken dataToken) && + dataToken is JObject data && + data.TryGetValue("smbios", out JToken smbiosToken)) + { + string smbiosString = smbiosToken.ToString(); + smbios = ProxmoxVMSMBIOS.FromProxmoxString(smbiosString); + } + + WriteObject(smbios); + } + catch (Exception ex) + { + WriteError(new ErrorRecord(ex, "GetProxmoxVMSMBIOSError", ErrorCategory.OperationStopped, Connection)); + } + } + } +} diff --git a/PSProxmox/Cmdlets/NewProxmoxVMBuilderCmdlet.cs b/PSProxmox/Cmdlets/NewProxmoxVMBuilderCmdlet.cs index eee9810..02617fc 100644 --- a/PSProxmox/Cmdlets/NewProxmoxVMBuilderCmdlet.cs +++ b/PSProxmox/Cmdlets/NewProxmoxVMBuilderCmdlet.cs @@ -92,6 +92,55 @@ namespace PSProxmox.Cmdlets [Parameter(Mandatory = false)] public string IPPool { get; set; } + /// + /// The SMBIOS manufacturer information. + /// + [Parameter(Mandatory = false)] + public string SMBIOSManufacturer { get; set; } + + /// + /// The SMBIOS product information. + /// + [Parameter(Mandatory = false)] + public string SMBIOSProduct { get; set; } + + /// + /// The SMBIOS version information. + /// + [Parameter(Mandatory = false)] + public string SMBIOSVersion { get; set; } + + /// + /// The SMBIOS serial number. + /// + [Parameter(Mandatory = false)] + public string SMBIOSSerial { get; set; } + + /// + /// The SMBIOS family information. + /// + [Parameter(Mandatory = false)] + public string SMBIOSFamily { get; set; } + + /// + /// The SMBIOS UUID. + /// + [Parameter(Mandatory = false)] + public string SMBIOSUUID { get; set; } + + /// + /// Whether to automatically generate SMBIOS values. + /// + [Parameter(Mandatory = false)] + public SwitchParameter AutomaticSMBIOS { get; set; } + + /// + /// The manufacturer profile to use for SMBIOS values. Valid values are: Proxmox, Dell, HP, Lenovo, VMware, HyperV, VirtualBox, Random. + /// + [Parameter(Mandatory = false)] + [ValidateSet("Proxmox", "Dell", "HP", "Lenovo", "VMware", "HyperV", "VirtualBox", "Random")] + public string SMBIOSProfile { get; set; } = "Random"; + /// /// Processes the cmdlet. /// @@ -129,6 +178,47 @@ namespace PSProxmox.Cmdlets builder.WithTags(Tags); } + // Set SMBIOS settings based on parameters + if (AutomaticSMBIOS.IsPresent) + { + // Use the specified profile or Random if not specified + builder.WithSMBIOSProfile(SMBIOSProfile); + WriteVerbose($"Using automatic SMBIOS settings with profile: {SMBIOSProfile}"); + } + else + { + // Set individual SMBIOS settings if provided + if (!string.IsNullOrEmpty(SMBIOSManufacturer)) + { + builder.WithSMBIOSManufacturer(SMBIOSManufacturer); + } + + if (!string.IsNullOrEmpty(SMBIOSProduct)) + { + builder.WithSMBIOSProduct(SMBIOSProduct); + } + + if (!string.IsNullOrEmpty(SMBIOSVersion)) + { + builder.WithSMBIOSVersion(SMBIOSVersion); + } + + if (!string.IsNullOrEmpty(SMBIOSSerial)) + { + builder.WithSMBIOSSerial(SMBIOSSerial); + } + + if (!string.IsNullOrEmpty(SMBIOSFamily)) + { + builder.WithSMBIOSFamily(SMBIOSFamily); + } + + if (!string.IsNullOrEmpty(SMBIOSUUID)) + { + builder.WithSMBIOSUUID(SMBIOSUUID); + } + } + WriteObject(builder); } catch (Exception ex) diff --git a/PSProxmox/Cmdlets/NewProxmoxVMCmdlet.cs b/PSProxmox/Cmdlets/NewProxmoxVMCmdlet.cs index bf2e7dd..b378444 100644 --- a/PSProxmox/Cmdlets/NewProxmoxVMCmdlet.cs +++ b/PSProxmox/Cmdlets/NewProxmoxVMCmdlet.cs @@ -112,6 +112,19 @@ namespace PSProxmox.Cmdlets [Parameter(Mandatory = false, ParameterSetName = "Direct")] public string IPPool { get; set; } + /// + /// Whether to automatically generate SMBIOS values. + /// + [Parameter(Mandatory = false, ParameterSetName = "Direct")] + public SwitchParameter AutomaticSMBIOS { get; set; } + + /// + /// The manufacturer profile to use for SMBIOS values. Valid values are: Proxmox, Dell, HP, Lenovo, VMware, HyperV, VirtualBox, Random. + /// + [Parameter(Mandatory = false, ParameterSetName = "Direct")] + [ValidateSet("Proxmox", "Dell", "HP", "Lenovo", "VMware", "HyperV", "VirtualBox", "Random")] + public string SMBIOSProfile { get; set; } = "Random"; + /// /// Processes the cmdlet. /// @@ -180,6 +193,18 @@ namespace PSProxmox.Cmdlets // Add disk parameters["ide0"] = $"{Storage}:{DiskSize}"; + // Add SMBIOS settings if requested + if (AutomaticSMBIOS.IsPresent) + { + var smbios = ProxmoxVMSMBIOSProfile.GetProfile(SMBIOSProfile); + string smbiosString = smbios.ToProxmoxString(); + if (!string.IsNullOrEmpty(smbiosString)) + { + parameters["smbios"] = smbiosString; + WriteVerbose($"Using automatic SMBIOS settings with profile: {SMBIOSProfile}"); + } + } + vmid = VMID.Value; vmName = Name; ipPool = IPPool; diff --git a/PSProxmox/Cmdlets/SetProxmoxVMSMBIOSCmdlet.cs b/PSProxmox/Cmdlets/SetProxmoxVMSMBIOSCmdlet.cs new file mode 100644 index 0000000..59f9f60 --- /dev/null +++ b/PSProxmox/Cmdlets/SetProxmoxVMSMBIOSCmdlet.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Management.Automation; +using PSProxmox.Models; +using PSProxmox.Session; + +namespace PSProxmox.Cmdlets +{ + /// + /// Sets the SMBIOS settings for a Proxmox VM. + /// The Set-ProxmoxVMSMBIOS cmdlet sets the SMBIOS settings for a Proxmox VM. + /// + /// Set SMBIOS settings for a VM + /// Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Dell Inc." -Product "PowerEdge R740" -Serial "ABC123" + /// + /// + /// Set SMBIOS settings using a SMBIOS object + /// $smbios = New-Object PSProxmox.Models.ProxmoxVMSMBIOS + /// $smbios.Manufacturer = "Dell Inc." + /// $smbios.Product = "PowerEdge R740" + /// $smbios.Serial = "ABC123" + /// Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios + /// + /// + [Cmdlet(VerbsCommon.Set, "ProxmoxVMSMBIOS", SupportsShouldProcess = true)] + [OutputType(typeof(ProxmoxVMSMBIOS))] + public class SetProxmoxVMSMBIOSCmdlet : PSCmdlet + { + /// + /// The connection to the Proxmox VE server. + /// + [Parameter(Mandatory = true, Position = 0)] + public ProxmoxConnection Connection { get; set; } + + /// + /// The node where the VM is located. + /// + [Parameter(Mandatory = true, Position = 1)] + public string Node { get; set; } + + /// + /// The ID of the VM. + /// + [Parameter(Mandatory = true, Position = 2)] + public int VMID { get; set; } + + /// + /// The SMBIOS settings object. + /// + [Parameter(Mandatory = false, ParameterSetName = "SMBIOSObject")] + public ProxmoxVMSMBIOS SMBIOS { get; set; } + + /// + /// The manufacturer information. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string Manufacturer { get; set; } + + /// + /// The product information. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string Product { get; set; } + + /// + /// The version information. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string Version { get; set; } + + /// + /// The serial number. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string Serial { get; set; } + + /// + /// The system family. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string Family { get; set; } + + /// + /// The system UUID. + /// + [Parameter(Mandatory = false, ParameterSetName = "Individual")] + public string UUID { get; set; } + + /// + /// Return the updated SMBIOS settings. + /// + [Parameter(Mandatory = false)] + public SwitchParameter PassThru { get; set; } + + /// + /// Processes the cmdlet. + /// + protected override void ProcessRecord() + { + try + { + var client = new ProxmoxApiClient(Connection, this); + + // Create SMBIOS settings + ProxmoxVMSMBIOS smbiosSettings; + if (ParameterSetName == "SMBIOSObject") + { + smbiosSettings = SMBIOS ?? new ProxmoxVMSMBIOS(); + } + else + { + // Get current settings first + string response = client.Get($"nodes/{Node}/qemu/{VMID}/config"); + var configData = JsonUtility.DeserializeResponse(response); + + string currentSmbiosString = configData.data.smbios; + smbiosSettings = string.IsNullOrEmpty(currentSmbiosString) + ? new ProxmoxVMSMBIOS() + : ProxmoxVMSMBIOS.FromProxmoxString(currentSmbiosString); + + // Update with provided values + if (!string.IsNullOrEmpty(Manufacturer)) + smbiosSettings.Manufacturer = Manufacturer; + + if (!string.IsNullOrEmpty(Product)) + smbiosSettings.Product = Product; + + if (!string.IsNullOrEmpty(Version)) + smbiosSettings.Version = Version; + + if (!string.IsNullOrEmpty(Serial)) + smbiosSettings.Serial = Serial; + + if (!string.IsNullOrEmpty(Family)) + smbiosSettings.Family = Family; + + if (!string.IsNullOrEmpty(UUID)) + smbiosSettings.UUID = UUID; + } + + // Convert to Proxmox format + string smbiosString = smbiosSettings.ToProxmoxString(); + + if (string.IsNullOrEmpty(smbiosString)) + { + WriteWarning("No SMBIOS settings specified. No changes will be made."); + return; + } + + // Confirm the operation + if (!ShouldProcess($"VM {VMID} on node {Node}", $"Set SMBIOS settings to {smbiosString}")) + { + return; + } + + // Update the VM configuration + var parameters = new Dictionary + { + ["smbios"] = smbiosString + }; + + client.Put($"nodes/{Node}/qemu/{VMID}/config", parameters); + WriteVerbose($"SMBIOS settings updated for VM {VMID} on node {Node}"); + + // Return the updated settings if requested + if (PassThru.IsPresent) + { + WriteObject(smbiosSettings); + } + } + catch (Exception ex) + { + WriteError(new ErrorRecord(ex, "SetProxmoxVMSMBIOSError", ErrorCategory.OperationStopped, Connection)); + } + } + } +} diff --git a/PSProxmox/Models/ProxmoxVMBuilder.cs b/PSProxmox/Models/ProxmoxVMBuilder.cs index fddf7f3..cad466c 100644 --- a/PSProxmox/Models/ProxmoxVMBuilder.cs +++ b/PSProxmox/Models/ProxmoxVMBuilder.cs @@ -71,6 +71,11 @@ namespace PSProxmox.Models /// public string IPPool { get; set; } + /// + /// Gets or sets the SMBIOS settings for the VM. + /// + public ProxmoxVMSMBIOS SMBIOS { get; set; } = new ProxmoxVMSMBIOS(); + /// /// Initializes a new instance of the class. /// @@ -341,6 +346,94 @@ namespace PSProxmox.Models return this; } + /// + /// Sets the SMBIOS manufacturer for the VM. + /// + /// The manufacturer name. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSManufacturer(string manufacturer) + { + SMBIOS.Manufacturer = manufacturer; + return this; + } + + /// + /// Sets the SMBIOS product name for the VM. + /// + /// The product name. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSProduct(string product) + { + SMBIOS.Product = product; + return this; + } + + /// + /// Sets the SMBIOS version for the VM. + /// + /// The version. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSVersion(string version) + { + SMBIOS.Version = version; + return this; + } + + /// + /// Sets the SMBIOS serial number for the VM. + /// + /// The serial number. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSSerial(string serial) + { + SMBIOS.Serial = serial; + return this; + } + + /// + /// Sets the SMBIOS family for the VM. + /// + /// The family. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSFamily(string family) + { + SMBIOS.Family = family; + return this; + } + + /// + /// Sets the SMBIOS UUID for the VM. + /// + /// The UUID. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSUUID(string uuid) + { + SMBIOS.UUID = uuid; + return this; + } + + /// + /// Sets all SMBIOS settings for the VM at once. + /// + /// The SMBIOS settings. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOS(ProxmoxVMSMBIOS smbios) + { + SMBIOS = smbios ?? new ProxmoxVMSMBIOS(); + return this; + } + + /// + /// Sets SMBIOS settings based on a manufacturer profile. + /// + /// The manufacturer profile to use. + /// The builder instance. + public ProxmoxVMBuilder WithSMBIOSProfile(string manufacturer) + { + SMBIOS = ProxmoxVMSMBIOSProfile.GetProfile(manufacturer); + return this; + } + /// /// Builds the VM configuration parameters. /// @@ -366,6 +459,13 @@ namespace PSProxmox.Models parameters["tags"] = Tags; } + // Add SMBIOS settings if any are specified + string smbiosString = SMBIOS.ToProxmoxString(); + if (!string.IsNullOrEmpty(smbiosString)) + { + parameters["smbios"] = smbiosString; + } + // Add network interfaces for (int i = 0; i < _networkInterfaces.Count; i++) { diff --git a/PSProxmox/Models/ProxmoxVMSMBIOS.cs b/PSProxmox/Models/ProxmoxVMSMBIOS.cs new file mode 100644 index 0000000..364792a --- /dev/null +++ b/PSProxmox/Models/ProxmoxVMSMBIOS.cs @@ -0,0 +1,124 @@ +using System; +using Newtonsoft.Json; + +namespace PSProxmox.Models +{ + /// + /// Represents SMBIOS settings for a Proxmox VM. + /// + public class ProxmoxVMSMBIOS + { + /// + /// Gets or sets the manufacturer information. + /// + [JsonProperty("manufacturer")] + public string Manufacturer { get; set; } + + /// + /// Gets or sets the product information. + /// + [JsonProperty("product")] + public string Product { get; set; } + + /// + /// Gets or sets the version information. + /// + [JsonProperty("version")] + public string Version { get; set; } + + /// + /// Gets or sets the serial number. + /// + [JsonProperty("serial")] + public string Serial { get; set; } + + /// + /// Gets or sets the system family. + /// + [JsonProperty("family")] + public string Family { get; set; } + + /// + /// Gets or sets the system UUID. + /// + [JsonProperty("uuid")] + public string UUID { get; set; } + + /// + /// Converts the SMBIOS settings to a Proxmox API compatible string. + /// + /// A string representation of the SMBIOS settings. + public string ToProxmoxString() + { + var parts = new System.Collections.Generic.List(); + + if (!string.IsNullOrEmpty(Manufacturer)) + parts.Add($"manufacturer={Manufacturer}"); + + if (!string.IsNullOrEmpty(Product)) + parts.Add($"product={Product}"); + + if (!string.IsNullOrEmpty(Version)) + parts.Add($"version={Version}"); + + if (!string.IsNullOrEmpty(Serial)) + parts.Add($"serial={Serial}"); + + if (!string.IsNullOrEmpty(Family)) + parts.Add($"family={Family}"); + + if (!string.IsNullOrEmpty(UUID)) + parts.Add($"uuid={UUID}"); + + return string.Join(",", parts); + } + + /// + /// Parses a Proxmox API SMBIOS string into a ProxmoxVMSMBIOS object. + /// + /// The SMBIOS string from the Proxmox API. + /// A ProxmoxVMSMBIOS object. + public static ProxmoxVMSMBIOS FromProxmoxString(string smbiosString) + { + if (string.IsNullOrEmpty(smbiosString)) + return new ProxmoxVMSMBIOS(); + + var result = new ProxmoxVMSMBIOS(); + var parts = smbiosString.Split(','); + + foreach (var part in parts) + { + var keyValue = part.Split('='); + if (keyValue.Length != 2) + continue; + + var key = keyValue[0].Trim(); + var value = keyValue[1].Trim(); + + switch (key.ToLowerInvariant()) + { + case "manufacturer": + result.Manufacturer = value; + break; + case "product": + result.Product = value; + break; + case "version": + result.Version = value; + break; + case "serial": + result.Serial = value; + break; + case "family": + result.Family = value; + break; + case "uuid": + result.UUID = value; + break; + } + } + + return result; + } + } +} diff --git a/PSProxmox/Models/ProxmoxVMSMBIOSProfile.cs b/PSProxmox/Models/ProxmoxVMSMBIOSProfile.cs new file mode 100644 index 0000000..b01826d --- /dev/null +++ b/PSProxmox/Models/ProxmoxVMSMBIOSProfile.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace PSProxmox.Models +{ + /// + /// Represents a manufacturer profile for SMBIOS settings. + /// + public class ProxmoxVMSMBIOSProfile + { + private static readonly Random _random = new Random(); + + /// + /// Gets the available manufacturer profiles. + /// + public static readonly string[] AvailableProfiles = new string[] + { + "Proxmox", + "Dell", + "HP", + "Lenovo", + "VMware", + "HyperV", + "VirtualBox", + "Random" + }; + + /// + /// Gets a SMBIOS profile for the specified manufacturer. + /// + /// The manufacturer profile to use. + /// A ProxmoxVMSMBIOS object with the manufacturer profile settings. + public static ProxmoxVMSMBIOS GetProfile(string manufacturer) + { + if (string.IsNullOrEmpty(manufacturer) || manufacturer.Equals("Random", StringComparison.OrdinalIgnoreCase)) + { + // Choose a random manufacturer (excluding "Random") + var profiles = AvailableProfiles.Where(p => !p.Equals("Random", StringComparison.OrdinalIgnoreCase)).ToArray(); + manufacturer = profiles[_random.Next(profiles.Length)]; + } + + switch (manufacturer.ToLowerInvariant()) + { + case "proxmox": + return GetProxmoxProfile(); + case "dell": + return GetDellProfile(); + case "hp": + return GetHPProfile(); + case "lenovo": + return GetLenovoProfile(); + case "vmware": + return GetVMwareProfile(); + case "hyperv": + return GetHyperVProfile(); + case "virtualbox": + return GetVirtualBoxProfile(); + default: + throw new ArgumentException($"Unknown manufacturer profile: {manufacturer}"); + } + } + + private static ProxmoxVMSMBIOS GetProxmoxProfile() + { + return new ProxmoxVMSMBIOS + { + Manufacturer = "Proxmox", + Product = $"Virtual Environment {_random.Next(1, 8)}.{_random.Next(0, 10)}", + Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}", + Serial = GenerateRandomSerial(10), + UUID = GenerateRandomUUID(), + Family = "Virtual Machine" + }; + } + + private static ProxmoxVMSMBIOS GetDellProfile() + { + var models = new string[] + { + "PowerEdge R640", + "PowerEdge R740", + "PowerEdge R750", + "PowerEdge R840", + "PowerEdge R940", + "PowerEdge T640" + }; + + return new ProxmoxVMSMBIOS + { + Manufacturer = "Dell Inc.", + Product = models[_random.Next(models.Length)], + Version = $"{_random.Next(1, 5)}.{_random.Next(0, 10)}", + Serial = $"{GenerateRandomString(5, true)}{_random.Next(10000, 99999)}", + UUID = GenerateRandomUUID(), + Family = "PowerEdge" + }; + } + + private static ProxmoxVMSMBIOS GetHPProfile() + { + var models = new string[] + { + "ProLiant DL360 Gen10", + "ProLiant DL380 Gen10", + "ProLiant DL560 Gen10", + "ProLiant ML350 Gen10", + "ProLiant BL460c Gen10" + }; + + return new ProxmoxVMSMBIOS + { + Manufacturer = "HP", + Product = models[_random.Next(models.Length)], + Version = $"U{_random.Next(10, 50)}", + Serial = $"USE{_random.Next(100000, 999999)}", + UUID = GenerateRandomUUID(), + Family = "ProLiant" + }; + } + + private static ProxmoxVMSMBIOS GetLenovoProfile() + { + var models = new string[] + { + "ThinkSystem SR650", + "ThinkSystem SR630", + "ThinkSystem SR850", + "ThinkSystem SR950", + "ThinkSystem ST550" + }; + + return new ProxmoxVMSMBIOS + { + Manufacturer = "Lenovo", + Product = models[_random.Next(models.Length)], + Version = $"ThinkSystem {_random.Next(1, 5)}", + Serial = $"{GenerateRandomString(4, true)}{GenerateRandomString(6, false)}", + UUID = GenerateRandomUUID(), + Family = "ThinkSystem" + }; + } + + private static ProxmoxVMSMBIOS GetVMwareProfile() + { + return new ProxmoxVMSMBIOS + { + Manufacturer = "VMware, Inc.", + Product = $"VMware Virtual Platform {_random.Next(1, 8)}", + Version = $"VMware-{_random.Next(1, 10)}.{_random.Next(0, 10)}", + Serial = GenerateRandomSerial(10), + UUID = GenerateRandomUUID(), + Family = "Virtual Machine" + }; + } + + private static ProxmoxVMSMBIOS GetHyperVProfile() + { + return new ProxmoxVMSMBIOS + { + Manufacturer = "Microsoft Corporation", + Product = $"Hyper-V {_random.Next(2012, 2023)}", + Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}", + Serial = $"MS-{GenerateRandomString(8, false)}", + UUID = GenerateRandomUUID(), + Family = "Virtual Machine" + }; + } + + private static ProxmoxVMSMBIOS GetVirtualBoxProfile() + { + return new ProxmoxVMSMBIOS + { + Manufacturer = "Oracle Corporation", + Product = $"VirtualBox {_random.Next(5, 8)}.{_random.Next(0, 10)}", + Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}", + Serial = $"VB-{GenerateRandomString(8, false)}", + UUID = GenerateRandomUUID(), + Family = "Virtual Machine" + }; + } + + private static string GenerateRandomSerial(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + return new string(Enumerable.Repeat(chars, length) + .Select(s => s[_random.Next(s.Length)]).ToArray()); + } + + private static string GenerateRandomString(int length, bool uppercase) + { + const string upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const string lowerChars = "abcdefghijklmnopqrstuvwxyz"; + const string digits = "0123456789"; + + string chars = uppercase ? upperChars : lowerChars + digits; + + return new string(Enumerable.Repeat(chars, length) + .Select(s => s[_random.Next(s.Length)]).ToArray()); + } + + private static string GenerateRandomUUID() + { + return Guid.NewGuid().ToString(); + } + } +}