aggregate 主机管理管理
可以向主机中添加,或者移除一个主机,也可以管理metadata
一. URL 及命令行:
/os-aggregates/{aggregate_id}/action
命令行:
[root@nova ~]# nova help | grep agg
aggregate-add-host Add the host to the specified aggregate.
aggregate-remove-host Remove the specified host from the specified aggregate.
aggregate-set-metadata Update the metadata associated with the aggregate.
二. 源码分析:
aggregate 主机管理功能也是定义在AggregateController 中:
class AggregateController(wsgi.Controller):
- 添加主机操作:
@wsgi.action('add_host')
@validation.schema(aggregates.add_host)
def _add_host(self, req, id, body):
"""Adds a host to the specified aggregate."""
host = body['add_host']['host']
context = _get_context(req)
context.can(aggr_policies.POLICY_ROOT % 'add_host')
try:
aggregate = self.api.add_host_to_aggregate(context, id, host)
except (exception.AggregateNotFound,
exception.ComputeHostNotFound) as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except (exception.AggregateHostExists,
exception.InvalidAggregateAction) as e:
raise exc.HTTPConflict(explanation=e.format_message())
return self._marshall_aggregate(req, aggregate)
调用add_host_to_aggregate
定义如下:
def add_host_to_aggregate(self, context, aggregate_id, host_name):
"""Adds the host to an aggregate."""
aggregate_payload = {'aggregate_id': aggregate_id,
'host_name': host_name}
compute_utils.notify_about_aggregate_update(context,
"addhost.start",
aggregate_payload)
# validates the host; ComputeHo