感谢朋友支持本博客,欢迎共同探讨交流,由于能力和时间有限,错误之处在所难免,欢迎指正!
如有转载,请保留源作者博客信息。
Better Me的博客:blog.csdn.net/tantexian
获得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的传参方式: