Beispiel #1
0
def getSytemCharacteristics():
    global ppn
    while True:   
        try:                 
            logging.input("Enter processors (cores) per node count:")
            ppn=int(raw_input(""))
            break
        except Exception,e:
            logging.error("Incorrect entry, try again.")
Beispiel #2
0
    def read_sql_root_creds(self):
        while True:
            log.input("""Please provide an administrative database user under which the installation sql script should
run (This user must have privileges to create users and databases):""")
            self.sql_root_name=raw_input()
            log.input("Please provide the password for the the user which you previously entered:")
            self.sql_root_password=getpass.getpass()
            
            try:
                self.get_db(user=self.sql_root_name,password=self.sql_root_password)
                break
            except Exception,e:
                log.error("Entered credential is not valid. Please try again.")
Beispiel #3
0
 def ask_cron_email(self):
     """ask_cron_email."""
     try:
         crontanContent=subprocess.check_output("crontab -l", shell=True)
         crontanContent=crontanContent.splitlines(True)
     except:
         #probably no crontab was setup yet
         crontanContent=[]
     for l in crontanContent:
         if len(l.strip())>1 and l.strip()[0]!="#":
             m=re.match(r'^MAILTO\s*=\s*(.*)',l.strip())
             if m:
                 self.cronemail=m.group(1)
                 self.cronemail=self.cronemail.replace('"','')
     if self.cronemail==None:
         log.input("Please enter the e-mail where cron will send messages (leave empty to opt out):")
         self.cronemail=raw_input()
     else:
         log.input("Please enter the e-mail where cron will send messages:")
         cronemail=raw_input('[{0}] '.format(self.cronemail)) 
         if cronemail!="":self.cronemail=cronemail
     if self.cronemail=="":self.cronemail=None
Beispiel #4
0
    def read_akrr_creds(self):
        log.info("Before Installation continues we need to setup the database.")

        log.input("Please specify a database user for AKRR (This user will be created if it does not already exist):")
        self.akrr_user_name=raw_input('[{0}] '.format(self.default_akrr_user)) 
        if self.akrr_user_name=='':self.akrr_user_name=self.default_akrr_user
        
        while True:
            log.input("Please specify a password for the AKRR database user:"******"Please reenter password:"******"Entered passwords do not match. Please try again.")
Beispiel #5
0
 def read_modw_creds(self):
     log.input("Please specify the user that will be connecting to the XDMoD database (modw):")
     self.xd_user_name=raw_input('[{0}] '.format(self.default_akrr_user))
     if self.xd_user_name=='':self.xd_user_name=self.default_akrr_user
     if self.xd_user_name==self.akrr_user_name:
         log.info("Same user as for AKRR database user, will set same password")
         self.xd_user_password=self.akrr_user_password
     else:
         while True:
             log.input("Please specify the password:"******"Please reenter password:"******"Entered passwords do not match. Please try again.")
