In this post we will learn how can we configure some of the network settings like DNS/Syslog and NTP configurations in NSX manager via Rest API.
We can do all this from NSX manager GUI also but if you are thinking about automating NSX manager deployment, then these Rest API knowledge can be pretty handy for configuring the appliance post its deployment.
Lets get started.
Query Network Settings
Below API query will give you an overview of NSX Manager IP settings, Hostname, DNS settings and domain name
# curl -k -u “admin:adminpwd” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/network/ | xmllint –format –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="UTF-8"?> <network> <hostName>nsxmgr</hostName> <domainName>alex.local</domainName> <networkIPv4AddressDto> <ipv4Address>192.168.109.6</ipv4Address> <ipv4NetMask>255.255.255.0</ipv4NetMask> <ipv4Gateway>192.168.109.1</ipv4Gateway> </networkIPv4AddressDto> <dns> <ipv4Address>192.168.109.2</ipv4Address> <domainList>alex.local</domainList> </dns> </network> |
Configure DNS Server
If you have not configured any DNS server settings on your NSX appliance, you can do so by firing below query.
You need to supply an xml file which have info about your domain name and IP of DNS servers. If you have only one DNS server in your environment, you can remove one of the <ipv4Address> tag from the xml file
# curl -k -u “admin:admin:adminpwd” -H “Content-Type:application/xml” -d @dns.xml -X PUT https://nsxmgr.alex.local/api/1.0/appliance-management/system/network/dns
1 2 3 4 5 6 |
<?xml version="1.0" encoding="UTF-8"?> <dns> <ipv4Address>192.168.109.2</ipv4Address> <ipv4Address>192.168.109.40</ipv4Address> <domainList>alex.local</domainList> </dns> |
Cross Verify whether or not NSX appliance have been updated with DNS settings or not
Delete DNS Servers
This query will wipe out the DNS settings from the NSX appliance.
# curl -k -u “admin:adminpwd” -X DELETE https://nsxmgr.alex.local/api/1.0/appliance-management/system/network/dns
Query NTP Settings
If you have already configured time settings on NSX appliance from UI then below GET call to NSX will provide you three things. IP address of the NTP server, Current Time and Date and Timezone
# curl -k -u “admin:adminpwd” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/timesettings | xmllint –format –
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="UTF-8"?> <timeSettings> <ntpServer> <string>192.168.109.2</string> </ntpServer> <datetime>06/25/2017 13:38:16</datetime> <timezone>Asia/Kolkata</timezone> </timeSettings> |
Configure NTP Settings
If you have not specified any time settings on your NSX manager yet, then you can use below API call alongwith an xml file which have the details about IP of NTP server, your country timezone and current date and time
# curl -k -u “admin:adminpwd” -H “Content-Type:application/xml” -d @ntp.xml -X PUT https://nsxmgr.alex.local/api/1.0/appliance-management/system/timesettings
Content of the supplied XML file (ntp.xml) in this example
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="UTF-8"?> <timeSettings> <ntpServer> <string></string> <-- IP Address of NTP Server </ntpServer> <datetime></datetime> <-- Current date and time <timezone></timezone> </timeSettings> |
Delete NTP Settings
This API call will wipe out NTP settings from the NSX manager appliance
# curl -k -u “admin:adminpwd” -X DELETE https://nsxmgr.alex.local/api/1.0/appliance-management/system/timesettings/ntp
Query Syslog Server
# curl -k -u “admin:adminpwd” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/syslogserver | xmllint –format –
If you have not configured any syslog related settings then above query will produce below message
1 |
-:1: parser error : Document is empty |
Configure Syslog Server
To configure syslog server you need to pass three parameters in the xml file i.e syslog server IP, syslog port and protocol to be used
# curl -k -u “admin:adminpwd” -H “Content-Type:application/xml” -d @syslog.xml -X PUT https://nsxmgr.alex.local/api/1.0/appliance-management/system/syslogserver
1 2 3 4 5 6 |
<?xml version="1.0" encoding="UTF-8"?> <syslogserver> <syslogServer>192.168.109.40</syslogServer> <port>514</port> <protocol>UDP</protocol> </syslogserver> |
You can verify the syslog settings by logging into your appliance.
Delete syslog server
# curl -k -u “admin:adminpwd” -X DELETE https://nsxmgr.alex.local/api/1.0/appliance-management/system/syslogserver
I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing. Be sociable