mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
add virtual disk
This commit is contained in:
parent
3abf2264d9
commit
5a72501be2
6 changed files with 333 additions and 14 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
||||
'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort',
|
||||
'Add-NetboxVirtualMachineInterface', 'BuildNewURI',
|
||||
'BuildURIComponents', 'CheckNetboxIsConnected',
|
||||
'Add-NetboxVirtualMachinedisk', 'Add-NetboxVirtualMachineInterface',
|
||||
'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected',
|
||||
'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum',
|
||||
'Get-ModelDefinition', 'Get-NetboxAPIDefinition',
|
||||
'GetNetboxAPIErrorBody', 'Get-NetboxCircuit',
|
||||
|
|
@ -94,8 +94,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
|||
'Get-NetboxTimeout', 'Get-NetboxVersion',
|
||||
'Get-NetboxVirtualizationCluster',
|
||||
'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine',
|
||||
'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest',
|
||||
'New-NetboxCircuit', 'New-NetboxContact',
|
||||
'Get-NetboxVirtualMachinedisk', 'Get-NetboxVirtualMachineInterface',
|
||||
'InvokeNetboxRequest', 'New-NetboxCircuit', 'New-NetboxContact',
|
||||
'New-NetboxContactAssignment', 'New-NetboxContactRole',
|
||||
'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress',
|
||||
'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix',
|
||||
|
|
@ -114,9 +114,10 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
|||
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
|
||||
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
|
||||
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
|
||||
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface',
|
||||
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected',
|
||||
'ThrowNetboxRESTError', 'VerifyAPIConnectivity'
|
||||
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
|
||||
'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
|
||||
'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.
|
||||
CmdletsToExport = @()
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
||||
'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort',
|
||||
'Add-NetboxVirtualMachineInterface', 'BuildNewURI',
|
||||
'BuildURIComponents', 'CheckNetboxIsConnected',
|
||||
'Add-NetboxVirtualMachinedisk', 'Add-NetboxVirtualMachineInterface',
|
||||
'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected',
|
||||
'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum',
|
||||
'Get-ModelDefinition', 'Get-NetboxAPIDefinition',
|
||||
'GetNetboxAPIErrorBody', 'Get-NetboxCircuit',
|
||||
|
|
@ -94,8 +94,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
|||
'Get-NetboxTimeout', 'Get-NetboxVersion',
|
||||
'Get-NetboxVirtualizationCluster',
|
||||
'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine',
|
||||
'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest',
|
||||
'New-NetboxCircuit', 'New-NetboxContact',
|
||||
'Get-NetboxVirtualMachinedisk', 'Get-NetboxVirtualMachineInterface',
|
||||
'InvokeNetboxRequest', 'New-NetboxCircuit', 'New-NetboxContact',
|
||||
'New-NetboxContactAssignment', 'New-NetboxContactRole',
|
||||
'New-NetboxDCIMDevice', 'New-NetboxDCIMSite', 'New-NetboxIPAMAddress',
|
||||
'New-NetboxIPAMAddressRange', 'New-NetboxIPAMPrefix',
|
||||
|
|
@ -114,9 +114,10 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface',
|
|||
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
|
||||
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
|
||||
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
|
||||
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachineInterface',
|
||||
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected',
|
||||
'ThrowNetboxRESTError', 'VerifyAPIConnectivity'
|
||||
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
|
||||
'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
|
||||
'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.
|
||||
CmdletsToExport = @()
|
||||
|
|
|
|||
|
|
@ -230,6 +230,41 @@ function Add-NetboxDCIMRearPort {
|
|||
|
||||
#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
|
||||
|
||||
|
||||
|
|
@ -3375,6 +3410,84 @@ function Get-NetboxVirtualMachine {
|
|||
|
||||
#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
|
||||
|
||||
|
||||
|
|
@ -6198,6 +6311,59 @@ function Set-NetboxVirtualMachine {
|
|||
|
||||
#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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue