in src/services/region_mutator_service.py [0:0]
def create(self, maestro_name: str, native_name: str, region_id: str,
cloud: str, is_active=True):
if cloud not in CLOUD_PROVIDERS:
_LOG.error(f'Unsupported cloud specified: \'{cloud}\'. '
f'Available options: {CLOUD_PROVIDERS}')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Unsupported cloud specified: \'{cloud}\'. '
f'Available options: {CLOUD_PROVIDERS}'
)
all_region = self.get_all_regions()
if region_id:
for region in all_region:
if region.region_id == region_id and \
maestro_name != region.maestro_name:
_LOG.error(f'The region id {region_id} is already used by '
f'the {region.maestro_name} region.')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'The region id {region_id} is already used by'
f' the {region.maestro_name} region.')
all_region_in_cloud = [region for region in all_region
if region.cloud == cloud]
for region in all_region_in_cloud:
if region.native_name == native_name and \
maestro_name != region.maestro_name:
_LOG.error(f'The native name {native_name} is already '
f'used by the {region.maestro_name} region.')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'The native name {native_name} is already '
f'used by the {region.maestro_name} region.')
return RegionModel(
region_id=region_id, maestro_name=maestro_name,
native_name=native_name, cloud=cloud,
is_active=is_active
)