Sahdev P. Zala and Eduardo Patrocinio from IBM show us how they created a Docker container using Heat-Translator.

image

The OpenStack Heat Translator is one of the projects under the main OpenStack Heat orchestration project. It facilitates translation of OASIS TOSCA service template to Heat Orchestration Template (HOT) and the deployment of translated template into an OpenStack cloud. To use it, you simply download a stable release through PyPI or by forking the master branch to use the latest source code. Docker containers are now widely used to consume applications and tools, and such usage are just growing. Building a container is fun and using it can be even more fun and highly productive. We have created a container using the latest stable release of the Heat-Translator available at the PyPI. This blog post will show where the image is located and how it can be used.

Get the image

The Heat Translator Docker container image is available on the Docker hub and it’s called patrocinio/h-t-container-stable.

Use the container

You can invoke the Heat Translator at the same time you run the container. The Heat Translator is commonly used to translate TOSCA service template available in the local file system or providing it via an URL. We will walk you through invoking Heat Translator in both ways.

Translate TOSCA service template from local file system

Let’s say you have TOSCA service template called tosca_helloworld.yamlon your local machine. Assume that the tosca_helloworld.yaml is located in your /tmp/tosca_testfiles. To translate it to HOT, run the container as follows:

$ docker run -v /tmp/tosca_testfiles:/tosca patrocinio/h-t-container-stable --template-file /tosca/tosca_helloworld.yaml

The patrocinio/h-t-container-stable will pull the image if it is not already available in your environment. Also note that the container requires that you provide /tmp/tosca_testfiles directory as a volume which will be mapped as the /tosca directory inside the container. You can think of /tmp/tosca_testfiles as a host source directory. It can be an arbitrary name but must be provided as an absolute path. The rest is simple: you provide the arguments that are understood by the Heat Translator. In this case, we provided the required –template-file argument with your TOSCA service template as a value to the argument. The service template can be a YAML file as provided above or it can be a TOSCA CSAR file. If you are new to CSAR, learn more about it from Sahdev Zala’s post Package Cloud Workloads with TOSCA Cloud Service Archive. Assuming your tosca_helloworld.yaml looks as below:

 
tosca_definitions_version: tosca_simple_yaml_1_0

description: Template for deploying a single server with predefined properties.

topology_template:
  node_templates:
    my_server:
      type: tosca.nodes.Compute
      capabilities:
        # Host container properties
        host:
         properties:
           num_cpus: 2
           disk_size: 10 GB
           mem_size: 512 MB
        # Guest Operating System properties
        os:
          properties:
            # host Operating System image properties
            architecture: x86_64
            type: Linux
            distribution: RHEL
            version: 6.5

The output of the above command will produce following HOT template,

heat_template_version: 2013-05-23

description: >
  Template for deploying a single server with predefined properties.
parameters: {}
resources:
  my_server:
    type: OS::Nova::Server
    properties:
      flavor: m1.medium
      image: rhel-6.5-test-image
      user_data_format: SOFTWARE_CONFIG
outputs: {}

Translate TOSCA service template via an URL

Translating by providing service template or CSAR as URL is very simple. All you need to do is provide a URL as a value to the –template-file argument. For example, tosca_helloworld.yaml located on the TOSCA Parsergithub project can be translated using the following command,

$ docker run patrocinio/h-t-container-stable
--template-file https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/tosca_helloworld.yaml

Heat Translator help

You can get to the Heat Translator help by simply running:

docker run patrocinio/h-t-container-stable --help

Dockerfile

Given below is the content of Dockerfile used to build the h-t-container-stable image. The file is also available in the Heat Translator project.

FROM ubuntu

MAINTAINER Eduardo Patrocinio and Sahdev P. Zala

RUN apt-get -y update && apt-get install -y \ 
    python-pip 

RUN pip install heat-translator

COPY heat_translator_logging.conf /usr/local/lib/python2.7/dist-packages/translator/conf/

# Have some test TOSCA templates in my_tosca directory to copy to the container as an example.
# This is an optional step and can be removed.
COPY my_tosca /tmp/my_tosca

ENTRYPOINT ["heat-translator"]

Conclusion

In this article, we showed you how to use the OpenStack Heat Translator using a Docker image by passing the source file during the docker run command. We have also shared Dockerfile to use as a base to create a modified Docker container of the Heat Translator.

This post first appeared on the IBM OpenTech blog. Superuser is always interested in community content, email: editorATsuperuser.org.

Cover Photo // CC BY NC