Nutanix Calm DSL – Quick Tips Part 2

Nutanix Calm DSL – Quick Tips Part 2

In this edition of Nutanix Calm DSL Quick Tips, I’ll cover a few more things that are in the docs, but that new users may skip over. In isolation these things may seem minor (as with many things in the developer world), but when used as part of an overall workflow, can increase both efficiency and productivity.

Environment Variables for Configuration

The first quick tip to look at today is the use of environment variables. Specifically, we can use environment variables to instruct the Calm DSL which Prism Central IP address and port to connect on, the credentials to use (etc). By default, these settings are empty when using the Calm DSL for the first time – this applies to both local development environments and those using the Calm DSL container.

The Calm DSL repo’s documentation covers this in text format, but I’ll illustrate the process a bit more here. First, let’s look at what happens if you try to run any Calm DSL command when this configuration missing.

Missing Calm DSL configuration produces an error

The issue here is obvious, since the Calm DSL has told us exactly what’s going. We can either fix this by running the following to configure the DSL directly:

calm init dsl

Or, we can use environment variables. In the error message above, one of the available environment variables is shown – CALM_DSL_PC_IP. What happens if we set that?

Doing “as we’re told” and setting the CALM_DSL_PC_IP environment variable

Ok, now we’re making progress. If we were to repeat this process enough, we’d eventually have all the environment variables set and the Calm DSL could be used. However, that’s not particularly efficient, so let’s just look at a list of all the available variables being set via a simple Bash script. In my development environment I’ve called this script and made that script executable.


# set all required environment variables
export CALM_DSL_PC_IP=
export CALM_DSL_PC_PORT=9440

In a Linux environment, we can run that script as follows.

. ./

Following that, we can then check that the configuration has been set correctly by using another simple Calm DSL command.

calm show config

As expected, we can now see the environment has been configured and the Calm DSL is ready to be used. Note we do have the option to specify the log level by setting the CALM_DSL_LOG_LEVEL environment variable, but haven’t changed it here.

Asking the Calm DSL to show us the current environment configuration

Why do this?

While it’s true the environment can be set by running calm init dsl, this requires manual user input. From an automation perspective, any pause for manual user input effectively removes the whole point of automation.

Custom Container Environment Variables

Looking at the above, it’s been shown that a custom script could be used to set environment variables – in that example, the Calm DSL was being used locally i.e. without Docker. That’s fine, but there’s another similar option that’s aimed specifically at Calm DSL usage within a Docker container – the use of a machine-readable configuration file that contains similar settings to the script above.

Let’s look at one of those files now.


Please note the following sections assume your environment has been setup to run Docker. If you haven’t done that yet, please see Introducing the Calm DSL.

Now let’s look at launching the Calm DSL container but with our configuration file.

docker run -it --env-file ./calm_env ntnx/calm-dsl

Note use of the “–env-file” argument. Once we have the Calm DSL container running, it’s a simple command to check our environment.

Running set | grep DSL to check the configuration passed in from our configuration file

Note: As I write this, the Calm DSL has been updated to not show passwords in plain text anymore, as shown in the screenshot above. Please make sure you are working from the latest version if you are still seeing passwords in plain text.

Custom Dockerfile

The last thing to look at today is the use of a custom Dockerfile. This is a no-brainer for those with Docker experience/exposure, so is being added here mostly as an FYI.

The Calm DSL container that gets pulled and run via the commands above will run Alpine Linux if the default Dockerfile is used. Shown below is an example of a custom Dockerfile that will pull and build an image based on the Dockerhub Python images. This example is courtesy of Jose Gomez, Solutions Architect here at Nutanix and was created to match various use cases in Jose’s workflow.

FROM python:${VARIANT}

RUN mkdir -p `python3 -m site --user-site`
ENV PATH=/root/.local/bin:$PATH

RUN apt-get update && apt-get install -y sudo jq \
    && rm -rf /var/lib/apt/lists/*

RUN wget -q -O /tmp/ $CALM_DSL_TARBALL

RUN unzip /tmp/ -d /tmp \
    && rm /tmp/ \
    && cd /tmp/calm-dsl-master \
    && pip3 install --no-cache-dir -r requirements.txt virtualenv --user \
    && make dist \
    && pip3 install --no-cache-dir dist/calm.dsl*.whl --user \
    && cd ~ \
    && rm -fR /tmp/calm-dsl-master 

CMD ["bash"]

Wrapping Up

Even though these quick tips are about as simple as things can get, there are many other Calm DSL resources available to you.

Thanks for reading and have a great day! 🙂