• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Python
  6. RTS Python SDK Demo

RTS Python SDK Demo

Preparing a Heat Template

A Heat template describes the infrastructure for a cloud application in a text file that is readable and writable by humans.

Prepare the Heat template file, for example, heatTemplate.yaml, as shown in the following.

# 
# Minimal HOT template defining a single compute server. 
# 
heat_template_version: 2013-05-23 

description: > 
  Minimal HOT template for stack 

parameters: 
  key_name: 
    type: string 
    description: Name of an existing key pair to use for the server 
    constraints: 
      - custom_constraint: nova.keypair 
  flavor: 
    type: string 
    description: Flavor for the server to be created 
    default: s1.large 
    constraints: 
      - custom_constraint: nova.flavor 
  image: 
    type: string 
    description: Image ID or image name to use for the server 
    constraints: 
      - custom_constraint: glance.image 
  network: 
    type: string 
    description: Network used by the server 

resources: 
  server: 
    type: OS::Nova::Server 
    properties: 
      key_name: { get_param: key_name } 
      image: { get_param: image } 
      flavor: { get_param: flavor } 
      networks: [{network: {get_param: network} }] 

outputs: 
  server_networks: 
    description: The networks of the deployed server 
    value: { get_attr: [server, networks] }

Creating a Stack

The templates enable the creation of most OpenStack resource types, such as instances, EIPs, volumes, security groups, and users. The resources, once created, are referred to as stacks.

You can use the following code to create a stack:

def create_heat_stack(): 
    tname = "hello_world.yaml" 
    with open(tname) as f: 
        template = f.read() 
        parameters = { 
            'image': 'imageId', 
            'key_name': 'keyname', 
            'network': 'networkId', 
        } 
        sot = cls.conn.orchestration.create_stack( 
            name='stackName', 
            parameters=parameters, 
            template=template, 
        ) 
        conn.orchestration.wait_for_status( 
            sot, status='CREATE_COMPLETE', failures=['CREATE_FAILED'])  

Deleting a Stack

You can delete a stack based on the following code:

def delete_stack(conn): 
    conn.orchestration.delete_stack(stack)