According to the Gartner blog post, 2019 Network Resolution: Invest in Network Automation, the top network resolution of 2019 was network automation. This isn’t surprising since traditional automation of networking and security has always been a challenge due to the cumbersome processes, lack of governance, and limited or non-existent management tools.
Organizations that automate more than 70% of their network change activities will reduce the number of outages by at least 50% and deliver services to their business constituents 50% faster
VMware NSX-T Data Center solves this by enabling rapid provisioning of network and security resources with layered security and governance. By using various network automation tools, you can quickly and effectively keep up with the demands of your developers and application owners who expect a quick turnaround on resource requests. In this blog post we’ll look at how NSX-T Policy APIs simplifies network automation.
What Are NSX-T Policy APIs?
At the center of NSX network automation lies the single point of entry into NSX via REST APIs. Just like traditional REST APIs, NSX-T APIs support the following API verbs: GET, PATCH, POST, PUT, DELETE. The table below shows the usage:
A New API Object Model
Introduced in NSX-T 2.4, the new NSX Policy APIs reduces the number of configuration steps by allowing users to describe the desired end-goal while letting the system figure out how best to achieve it. NSX-T Policy APIs provide a simplified data model and allow for consumption using an intent-based approach. The data model is based on a hierarchical tree structure shown below.
The hierarchical tree structure is made of strongly typed nodes and have parent/child, peer relationships with each other. Of course, this model maps easily into the RESAT APIs. Because the object model is based as a single tree, Object Names/IDs, which translates to URI and is user friendly. Users can configure the ID unlike traditional API models where the ID is system generated. This helps in accelerated development of network automation. Since objects are easily identifiable, they can be referenced without having to make a GET API call to retrieve the system generated IDs.
While NSX-T enjoys an ever growing customer base, questions like below always boil down to how good of a network automation solution you can develop:
I want to create the entire intent in one go without requiring to care about ordering or having to make multiple API calls. Can I do it?
And I would like to do it in a single API call and would like to replicate it across our dev, test, staging and production pods
The above can be applicable when you’re creating a complex routing topology with multiple Tier-1s and services or when you’re deploying various distributed firewall rules to cater to your security team’s design (or perhaps both!). The take away is you need a flexible solution that can create the entire intent in one go while realizing the objects in the right order. Correctly. The Policy APIs supports the traditional way where you can operate on each of the objects and you can perform the CURD operations, but that’s not all NSX-T Policy APIs can do.
How Does NSX Policy APIs Help?
As mentioned before, a unique ability of the NSX-T Policy API is the ability to describe the complete end-goal without having to worry about the order and dependency. Because you can define the object ID, you can describe objects which refer to other objects even if the object is not yet created!
Consider the below API:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
PATCH /policy/api/v1/infra { "resource_type": "Infra", "display_name": "infra", "children": [ { "resource_type": "ChildTier1", "Tier1": { "resource_type": "Tier1", "display_name": "my-Tier-1-GW-Prod", "id": "my-Tier-1-GW-Prod", "tier0_path": "/infra/tier-0s/Tier-0-GW-West-01" } }, { "resource_type": "ChildTier0", "Tier0": { "resource_type": "Tier0", "display_name": "Tier-0-GW-West-01", "id": "Tier-0-GW-West-01" } } ] } |
The API creates both Tier-0 Gateway and a Tier-1 Gateway that connects to the Tier-0 just created. In just 1 API call!
A few things to note here:
- The API is a PATCH call with the URI as /policy/api/v1/infra. It is important to remember that while traditional API endpoints, to perform traditional CRUD operations on individual objects can be used, hierarchical Policy APIs work on the infra/ endpoint.
- The IDs for both Tier-0 and Tier-1 Gateways are defined in the request itself!
- Reference to Tier-0 in the Tier-1 object is via its path! The path follows the exact tree traversal as shows in the diagram above.
- Tier1 Gateway is defined first (which has a reference to Tier0 Gateway). This is completely OK!
Combine all these, and you get a simple powerful declarative model which can achieve outcomes rather than execute actions. It simplifies automation and operations.
What About Deletion? You Need to Use the DELETE Call, Right?
Well, no. The policy object model has a special flag marked_for_delete. This boolean flag can be used to delete objects in the same PATCH call as above! On top of that, you can create or edit objects and delete other objects in just 1 API call.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
PATCH /policy/api/v1/infra/ { "resource_type": "Infra", "display_name": "infra", "children": [ { "resource_type": "ChildTier1", "marked_for_delete": "true", "Tier1": { "resource_type": "Tier1", "display_name": "my-Tier-1-GW-Prod", "id": "my-Tier-1-GW-Prod", "tier0_path": "/infra/tier-0s/Tier-0-GW-West-01" } }, { "resource_type": "ChildTier0", "marked_for_delete": "false", "Tier0": { "resource_type": "Tier0", "display_name": "Tier-0-GW-West-01-Disconnected", "id": "Tier-0-GW-West-01" } } ] } |
In the call above, the Tier1 Gateway is deleted and the display name of Tier0 Gateway is changed! In just 1 PATCH call.
The object hierarchy described above also plays a significant role in understanding the parent/child relationship. This is especially important when defining objects like Distributed Firewall Policy and Rules. I’m extending the API call above to now include a Group with dynamic member and creating a Security Policy with one Rule that uses the Group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
PATCH /policy/api/v1/infra { "resource_type": "Infra", "display_name": "infra", "children": [ { "resource_type": "ChildTier1", "Tier1": { "resource_type": "Tier1", "display_name": "my-Tier-1-GW-Prod", "id": "my-Tier-1-GW-Prod", "tier0_path": "/infra/tier-0s/Tier-0-GW-West-01" } }, { "resource_type": "ChildTier0", "Tier0": { "resource_type": "Tier0", "display_name": "Tier-0-GW-West-01", "id": "Tier-0-GW-West-01" } }, { "resource_type": "ChildDomain", "Domain": { "resource_type": "Domain", "id": "default", "children": [ { "resource_type": "ChildGroup", "Group": { "resource_type": "Group", "display_name": "DEV-RED-web-vms", "id": "DEV-RED-web-vms", "expression": [ { "member_type": "VirtualMachine", "key": "Tag", "operator": "EQUALS", "value": "web", "resource_type": "Condition" } ] } }, { "resource_type": "ChildSecurityPolicy", "SecurityPolicy": { "resource_type": "SecurityPolicy", "id": "DEV-RED-intra-app-policy", "display_name": "DEV-RED-intra-app-policy", "rules": [ { "resource_type": "Rule", "description": "Communication Entry", "display_name": "any-to-DEV-RED-web", "sequence_number": 1, "source_groups": [ "ANY" ], "destination_groups": [ "/infra/domains/default/groups/DEV-RED-web-vms" ], "services": [ "/infra/services/HTTPS" ], "action": "ALLOW" } ] } } ] } } ] } |
Just like before, I can define my own IDs, refer to objects using their path. But how did I know the path? One obvious solution is that I referred the hierarchical tree structure shown above. Based on that diagram, I can see that Groups and Security Polices are child objects of Domain. But wait, the picture isn’t complete. What about other objects that I need? What about other attributes? Well, all of that is available in the NSX-T API Guide. The allowed child objects are clearly listed out. Looking at Domain object I see the following:
This shows that I can have ChildGroups and ChildSecurityPolicy as child objects. I can then navigate into each of them to understand their schema and use any available child objects. Its that easy! More details and information can be got from this handy Getting Started Guide on Policy APIs.
What Else Can NSX-T APIs Do?
NSX-T APIs also allow you to create complex queries to search for objects. While the feature to search was always available in the UI (and quite popular), NSX-T 3.0 adds the search API /policy/api/v1/search/query to its long list of public, supported APIs. The complete description and documentation is available in the NSX-T Rest API Guide. The search API supports an exhaustive list of resource types you can search on. The API also supports Wildcards and Boolean Operators – AND, OR, NOT. You can create simple but powerful queries like this:
1 2 3 4 5 |
GET /policy/api/v1/search/query?query=resource_type:Segment AND display_name=* GET /policy/api/v1/search/query?query=NOT tags.scope=*web* AND resource_type:FirewallRule GET /policy/api/v1/search/query?query=resource_type:Group AND display_name=*web* OR display_name=*app* |
NSX-T Policy APIs are a powerful tool to directly automate your tasks. Its easy, declarative nature allows you to create hierarchical APIs that define the entire topology in one go.
Replication through NSX-T Policy APIs
Sometimes you will need to replicate an existing configuration in a new pod or NSX deployment. In such a case, just do the following:
1 |
GET /policy/api/v1/infra?filter=Type- |
This returns the entire configuration. Before the response is applied to a new pod using the PATCH API, the system owned objects have to be cleaned up. Along with that, any UUIDs related to the system/fabric (like Edge UUID, Edge Cluster UUIDs or Transport Zone UUIDs) have to be updated to reflect the new system. You can then apply it in your new pod!
Another option is you retrieve the configuration and start versioning it. This will enable you to see the changes that happened to your configuration over time and revert to any particular one. How’s that for simplifying Infrastructure as Code?
With all this, it is easy to summarize that NSX-T Policy APIs is a powerful tool for NSX-T Network Automation.
Resources
- To get more details read the NSX-T REST APIs Guide
- Learn about what’s new in NSX-T
- More on Policy APIs in the Getting Started Guide
Comments
0 Comments have been added so far