How to launch Nutanix CALM blueprint with REST API

In this article we will see how to call some blueprint from Nutanix CALM with REST API. This can be useful for integration with other tools or just to check periodically if your blueprint still works. We all know that environment changes can have an effect to application deployment... A network change for example! For this example we are using a multi-vm blueprint but containing only one resource VM.

We are assuming in this article that you already know how to create Nutanix CALM blueprints manually and that you understand basic use of REST APIs.

The first thing to do is to retrieve the ID from the blueprint we want to launch. Note that you can have different version of the same blueprint published in you CALM market place. So be sure to get the ID from the right blueprint with the right version.

To do this we will have to do an HTTP POST request on

https://your_prism_url:9440/api/nutanix/v3/blueprints/list

With the body

{"kind":"blueprint"}

Find the ID of the blueprint in the result:

...
    "status": {
                    "last_update_time": 1603452414763729,
                    "name": "My_blueprint_name",
                    "deletion_time": 1,
                    "deleted": false,
                    "spec_version": 53,
                    "description": "My blueprint description",
                    "application_count": 1,
                    "creation_time": 1591605939164920,
                    "state": "ACTIVE",
                    "schema_version": "1.1.0",
                    "entity_verison": 53,
                    "messages": [],
                    "tenant_uuid": "",
    //--->          "uuid": "e5025611-f75d-4114-a614-9f27ebf71cdd"
                },
                "spec": {},
                "api_version": "3.0",
...

Okay once you have the blueprint ID you need to get the profile reference and the runtime editables. This basically is the profile you choose when starting a blueprint and the different variables from the form. To retrieve these information we need to make a HTTP GET request on

https://your_prism_url:9440/api/nutanix/v3/blueprints/THE_BLUEPRINT_UID/runtime_editables

The response body should look like:

...
    {
        "resources": [
            {
                "app_profile_reference": {
                    "kind": "app_profile",
                    "name": "Default",
                    "uuid": "365b661b-1dfb-49e7-9c23-d004b97f6901"
                },
                "runtime_editables": {
                    "substrate_list": [
                        {
                            "description": "",
                            "uuid": "400dfae0-30a7-4d9f-8851-4978a3df0d2b",
                            "value": {
                                "spec": {
                                    "resources": {
                                        "nic_list": {
                                            "0": {
                                                "subnet_reference": {
                                                    "kind": "subnet",
                                                    "name": "",
                                                    "uuid": "126d67a4-4f7c-4460-923f-5b8c1df08ea8"
                                                }
                                            }
                                        },
                                        "num_sockets": 2,
                                        "memory_size_mib": 8192
                                    }
                                }
                            },
                            "context": "app_profile.Default.deployment.6e2d267e_deployment.substrate",
                            "type": "AHV_VM",
                            "name": "VM1"
                        }
                    ],
                    "variable_list": [
                        {
                            "description": "Company Name",

...

Okay now save the json objects "app_profile_reference" and "runtime_editables" that you want for your blueprint. In this example we just use the default profile. The runtime_editables contains the resources like memory of our VM, CPU, but also the list of variables that you usually fill from the form. You will have to edit these to your needs.

Once this is done, we are good to go! We can launch our blueprint. We need to use an HTTP POST request with this URL:

https://prism.cisel.lan:9440/api/nutanix/v3/blueprints/YOUR_BLUEPRING_ID/simple_launch

With the following BODY:

...

    {
        "spec": {
# Provide and application name and a description below
            "app_name": "SimpleLaunchDemo",
            "app_description": "An example of a simple blueprint launch via the v3 REST API",
            "app_profile_reference": {
                "kind": "app_profile",
                "name": "Default",
                "uuid": "365b661b-1dfb-49e7-9c23-d004b97f6901"
            },
#use the runtime_editables retrieved previsouly with your inputs
            "runtime_editables": {
                    "substrate_list": [
                        {
                            "description": "",
                            "uuid": "400dfae0-30a7-4d9f-8851-4978a3df0d2b",
                            "value": {
                                "spec": {
                                    "resources": {
                                        "nic_list": {
                                            "0": {
                                                "subnet_reference": {
                                                    "kind": "subnet",
                                                    "name": "",
                                                    "uuid": "126d67a4-4f7c-4460-923f-5b8c1df08ea8"
                                                }
                                            }
                                        },
                                        "num_sockets": 2,
                                        "memory_size_mib": 8192
                                    }
                                }
                            },
                            "context": "app_profile.Default.deployment.6e2d267e_deployment.substrate",
                            "type": "AHV_VM",
                            "name": "VM1"
                        }
                    ],
                    "variable_list": [
                        {
                            "description": "Company name",
                            "uuid": "e6cc73b5-d076-9776-5c7a-819f5eb7362d",
                            "value": {
                                "value": "CISEL"
                        },
...

In the response you will get the request ID. This is important to monitor our deployment.

request_id: "ba4d2f55-4fda-414d-a17a-da276a7db578"

We will now verifiy that our appllication deployment started successfully with and HTTP GET request:


https://prism.cisel.lan:9440/api/nutanix/v3/blueprints/YOUR_BLUEPRINT_ID/pending_launches/YOUR_REQUEST_ID

Response

...
 "status": {
    "application_uuid": "cb59b701-8648-43e5-99d0-54486438a858",
    "app_name": "SimpleLaunchDemo",
    "state": "success",
...

We can see that the deployment started successfully and we now have the application ID. This ID is needed to get the final state of the application deployment. It can take several minutes depending of your blueprint in order to complete the deployment.

So you can wait a bit or maybe loop on the following HTTP GET request in order to see the application state "running" or "failed"

https://prism.cisel.lan:9440/api/nutanix/v3/apps/YOUR_APP_ID

you will see the state in the response

{
    "status": {
        "active_app_profile_instance_reference": {
            "kind": "app_profile",
            "name": "SimpleLaunchDemo_Default_instance",
            "uuid": "4f54d325-1e7f-46f1-b982-55662fc25c46"
        },
        "protection_status": {
            ...
            ],
            ...
        },
        "description": "DEMO DEPLOYMENT",
        "action_list": [],
        "uuid": "cb59b701-8648-43e5-99d0-54486438a858",
        "beam_sync_status": {
           ...
        },
        # the state is just blelow, running
        "state": "running",
        "app_state_meta": null,
        "resources": {
         ...
         }
}

Et voilà! the application is running

Enjoy!!

Feel free to comment this article if you have some question.

www.cisel.ch

No Comments Yet