StyleBook configuration

Use APIs to create configurations from StyleBooks

After you have built your StyleBook, you have to import it either by using the NetScaler Console GUI or by using the NetScaler Console APIs. NetScaler Console validates your StyleBook when you import it. If the validation is successful, your StyleBook appears on the NetScaler Console catalog of StyleBooks, ready to be used for creating configurations.

You can now use the StyleBook APIs to create configurations based on this StyleBook. You can use any tool such as the cURL command line tool or the Postman chrome browser extension to send HTTP requests to NetScaler Console.

Note:

The StyleBooks APIs are fully documented using the OpenAPI specification on the Developer Portal.

Example 1

Consider the lb-vserver StyleBook created in StyleBook to Create a Load Balancing Virtual Server. Use the following REST APIs to create a configuration pack from this StyleBook:

HTTP METHOD: POST

URL: https://<IP>/stylebook/nitro/v2/config/configpacks

REQUEST Headers:

Content-Type: application/json

Accept: application/json

REQUEST BODY PAYLOAD:

{
  "configpack":
  {
    "parameters": {
      "name": "lb1",
      "vip-ipaddress": "10.102.117.31"
    },
    "targets":
    [
      {
        "instance_id": "deecee30-f478-4446-9741-a85041903410"
      }
    ],
    "stylebook": {
            "name": "lb-vserver",
            "namespace": "com.example.stylebooks",
            "version": "1.0"
        }
  }
}
<!--NeedCopy-->

In this HTTP request, the ID, deecee30-f478-4446-9741-a85041903410, is the instance ID of the NetScaler instance on which the load balancing virtual server lb1 with IP address 10.102.117.31 is created. The instance ID of the NetScaler instance is retrieved from NetScaler Console.

To get the ID of an instance managed by NetScaler Console, you can use the NetScaler Console APIs. For example, to retrieve the instance ID or a NetScaler instance whose IP address is 192.168.153.160, you can use the following API:

HTTP METHOD: GET

URL: https://<IP>/nitro/v2/config/ns?filter=ip_address:192.168.153.160

REQUEST HEADERS:

Accept: application/json

The response has the ID in the json payload:

EXPECTED RESPONSE HEADERS (on success):

200 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
  "errorcode": 0,
  "message": "Done",
  "operation": "get",
  "resourceType": "ns",
  "username": "nsroot",
  "tenant_name": "Owner",
  "resourceName": "",
  "ns":
  [
    {
    "is_grace": "false",
    "hostname": "",
    "std_bw_config": "0",
    "gateway_deployment": "false",
    "id": "deecee30-f478-4446-9741-a85041903410",
   }
 ]
}
<!--NeedCopy-->

If the configuration (configuration pack) is successfully created, you receive the following HTTP response:

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
  "job":
  {
    "job_id": "1460806080"
  }
}
<!--NeedCopy-->

You have created your first job that is uniquely identified by using the ID, 1460806080. You can use this ID to query, update, or delete the configuration.

You can use the following URL to query the job status:

https://<IP>/stylebook/nitro/v2/config/jobs/<jobid>

Example 2

You can use the same StyleBook to create another configuration or configuration pack and run it on the same or different NetScaler instances. In this example, create another configuration and provide a different name and IP address for the virtual server. Specify LEASTCONNECTION as the load balancing method. Deploy this configuration on two NetScaler instances.

The HTTP request is as follows:

HTTP METHOD: POST

URL: https://<IP>/stylebook/nitro/v2/config/configpacks

REQUEST HEADERS:

Content-Type: application/json

Accept: application/json

REQUEST BODY PAYLOAD:

{
  "configpack":
  {
    "parameters": {
      "name": "lb1",
      "vip-ipaddress": "10.102.117.31",
      "lb-alg": "LEASTCONNECTION"
    },
    "targets":
    [
      {
        "instance_id": "deecee30-f478-4446-9741-a85041903410"
      },
      {
        "instance_id": "abcdee30-f478-4446-9741-a85041903410"
      }
    ],
    "stylebook": {
            "name": "lb-vserver",
            "namespace": "com.example.stylebooks",
            "version": "1.0"
        }
  }
}
<!--NeedCopy-->

In this HTTP request, the load balancing virtual server lb1 with IP address 10.102.117.31 is created on the two NetScaler instances with IDs “deecee30-f478-4446-9741-a85041903410” and “abcdee30-f478-4446-9741-a85041903410”.

On successful creation of the configuration pack, the following HTTP response is received:

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
    "job": {
        "job_id": "165769629"
    }
}
<!--NeedCopy-->

This new configuration pack has a different ID, 165769629. You can update or remove this configuration by using this ID.

Example 3

