Skip to content

Commit 438824b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use neutron contants in cmd/manage.py"
2 parents 5d8c8ab + d939ead commit 438824b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

nova/cmd/manage.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from nova import exception
5858
from nova.i18n import _
5959
from nova.network.neutronv2 import api as neutron_api
60+
from nova.network.neutronv2 import constants
6061
from nova import objects
6162
from nova.objects import block_device as block_device_obj
6263
from nova.objects import build_request as build_request_obj
@@ -1676,16 +1677,17 @@ def _get_ports(ctxt, instance, neutron):
16761677
try:
16771678
return neutron.list_ports(
16781679
ctxt, device_id=instance.uuid,
1679-
fields=['id', 'resource_request', 'binding:profile'])['ports']
1680+
fields=['id', 'resource_request', constants.BINDING_PROFILE]
1681+
)['ports']
16801682
except neutron_client_exc.NeutronClientException as e:
16811683
raise exception.UnableToQueryPorts(
16821684
instance_uuid=instance.uuid, error=six.text_type(e))
16831685

16841686
@staticmethod
16851687
def _has_request_but_no_allocation(port):
16861688
request = port.get('resource_request')
1687-
binding_profile = port.get('binding:profile', {}) or {}
1688-
allocation = binding_profile.get('allocation')
1689+
binding_profile = port.get(constants.BINDING_PROFILE, {}) or {}
1690+
allocation = binding_profile.get(constants.ALLOCATION)
16891691
# We are defensive here about 'resources' and 'required' in the
16901692
# 'resource_request' as neutron API is not clear about those fields
16911693
# being optional.
@@ -1871,9 +1873,9 @@ def _get_port_allocations_to_heal(
18711873
# We also need to record the RP we are allocated from in the
18721874
# port. This will be sent back to Neutron before the allocation
18731875
# is updated in placement
1874-
binding_profile = port.get('binding:profile', {}) or {}
1875-
binding_profile['allocation'] = rp_uuid
1876-
port['binding:profile'] = binding_profile
1876+
binding_profile = port.get(constants.BINDING_PROFILE, {}) or {}
1877+
binding_profile[constants.ALLOCATION] = rp_uuid
1878+
port[constants.BINDING_PROFILE] = binding_profile
18771879

18781880
output(_("Found resource provider %(rp_uuid)s having matching "
18791881
"traits for port %(port_uuid)s with resource request "
@@ -1890,7 +1892,8 @@ def _update_ports(self, neutron, ports_to_update, output):
18901892
for port in ports_to_update:
18911893
body = {
18921894
'port': {
1893-
'binding:profile': port['binding:profile']
1895+
constants.BINDING_PROFILE:
1896+
port[constants.BINDING_PROFILE]
18941897
}
18951898
}
18961899
output(
@@ -1917,11 +1920,11 @@ def _rollback_port_updates(neutron, ports_to_rollback, output):
19171920
manual_rollback_needed = []
19181921
last_exc = None
19191922
for port in ports_to_rollback:
1920-
profile = port['binding:profile']
1921-
profile.pop('allocation')
1923+
profile = port[constants.BINDING_PROFILE]
1924+
profile.pop(constants.ALLOCATION)
19221925
body = {
19231926
'port': {
1924-
'binding:profile': profile
1927+
constants.BINDING_PROFILE: profile
19251928
}
19261929
}
19271930
try:

0 commit comments

Comments
 (0)