简体   繁体   English

使用OpenStack Nova API以编程方式设置实例名称

[英]Programmatically setting instance name with the OpenStack Nova API

I have resigned myself to the fact that many of the features that EC2 users are accustomed to (in particular, tagging) do not exist in OpenStack. 我已经让自己认识到EC2用户习惯使用的许多功能(特别是标记)在OpenStack中不存在。 There is, however, one piece of functionality whose absence is driving me crazy. 然而,有一项功能的缺席让我发疯。

Although OpenStack doesn't have full support for instance tags (like EC2 does), it does have the notion of an instance name. 尽管OpenStack并不完全支持实例标签(如EC2那样),但它确实具有实例名称的概念。 This name is exposed by the Web UI, which even allows you to set it: 此UI名称由Web UI公开,甚至允许您设置它:

实例列表中的实例名称

编辑实例名称

This name is also exposed through the nova list command line utility. 此名称也通过nova list命令行实用程序公开。

However (and this is my problem) this field is not exposed through the nova-ec2 API layer. 但是(这是我的问题)这个字段没有通过nova-ec2 API层公开。 The cleanest way for them to integrate this with existing EC2 platform tools would be to simulate an instance Tag with name "Name", but they don't do this. 他们将此与现有EC2平台工具集成的最简洁方法是模拟名称为“Name”的实例Tag,但他们不会这样做。 What's more, I can't figure out which Nova API endpoint I can use to read and write the name (it doesn't seem to be documented on the API reference ); 更重要的是,我无法弄清楚我可以使用哪个Nova API端点来读取和写入名称(它似乎没有在API参考文档中记录); but of course it must be somehow possible since the web client and nova-client can both somehow do it. 但当然它必须以某种方式可能,因为Web客户端和nova-client都可以以某种方式做到这一点。

At the moment, I'm forced to change it manually from the website every time I launch a new instance. 目前,我每次启动新实例时都被迫从网站上手动更改它。 (I can't do it during instance creation because I use the nova-ec2 API, not the nova command line client). (在实例创建期间我不能这样做,因为我使用的是nova-ec2 API,而不是nova命令行客户端)。

My question is: 我的问题是:

  1. Is there a way to read/write the instance name through the EC2 API layer? 有没有办法通过EC2 API层读/写实例名称?
  2. Failing that, what is the REST endpoint to set it programmatically? 如果失败了,以编程方式设置它的REST端点是什么?
  3. (BONUS) : What is Nova's progress on supporting general instance tagging? (奖励) :Nova在支持通用实例标记方面取得了哪些进展?

The Python novaclient.v1_1 package has a method on the server object: Python novaclient.v1_1包在server对象上有一个方法:

def update(self, server, name=None):
    """
    Update the name or the password for a server.

    :param server: The :class:`Server` (or its ID) to update.
    :param name: Update the server's name.
    """
    if name is None:
        return

    body = {
        "server": {
            "name": name,
        },
    }

    self._update("/servers/%s" % base.getid(server), body)

This indicates that you can update the name of a server by POST-ing the following JSON to http://nova-api:port/v2.0/servers/{server-id} : 这表示您可以通过将以下JSON发布到http://nova-api:port/v2.0/servers/{server-id}来更新服务器的名称:

{
  "server": {
      "name": "new_name"
  }
}

Of course, all of the usual authentication headers (namely X-Auth-Token from your Keystone server) are still required, so it is probably easier to use a client library for whatever language you prefer to manage all that. 当然,仍然需要所有常用的身份验证标头(即来自Keystone服务器的X-Auth-Token ),因此使用客户端库可能更容易使用您喜欢的任何语言来管理所有这些。

Openstack instance tagging Openstack实例标记

a. 一个。 DescribeTags b. DescribeTags b。 CreateTags CreateTags

c. C。 DeleteTags DeleteTags

Following tentative policies to be added in mapping.json : 遵循在mapping.json中添加的暂定策略:

“CreateTags”:
{
“action”: “arn:acs:compute:CreateTags”,
“resources”: [
{
“resource”: “arn:acs:compute::Resource”,
“resourcePath” : “params.ResourceId.N”,
“isResourceValueRequired”: “False”
}
]
},
“DeleteTags”:
{
“action”: “arn:acs:compute:DeleteTags”,
“resources”: [
{
“resource”: “arn:acs:compute::Resource”,
“resourcePath” : “params.ResourceId.N”,
“isResourceValueRequired”: “True”
}
]
},
“DescribeTags”:
{
“action”: “arn:acs:compute:DescribeTags”,
“resources”: [
{
“resource”: “arn:acs:compute::Resource”,
“resourcePath” : “params.ResourceId.N”,
“isResourceValueRequired”: “False”
}
]
},

Same mapping needs to be stored in IAM DB. 需要在IAM DB中存储相同的映射。

Note , here a new resource type Resource is added as compared to defaults like Images , Instances etc. so respective changes are required in IAM side . 注意,这里添加了一个新的资源类型资源,与图像,实例等默认值相比,因此在IAM端需要相应的更改。

Sample request and response detailed at following url : 以下网址详细说明了示例请求和响应:

http://www.writeulearn.com/openstack-instance-tagging/ http://www.writeulearn.com/openstack-instance-tagging/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM