3 Replies Latest reply on Dec 12, 2017 1:44 AM by navi86

    vCloud NAT rule problem

    BastiaanvanH Novice

      Hello,

       

      It seems like I';m the first person even to try to configure NAT rules thru native PowerlCLI, al other scripts found on the net are done directly against the API.

       

      This is my script:

      $edges = Search-Cloud -QueryType EdgeGateway
      $edge = $edges | Where-Object {$_.Name -eq $UserRT}
      $edgeview = $edge | get-ciview
      
      $natService = New-Object VMware.VimAutomation.Cloud.Views.NatService
      $natService.IsEnabled = $true
      
      $natRule = New-Object VMware.VimAutomation.Cloud.Views.NatRule
      $natRule.IsEnabled = $true
      $natRule.RuleType = "DNAT"
      $gatewaynatRule = New-Object VMware.VimAutomation.Cloud.Views.NatPortForwardingRule
      $gatewaynatRule.ExternalIpAddress = "1.2.3.4"
      $gatewaynatRule.InternalIpAddress = "172.31.255.0/24"
      $gatewaynatRule.Protocol = 0
      $natRule.Item = $gatewaynatRule
      
      $natService.NatRule = $natRule
      
      $edgeview.ConfigureServices($natService)
      

      When I run this a get a strange error, not like there's a property missing, but an java error:

      Exception calling "ConfigureServices" with "1" argument(s): "[ c8d9197f-93ac-434d-9f94-8f978cd765f0 ] class java.lang.NullPointerException"

      At C:\Users\Bastiaan\OneDrive\Technisch\Scripts\PowerCLI\vCloud\vCloud VDC aanmaken.ps1:319 char:1

      + $edgeview.ConfigureServices($natService)

      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

          + FullyQualifiedErrorId : CloudException

       

      I've tried various syntax options, but I'm unable to find an solution in this. I'm hoping someone can help me out on this.

       

      Kind Regards,

      Bastiaan

        • 1. Re: vCloud NAT rule problem
          RvdNieuwendijk Virtuoso
          User ModeratorsvExpert

          The ConfigureServices method requires a VMware.VimAutomation.Cloud.Views.NetworkService object as a parameter, not a VMware.VimAutomation.Cloud.Views.NatService object. If you use the ConfigureServices_Task method, you can also specify a VMware.VimAutomation.Cloud.Views.GatewayFeatures object as a parameter.

           

          PowerCLI C:\Users\a-rvdnieuwendijk\Documents\Scripts> $edgeView | Get-Member

           

             TypeName: VMware.VimAutomation.Cloud.Views.Gateway

           

          Name                               MemberType Definition

          ----                               ---------- ----------

          ConfigureServices                  Method     void ConfigureServices(VMware.VimAutomation.Cloud.Views.NetworkService[] networkService)

          ConfigureServices_Task             Method     VMware.VimAutomation.Cloud.Views.Task ConfigureServices_Task(VMware.VimAutomation.Cloud.Views.NetworkService[] networkService), VMware.VimAutomation.Cloud.Views.Task ConfigureServices_Task(VMware.VimAutomation.Cloud.Views.GatewayFeatures gatewayFeatures)

          • 2. Re: vCloud NAT rule problem
            BastiaanvanH Novice

            Thank you for your reply. Much appreciated.

             

            I've drilled down on an existing edge with a NatRule configured. The GatewayFeatures object is empty. So NatRules are not stored there.

             

            C:\Users\Bastiaan\Documents> $edgeview.Configuration

             

            BackwardCompatibilityMode       :

            GatewayBackingConfig            : compact

            GatewayInterfaces               : VMware.VimAutomation.Cloud.Views.GatewayInterfaces

            EdgeGatewayServiceConfiguration : VMware.VimAutomation.Cloud.Views.GatewayFeatures

            HaEnabled                       : False

            UseDefaultRouteForDnsRelay      : False

            SyslogServerSettings            : VMware.VimAutomation.Cloud.Views.SyslogServer

            AdvancedNetworkingEnabled       : False

            AnyAttr                         :

            VCloudExtension                 :

             

            C:\Users\Bastiaan\Documents> $edgeview.Configuration.EdgeGatewayServiceConfiguration

             

            NetworkService AnyAttr VCloudExtension

            -------------- ------- ---------------

             

            Is there a way to find out where ' VMware.VimAutomation.Cloud.Views.NatService' object can be applied on?

            • 3. Re: vCloud NAT rule problem
              navi86 Novice

              You should replace object from NatPortForwardingRule  to GatewayNatRule

              $edges = Search-Cloud -QueryType EdgeGateway

              $edge = $edges | Where-Object {$_.Name -eq $UserRT}

              $edgeview = $edge | get-ciview

               

              $natService = New-Object VMware.VimAutomation.Cloud.Views.NatService

              $natService.IsEnabled = $true

               

              $natRule = New-Object VMware.VimAutomation.Cloud.Views.NatRule

              $natRule.IsEnabled = $true

              $natRule.RuleType = "DNAT"

              #should be

              $gatewaynatRule = New-Object VMware.VimAutomation.Cloud.Views.GatewayNatRule

              $gatewaynatRule.OriginalIp = "172.31.255.0/24"

              $gatewaynatRule.TranslatedIp = "1.2.3.4"

              ###

              $natRule.Item = $gatewaynatRule

              $natService.NatRule = $natRule

              $edgeview.ConfigureServices($natService)