VMware NSX

 View Only
  • 1.  Power NSX - Output log

    Posted Feb 26, 2018 11:55 AM

    I am using Power NSX tool to automate adding IP address to IPSets periodically along with Power Shell.

    I am using rest invoke method.

    Invoke-RestMethod -method "put"-uri "/api/2.0/services/ipset/

    The script executes fine & no issue with the script. Would like to generate log output which indicates that the script has executed successfully.

    Let me know how to get the required log out put when the script is executed successfully indicating it is fine.



  • 2.  RE: Power NSX - Output log

    Posted Feb 26, 2018 02:39 PM

    Hi Rajeev,

    There should be multiple ways to handle exception handing.. Here i can suggest try & catch blocks in powercli script.

    $URI = "/api/2.0/services/ipset/"

      try {

            $response = invoke-nsxrestmethod -method "POST" -uri $URI -connection $connection -body $body

            write-host "IP-Set created sucessfully"

        }

        catch {

            Throw "Unable to create ipset's $_"

        }



  • 3.  RE: Power NSX - Output log

    Posted Feb 27, 2018 07:54 AM

    Thanks Amol

    Few clarifications.

    If the API is executed properly my understanding is that, the output should generate some value like 200 indicating the script is executed rightly.

    If not i will generate output like 4XX, ect

    Can this be taken as output & generate log file



  • 4.  RE: Power NSX - Output log

    Posted Feb 27, 2018 11:30 PM

    any inputs



  • 5.  RE: Power NSX - Output log

    Posted Feb 28, 2018 03:01 PM

    Hi Rajeev,

      

         I understood your point.

         In this case $response variable will have XML file as a output, when web-invoke command successfully completed. In case API command unable to execute you don't need to handle in the script it will return error in case it failed on the screen.



  • 6.  RE: Power NSX - Output log

    Posted Mar 19, 2018 07:20 AM

    Hi Amol

    Regarding the below point how to capture the output into the XML  ?

    Below is the command which I am suing the script.

    Invoke-RestMethod -method "put"-uri "/api/2.0/services/ipset/

    How to export the output of this into the xml file ?



  • 7.  RE: Power NSX - Output log

    Posted Mar 19, 2018 01:46 PM

    Hi Rajeev,

      Are you getting any error while running the command?

      Following command should return you the output in xml format :

    [xml]$ipSets= Invoke-RestMethod -method "put"-uri "/api/2.0/services/ipset/



  • 8.  RE: Power NSX - Output log

    Posted Mar 21, 2018 10:14 AM

    Hi Amol

    Thanks.

    The command works fine. But what I am expecting is that I want to log the output of the command.

    Even if it is successful or failed, I need to log the output in the output file.

    I tried the command which u highlighted below. The .xml file did not have any details & it was empty.



  • 9.  RE: Power NSX - Output log

    Posted Mar 25, 2018 09:27 AM

    Hi Rajeev,

        

         I am not quite sure why it is not returns the output to variable in case of failure.

         May be you use try & catch block to resolve this issue. In case command failed it will go to catch block.



  • 10.  RE: Power NSX - Output log

    Posted Feb 28, 2018 03:03 PM

    Please go though this blog post. it may help you to solve your issue

    Aaron's Code Notes: How to make an HTTP request with PowerShell



  • 11.  RE: Power NSX - Output log

    Broadcom Employee
    Posted Mar 15, 2018 09:07 AM

    Why not just use the built in cmdlets in PowerNSX? We put a lot of work into making this really useable for Day 2 operations. After  the cmdlet executes, it return the updated object.

    Get-NsxIpSet blah | Add-NsxIpSetMember -IPAddress 1.2.3.4,192.168.0.0/16,10.1.2.1-10.1.3.15

    Dale