user2985306
user2985306

Reputation: 111

How to pass user_data script to Python Openstack Heat-API client

How to pass user_data script to Python Heat-API client.

I have the following script in a file I want to pass into an instance as user_data during creating, but I am not sure how to go about it doing. I am using the Heat API to create the instance. The below code creates the stack with the heat template file with no user_data. Any pointers would be appreciated.

env.yml

user_data:
     #!/bin/bash
     rpm install -y git vim 


template_file = 'heattemplate.yaml'
template = open(template_file, 'r')
stack = heat.stacks.create(stack_name='Tutorial', template=template.read(), parameters={})

Upvotes: 0

Views: 1637

Answers (1)

Franza Cavalcante
Franza Cavalcante

Reputation: 11

On your yaml Heat template, you should add:

parameters:
  install_command:
    type: string
    description: Command to run from user_data
    default: #!/bin/bash rpm install -y git vim
...
myserver:
  type: OS::Nova::Server
  properties:
    ...
    user_data_format: RAW
    user_data: { get_param: install_command }

And pass the new parameter through parameters = {}, from your create line on Python:

heat.stacks.create(stack_name='Tutorial', template=template.read(), 
    parameters={  'install_command': '...' })

Upvotes: 1

Related Questions