22
22
from neutronclient .common import exceptions as neutron_client_exc
23
23
from neutronclient .v2_0 import client as clientv20
24
24
from oslo_log import log as logging
25
+ from oslo_middleware import request_id
25
26
from oslo_utils import excutils
26
27
from oslo_utils import strutils
27
28
from oslo_utils import uuidutils
@@ -1290,7 +1291,7 @@ def bind_ports_to_host(self, context, instance, host,
1290
1291
binding ['profile' ] = port_profiles [port_id ]
1291
1292
1292
1293
data = dict (binding = binding )
1293
- resp = self ._create_port_binding (client , port_id , data )
1294
+ resp = self ._create_port_binding (context , client , port_id , data )
1294
1295
if resp :
1295
1296
bindings_by_port_id [port_id ] = resp .json ()['binding' ]
1296
1297
else :
@@ -1313,9 +1314,10 @@ def bind_ports_to_host(self, context, instance, host,
1313
1314
return bindings_by_port_id
1314
1315
1315
1316
@staticmethod
1316
- def _create_port_binding (client , port_id , data ):
1317
+ def _create_port_binding (context , client , port_id , data ):
1317
1318
"""Creates a port binding with the specified data.
1318
1319
1320
+ :param context: The request context for the operation.
1319
1321
:param client: keystoneauth1.adapter.Adapter
1320
1322
:param port_id: The ID of the port on which to create the binding.
1321
1323
:param data: dict of port binding data (requires at least the host),
@@ -1324,8 +1326,9 @@ def _create_port_binding(client, port_id, data):
1324
1326
{'binding': {'host': 'dest.host.com'}}
1325
1327
:return: requests.Response object
1326
1328
"""
1327
- return client .post ('/v2.0/ports/%s/bindings' % port_id ,
1328
- json = data , raise_exc = False )
1329
+ return client .post (
1330
+ '/v2.0/ports/%s/bindings' % port_id , json = data , raise_exc = False ,
1331
+ headers = {request_id .INBOUND_HEADER : context .global_id })
1329
1332
1330
1333
def delete_port_binding (self , context , port_id , host ):
1331
1334
"""Delete the port binding for the given port ID and host
@@ -1340,7 +1343,7 @@ def delete_port_binding(self, context, port_id, host):
1340
1343
response is received from neutron.
1341
1344
"""
1342
1345
client = _get_ksa_client (context , admin = True )
1343
- resp = self ._delete_port_binding (client , port_id , host )
1346
+ resp = self ._delete_port_binding (context , client , port_id , host )
1344
1347
if resp :
1345
1348
LOG .debug ('Deleted binding for port %s and host %s.' ,
1346
1349
port_id , host )
@@ -1357,16 +1360,18 @@ def delete_port_binding(self, context, port_id, host):
1357
1360
port_id = port_id , host = host )
1358
1361
1359
1362
@staticmethod
1360
- def _delete_port_binding (client , port_id , host ):
1363
+ def _delete_port_binding (context , client , port_id , host ):
1361
1364
"""Deletes the binding for the given host on the given port.
1362
1365
1366
+ :param context: The request context for the operation.
1363
1367
:param client: keystoneauth1.adapter.Adapter
1364
1368
:param port_id: ID of the port from which to delete the binding
1365
1369
:param host: A string name of the host on which the port is bound
1366
1370
:return: requests.Response object
1367
1371
"""
1368
- return client .delete ('/v2.0/ports/%s/bindings/%s' % (port_id , host ),
1369
- raise_exc = False )
1372
+ return client .delete (
1373
+ '/v2.0/ports/%s/bindings/%s' % (port_id , host ), raise_exc = False ,
1374
+ headers = {request_id .INBOUND_HEADER : context .global_id })
1370
1375
1371
1376
def activate_port_binding (self , context , port_id , host ):
1372
1377
"""Activates an inactive port binding.
@@ -1387,7 +1392,8 @@ def activate_port_binding(self, context, port_id, host):
1387
1392
# to ACTIVE, it's more like a POST action method in the compute API.
1388
1393
resp = client .put (
1389
1394
'/v2.0/ports/%s/bindings/%s/activate' % (port_id , host ),
1390
- raise_exc = False )
1395
+ raise_exc = False ,
1396
+ headers = {request_id .INBOUND_HEADER : context .global_id })
1391
1397
if resp :
1392
1398
LOG .debug ('Activated binding for port %s and host %s.' ,
1393
1399
port_id , host )
@@ -2693,8 +2699,10 @@ def migrate_instance_start(self, context, instance, migration):
2693
2699
# Not all compute migration flows use the port binding-extended
2694
2700
# API yet, so first check to see if there is a binding for the
2695
2701
# port and destination host.
2696
- resp = client .get ('/v2.0/ports/%s/bindings/%s' %
2697
- (vif ['id' ], dest_host ), raise_exc = False )
2702
+ resp = client .get (
2703
+ '/v2.0/ports/%s/bindings/%s' % (vif ['id' ], dest_host ),
2704
+ raise_exc = False ,
2705
+ headers = {request_id .INBOUND_HEADER : context .global_id })
2698
2706
if resp :
2699
2707
if resp .json ()['binding' ]['status' ] != 'ACTIVE' :
2700
2708
self .activate_port_binding (context , vif ['id' ], dest_host )
0 commit comments