pythonopenstacknovaclient

Specify post-installation script when creating an instance in OpenStack [python-novaclient]


I have a working python program which is able to create instances on OpenStack thanks to the python-novaclient library.

Now I'd like to give a post-installation script at the creation time. I looked at the documentation of the Servers.create() method but it doesn't seem to be implemented.

Did anyone faced this problem?


EDIT

In Horizon, when we create an instance, there is this information next to the textarea for the post-installation script:

The "Customisation Script" field is analogous to "User Data" in other systems.

Does it mean userdata is the parameter I need?

userdata – user data to pass to be exposed by the metadata server this can be a file type object as well or a string.


Solution

  • Indeed the solution is on userdata

    Here's the Python code I wrote to solve my problem:

    ## Return the new created instance
    # @param name Name of the instance to create in a String format
    # @param image OpenStack image to deploy on the virtual machine
    # @param flavor OpenStack flavor to use for the virtual machine
    # @param keypair Name of the keypair to copy on the instance
    # @param sec_groups List of security groups to link to the instance
    def create_instance(self,name,image,flavor,keypair=None,sec_groups=None):
      instance = self.client.servers.create(
        name=name,
        image=image,
        flavor=flavor,
        key_name=keypair,
        security_groups=sec_groups,
        userdata="#!/bin/bash \n echo 'AMAZING TEST' > /root/test"
      )
      return instance