def targetParamsListGet(interactive=False): """ Returns a list of path to targetSpecifiers. If interactive args have been specified, an ephemera targetPathSpecifier is added to list of path to be returned. Loaded TARGET_list is appended to returnedList. """ try: icm.callableEntryEnhancer(type='cmnd') except StopIteration: return G = icm.IcmGlobalContext() icmRunArgs = G.icmRunArgsGet() if interactive == True: if not len(icmRunArgs.cmndArgs) == 0: try: icm.EH_runTime('Bad Number Of cmndArgs') except RuntimeError: return tpl = Target_Param_List() paramList = tpl.parameterListGet() return paramList
def ticmoBxpOutputsBaseGetCmnd(interactive=False, targetType="bxp", collective=None, district=None, targetId=None): """ """ try: icm.callableEntryEnhancer(type='cmnd') except StopIteration: return if targetType != "bxp": return icm.EH_problem_usageError("Unsupported Target Type: " + targetType) G = icm.IcmGlobalContext() icmRunArgs = G.icmRunArgsGet() #icmParamDict = G.icmParamDictGet() if interactive == True: if not len(icmRunArgs.cmndArgs) == 0: try: icm.EH_runTime('Bad Number Of cmndArgs') except RuntimeError: return if icmRunArgs.collective: collective = icmRunArgs.collective if icmRunArgs.district: district = icmRunArgs.district if icmRunArgs.targetType: targetType = icmRunArgs.targetType if icmRunArgs.targetId: targetId = icmRunArgs.targetId # /de/bx/ticmo/int/libreCenter/targets/bxp/bue/ return (format("/de/bx/ticmo/%s/%s/targets/%s/%s" % (collective, district, targetType, targetId)))
def targetBaseGet( interactive=False, # Both Non-Interactive and Interactive targetElem=None, collective="int", district="libreCenter", targetType="bxp", targetId=None): """ """ try: icm.callableEntryEnhancer(type='cmnd') except StopIteration: return G = icm.IcmGlobalContext() icmRunArgs = G.icmRunArgsGet() #icmParamDict = G.icmParamDictGet() if interactive == True: if not len(icmRunArgs.cmndArgs) == 0: try: icm.EH_runTime('Bad Number Of cmndArgs') except RuntimeError: return if icmRunArgs.collective: collective = icmRunArgs.collective if icmRunArgs.district: district = icmRunArgs.district if icmRunArgs.targetType: targetType = icmRunArgs.targetType if icmRunArgs.targetId: targetId = icmRunArgs.targetId targetBase = ticmoBxpOutputsBaseGet(targetType=targetType, targetElem=targetElem, collective=collective, district=district, targetId=targetId) print(targetBase) return (targetBase)
def enetLibsUpdate( interactive=False, targetFqdn=None, # Optional accessMethod=None, # Optional userName=None, # Optional password=None, # Optional ): """ Given An ToIcmTag, dateVer in TICMO """ try: icm.callableEntryEnhancer(type='cmnd') except StopIteration: return cmndThis = icm.FUNC_currentGet().__name__ if interactive == True: G = icm.IcmGlobalContext() icmRunArgs = G.icmRunArgsGet() if not len(icmRunArgs.cmndArgs) == 0: try: icm.EH_runTime(format(cmndThis + 'Bad Number Of cmndArgs')) except RuntimeError: return targetsAccessList = toIcm.targetsAccessListGet(interactive=interactive, targetFqdn=targetFqdn, accessMethod=accessMethod, userName=userName, password=password) targetParamsList = toIcm.targetParamsListGet(interactive=interactive) @icm.subjectToTracking(fnLoc=True, fnEntry=True, fnExit=True) def targetsListProc(pathTargetsList): """Process List of Ephemera and Persistent Targets""" @icm.subjectToTracking(fnLoc=True, fnEntry=True, fnExit=True) def targetProc(thisPathTarget): """Process One Target""" @icm.subjectToTracking(fnLoc=True, fnEntry=True, fnExit=True) def paramsListProc(paramsList): """Process List of Parameters""" @icm.subjectToTracking(fnLoc=True, fnEntry=True, fnExit=True) def paramProc(thisParam): """At this point, we have the target and the parameter, ready for processing. - From thisParam's fileParams, get the agent and parName, - Then remoteExec the agent on target and get the results. - Record the obtained results with local invokation of the agent. """ icm.TM_here('targetPath=' + thisPathTarget) # Target Access Information icm.TM_here(format('ticmoBase=' + thisTicmoBase)) # TICMO Base paramBase = thisParam.base() icm.TM_here('paramBase=' + paramBase) agent = icm.FILE_ParamValueReadFrom(parRoot=paramBase, parName='agent') if not agent: return (icm.EH_problem_unassignedError()) parName = icm.FILE_ParamValueReadFrom(parRoot=paramBase, parName='parName') if not parName: return (icm.EH_problem_unassignedError()) commandLine = format(agent + ' -p mode=agent -i ' + parName) icm.LOG_here('RemoteExec: ' + commandLine) resultLines = linuxTarget.runCommand( connection, commandLine) pipeableResultLines = "" for thisResultLine in resultLines: pipeableResultLines = pipeableResultLines + thisResultLine + '\n' icm.LOG_here('ResultLines: ' + str(resultLines)) # We can now dateVer and empnaPkg write the resultLines for parName in TICMO #fileParWriteBase = os.path.join(thisTicmoBase, empnaPkg, dateVer) # updated = icm.FILE_ParamWriteTo(parRoot=fileParWriteBase, # parName=parName, # parValue=resultLines[0]) # # We ask the agent to capture the resultLines in ticmo # commandLine = format( agent + ' ' + '-n showRun -p mode=capture -p ticmoBase=' + ' -i ' + parName) commandArgs = shlex.split(commandLine) icm.LOG_here('SubProc: ' + commandLine) p = subprocess.Popen(commandArgs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate( input=format(pipeableResultLines.encode())) if out: icm.ANN_note("Stdout: " + out) if err: icm.ANN_note("Stderr: " + err) return for thisParam in paramsList: paramProc(thisParam) return linuxTarget = toIcm.TARGET_Proxy_Linux(basePath=thisPathTarget) accessParams = linuxTarget.accessParamsGet() targetId = accessParams.targetFqdnValue thisTicmoBase = toIcm.targetBaseGet(targetId=targetId) connection = linuxTarget.connect() paramsListProc(targetParamsList) return for thisPathTarget in pathTargetsList: targetProc(thisPathTarget) return targetsListProc(targetsAccessList) #empna.dateVerRecordForNext(dateVer=dateVer) return
def targetsAccessListGet(interactive=False, targetFqdn=None, accessMethod=None, userName=None, password=None): """ Returns a list of path to targetSpecifiers. If interactive args have been specified, an ephemera targetPathSpecifier is added to list of path to be returned. Loaded TARGET_list is appended to returnedList. """ try: icm.callableEntryEnhancer(type='cmnd') except StopIteration: return G = icm.IcmGlobalContext() icmRunArgs = G.icmRunArgsGet() #icmParamDict = G.icmParamDictGet() #thisFunc = icm.FUNC_currentGet() #cmndThis= thisFunc.__name__ #cmndMandatoryParams=[] #cmndOptionalParams=[] cmndPathTargets = [] if interactive == True: if not len(icmRunArgs.cmndArgs) == 0: try: icm.EH_runTime('Bad Number Of cmndArgs') except RuntimeError: return if icmRunArgs.targetFqdn: targetFqdn = icmRunArgs.targetFqdn if icmRunArgs.accessMethod: accessMethod = icmRunArgs.accessMethod if icmRunArgs.userName: userName = icmRunArgs.userName if icmRunArgs.password: password = icmRunArgs.password if targetFqdn != None: ephemeraTargetBase = format("/tmp/ephemera-target/" + targetFqdn) try: os.makedirs(ephemeraTargetBase, 0o777) except OSError: pass linuxTarget = TARGET_Proxy_Linux(basePath=ephemeraTargetBase) linuxTarget.accessParamsSet( accessMethod=accessMethod, targetFqdn=targetFqdn, userName=userName, password=password, ) cmndPathTargets.append(ephemeraTargetBase) # Check For cmndArgs and stdin and Add Them To cmndTargets for thisCmndArg in icmRunArgs.cmndArgs: icm.TM_here(thisCmndArg) cmndPathTargets.append(thisCmndArg) # NOTYET: Check For TargetParams and Add Them To cmndTargets tl = TARGET_List() targetList = tl.targetListGet() #icm.icm.TM_here(targetList) for thisTarget in targetList: targetType = thisTarget.targetType() if targetType != 'bxp': icm.EH_problem_usageError(targetType) continue dnType = thisTarget.dnType() #dnQualifier = thisTarget.dnQualifier() dnBase = thisTarget.base() if dnType == 'path': cmndPathTargets.append(dnBase) else: icm.EH_problem_usageError(dnType) # for thisPathTarget in cmndPathTargets: # print thisPathTarget return cmndPathTargets