如何使用 PowerCLI 创建 IP 池?

如何使用 PowerCLI 创建 IP 池?

数据中心对象有一个“IP 池”选项卡,用于为 vApp 创建 IP 池(据我了解)。如何使用 PowerCLI 创建或修改 IP 池?

答案1

没有专门的 cmdlet 来实现这个功能,但我之前用过 Get-View 来实现,下面是我当时使用的示例代码,需要进行调整才能正常工作,但你应该明白了

$dc = New-Object VMware.Vim.ManagedObjectReference
$dc.type = "Datacenter"
$dc.Value = "datacenter-2"

$pool = New-Object VMware.Vim.IpPool
$pool.name = "MyIPPool"
$pool.ipv4Config = New-Object VMware.Vim.IpPoolIpPoolConfigInfo
$pool.ipv4Config.subnetAddress = "192.168.1.0"
$pool.ipv4Config.netmask = "255.255.255.0"
$pool.ipv4Config.gateway = "192.168.1.1"
$pool.ipv4Config.range = "192.168.1.10#1"
$pool.ipv4Config.dns = New-Object System.String[] (1)
$pool.ipv4Config.dns[0] = ""
$pool.ipv4Config.dhcpServerAvailable = $false
$pool.ipv4Config.ipPoolEnabled = $true
$pool.ipv6Config = New-Object VMware.Vim.IpPoolIpPoolConfigInfo
$pool.ipv6Config.subnetAddress = ""
$pool.ipv6Config.netmask = "ffff:ffff:ffff:ffff:ffff:ffff::"
$pool.ipv6Config.gateway = ""
$pool.ipv6Config.dns = New-Object System.String[] (1)
$pool.ipv6Config.dns[0] = ""
$pool.ipv6Config.dhcpServerAvailable = $false
$pool.ipv6Config.ipPoolEnabled = $false
$pool.dnsDomain = ""
$pool.dnsSearchPath = ""
$pool.hostPrefix = ""
$pool.httpProxy = ""
$pool.networkAssociation = New-Object VMware.Vim.IpPoolAssociation[] (1)
$pool.networkAssociation[0] = New-Object VMware.Vim.IpPoolAssociation
$pool.networkAssociation[0].network = New-Object VMware.Vim.ManagedObjectReference
$pool.networkAssociation[0].network.type = "DistributedVirtualPortgroup"
$pool.networkAssociation[0].network.Value = "dvportgroup-178"
$pool.networkAssociation[0].networkName = ""

$PoolManager = Get-View -Id 'IpPoolManager-IpPoolManager'
$PoolManager.CreateIpPool($dc, $pool)

相关内容