in bulkprovision/bulkexecute/__init__.py [0:0]
def TerminateProducts(self):
'''
Terminates entries with the incmoing status
'''
qry_status = self.get_config_value("status")
new_items = self.dynamo_query("status",qry_status)
logger.info("Found {} items to Terminate with status {}".format(len(new_items), qry_status))
#track success and failure
count = 0
errors = 0
for drow in new_items:
# setup variables to use later
failed = False
errordetails = None
# keep the error message if we have one
if "errordetails" in drow:
errordetails = drow["errordetails"]
dbstatus = "TERMINATING"
ppid= drow["scproductdetails"]["ProvisionedProductId"]
param_dict = drow["launchparams"]
guidkey = drow["guidkey"]
ppdetails = {
'ProvisionedProductId':ppid,
'RecordId':drow["scproductdetails"]['RecordId'],
'CreatedTime':str(drow["scproductdetails"]['CreatedTime']),
'Status':drow["scproductdetails"]['Status']
}
try:
# terminate the product and record the important parts of the response
resp = self.sc_terminate_product(ppid)
ppdetails['RecordId']=resp['RecordDetail']['RecordId']
ppdetails['Status'] = resp['RecordDetail']['Status']
except ClientError as ce:
msg = ce.response['Error']['Message']
if msg.startswith("Provisioned product not found: "):
#This was a good status termination, lets mark it and we're done with it now.
dbstatus = "TERMINATED"
ppdetails["Status"] = "TERMINATED"
count += 1
else:
# something wrong from the API call. this is where you will see the CFn Errors
logger.error("ClientError: {}".format(msg))
errordetails = ce.response['Error']
failed = True
except Exception as e:
# Something else wrong?
logger.error(e)
failed = True
else:
count += 1
if failed:
errors += 1
dbstatus = "TERMINATION-ERROR"
#update the dynamo table
self.updateItem(guidkey,drow["status"],dbstatus, param_dict, ppdetails, errordetails)
if len(new_items) > 0:
logger.info("Terminated {} of {} products with {} errors using status:{}".format(count, len(new_items), errors, qry_status))
return(self.generate_return(count))