in patch_scripts/3.3.0/patch_parent_scope.py [0:0]
def __call__(self):
old_parents = ParentsCol('old_parents.json')
new_parents = ParentsCol('new_parents.json')
it = Parent.scan(
rate_limit=1,
filter_condition=(Parent.meta['scope'] == ParentScope.ALL.value)
)
for parent in it:
_LOG.info(f'Going to patch '
f'parent: {parent.parent_id}:{parent.type}')
clouds = parent.meta.as_dict().get('clouds') or []
if not clouds:
_LOG.info('Parent has no clouds in its scope. '
'Patching with no clouds')
parent.update(actions=[
Parent.type_scope.set(
f'{parent.type}{COMPOUND_KEYS_SEPARATOR}{ParentScope.ALL}{COMPOUND_KEYS_SEPARATOR}')
# noqa
])
elif len(clouds) == 1:
_LOG.info('Parent has one cloud in its scope. '
'Patching with one clouds')
parent.update(actions=[
Parent.type_scope.set(
f'{parent.type}{COMPOUND_KEYS_SEPARATOR}{ParentScope.ALL}{COMPOUND_KEYS_SEPARATOR}{clouds[0]}')
# noqa
])
elif len(clouds) == 3: # all clouds
_LOG.info(f'Parent contains all the '
f'clouds: {", ".join(clouds)}. Can be patched')
parent.update(actions=[
Parent.type_scope.set(
f'{parent.type}{COMPOUND_KEYS_SEPARATOR}{ParentScope.ALL}{COMPOUND_KEYS_SEPARATOR}')
# noqa
])
else: # multiple clouds but not all
if not query_yes_no(TermColor.blue(QUESTION2)):
_LOG.info('Skipping patch')
continue
old_parents.add(parent.parent_id)
_LOG.info(
f'Parent with id {parent.parent_id} won`t be changed')
for copy in self.divide_by_cloud(parent):
_LOG.info(
f'Creating a new parent with id {copy.parent_id}')
copy.save()
new_parents.add(copy.parent_id)
_LOG.info(f'Parent {parent.parent_id} was patched')