Skip to content

Commit f4b7911

Browse files
authored
Improve teardown functionality and support purge mode (#18)
* Fix Datalake teardown request when teardown already in progress * Fix Datalake removable states * Fix Datalake storage mismatch check * Switch ML to use standard states from cdpy instead of local listings Signed-off-by: Daniel Chaffelson <chaffelson@gmail.com>
1 parent 31d3513 commit f4b7911

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

plugins/modules/datalake.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -415,38 +415,35 @@ def process(self):
415415
if existing['status'] in self.cdpy.sdk.FAILED_STATES:
416416
self.module.fail_json(msg='Attempting to restart a failed datalake')
417417

418-
# Warn if attempting to start an datalake amidst the creation cycle
419-
elif existing['status'] in self.cdpy.sdk.CREATION_STATES:
418+
# Check for Datalake actions during create or started
419+
elif existing['status'] in self.cdpy.sdk.CREATION_STATES + self.cdpy.sdk.STARTED_STATES:
420420
# Reconcile and error if specifying invalid cloud parameters
421421
if self.environment is not None:
422422
env = self.cdpy.environments.describe_environment(self.environment)
423-
424423
if env['crn'] != existing['environmentCrn']:
425424
self.module.fail_json(
426425
msg="Datalake exists in a different Environment: %s" % existing['environmentCrn'])
427-
428-
# Check for changes
429-
mismatch = self._reconcile_existing_state(existing)
430-
if mismatch:
431-
msg = ''
432-
for m in mismatch:
433-
msg += "Parameter '%s' found to be '%s'\n" % (m[0], m[1])
434-
self.module.fail_json(
435-
msg='Datalake exists and differs from expected:\n' + msg, violations=mismatch)
426+
# Check for changes
427+
mismatch = self._reconcile_existing_state(existing)
428+
if mismatch:
429+
msg = ''
430+
for m in mismatch:
431+
msg += "Parameter '%s' found to be '%s'\n" % (m[0], m[1])
432+
self.module.fail_json(
433+
msg='Datalake exists and differs from expected:\n' + msg, violations=mismatch)
434+
# Wait
435+
if not self.wait:
436+
self.module.warn('Datalake already creating or started, changes may not be possible')
436437
else:
437-
if not self.wait:
438-
self.module.warn('Attempting to modify a datalake during its creation cycle')
439-
440-
else:
441-
# Wait for creation to complete if previously requested and still running
442-
self.datalake = self.cdpy.sdk.wait_for_state(
443-
describe_func=self.cdpy.datalake.describe_datalake,
444-
params=dict(name=self.name),
445-
field='status',
446-
state='RUNNING',
447-
delay=self.delay,
448-
timeout=self.timeout
449-
)
438+
# Wait for creation to complete if previously requested and still running
439+
self.datalake = self.cdpy.sdk.wait_for_state(
440+
describe_func=self.cdpy.datalake.describe_datalake,
441+
params=dict(name=self.name),
442+
field='status',
443+
state='RUNNING',
444+
delay=self.delay,
445+
timeout=self.timeout
446+
)
450447
# Else create the datalake if not exists already
451448
else:
452449
if self.environment is not None:
@@ -550,16 +547,16 @@ def _configure_payload(self):
550547
def _reconcile_existing_state(self, existing):
551548
mismatched = list()
552549

553-
if existing['cloudPlatform'] == 'AWS':
550+
if 'cloudPlatform' in existing and existing['cloudPlatform'] == 'AWS':
554551
if self.instance_profile is not None and \
555552
self.instance_profile != existing['awsConfiguration']['instanceProfile']:
556553
mismatched.append(['instance_profile', existing['awsConfiguration']['instanceProfile']])
557554

558-
if self.storage is not None:
559-
self.module.warn("Updating an existing Datalake's 'storage'"
560-
"directly is not supported at this time. If "
561-
"you need to change the storage, explicitly "
562-
"delete and recreate the Datalake.")
555+
if self.storage is not None:
556+
self.module.warn("Updating an existing Datalake's 'storage' "
557+
"directly is not supported at this time. If "
558+
"you need to change the storage, explicitly "
559+
"delete and recreate the Datalake.")
563560

564561
if self.runtime:
565562
self.module.warn("Updating an existing Datalake's 'runtime' "

plugins/modules/ml.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -570,19 +570,6 @@
570570
elements: str
571571
'''
572572

573-
STARTING_STATES = [
574-
'provision:started',
575-
'installation:started'
576-
]
577-
578-
ACTIVE_STATES = [
579-
'installation:finished'
580-
]
581-
582-
TERMINATING_STATES = [
583-
'deprovision:started'
584-
]
585-
586573

587574
class MLWorkspace(CdpModule):
588575
def __init__(self, module):
@@ -632,9 +619,9 @@ def process(self):
632619
if self.module.check_mode:
633620
self.workspace = self.target
634621
else:
635-
if self.target['instanceStatus'] in ACTIVE_STATES:
622+
if self.target['instanceStatus'] in self.cdpy.sdk.REMOVABLE_STATES:
636623
self._delete_workspace()
637-
elif self.target['instanceStatus'] in TERMINATING_STATES:
624+
elif self.target['instanceStatus'] in self.cdpy.sdk.TERMINATION_STATES:
638625
self.module.log(
639626
"ML Workspace already performing Delete operation: %s" % self.target['instanceStatus'])
640627
else:
@@ -717,7 +704,7 @@ def _wait_delete_state(self):
717704
return self.cdpy.sdk.wait_for_state(
718705
describe_func=self.cdpy.ml.describe_workspace,
719706
params=dict(name=self.name, env=self.env),
720-
field=None, delay=self.delay, timeout=self.timeout
707+
field=None, delay=self.delay, timeout=self.timeout, ignore_failures=self.force
721708
)
722709

723710
@staticmethod

0 commit comments

Comments
 (0)