Optimizing some logic in the code when creating pod
1. What is the problem? There are so many if branches for az_name in pod.py, this will lead to confusion. 2. What is the solution to the problem? We can optimize them to keep the logic more clearly 3. What features need to be implemented to the Tricircle to realize the solution? None Closes-Bug: #1691653 Change-Id: I1f31ff685de2e516d36027388a7b0eacc1a76f5e
This commit is contained in:
parent
0339688f26
commit
62801d714b
|
@ -59,31 +59,30 @@ class PodsController(rest.RestController):
|
|||
dc_name = pod.get('dc_name', '').strip()
|
||||
az_name = pod.get('az_name', '').strip()
|
||||
_uuid = uuidutils.generate_uuid()
|
||||
top_region_name = self._get_top_region(context)
|
||||
|
||||
if az_name == '' and region_name == '':
|
||||
return Response(_('Valid region_name is required for top region'),
|
||||
422)
|
||||
if az_name == '':
|
||||
if region_name == '':
|
||||
return Response(
|
||||
_('Valid region_name is required for top region'),
|
||||
422)
|
||||
|
||||
if az_name != '' and region_name == '':
|
||||
return Response(_('Valid region_name is required for pod'), 422)
|
||||
|
||||
if pod.get('az_name') is None:
|
||||
if self._get_top_region(context) != '':
|
||||
if top_region_name != '':
|
||||
return Response(_('Top region already exists'), 409)
|
||||
# to create the top region, make the pod_az_name to null value
|
||||
pod_az_name = ''
|
||||
|
||||
# if az_name is not null, then the pod region name should not
|
||||
# be same as that the top region
|
||||
if az_name != '':
|
||||
if (self._get_top_region(context) == region_name and
|
||||
region_name != ''):
|
||||
if region_name == '':
|
||||
return Response(
|
||||
_('Valid region_name is required for pod'), 422)
|
||||
# region_name != ''
|
||||
# then the pod region name should not be same as the top region
|
||||
if top_region_name == region_name:
|
||||
return Response(
|
||||
_('Pod region name duplicated with the top region name'),
|
||||
409)
|
||||
|
||||
# to create the top region, make the pod_az_name to null value
|
||||
if az_name == '':
|
||||
pod_az_name = ''
|
||||
|
||||
try:
|
||||
with context.session.begin():
|
||||
new_pod = core.create_resource(
|
||||
|
|
Loading…
Reference in New Issue