I have an edge gateway that I can set firewall rules on, and nat however when I try to add DHCP through powercli I don't get an error but nothing get's applied to the gateway, can anyone help?
Here is the function I have:
function configureDHCP {
param ([String]$gwName )
$edgeGWview = Search-Cloud -QueryType EdgeGateway -name $gwName | Get-CIView
$dhcpService = New-Object vmware.vimautomation.cloud.views.dhcpservice
$dhcpService.DefaultLeaseTime = "3600"
$dhcpService.MaxLeaseTime = "7200"
$dhcpService.IsEnabled = $true
$dhcpService.IpRange = New-Object vmware.vimautomation.cloud.views.iprange
$dhcpService.IpRange.StartAddress = "192.168.1.1"
$dhcpService.IpRange.EndAddress = "192.168.1.254"
$edgeGWview.ConfigureServices($dhcpService)
}
Interested to understand why DHCP is different and what I'm doing wrong. The API guide here does'nt really help as page 187 just says do the same thing as before (eg Firewall rules).
This has been a great source so far but doesn't cover DHCP.
Hi Toby,
You're not using the correct object type to pass to the ConfigureServices method. The correct one is VMware.VimAutomation.Cloud.Views.GatewayDhcpService.
Here is a sample code:
$gw = Search-Cloud -QueryType EdgeGateway | Get-CIView
$network = Get-OrgNetwork kamentestedgegatewaynetwork
$dhcpService = New-Object VMware.VimAutomation.Cloud.Views.GatewayDhcpService
$dhcpService.IsEnabled = $true
$pool = New-Object VMware.VimAutomation.Cloud.Views.DhcpPoolService
$pool.IsEnabled = $true
$pool.DefaultLeaseTime = "3600"
$pool.MaxLeaseTime = "7200"
$pool.LowIpAddress = "192.168.1.2"
$pool.HighIpAddress = "192.168.1.254"
$pool.Network = New-Object VMware.VimAutomation.Cloud.Views.Reference
$pool.Network.Href = $network.Href
$dhcpService.Pool = @($pool)
$networkServiceArray = @($dhcpService)
$gw.ConfigureServices($networkServiceArray)
Notice that the DHCP service of the Edge Gateway is set per OrgVdc Network (the Network property of the pool object)
Kamen
PowerCLI Dev Team
You should really post this in the API forum.
I can never remember if the search has a single result if it'll still be an array of 1 item or a direct reference if there is one 1 result returned.
Hi Toby,
You're not using the correct object type to pass to the ConfigureServices method. The correct one is VMware.VimAutomation.Cloud.Views.GatewayDhcpService.
Here is a sample code:
$gw = Search-Cloud -QueryType EdgeGateway | Get-CIView
$network = Get-OrgNetwork kamentestedgegatewaynetwork
$dhcpService = New-Object VMware.VimAutomation.Cloud.Views.GatewayDhcpService
$dhcpService.IsEnabled = $true
$pool = New-Object VMware.VimAutomation.Cloud.Views.DhcpPoolService
$pool.IsEnabled = $true
$pool.DefaultLeaseTime = "3600"
$pool.MaxLeaseTime = "7200"
$pool.LowIpAddress = "192.168.1.2"
$pool.HighIpAddress = "192.168.1.254"
$pool.Network = New-Object VMware.VimAutomation.Cloud.Views.Reference
$pool.Network.Href = $network.Href
$dhcpService.Pool = @($pool)
$networkServiceArray = @($dhcpService)
$gw.ConfigureServices($networkServiceArray)
Notice that the DHCP service of the Edge Gateway is set per OrgVdc Network (the Network property of the pool object)
Kamen
PowerCLI Dev Team
Hi Kamen,
Excellent - works perfectly - thanks for taking the time to look into this.
Cheers
Toby