Beispiel #6
0
def getFileSytemAccessPoints():
    global networkScratch
    global localScratch
    global akrrData
    global appKerDir
    
    homeDir=akrr.sshCommand(rsh,"echo $HOME").strip()
    scratchNetworkDir=akrr.sshCommand(rsh,"echo $SCRATCH").strip()
    
    #localScratch
    localScratchDefault="/tmp"
    while True:                    
        logging.input("Enter location of local scratch (visible only to single node):")
        localScratch=raw_input("[%s]"%localScratchDefault)
        if localScratch.strip()=="":
            localScratch=localScratchDefault
        status,msg=resource_validation_and_deployment.CheckDirSimple(rsh, localScratch)
        if status:
            logging.info(msg)
            print
            break
        else:
            logging.warning(msg)
            logging.warning('local scratch might be have a different location on head node, so if it is by design it is ok')
            print
            break
    localScratch=akrr.sshCommand(rsh,"echo %s"%(localScratch,)).strip()
    #networkScratch
    networkScratchDefault=""
    if scratchNetworkDir!="":
        networkScratchDefault=scratchNetworkDir
    networkScratchVisible=False
    while True:                    
        logging.input("Enter location of network scratch (visible only to all nodes), used for temporary storage of app kernel input/output:")
        if networkScratchDefault!="":
            networkScratch=raw_input("[%s]"%networkScratchDefault)
            if networkScratch.strip()=="":
                networkScratch=networkScratchDefault
        else:
            networkScratch=raw_input("")
            
        if networkScratch=="":
            logging.error("Incorrect value for networkScratch, try again")
            continue
        
        
        status,msg=resource_validation_and_deployment.CheckDir(rsh, networkScratch,exitOnFail=False,tryToCreate=True)
        if status:
            logging.info(msg)
            networkScratchVisible=True
            print
            break
        else:
            logging.warning(msg)
            #logging.warning('network scratch might be have a different location on head node, so if it is by design it is ok')
            #print
            break
    networkScratch=akrr.sshCommand(rsh,"echo %s"%(networkScratch,)).strip()
    #appKerDir
    appKerDirDefault=os.path.join(homeDir,"appker",resourceName)   
    while True:                    
        logging.input("Enter future location of app kernels input and executable files:")
        appKerDir=raw_input("[%s]"%appKerDirDefault)
        if appKerDir.strip()=="":
            appKerDir=appKerDirDefault
        status,msg=resource_validation_and_deployment.CheckDir(rsh, appKerDir,exitOnFail=False,tryToCreate=True)
        if status:
            logging.info(msg)
            print
            break
        else:
            logging.error(msg)
    appKerDir=akrr.sshCommand(rsh,"echo %s"%(appKerDir,)).strip()
    #akrrData
    akrrDataDefault=os.path.join(homeDir,"akrrdata",resourceName)
    if networkScratchVisible:
        akrrDataDefault=os.path.join(networkScratch,"akrrdata",resourceName)
    while True:                    
        logging.input("Enter future locations for app kernels working directories (can or even should be on scratch space):")
        akrrData=raw_input("[%s]"%akrrDataDefault)
        if akrrData.strip()=="":
            akrrData=akrrDataDefault
        status,msg=resource_validation_and_deployment.CheckDir(rsh, akrrData,exitOnFail=False,tryToCreate=True)
        if status:
            logging.info(msg)
            print
            break
        else:
            logging.error(msg) 
    akrrData=akrr.sshCommand(rsh,"echo %s"%(akrrData,)).strip()
