2022-12-06 13:34:52 -05:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
function New-NetboxVirtualMachine {
|
2021-07-23 22:06:42 +02:00
|
|
|
|
[CmdletBinding(ConfirmImpact = 'low',
|
|
|
|
|
|
SupportsShouldProcess = $true)]
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[OutputType([pscustomobject])]
|
|
|
|
|
|
param
|
|
|
|
|
|
(
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
|
[string]$Name,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[Parameter(Mandatory = $true)]
|
2022-11-28 15:45:19 -05:00
|
|
|
|
[uint16]$Site,
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Cluster,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Tenant,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[object]$Status = 'Active',
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Role,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Platform,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$vCPUs,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Memory,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Disk,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Primary_IP4,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[uint16]$Primary_IP6,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[hashtable]$Custom_Fields,
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
[string]$Comments
|
|
|
|
|
|
)
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
|
|
|
|
|
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
|
|
|
|
|
|
|
|
|
|
|
|
# # Validate the status against the APIDefinition
|
|
|
|
|
|
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
|
|
|
|
|
|
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
2021-03-25 16:52:08 -04:00
|
|
|
|
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2022-11-28 15:45:19 -05:00
|
|
|
|
if ($PSBoundParameters.ContainsKey('Cluster') -and (-not $PSBoundParameters.ContainsKey('Site'))) {
|
|
|
|
|
|
throw "You must specify a site ID with a cluster ID"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2020-03-23 12:18:01 -04:00
|
|
|
|
$URI = BuildNewURI -Segments $URIComponents.Segments
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
|
|
|
|
|
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
|
|
|
|
|
|
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
|
|
|
|
|
|
}
|
2021-03-25 16:52:08 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|