在 OpenStack 中创建实例时指定 post-安装脚本 [python-novaclient]

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

我有一个工作的 python 程序,由于 python-novaclient 库,它能够在 OpenStack 上创建实例。

现在我想在创建时给出一个post-安装脚本。我查看了Servers.create()方法的文档,但似乎没有实现。

有人遇到过这个问题吗?


编辑

在 Horizo​​n 中,当我们创建实例时,post-安装脚本的文本区域旁边有以下信息:

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

是否意味着userdata是我需要的参数?

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

确实有解决方案userdata

这是我为解决问题而编写的 Python 代码:

## 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

尝试启用配置驱动器。用户数据可以通过配置驱动器发送到VM。