public/New-NetworkAdapter.ps1
|
function New-ZStackNetworkAdapter { # .SYNOPSIS # Attaches an adapter on the selected L3 network. # .DESCRIPTION # ZStack PowerCLI (ZStack.PowerCLI 1.1.5) uses CLI 1.1.5, commit 6fcf509ff540d0098f54c1c33609dbe9f572c837. # Connection configuration namespace: zstack-powershell. # .LINK # https://github.com/terraform-zstack-modules/zstack-cli-go/blob/main/docs/powershell.md [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [object[]] $VM, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [object] $L3Network, [ValidatePattern('\A([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}\z')] [string] $MacAddress, [ValidateNotNullOrEmpty()] [string] $StaticIP, [ValidateRange(1, 3600)] [int] $TimeoutSeconds = 300, [object] $Server ) process { foreach ($item in $VM) { try { $target = Get-CloudResourceSelection $item VM $Server NewNetworkAdapter $network = Get-CloudResourceSelection $L3Network L3Network $target.Connection.Public NewNetworkAdapter $arguments = @('instance', 'attach-l3', $target.Id, '--l3-network', $network.Id) if ($PSBoundParameters.ContainsKey('MacAddress')) { $arguments += @('--mac', $MacAddress) } if ($PSBoundParameters.ContainsKey('StaticIP')) { $arguments += @('--static-ip', $StaticIP) } Invoke-CloudDeviceWrite $PSCmdlet $target $arguments attach-nic NewNetworkAdapter "Add adapter on L3 network $($network.Id)" $TimeoutSeconds NetworkAdapter -NewIdentity } catch { $PSCmdlet.WriteError($_) } } } } |