@@ -82,7 +82,7 @@ def _load_auth_plugin(conf):
82
82
raise neutron_client_exc .Unauthorized (message = err_msg )
83
83
84
84
85
- def _get_binding_profile (port ):
85
+ def get_binding_profile (port ):
86
86
"""Convenience method to get the binding:profile from the port
87
87
88
88
The binding:profile in the port is undefined in the networking service
@@ -272,7 +272,7 @@ def _clear_migration_port_profile(
272
272
# If the port already has a migration profile and if
273
273
# it is to be torn down, then we need to clean up
274
274
# the migration profile.
275
- port_profile = _get_binding_profile (p )
275
+ port_profile = get_binding_profile (p )
276
276
if not port_profile :
277
277
continue
278
278
if constants .MIGRATING_ATTR in port_profile :
@@ -293,7 +293,7 @@ def _setup_migration_port_profile(
293
293
# the given 'host'.
294
294
host_id = p .get (constants .BINDING_HOST_ID )
295
295
if host_id != host :
296
- port_profile = _get_binding_profile (p )
296
+ port_profile = get_binding_profile (p )
297
297
# If the "migrating_to" attribute already points at the given
298
298
# host, then skip the port update call since we're not changing
299
299
# anything.
@@ -587,7 +587,7 @@ def _unbind_ports(self, context, ports,
587
587
port_profile = {}
588
588
network = {}
589
589
else :
590
- port_profile = port . get ( constants . BINDING_PROFILE , {} )
590
+ port_profile = get_binding_profile ( port )
591
591
net_id = port .get ('network_id' )
592
592
if net_id in networks :
593
593
network = networks .get (net_id )
@@ -1004,7 +1004,7 @@ def allocate_for_instance(self, context, instance, vpn,
1004
1004
# only communicate the allocations if the port has resource
1005
1005
# requests
1006
1006
if port .get (constants .RESOURCE_REQUEST ):
1007
- profile = port . get ( constants . BINDING_PROFILE , {} )
1007
+ profile = get_binding_profile ( port )
1008
1008
# NOTE(gibi): In the resource provider mapping there can be
1009
1009
# more than one RP fulfilling a request group. But resource
1010
1010
# requests of a Neutron port is always mapped to a
@@ -1117,11 +1117,9 @@ def _update_ports_for_instance(self, context, instance, neutron,
1117
1117
'device_owner' : zone }}
1118
1118
if (requested_ports_dict and
1119
1119
request .port_id in requested_ports_dict and
1120
- requested_ports_dict [request .port_id ].get (
1121
- constants .BINDING_PROFILE )):
1122
- port_req_body ['port' ][constants .BINDING_PROFILE ] = (
1123
- requested_ports_dict [request .port_id ][
1124
- constants .BINDING_PROFILE ])
1120
+ get_binding_profile (requested_ports_dict [request .port_id ])):
1121
+ port_req_body ['port' ][constants .BINDING_PROFILE ] = \
1122
+ get_binding_profile (requested_ports_dict [request .port_id ])
1125
1123
try :
1126
1124
self ._populate_neutron_extension_values (
1127
1125
context , instance , request .pci_request_id , port_req_body ,
@@ -1441,10 +1439,7 @@ def _populate_neutron_binding_profile(self, instance, pci_request_id,
1441
1439
_ ('PCI device not found for request ID %s.' ) %
1442
1440
pci_request_id )
1443
1441
pci_dev = pci_devices .pop ()
1444
- if port_req_body ['port' ].get (constants .BINDING_PROFILE ) is None :
1445
- port_req_body ['port' ][constants .BINDING_PROFILE ] = {}
1446
- profile = copy .deepcopy (
1447
- port_req_body ['port' ][constants .BINDING_PROFILE ])
1442
+ profile = copy .deepcopy (get_binding_profile (port_req_body ['port' ]))
1448
1443
profile .update (self ._get_pci_device_profile (pci_dev ))
1449
1444
port_req_body ['port' ][constants .BINDING_PROFILE ] = profile
1450
1445
@@ -1669,8 +1664,8 @@ def deallocate_port_for_instance(self, context, instance, port_id):
1669
1664
# if there is resource associated to this port then that needs to
1670
1665
# be deallocated so lets return info about such allocation
1671
1666
resource_request = port .get (constants .RESOURCE_REQUEST )
1672
- allocated_rp = port . get (
1673
- constants . BINDING_PROFILE , {}) .get (constants .ALLOCATION )
1667
+ profile = get_binding_profile ( port )
1668
+ allocated_rp = profile .get (constants .ALLOCATION )
1674
1669
if resource_request and allocated_rp :
1675
1670
port_allocation = {
1676
1671
allocated_rp : resource_request .get ('resources' , {})}
@@ -1935,7 +1930,7 @@ def _get_trusted_mode_from_port(port):
1935
1930
If port binding does not provide any information about trusted
1936
1931
status this function is returning None
1937
1932
"""
1938
- value = _get_binding_profile (port ).get ('trusted' )
1933
+ value = get_binding_profile (port ).get ('trusted' )
1939
1934
if value is not None :
1940
1935
# This allows the user to specify things like '1' and 'yes' in
1941
1936
# the port binding profile and we can handle it as a boolean.
@@ -2889,7 +2884,7 @@ def _build_vif_model(self, context, client, current_neutron_port,
2889
2884
vnic_type = current_neutron_port .get ('binding:vnic_type' ,
2890
2885
network_model .VNIC_TYPE_NORMAL ),
2891
2886
type = current_neutron_port .get ('binding:vif_type' ),
2892
- profile = _get_binding_profile (current_neutron_port ),
2887
+ profile = get_binding_profile (current_neutron_port ),
2893
2888
details = current_neutron_port .get ('binding:vif_details' ),
2894
2889
ovs_interfaceid = ovs_interfaceid ,
2895
2890
devname = devname ,
@@ -3218,7 +3213,7 @@ def _update_port_binding_for_instance(self, context, instance, host,
3218
3213
network_model .VIF_TYPE_BINDING_FAILED )
3219
3214
for p in ports :
3220
3215
updates = {}
3221
- binding_profile = _get_binding_profile (p )
3216
+ binding_profile = get_binding_profile (p )
3222
3217
3223
3218
# We need to update the port binding if the host has changed or if
3224
3219
# the binding is clearly wrong due to previous lost messages.
0 commit comments