-
Notifications
You must be signed in to change notification settings - Fork 13
Home
This project is a Golang library for talking to NSX API.
Feature | Create | Read | Update | Delete |
---|---|---|---|---|
DHCP Relay | Y | Y | Y | Y |
Edge Interface | Y | Y | Y | Y |
Security Group | Y | Y | Y | Y |
Security Policy | Y | Y | Y | Y |
Security Tag | Y | Y | Y | Y |
Security Tag Attachment | Y | Y | Y | Y |
Service | Y | Y | Y | Y |
Transport Zone | N | Y | N | N |
Virtual Wire | Y | Y | Y | Y |
Implementation of CRUD in above features is partial in some cases.
The NSXClient is the class used to send requests to the NSX host and pass through credentials.
Import the following files.
To create an NSX object run the following code, with the correct params.
import (
"github.com/sky-uk/gonsx"
)
nsxclient := gonsx.NewNSXClient(url, username, password, ignoreSSL, debug)
The params used:
- url: URL of NSX host
E.G. https://nsxhost.com
- username: NSX username
- password: NSX password
- ignoreSSL: bool on whether to ignore ssl (default false)
- debug: bool on whether to debug output (default false)
The client is also used run the api calls once you have created the resource object.
nsxclient.Do(my_resource_obj)
Virtual Wire resource. This resource will call the Virtual Wires api within NSX. Import the following class:
github.com/sky-uk/gonsx/api/virtualwire
Create:
var virtualWireCreateSpec virtualwire.CreateSpec
virtualWireCreateSpec.Name = "name"
virtualWireCreateSpec.Description = "desc"
virtualWireCreateSpec.ControlPlaneMode = "UNICAST_MODE"
virtualWireCreateSpec.TenantID = "tenant id"
scopeID := "vdnscope-1"
api := virtualwire.NewCreate(virtualWireCreateSpec, scopeID)
nsxclient.Do(api)
Read: Get a list of virtual wires back, or filter them by name
api := virtualwire.NewGetAll(scopeID)
nsxclient.Do(api)
resp := api.GetResponse().FilterByName(virtualWireName)
Read single virtualwire: Get a single virtual wire object back given its unique ID
api := virtualwire.NewGet(virtualwireID)
nsxclient.Do(api)
resp := api.GetResponse()
Update:
api := virtualwire.NewUpdate(name, desc, virtualwireID)
nsxclient.Do(api)
Delete:
api := virtualwire.NewDelete(virtualWireID)
nsxclient.Do(delete_api)
Interface resource. This resource will call the interface api within NSX. Import the following class:
github.com/sky-uk/gonsx/api/edgeinterface
Create:
addressGroup := edgeinterface.AddressGroup{PrimaryAddress: "10.10.10.1", SubnetMask: "255.255.255.0"}
addressGroupList := []edgeinterface.AddressGroup{addressGroup}
edgeInterface := edgeinterface.EdgeInterface{
Name: "app_virtualwire_one",
ConnectedToID: <a valid virtual wire ID>,
Type: "internal",
Mtu: 1500,
IsConnected: true,
AddressGroups: edgeinterface.AddressGroups{addressGroupList},
}
requestPayload := new(edgeinterface.EdgeInterfaces)
requestPayload.Interfaces = []edgeinterface.EdgeInterface{edgeInterface}
edgeId := "edge-7"
api := edgeinterface.NewCreate(&edgeInterfaces, edgeId)
nsxclient.Do(api)
createdEdgeInterfaces := api.GetResponse()
Read: Get a single edgeinterface.EdgeInterface object back
api := edgeinterface.NewGet(edgeid, index)
nsxclient.Do(api)
edge := api.GetResponse()
Read: Get all edge interfaces back
api := edgeinterface.NewGetAll(edgeid)
nsxclient.Do(api)
edges := api.GetResponse()
Update:
api := edgeinterface.NewUpdate(edgeid, index, edge)
nsxclient.Do(api)
Delete:
api := edgeinterface.NewDelete(edgeid, index)
nsxclient.Do(api)
DHCP resource. This resource will call the DHCP relay api within NSX. Import the following class:
github.com/sky-uk/gonsx/api/dhcprelay
The Dhcp relay behaves differently in the API and as such it doesn't have a create and only an update and delete. The delete function will remove the whole relay and all of its information. If you do not wish to do this and only remove interfaces from the DHCP relay, then you must run an update instead.
Read:
api := dhcp.NewGetAll(edgeId)
nsxclient.Do(api)
Update:
api := dhcprelay.NewUpdate(dhcpIpAddress, edgeId, relayAgentslist)
nsxclient.Do(api)
Delete:
api := dhcprelay.NewDelete(edgeId)
nsxclient.Do(api)
Security tag resource. This resource will call the security tag api within NSX. Import the following class:
github.com/sky-uk/gonsx/api/securitytag
Create:
api := securitytag.NewCreate(name, desc)
nsxclient.Do(api)
Read:
api := securitytag.NewGetAll()
nsxclient.Do(api)
Update:
Not yet implemented
Delete:
api := securitytag.NewDelete(securitytagID)
nsxclient.Do(api)
Detach:
api := securitytag.NewDetach(securityTagID, vmID)
nsxclient.Do(api)
Attach:
api := securitytag.NewAttach(securityTagID, vmID)
nsxclient.Do(api)
Service resource. This resource will call the service api with NSX. Import the following class:
github.com/sky-uk/gonsx/api/service
Create:
api := service.NewCreate(scopeID, name, desc, proto, ports)
nsxclient.Do(api)
Read:
api := service.NewGetAll(scopeID)
nsxclient.Do(api)
Update:
Not yet implemented
Delete:
api := service.NewDelete(serviceID)
nsxclient.Do(api)
Security Group resource. This resource will call the security group api with NSX. Import the following class:
github.com/sky-uk/gonsx/api/securitygroup
Create:
api := securitygroup.NewCreate(scopeID, name, setOperator, criteriaOperator, criteriaKey, criteriaValue, criteria)
nsxclient.Do(api)
Read:
api := securitygroup.NewGetAll(scopeID)
nsxclient.Do(api)
Update:
Not yet implemented
Delete:
api := securitygroup.NewDelete(serviceID)
nsxclient.Do(api)
Security Policy resource. This resource will call the security policy with NSX. Import the following class:
github.com/sky-uk/gonsx/api/securitypolicy
Create:
api := securitypolicy.NewCreate(name, precendence, desc, securityGroupsIDs, actions)
nsxclient.Do(api)
Read:
api := securitypolicy.NewGetAll()
nsxclient.Do(api)
Update:
Not yet implemented
Delete:
api := securitypolicy.NewDelete(securityPolicyID, force)
nsxclient.Do(api)
AddOutboundFirewall:
securityPolicyToModify := getAllAPI.GetResponse().FilterByName(securityPolicyName)
// we will use a help function to add a firewall rule.
securityPolicyToModify.AddOutboundFirewallAction(
firewallName,
action,
direction,
secGroupObjectIDs,
serviceIDs,
)
updateAPI := securitypolicy.NewUpdate(securityPolicyToModify.ObjectID, securityPolicyToModify)
nsxclient.Do(updateAPI)
RemoveFirewall:
securityPolicyToModify := getAllAPI.GetResponse().FilterByName(securityPolicyName)
securityPolicyToModify.RemoveFirewallActionByName(firewallName)
updateAPI := securitypolicy.NewUpdate(securityPolicyToModify.ObjectID, securityPolicyToModify)
nsxclient.Do(updateAPI)