Load Balancer as a Service – Part 1

Creation of a Virtual Server

Now that we have all the cards in our hands, we can create our Virtual Server.
PATCH https://<nsx-mgr>/policy/api/v1/infra/lb-virtual-servers/VS-LB-its_mysql-Prod-01
{
"enabled": false,
"ip_address": "10.110.1.2",
"ports": [
"80"
],
"access_log_enabled": false,
"lb_service_path": "/infra/lb-services/LB-ITSERVICES-PROD",
"pool_path": "/infra/lb-pools/POOL-LB-ITSERVICES-Prod-1",
"application_profile_path": "/infra/lb-app-profiles/default-http-lb-app-profile",
"resource_type": "LBVirtualServer",
"display_name": "VS-LB-its_mysql-Prod-01",
"description": "Virtual Serveur ITSERVICES PROD - its_mysql",
"tags": [
{
"scope": "lb",
"tag": "st.prod"
},
{
"scope": "lb",
"tag": "st.its_mysql"
}
],
"path": "/infra/lb-virtual-servers/VS-LB-its_mysql-Prod-01",
"relative_path": "VS-LB-its_mysql-Prod-01",
"parent_path": "/infra/lb-virtual-servers/VS-LB-its_mysql-Prod-01",
"marked_for_delete": false
}

The virtual server is actually down.
At that moment we can tag our VMs, which will automatically add them into our LB POOL Members group.


Adding tags to VMs

For this purpose, we first need to find the ID of our VMs.
GET https://<nsx-mgr>/api/v1/fabric/virtual-machines

{
"external_id": "5009c812-00b5-c3f8-cd71-c3a7ab30fb8d",
"guest_info": {
"os_name": "CentOS 7 (64-bit)",
"computer_name": "itstxaas0622"
},
"resource_type": "VirtualMachine",
"display_name": "itstxaas0622",
"tags": [
{
"scope": "",
"tag": "st.its_mysql"
},
{
"scope": "",
"tag": "st.production"
}
],
},
{
"external_id": "5009ee31-8c2e-5103-656e-718f800683a9",
"guest_info": {
"os_name": "CentOS 7 (64-bit)",
"computer_name": "itstxaas0623"
},
"resource_type": "VirtualMachine",
"display_name": "itstxaas0623",
"tags": [
{
"scope": "",
"tag": "st.its_mysql"
},
{
"scope": "",
"tag": "st.production"
}
],
}

At that point, we can add the tag st.lb.its_mysql.prod.01 to these VMs.
This tag was defined previously as a membership criteria for the group POOL-LB-ITS_MYSQL-Prod-01-Members.
Note: Be careful if you already had some tags, you have to include them in the REST API call otherwise they are going to be erase!

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=update_tags

{
"external_id": "5009c812-00b5-c3f8-cd71-c3a7ab30fb8d",
"tags": [
{"scope": "", "tag": "st.production"},
{"scope": "", "tag": "st.its_mysql"},
{"scope": "lb", "tag": "st.lb.its_mysql.prod.01"}
]
}

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=update_tags

{
"external_id": "5009ee31-8c2e-5103-656e-718f800683a9",
"tags": [
{"scope": "", "tag": "st.production"},
{"scope": "", "tag": "st.its_mysql"},
{"scope": "lb", "tag": "st.lb.its_mysql.prod.01"}
]
}

Once done, we can turn on our Virtual Server.

PATCH https://<nsx-mgr>/policy/api/v1/infra/lb-virtual-servers/VS-LB-its_mysql-Prod-01
{
"enabled": true,
"ip_address": "10.110.1.2",
"ports": [
"80"
],
"application_profile_path": "/infra/lb-app-profiles/default-http-lb-app-profile"
}



Leave a Comment