Beispiel #7
0
def getRemoteAccessMethod():
    global remoteAccessNode
    global remoteAccessMethod
    global remoteCopyMethod
    global sshUserName
    global sshPassword
    global sshPassword4thisSession
    global sshPrivateKeyFile
    global sshPrivateKeyPassword
    global rsh
    #set remoteAccessNode
    while True:
        logging.input("Enter Resource head node (access node) full name (e.g. headnode.somewhere.org):")
        remoteAccessNode=raw_input("[%s] "%resourceName)
        if remoteAccessNode.strip()=="":
            remoteAccessNode=resourceName
        
        response = os.system("ping -c 1 -w2 " + remoteAccessNode + " > /dev/null 2>&1")
        
        if response==0:
            break
        else:
            logging.error("Incorrect head node name (can not ping %s), try again"%remoteAccessNode)
    #set sshUserName
    curentuser=getpass.getuser()
    askForUserName=True
    successfullyConnected=False
    while True:
        if askForUserName:
            logging.input("Enter username for resource access:")
            sshUserName=raw_input("[%s] "%curentuser)
            if sshUserName.strip()=="":
                sshUserName=curentuser
            curentuser=sshUserName
        
        #check passwordless access
        if sshPassword==None:
            logging.info("Checking for password-less access")
        else:
            logging.info("Checking for resource access")
        successfullyConnected=checkConnectionToResource()
        if successfullyConnected:
            if sshPassword==None:
                logging.info("Can access resource without password")
            else:
                logging.info("Can access resource")
        
        if successfullyConnected==False:
            logging.info("Can not access resource without password")
            actionList=[]
            actionList.append(["TryAgain","The private and public keys was generated manually, right now. Try again."])
            #check private keys
            userHomeDir = os.path.expanduser("~")
            privateKeys = [ os.path.join(userHomeDir,'.ssh',f[:-4]) for f in os.listdir(os.path.join(userHomeDir,'.ssh')) if os.path.isfile(os.path.join(userHomeDir,'.ssh',f)) \
                       and f[-4:]=='.pub' and os.path.isfile(os.path.join(userHomeDir,'.ssh',f[:-4]))]
            if len(privateKeys)>0:
                actionList.append(["UseExistingPrivateKey","Use existing private and public key."])
            
            actionList.append(["GenNewKey","Generate new private and public key."])
            actionList.append(["UsePassword","Use password directly."])
            
            print
            print "Select authentication method:"
            for i in range(len(actionList)):
                print "%3d  %s"%(i,actionList[i][1])
            while True:
                logging.input("Select option from list above:")
                try:
                    action=raw_input("[2] ")
                    if action.strip()=="":action=2
                    else: action=int(action)
                    
                    if action<0 or action>=len(actionList):
                        raise
                    break
                except Exception,e:
                    logging.error("Incorrect entry, try again.")
            
            #do the action
            print
            if actionList[action][0]=="TryAgain":
                continue
            if actionList[action][0]=="UsePassword":
                logging.input("Enter password for %s@%s:"%(sshUserName,remoteAccessNode))
                sshPassword=getpass.getpass("")
                askForUserName=not askForUserName
                continue
            if actionList[action][0]=="UseExistingPrivateKey":
                print "Available private keys:"
                for i in range(len(privateKeys)):
                    print "%3d  %s"%(i,privateKeys[i])
                while True:
                    logging.input("Select key number from list above:")
                    try:
                        iKey=raw_input("")
                        iKey=int(iKey)
                        
                        if iKey<0 or iKey>=len(privateKeys):
                            raise
                        break
                    except Exception,e:
                        logging.error("Incorrect entry, try again.")
                sshPrivateKeyFile=privateKeys[iKey]
                askForUserName=not askForUserName
                continue
            if actionList[action][0]=="GenNewKey":
                count=0
                while True:
                    logging.input("Enter password for %s@%s (will be used only during this session):"%(sshUserName,remoteAccessNode))
                    sshPassword4thisSession=getpass.getpass("")
                    sshPassword=sshPassword4thisSession
                    
                    if checkConnectionToResource():
                        break
                    count+=1
                    if count>=3:
                        break
                sshPassword=None
                #generate keys
                logging.input("Enter private key name:")
                sshPrivateKeyFile=raw_input("[id_rsa_%s]"%resourceName)
                if sshPrivateKeyFile.strip()=="":
                    sshPrivateKeyFile="id_rsa_%s"%resourceName
                sshPrivateKeyFile=os.path.join(userHomeDir,'.ssh',sshPrivateKeyFile)
                logging.input("Enter passphrase for new key (leave empty for passwordless access):")
                sshPrivateKeyPassword=getpass.getpass("")
                os.system("ssh-keygen -t rsa -N \"%s\" -f %s"%(sshPrivateKeyPassword,sshPrivateKeyFile))
                if sshPrivateKeyPassword.strip()=="":
                    sshPrivateKeyPassword=None
                #copy keys
                akrr.sshAccess(remoteAccessNode, ssh='ssh-copy-id', username=sshUserName, password=sshPassword4thisSession,
                            PrivateKeyFile=sshPrivateKeyFile, PrivateKeyPassword=None, logfile=sys.stdout,
                            command='')
                askForUserName=not askForUserName
                continue
