In parts 1-6 of this series, we looked at how to work with curl and the NSX API to do many different tasks. In this post, we are going to put all of the things we learned in an Ubuntu OVA that we can use to do some basic NSX API configurations.
The software:
The NSX Config Ubuntu OVA is no longer av available.
How to login:
SSH into the newly built VM and login using userid “nsxadmin” and the password that you supplied during installation. Once logged in, the scripts can be found in the home directory. BTW, the default password is “nsxconfig”.
How to use:
Here is the list of scripts:
Add NSX Manager credentials. You should execute this script first to setup the NSX Manager credentials. You only have to run this one time, unless you want to change the credentials.
Usage: nsx-add-creds.sh nsxadmin@nsxconfig:~$ ./nsx-add-creds.sh
now, you are ready to proceed with any script.
Add controller syslog server
Usage: nsx-add-contsyslog.sh controllerid syslogserver port {UDP|TCP} {INFO|ERROR|WARN}
nsxadmin@nsxconfig:~$ ./nsx-add-contsyslog.sh controller-1 10.1.1.1 514 UDP INFO
Add LIFs based on data from a CSV file
Usage: nsx-add-lif.sh edge-dlr csvfile
nsxadmin@nsxconfig:~$ cat dlr.csv
name,primaryAddress,subnetMask,mtu,type,isConnected,connectedToId
ls-1,10.10.10.1,255.255.255.0,8900,internal,true,virtualwire-10
ls-2,10.10.10.2,255.255.255.0,8900,internal,true,virtualwire-11
ls-3,10.10.10.3,255.255.255.0,8900,internal,true,virtualwire-12
nsxadmin@nsxconfig:~$ ./nsx-add-lif.sh edge-1 dlr.csv
Add Logical Switches based on data from a CSV File to a Specific Transport Zone (vdnscope)
Usage: nsx-add-ls.sh vdnscope-number csvfile
vdnscope = Transport Zone
nsxadmin@nsxconfig:~$ cat ls.csv
name,description,tenantId
ls-1,ls-1 desc,virtual wire tenant
ls-2,ls-2 desc,virtual wire tenant
ls-3,ls-3 desc,virtual wire tenant
ls-4,ls-4 desc,virtual wire tenant
ls-5,ls-5 desc,virtual wire tenant
nsxadmin@nsxconfig:~$ ./nsx-add-ls.sh 1 ls.csv
Create a CSV file from the NSX Manager data
Usage: nsx-create-csv.sh {contsyslog|tz|ls|lif|segid|spoofg|job|sslippool|routes} {<file>|curl} <outfile>
nsxadmin@nsxconfig:~$ ./nsx-create-csv.sh ls curl junk
Please choose the fields that you would like to dump in CSV format, answer y or n to following: Do you want all fields in your report (y or n): n We will use curl as input Do you want to use the fields previuosly selected (y or n): y Fields: //virtualWire/objectId|//virtualWire/objectTypeName|//virtualWire/vsmUuid|//virtualWire/name|//virtualWire/description|//virtualWire/vdnScopeId| Start:objectId End:vdnScopeId Partial Fields Output TAG: virtualWire nsxadmin@nsxconfig:~$ cat junk objectId,objectTypeName,vsmUuid,name,description,vdnScopeId virtualwire-37,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,ls-1,ls-1 desc,vdnscope-2 virtualwire-38,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,ls-2,ls-2 desc,vdnscope-2 virtualwire-39,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,ls-3,ls-3 desc,vdnscope-2 virtualwire-40,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,ls-4,ls-4 desc,vdnscope-2 virtualwire-41,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,ls-5,ls-5 desc,vdnscope-2
Delete all LIFs from a specific dlr or edge
Usage: nsx-del-all-lif.sh edge-dlr nsxadmin@nsxconfig:~$ ./nsx-del-all-lif.sh edge-1 You are about to delete all interface on edge-1, are you sure? Please answer (y or n): y
Delete controller syslog assignment
Usage: nsx-del-contsyslog.sh controllerid
nsxadmin@nsxconfig:~$ ./nsx-del-contsyslog.sh controller-1
You are about to delete syslog exporter on controller controller-1, are you sure? Please answer (y or n): y
Delete certain LIFs from a specific dlr or edge
Usage: nsx-del-lif.sh edge-dlr
nsxadmin@nsxconfig:~$ ./nsx-del-lif.sh edge-1
You are about to delete LIFs on NSX edge-1, are you sure? Please answer (y or n): n
Delete Logical Switches
Usage: nsx-del-ls.sh
nsxadmin@nsxconfig:~$ ./nsx-del-ls.sh
You are about to delete Logical Switches on NSX, are you sure? Please answer (y or n):n
Get the NSX Manager Certs
Usage: nsx-get-cert.sh
Get the NSX Manager CPU info
Usage: nsx-get-cpu.sh
nsxadmin@nsxconfig:~$ ./nsx-get-cpu.sh
{"totalNoOfCPUs":4,"capacity":"1800 MHZ","usedCapacity":"27 MHZ","freeCapacity":"1773 MHZ","usedPercentage":2}
Get The Logical Switches
Usage: nsx-get-ls.sh
nsxadmin@nsxconfig:~$ ./nsx-get-ls.sh
objectId,objectTypeName,vsmUuid,revision,type_typeName,type,name,description,clientHandle,extendedAttributes,tenantId,vdnScopeId,vdsContextWithBacking_switch_objectId,vdsContextWithBacking_switch_objectTypeName,vdsContextWithBacking_switch_vsmUuid,vdsContextWithBacking_switch_revision,vdsContextWithBacking_switch_type_typeName,vdsContextWithBacking_switch_type,vdsContextWithBacking_switch_name,vdsContextWithBacking_switch_scope_id,vdsContextWithBacking_switch_scope_objectTypeName,vdsContextWithBacking_switch_scope_name,vdsContextWithBacking_switch_scope,vdsContextWithBacking_switch_clientHandle,vdsContextWithBacking_switch_extendedAttributes,vdsContextWithBacking_switch,vdsContextWithBacking_mtu,vdsContextWithBacking_promiscuousMode,vdsContextWithBacking_backingType,vdsContextWithBacking_backingValue,vdsContextWithBacking,vdnId,guestVlanAllowed,controlPlaneMode
virtualwire-37,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,2,VirtualWire,,ls-1,ls-1 desc,,,virtual wire tenant,vdnscope-2,dvs-21,VmwareDistributedVirtualSwitch,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,68,VmwareDistributedVirtualSwitch,,Ninja-DvS,datacenter-2,Datacenter,Ninja Lab,,,,,1600,false,portgroup,dvportgroup-209,,5004,false,UNICAST_MODE
virtualwire-38,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,2,VirtualWire,,ls-2,ls-2 desc,,,virtual wire tenant,vdnscope-2,dvs-21,VmwareDistributedVirtualSwitch,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,68,VmwareDistributedVirtualSwitch,,Ninja-DvS,datacenter-2,Datacenter,Ninja Lab,,,,,1600,false,portgroup,dvportgroup-210,,5000,false,UNICAST_MODE
virtualwire-39,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,2,VirtualWire,,ls-3,ls-3 desc,,,virtual wire tenant,vdnscope-2,dvs-21,VmwareDistributedVirtualSwitch,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,68,VmwareDistributedVirtualSwitch,,Ninja-DvS,datacenter-2,Datacenter,Ninja Lab,,,,,1600,false,portgroup,dvportgroup-211,,5003,false,UNICAST_MODE
virtualwire-40,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,2,VirtualWire,,ls-4,ls-4 desc,,,virtual wire tenant,vdnscope-2,dvs-21,VmwareDistributedVirtualSwitch,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,68,VmwareDistributedVirtualSwitch,,Ninja-DvS,datacenter-2,Datacenter,Ninja Lab,,,,,1600,false,portgroup,dvportgroup-212,,5002,false,UNICAST_MODE
virtualwire-41,VirtualWire,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,2,VirtualWire,,ls-5,ls-5 desc,,,virtual wire tenant,vdnscope-2,dvs-21,VmwareDistributedVirtualSwitch,421B4419-AD1D-FB92-ECC7-7FBD9BD0BF4E,68,VmwareDistributedVirtualSwitch,,Ninja-DvS,datacenter-2,Datacenter,Ninja Lab,,,,,1600,false,portgroup,dvportgroup-213,,5001,false,UNICAST_MODE
Get the system information
Usage: nsx-get-system.sh
nsxadmin@nsxconfig:~$ ./nsx-get-system.sh
{"ipv4Address":"10.6.1.10","ipv6Address":null,"hostName":"nsx-manager","domainName":"zenet.nemtallahdaher.com","applianceName":"vShield Virtual Appliance Management","versionInfo":{"majorVersion":"6","minorVersion":"1","patchVersion":"0","buildNumber":"2107742"},"uptime":"9 days, 3 hours, 16 minutes","cpuInfoDto":{"totalNoOfCPUs":4,"capacity":"1800 MHZ","usedCapacity":"28 MHZ","freeCapacity":"1772 MHZ","usedPercentage":2},"memInfoDto":{"totalMemory":"11996 MB","usedMemory":"5810 MB","freeMemory":"6185 MB","usedPercentage":48},"storageInfoDto":{"totalStorage":"71G","usedStorage":"20G","freeStorage":"51G","usedPercentage":28},"currentSystemDate":"Tuesday, 30 September 2014 05:18:02 PM UTC"}
Get NSX Version information
Usage: nsx-get-ver.sh
nsxadmin@nsxconfig:~$ ./nsx-get-ver.sh
{"currentLoggedInUser":"admin","versionInfo":{"majorVersion":"6","minorVersion":"1","patchVersion":"0","buildNumber":"2107742"}}