openstack-nova源码分析(八)aggregates主机组管理 metadata

本文详细介绍了OpenStack Nova中的主机组(aggregates)管理,包括如何通过命令行和URL添加、移除主机,以及如何管理metadata。分析了AggregateController中的关键函数,如add_host_to_aggregate、remove_host_from_aggregate和update_aggregate_metadata的实现,涉及到的日志记录、主机验证、主机组信息更新和调度器刷新等核心步骤。
摘要由CSDN通过智能技术生成

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):

  1. 添加主机操作:
    @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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值