Beispiel #8
0
def checkConnectionToResource():
    successfullyConnected=False
    global remoteAccessNode
    global remoteAccessMethod
    global remoteCopyMethod
    global sshUserName
    global sshPassword
    global sshPassword4thisSession
    global sshPrivateKeyFile
    global sshPrivateKeyPassword
    passphraseEntranceCount=0
    authorizeKeyCount=0
    while True:
        str_io=cStringIO.StringIO()
        try:
            sys.stdout = sys.stderr = str_io
            akrr.sshAccess(remoteAccessNode, ssh=remoteAccessMethod, username=sshUserName, password=sshPassword,
                    PrivateKeyFile=sshPrivateKeyFile, PrivateKeyPassword=sshPrivateKeyPassword, logfile=str_io,
                    command='ls')
            
            sys.stdout=sys.__stdout__
            sys.stderr=sys.__stderr__
            
            successfullyConnected=True
            break
        except Exception,e:
            sys.stdout=sys.__stdout__
            sys.stderr=sys.__stderr__
            if args.verbose:
                logging.info("Had attempted to access resource without password and failed, below is resource response")
                print "="*80
                print str_io.getvalue()
                print traceback.format_exc()
                print "="*80
            #check if it asking for passphrase
            m=re.search(r"Enter passphrase for key '(.*)':",str_io.getvalue())
            if m:
                if passphraseEntranceCount>=3:
                    sshPrivateKeyPassword=None
                    sshPrivateKeyFile=None
                    break
                if passphraseEntranceCount>0:
                    logging.error("Incorrect passphrase try again")
                sshPrivateKeyFile=m.group(1)
                logging.input("Enter passphrase for key '%s':"%sshPrivateKeyFile)
                sshPrivateKeyPassword=getpass.getpass("")
                passphraseEntranceCount+=1
                continue
            m2=re.search(r"[pP]assword:",str_io.getvalue())
            if m==None and sshPrivateKeyFile!=None and m2:
                logging.warning("Can not login to head node. Probably the public key of private key was not authorized on head node")
                print "Will try to add public key to list of authorized keys on head node"
                while True:
                    try:
                        authorizeKeyCount+=1
                        logging.input("Enter password for %s@%s (will be used only during this session):"%(sshUserName,remoteAccessNode))
                        sshPassword4thisSession=getpass.getpass("")
                        print
                        str_io=cStringIO.StringIO()
                        sys.stdout = sys.stderr = str_io
                        akrr.sshAccess(remoteAccessNode, ssh='ssh-copy-id', username=sshUserName, password=sshPassword4thisSession,
                            PrivateKeyFile=sshPrivateKeyFile, PrivateKeyPassword=None, logfile=str_io,
                            command='')
                    
                        sys.stdout=sys.__stdout__
                        sys.stderr=sys.__stderr__
                        print str_io.getvalue()
                        #successfullyConnected=True
                        logging.info("Have added public key to list of authorized keys on head node, will attempt to connect again.")
                        print
                        break
                    except Exception,e:
                        sys.stdout=sys.__stdout__
                        sys.stderr=sys.__stderr__
                        if args.verbose:
                            logging.info("Had attempted to add public key to list of authorized keys on head node and failed, below is resource response")
                            print "="*80
                            print str_io.getvalue()
                            print traceback.format_exc()
                            print "="*80
                        logging.info("Incorrect password try again.")
                        if authorizeKeyCount>=3:
                            break
                if authorizeKeyCount<3:
                     continue       
            break
Beispiel #9
0
    # PARSE: them arguments
    args = parser.parse_args()

    logging.info("Retrieving Resources from XDMoD Database...")
    # RETRIEVE: the resources from XDMoD
    resources = retrieve_resources()
    print
    print "Found following resources from XDMoD Database:"
    print
    print "resource_id  name"
    for resource_name,resource_id in resources:
        print "%11d  %-40s"%(resource_id,resource_name)
    print
    
    while True:
        logging.input('Enter resource_id for import (enter 0 for no match):')
        resource_id=raw_input()
        if validate_resource_id(resource_id,resources):
            break
        print "Incorrect resource_id try again"
    print
    resource_id=int(resource_id)
    if resource_id<=0:#i.e. no match from XDMoD DB
        resource_id=None
    
    resource_name=""
    while True:
        if resource_id==None:
            logging.input('Enter AKRR resource name:')
            resource_name=raw_input()
        else: