2
votes

I'm trying to implement a new weigher for cells on openstack. How can I get the client IP (the user who is requesting to create a new instance) inside openstack nova python code?

I already have tried

req.remote_addr

inside files nova/api/auth.py (NovaKeystoneContext.call method) and nova/api/compute_req_id.py (ComputeReqIdMiddleware method), but without success. LOG.debug seems to indicate those methods are not called when a new instance creation is requested.

Any suggestions on how can I achieve that?

Thanks

1

1 Answers

1
votes

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

weight_properties['context'].remote_address

One last details: you will need to restart nova services for that change take place:

service nova-cells restart (as root)