Host aggregates 主机组
主机组是一组主机compute节点的集合,默认只开放给管理员的功能,可以通过策略配置修改访问权限
官方api介绍:
Creates and manages host aggregates. An aggregate assigns metadata to groups of compute nodes.
Policy defaults enable only users with the administrative role to perform operations with aggregates.
Cloud providers can change these permissions through policy file configuration.
一. url及命令
-
url
标准的restful api
/os-aggregates
/os-aggregates/{aggregate_id} -
命令
[root@nova ~]# nova help | grep aggregate
aggregate-create Create a new aggregate with the specified
aggregate-delete Delete the aggregate.
aggregate-list Print a list of all aggregates.
aggregate-show Show details of the specified aggregate.
aggregate-update Update the aggregate's name and optionally
二. 源码分析:
在setup.cfg中定义如下:
aggregates = nova.api.openstack.compute.aggregates:Aggregates
Aggregates定义如下:
class Aggregates(extensions.V21APIExtensionBase):
"""Admin-only aggregate administration."""
name = "Aggregates"
alias = ALIAS
version = 1
def get_resources(self):
resources = [extensions.ResourceExtension(
ALIAS,
AggregateController(),
member_actions={'action': 'POST'})]
return resources
映射到AggregateController并增加了POST 方法映射到action
- 列表功能映射到index, 定义如下:
@extensions.expected_errors(())
def index(self, req):
"""Returns a list a host aggregate's id, name, availability_zone."""
context = _get_context(req)
context.can(aggr_policies.POLICY_ROOT % 'index')
aggregates = self.api.get_aggregate_list(context)
return {'aggregates': [self._marshall_aggregate(req, a)['aggregate']
for a in aggregates]}
self.api.get_aggregate_list(context) 获取列表
实际调用如下:
def get_aggregate_list(self, context):
"""Get all the aggregates."""
return objects.AggregateList.get_all(context)