[英]Openstack: how to get client's IP in the python API
I'm trying to implement a new weigher for cells on openstack.我正在尝试为 openstack 上的单元实现一个新的称重器。 How can I get the client IP (the user who is requesting to create a new instance) inside openstack nova python code?
如何在 openstack nova python 代码中获取客户端 IP(请求创建新实例的用户)?
I already have tried我已经试过了
req.remote_addr req.remote_addr
inside files nova/api/auth.py (NovaKeystoneContext. call method) and nova/api/compute_req_id.py (ComputeReqIdMiddleware method), but without success.内部文件新星/ API / auth.py(NovaKeystoneContext。调用方法)和Nova / API / compute_req_id.py(ComputeReqIdMiddleware法),但没有成功。 LOG.debug seems to indicate those methods are not called when a new instance creation is requested.
LOG.debug 似乎表明在请求创建新实例时不会调用这些方法。
Any suggestions on how can I achieve that?关于如何实现这一目标的任何建议?
Thanks谢谢
For anyone who might be interested, I found a solution.对于任何可能感兴趣的人,我找到了一个解决方案。
When you create a new weighter you will need to add a method like this:当你创建一个新的权重时,你需要添加一个这样的方法:
def _weigh_object(self, cell, weight_properties):
To obtain the client's IP you just need to call要获取客户端的 IP,您只需要调用
weight_properties['context'].remote_address
One last details: you will need to restart nova services for that change take place:最后一个细节:您需要重新启动 nova 服务才能进行更改:
service nova-cells restart (as root)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.