add virtual disk

This commit is contained in:
Pascal Liehne 2024-09-01 02:30:24 +02:00
parent 3abf2264d9
commit 5a72501be2
6 changed files with 333 additions and 14 deletions

View file

@ -0,0 +1,30 @@

function Add-NetboxVirtualMachineDisk {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint64]$Virtual_Machine,
[string]$MAC_Address,
[uint64]$Size,
[string]$Description,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks'))
$PSBoundParameters.Enabled = $Enabled
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
}

View file

@ -0,0 +1,73 @@

function Get-NetboxVirtualMachineDisk {
<#
.SYNOPSIS
Gets VM disks
.DESCRIPTION
Obtains the disk objects for one or more VMs
.PARAMETER Limit
Number of results to return per page.
.PARAMETER Offset
The initial index from which to return the results.
.PARAMETER Id
Database ID of the interface
.PARAMETER Name
Name of the disk
.PARAMETER Size
Size of the disk in GB
.PARAMETER Virtual_Machine_Id
ID of the virtual machine to which the interface(s) are assigned.
.PARAMETER Virtual_Machine
Name of the virtual machine to get interfaces
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxVirtualMachineDisk
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(ValueFromPipeline = $true)]
[uint64]$Id,
[string]$Name,
[string]$Query,
[uint64]$Size,
[uint64]$Virtual_Machine_Id,
[string]$Virtual_Machine,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
}

View file

@ -0,0 +1,48 @@

function Set-NetboxVirtualMachineDisk {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,
[string]$Name,
[uint64]$Size,
[string]$Description,
[uint64]$Virtual_Machine,
[switch]$Force
)
begin {
}
process {
foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM virtual disk..."
$CurrentVMI = Get-NetboxVirtualMachinedisk -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM disk"
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks', $CurrentVMI.Id))
if ($Force -or $pscmdlet.ShouldProcess("Disk $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}

View file

@ -71,8 +71,8 @@ CLRVersion = '2.0.50727'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort',
'Add-NetboxVirtualMachineInterface', 'BuildNewURI', 'Add-NetboxVirtualMachinedisk', 'Add-NetboxVirtualMachineInterface',
'BuildURIComponents', 'CheckNetboxIsConnected', 'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected',
'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum',
'Get-ModelDefinition', 'Get-NetboxAPIDefinition', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition',
'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit',
@ -94,8 +94,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxTimeout', 'Get-NetboxVersion',
'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationCluster',
'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine',
'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', 'Get-NetboxVirtualMachinedisk', 'Get-NetboxVirtualMachineInterface',
'New-NetboxCircuit', 'New-NetboxContact', 'InvokeNetboxRequest', 'New-NetboxCircuit', 'New-NetboxContact',
'New-NetboxContactAssignment', 'New-NetboxContactRole', 'New-NetboxContactAssignment', 'New-NetboxContactRole',
'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress',
'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix',
@ -114,9 +114,10 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface', 'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected', 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
'ThrowNetboxRESTError', 'VerifyAPIConnectivity' 'Test-NetboxAPIConnected', 'ThrowNetboxRESTError',
'VerifyAPIConnectivity'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @() CmdletsToExport = @()

View file

@ -71,8 +71,8 @@ CLRVersion = '2.0.50727'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort',
'Add-NetboxVirtualMachineInterface', 'BuildNewURI', 'Add-NetboxVirtualMachinedisk', 'Add-NetboxVirtualMachineInterface',
'BuildURIComponents', 'CheckNetboxIsConnected', 'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected',
'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum',
'Get-ModelDefinition', 'Get-NetboxAPIDefinition', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition',
'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit',
@ -94,8 +94,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxTimeout', 'Get-NetboxVersion',
'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationCluster',
'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine',
'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', 'Get-NetboxVirtualMachinedisk', 'Get-NetboxVirtualMachineInterface',
'New-NetboxCircuit', 'New-NetboxContact', 'InvokeNetboxRequest', 'New-NetboxCircuit', 'New-NetboxContact',
'New-NetboxContactAssignment', 'New-NetboxContactRole', 'New-NetboxContactAssignment', 'New-NetboxContactRole',
'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress', 'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress',
'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix', 'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix',
@ -114,9 +114,10 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL', 'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface', 'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected', 'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
'ThrowNetboxRESTError', 'VerifyAPIConnectivity' 'Test-NetboxAPIConnected', 'ThrowNetboxRESTError',
'VerifyAPIConnectivity'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @() CmdletsToExport = @()

View file

@ -230,6 +230,41 @@ function Add-NetboxDCIMRearPort {
#endregion #endregion
#region File Add-NetboxVirtualMachinedisk.ps1
function Add-NetboxVirtualMachineDisk {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint64]$Virtual_Machine,
[string]$MAC_Address,
[uint64]$Size,
[string]$Description,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks'))
$PSBoundParameters.Enabled = $Enabled
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
}
#endregion
#region File Add-NetboxVirtualMachineInterface.ps1 #region File Add-NetboxVirtualMachineInterface.ps1
@ -3375,6 +3410,84 @@ function Get-NetboxVirtualMachine {
#endregion #endregion
#region File Get-NetboxVirtualMachinedisk.ps1
function Get-NetboxVirtualMachineDisk {
<#
.SYNOPSIS
Gets VM disks
.DESCRIPTION
Obtains the disk objects for one or more VMs
.PARAMETER Limit
Number of results to return per page.
.PARAMETER Offset
The initial index from which to return the results.
.PARAMETER Id
Database ID of the interface
.PARAMETER Name
Name of the disk
.PARAMETER Size
Size of the disk in GB
.PARAMETER Virtual_Machine_Id
ID of the virtual machine to which the interface(s) are assigned.
.PARAMETER Virtual_Machine
Name of the virtual machine to get interfaces
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxVirtualMachineDisk
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(ValueFromPipeline = $true)]
[uint64]$Id,
[string]$Name,
[string]$Query,
[uint64]$Size,
[uint64]$Virtual_Machine_Id,
[string]$Virtual_Machine,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
}
#endregion
#region File Get-NetboxVirtualMachineInterface.ps1 #region File Get-NetboxVirtualMachineInterface.ps1
@ -6198,6 +6311,59 @@ function Set-NetboxVirtualMachine {
#endregion #endregion
#region File Set-NetboxVirtualMachinedisk.ps1
function Set-NetboxVirtualMachineDisk {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,
[string]$Name,
[uint64]$Size,
[string]$Description,
[uint64]$Virtual_Machine,
[switch]$Force
)
begin {
}
process {
foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM virtual disk..."
$CurrentVMI = Get-NetboxVirtualMachinedisk -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM disk"
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks', $CurrentVMI.Id))
if ($Force -or $pscmdlet.ShouldProcess("Disk $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}
#endregion
#region File Set-NetboxVirtualMachineInterface.ps1 #region File Set-NetboxVirtualMachineInterface.ps1