Consider the “basic-lb-config” StyleBook you have created in StyleBook to Create a Basic Load balancing Configuration. Use the REST API to create a configuration pack from this StyleBook as follows:

HTTP METHOD: POST

URL: https://<IP>/stylebook/nitro/v2/config/configpacks

REQUEST HEADERS:

Content-Type: application/json

Accept: application/json

REQUEST BODY PAYLOAD:

{
  "configpack":
  {
    "parameters":
    {
      "name": "myapp",
      "ip": "10.70.122.25",
      "svc-servers": ["192.168.100.11","192.168.100.12"],
       "svc-port": 8080
    },
    "targets":
    [
     {
      "instance_id": "deecee30-f478-4446-9741-a85041903410"
     },
     {
      "instance_id": "abcdefgi-d589-4557-8632-a74032802412"
     }
    ],
    "stylebook": {
            "name": "basic-lb-config",
            "namespace": "com.example.stylebooks",
            "version": "0.1"
        }
  }
}
<!--NeedCopy-->

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
    "job": {
        "job_id": "3628681382"
    }
}
<!--NeedCopy-->

In this HTTP request, the load balancing configuration is run on two NetScaler instances. You can log on to these NetScaler instances to verify whether a virtual server and a service group with two services bound are created.

Example 4

Consider the composite StyleBook composite-example you created in Create a Composite StyleBook. Use REST APIs to create a configuration pack from this StyleBook as follows:

HTTP METHOD: POST

URL: https://<IP>/stylebook/nitro/v2/config/configpacks

REQUEST HEADERS:

Content-Type: application/json

Accept: application/json

REQUEST BODY PAYLOAD:

{
  "configpack":
  {
    "parameters": {
      "name": "myapp",
      "ip": "2.2.2.2",
      "svc-servers": ["10.102.29.52","10.102.29.53"]
    },
    "targets":
    [
     {
      "id": "deecee30-f478-4446-9741-a85041903410"
     },
     {
      "id": "abcdefgg-d589-4557-8632-a74032802412"
     }
    ],
    "stylebook": {
            "name": "composite-example",
            "namespace": "com.example.stylebooks",
            "version": "0.1"
        }
  }
<!--NeedCopy-->

In this HTTP request, the configuration is created on two NetScaler instances represented by their IDs. If you log on to the NetScaler instances, you can view the configuration objects created by the “basic-lb-config” StyleBook that was imported into the “composite-example” StyleBook. You can also see a new HTTP monitor called myapp-mon that was part of the “composite-example” StyleBook.

On successful creation of the configuration pack, the following HTTP response is received:

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
    "job": {
        "job_id": "3628681382"
    }
}
<!--NeedCopy-->

Updating a configuration

To update the configuration, you can use the following API. Here, a back end server with the IP address 10.102.29.54 is added to the load balancing virtual server `myapp:

HTTP METHOD: PUT

URL: https://<IP>/stylebook/nitro/v2/config/configpacks/<configpackid>

REQUEST HEADERS:

Content-Type: application/json

Accept: application/json

REQUEST BODY PAYLOAD:

{
  "configpack": {
    "parameters": {
      "name": "myapp",
      "ip": "2.2.2.2",
      "svc-servers": ["10.102.29.52","10.102.29.53","10.102.29.54"]
  },
  "targets":
   [
     {
      "instance_id": "deecee30-f478-4446-9741-a85041903410"
     },
     {
      "instance_id": "abdcedff-d589-4557-8632-a74032802412"
     }
   ]
  }
}
<!--NeedCopy-->

On successful update of the configuration pack, the following HTTP response is received:

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE BODY (on success):

{
    "job": {
        "job_id": "3628681382"
    }
}
<!--NeedCopy-->

Deleting a configuration

To delete this configuration (from all the NetScaler instances), you can use the API for deleting a configuration pack as follows:

On successful deletion of the configuration pack, the following HTTP response is received:

HTTP METHOD: DELETE

URL: https://<DNS-or-IP>//stylebook/nitro/v2/config/configpacks/<configpackid>

REQUEST HEADERS:

Accept: application/json

EXPECTED RESPONSE HEADERS (on success):

202 OK

Content-Type: application/json

EXPECTED RESPONSE PAYLOAD (on success):

{
    "job": {
        "job_id": "3628681382"
    }
}
<!--NeedCopy-->

Log on to the NetScaler instance and verify that all the configuration objects that are part of this configuration pack have been removed.

To remove the configuration from specific NetScaler instances instead of from all the instances, use the update configuration pack operation in Updating a configuration. Change the targets attribute in the JSON payload to remove the specific NetScaler instance IDs.

Use APIs to create configurations from StyleBooks