问题导读
1、你觉得,获得network的可用fixed_ip个数有哪些方法呢?
2、在novaclient层实现了什么功能?
3、base.py里面的_list的传参方式是怎样的?
获得network的可用fixed_ip个数-openstackE版
方法一:直接在nova底层增加fixed_ip_count字段:
方法二:直接从dashboard封装api到底层:
其中api发布为:
以下为详细信息:
1、dashboard页面:
- dashboards/nova/zones_and_networks/views.py
- network_id = networks[0]['id']
- count = api.nova.get_available_count_ips(self.request, network_id)
复制代码
- api/nova.py
- def get_available_count_ips(request,network_id):
- return novaclient(request).networks.get_available_count_ips(network_id)
复制代码
2、novaclient层
- v1_1/networks.py
-
- def get_available_count_ips(self, network_id):
- """
- Get a specific flavor.
-
- :param flavor: The ID of the :class:`Flavor` to get.
- :rtype: :class:`Flavor`
- """
- return self._list("/os-networks/get_available_count_ips/%s" % network_id, "count")
复制代码
3、nova层
- api/openstack/compute/contrib/networks.py
- def get_available_count_ips(self, req, id):
- context = req.environ['nova.context']
- authorize(context)
- LOG.debug(_("Showing network_fixed_count with id %s") % id)
- try:
- count = self.network_api.get_available_count_ips(context, id)
- except exception.NetworkNotFound:
- raise exc.HTTPNotFound(_("Network not found"))
- return {'count': count}
复制代码
- collection_actions = {'list_limit': 'POST','get_available_count_ips': 'POST'},
复制代码
- vi network/api.py
- def get_available_count_ips(self, context,network_id):
- return rpc.call(context,
- FLAGS.network_topic,
- {'method': 'get_available_count_ips',
- 'args': {'network_id': network_id}})
复制代码
- vi network/manager.py
- @wrap_check_policy
- def get_available_count_ips(self, context, network_id):
- count = db.network_available_count_ips(context, network_id)
- return count
复制代码
- db/api.py
- def network_available_count_ips(context, network_id):
- """Return the number of reserved ips in the network."""
- return IMPL.network_available_count_ips(context, network_id)
复制代码
- db/sqlalchemy/api.py
- @require_admin_context
- def network_available_count_ips(context, network_id):
- return _network_ips_query(context, network_id).\
- filter_by(reserved=False).\
- filter_by(host='').\
- filter_by(instance_id='').\
- filter_by(allocated=False).\
- count()
复制代码
注释:一定要跟到base.py里面看_list的传参方式:
|