Skip to content
Snippets Groups Projects

Paramterize intervention uuids

Closed Priyanshu Khandelwal requested to merge addparams into master
3 files
+ 45
12
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -17,11 +17,6 @@ logging.basicConfig(level=logging.INFO,
logger = logging.getLogger(__name__)
CONF = ccitools.conf.CONF
# UUIDs of intervention triggers
MINOR_SERVER_INTERVENTION = 'c58c7515-5938-42aa-8b89-32f194c62bd0'
QUICK_REBOOT_INTERVENTION = '99ba923e-7b5b-4b3f-bb37-3c0d4240ebe8'
CANCEL_INTERVENTION = '30b36b76-ed8f-4d7a-a740-c0ad0b25c155'
#
# NOTE: Rundeck API will return a JSON object that contains the list
# of scheduled jobs in a specified project. Its structure is as follows:
@@ -126,7 +121,7 @@ class InterventionsManagerCMD(BaseRundeckCMD):
return datetime_iso
def is_intervention(self, execution, history):
def is_intervention(self, execution, history, intervention_uuids):
"""Check whether the passed execution is an intervention.
:param execution: Rundeck execution
@@ -167,9 +162,10 @@ class InterventionsManagerCMD(BaseRundeckCMD):
# This hacking is required in order to run the script from Rundeck
# During execution the job itself enters "running" state and
# has to be discarded among all the possible interventions
if execution['job']['id'] in (MINOR_SERVER_INTERVENTION,
QUICK_REBOOT_INTERVENTION,
CANCEL_INTERVENTION):
if execution['job']['id'] in (
intervention_uuids['minorserverintervention'],
intervention_uuids['quickrebootintervention'],
intervention_uuids['cancelintervention']):
logger.debug(
"Found execution with ID %s does not seem to be a "
"scheduled intervention. Reason: execution is an "
@@ -210,7 +206,7 @@ class InterventionsManagerCMD(BaseRundeckCMD):
return parsed_striped_date
def retrieve_interventions(self, args, rdeckclient):
def retrieve_interventions(self, args, rdeckclient, intervention_uuids):
if args.history:
if args.within_last:
query = {'recentFilter': args.within_last}
@@ -233,7 +229,10 @@ class InterventionsManagerCMD(BaseRundeckCMD):
logger.info("Cleaning executions which are not interventions...")
executions = [
ex for ex in executions if self.is_intervention(ex, args.history)]
ex for ex in executions if self.is_intervention(
ex,
args.history,
intervention_uuids)]
if args.user:
logger.info("Filter executions by user %s", args.user)
@@ -495,8 +494,16 @@ class InterventionsManagerCMD(BaseRundeckCMD):
except AttributeError:
self.parser.error("Too few arguments")
intervention_uuids = {}
intervention_uuids['minorserverintervention'] = CONF.rundeck.msint_uuid
intervention_uuids['quickrebootintervention'] = CONF.rundeck.qrint_uuid
intervention_uuids['cancelintervention'] = CONF.rundeck.cint_uuid
# Retrieve the scheduled interventions that match with the filters
interventions = self.retrieve_interventions(args, self.rundeckcli)
interventions = self.retrieve_interventions(
args,
self.rundeckcli,
intervention_uuids)
# Execute the command
call(args, interventions, self.rundeckcli)
Loading