def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    logging.info(sys.argv)
    apifilepath= None
    if len(mainargs) == 0 : #if len(sys.argv)>1 and len(sys.argv)<5:
        parser = argparse.ArgumentParser(description='Import an API into APICS by providing a json file; When not provided, loops through all json files in the current directory and imports them')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--apifile', dest='apifile', help='full path of file to be imported', required=True)
        cmdargs = parser.parse_args()
        logging.info(cmdargs)
        #serverargs = (cmdargs.server, cmdargs.user, cmdargs.passwd)
        serverargs = (cmdargs.configfile,)
        if (cmdargs.apifile): apifilepath = cmdargs.apifile #if (cmdargs.apifile) if (cmdargs.apifile) 
    else:
        logging.info(type(mainargs))
        #Feature specific args parse
        numargs = len(mainargs)
        logging.info(numargs)
        if numargs == 4: pass
        else: raise TypeError("Number of arguments expected is  4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        apifilepath = mainargs[3:4] [0]

    if(apifilepath):
        apisvr = apipserver(serverargs)
        apisvr.importapi_populateartifacts(apifilepath)
    else:
        for jsonfile in findalljsonfiles(): #Loop through all json files in CWD and import them
            logging.info('*** Processing json file {} found in current working directory '.format(jsonfile))
            apisvr = apipserver(serverargs)
            logging.info(jsonfile)
            apisvr.importapi_populateartifacts(jsonfile)
    return 'success'
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    logging.info(sys.argv)
    appfilepath= None
    if len(mainargs) == 0 : #if len(sys.argv)>1 and len(sys.argv)<5:
        parser = argparse.ArgumentParser(description='Import an Application into APICS by providing a json file;')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--apifile', dest='apifile', help='full path of file to be imported;', required=True)
        cmdargs = parser.parse_args()
        logging.info(cmdargs)
        serverargs = (cmdargs.configfile,)
        if (cmdargs.apifile): appfilepath = cmdargs.apifile  
    else:
        logging.info(type(mainargs))
        #Feature specific args parse
        numargs = len(mainargs)
        logging.info(numargs)
        if numargs==4: pass
        else: raise TypeError("Number of arguments expected is 4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        appfilepath = mainargs[3:4] [0]

    apisvr = apipserver(serverargs)
    apisvr.importapplication(appfilepath)
    return 'success'
예제 #3
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    logging.info(sys.argv)
    if len(mainargs) == 0 : #if len(sys.argv)>1 and len(sys.argv)<5:
        parser = argparse.ArgumentParser(description='This program exports all Gateways\' metadata from APICS and persist them on the file system') 
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--destdir', dest='destdir', default='./', help='directory path on local file system where all the exported gateway details will be saved to; defaults to current directory', required=False )
        cmdargs = parser.parse_args()
        logging.info(type(cmdargs))
        logging.info(cmdargs)
        #Feature specific args parse
        serverargs = (cmdargs.configfile,)
        logging.info(serverargs) 
        destdir = cmdargs.destdir   #default CWD
        logging.info(destdir)
    else:
        #Feature specific args parse
        numargs = len(mainargs)
        logging.info(numargs)
        if numargs in  (3,4): pass
        else: raise TypeError("Number of arguments expected is 3 or 4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        destdir = mainargs[3:4][0] if (numargs==4) else './'   #default CWD
        logging.info(destdir)
            
    apisvr = apipserver(serverargs)
    savethegatewaysto = apisvr.getall('gateway') #get the real method
    savethegatewaysto(destdir) # and execute it
    return 'success'
예제 #4
0
    def exportartifacts(self, arg, artifact):
        parser = NoExitArgumentParser(
            description='exportallapps repl command',
            prog='exportall{}s'.format(artifact),
            usage='exportall{}s [--destdir <path>]'.format(artifact))
        parser.add_argument(
            '--destdir',
            dest='destdir',
            default='./',
            help=
            'directory path on local file system where all the exported artifacts will be saved to; defaults to current directory',
            required=False)
        cmdargs, errors = parser.parse_args(arg.split())
        print(cmdargs)
        print(errors)
        if errors == 1:
            #print('Error in REPL command, check usage and try again')
            return
        destdir = cmdargs.destdir  #default CWD
        logging.info('-->destdir = ' + destdir)

        apisvr = apipserver(self.serverargs)
        exportf = apisvr.getall(artifact)
        exportf(destdir)
        return 'success'
예제 #5
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.INFO)  
    #logging.getLogger('urllib3').setLevel(logging.CRITICAL)      
    logging.getLogger("requests.packages.urllib3").setLevel(logging.CRITICAL) 
      
    #logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    #logging.info(sys.argv)
    apiid= None
    if len(mainargs) == 0 : 
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) # move here else will keep adding logger every loop
        logging.getLogger('urllib3').setLevel(logging.CRITICAL)        
        parser = argparse.ArgumentParser(description='Lists all APIs from APICS and writes to console. Only writes to the console, use exportallapis to persist details in File system')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        cmdargs = parser.parse_args()
        logging.debug(cmdargs)
        serverargs = (cmdargs.configfile,)
    elif len(mainargs) == 1: #REPL
        serverargs = mainargs[0]
    else:
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) # move here else will keep adding logger every loop
        logging.debug(mainargs)
        numargs = len(mainargs)
        if numargs==3: pass
        else: raise TypeError("Number of arguments expected is 3; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
    apisvr = apipserver(serverargs)
    allapis = apisvr.retrieveall('api')()
    prettyprint(allapis)
    #logging.info(tabulate(allapis))
    #for apiid in loopapis(allapis): 
        #logging.info('*** API id - {}'.format(apiid))
        #pass
    return 'success'
예제 #6
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.info(sys.argv)
    apiid= None
    if len(mainargs) == 0 : 
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
        parser = argparse.ArgumentParser(description='Lists all Plans from APICS and writes to console. Only writes to the console, use exportplans to persist details in File system')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        cmdargs = parser.parse_args()
        logging.info(cmdargs)
        serverargs = (cmdargs.configfile,)
    elif len(mainargs) == 1: #REPL
        serverargs = mainargs[0]
    else:
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
        logging.info(mainargs)
        numargs = len(mainargs)
        if numargs==3: pass
        else: raise TypeError("Number of arguments expected is 3; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
    apisvr = apipserver(serverargs)
    allplans = apisvr.retrieveall('plan')()
    prettyprint(allplans)
    #apisvr.listall('plan')()
    return 'success'
예제 #7
0
def main(*mainargs):
    logging.basicConfig(
        filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(
            datetime.datetime.now()),
        filemode='w',
        format='%(asctime)s %(message)s',
        level=logging.DEBUG)
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    if len(mainargs) == 0:  #if len(sys.argv)>1 and len(sys.argv)<5:
        parser = argparse.ArgumentParser(
            description=
            'This program exports all specified type of artifact (api, plan, application, gateway..) from APICS and persist them on the file system'
        )
        parser.add_argument(
            '-cf',
            '--configfile',
            dest='configfile',
            help=
            'config file specifying server, auth, proxy and other details in json format;',
            default='apipcs_config.json',
            required=False)
        parser.add_argument(
            '--destdir',
            dest='destdir',
            default='./',
            help=
            'directory path on local file system where all the exported API artifacts will be saved to; defaults to current directory',
            required=False)
        parser.add_argument(
            '-i',
            '--item',
            dest='item',
            help=
            'type of artifacts (api, plan, application, gateway..) to be exported',
            required=True)
        cmdargs = parser.parse_args()
        #Feature specific args parse
        serverargs = (cmdargs.configfile, )
        destdir = cmdargs.destdir  #default CWD
        item = cmdargs.item
    else:
        #Feature specific args parse
        numargs = len(mainargs)
        if numargs in (4, 5): pass
        else:
            raise TypeError(
                "Number of arguments expected is 4 or 5 ; got {} !".format(
                    numargs))
        serverargs = mainargs[0:3]
        destdir = mainargs[3:4][0] if (numargs == 5) else './'  #default CWD
        item = mainargs[4:5][0] if (numargs == 5) else './'  #default CWD

    apisvr = apipserver(serverargs)
    getanyandstoreat = apisvr.getall(item)
    getanyandstoreat(destdir)
예제 #8
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    logging.info(sys.argv)
    apiid= None
    if len(mainargs) == 0 : 
        parser = argparse.ArgumentParser(description='Deletes an Api from APICS by providing its api-id; When no API ID is provided deletes all APIs and can be used to cleanup')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--apiid', dest='apiid', help='apiid to be deleted from API Platform server, warning - deletes all API when omitted', required=False)
        parser.add_argument('--force', dest='force', help='flag to force the deletion of applications', action='store_true', required=True)

        cmdargs = parser.parse_args()
        logging.info(cmdargs)
        serverargs = (cmdargs.configfile,)
        if (cmdargs.apiid): apiid = cmdargs.apiid #if (cmdargs.apifile) if (cmdargs.apifile) 
    else:
        logging.info(mainargs)
        numargs = len(mainargs)
        if numargs in  (3,4): pass
        else: raise TypeError("Number of arguments expected is 3 or 4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        if numargs==4 : apiid = mainargs[3:4] [0]
        
    if(apiid):
        apisvr = apipserver(serverargs)
        #export before delete
        apisvr.persistdetails(apiid, 'api')
        apisvr.deleteapi(apiid)
    else: #deleteall
        apisvr = apipserver(serverargs)
        apisvr.createdirectories()
        #allapis = apisvr.retrieveallapis()
        allapis = apisvr.retrieveall('api')()
        for apiid in loopapis(allapis): #Loop through all json files in CWD and import them
            logging.info('*** Deleting API - {}'.format(apiid))
            #export before delete
            apisvr.persistdetails(apiid, 'api')
            apisvr.deleteapi(apiid)
    return 'deleted'
예제 #9
0
def main(*mainargs):
    logging.basicConfig(filename='apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.info(sys.argv)
    if len(mainargs) == 0 : #if len(sys.argv)>1 and len(sys.argv)<5:
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
        parser = argparse.ArgumentParser(description='Import Applications into APICS by reading all json files in specified dirpath;')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--dirpath', dest='dirpath', default='./', help='directory path; All json files from this directory will be imported', required=True)
        cmdargs = parser.parse_args()
        logging.debug(cmdargs)
        serverargs = (cmdargs.configfile,)
        appdirpath = cmdargs.dirpath 
    elif len(mainargs) == 2: #REPL
        serverargs = mainargs[0]
        appdirpath = mainargs[1]
        #destdir = './'
        logging.info('Directory used for importapps= '+appdirpath)
       
    else:
        #Feature specific args parse
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
        numargs = len(mainargs)
        if numargs in  (3,4): pass
        else: raise TypeError("Number of arguments expected is 3 or 4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        appdirpath= mainargs[3:4][0] if numargs==4 else '.'

    apisvr = apipserver(serverargs)
    found = None
    deletemappingfile("appmappings.json")
    for jsonfile in findalljsonfiles(appdirpath): #Loop through all json files in CWD and import them
        found = 1
        logging.info('*** Processing json file {} found in current working directory '.format(jsonfile))
        #apisvr = apipserver(serverargs)
        logging.info(jsonfile)
        apisvr.importapplication(jsonfile) #apisvr.importapi_stripartifacts(jsonfile) #todo use importapi when ready
    if not found: logging.info('No files to process in directory - {}'.format(appdirpath))     
    return 'success'
예제 #10
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.INFO)    
    logging.info(sys.argv)
    if len(mainargs) == 0 : 
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) # move here else will keep adding logger every loop
        parser = argparse.ArgumentParser(description='This program exports all APIs and its associated artifacts from APICS and persist them on the file system') 
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('--destdir', dest='destdir', default='./', help='directory path on local file system where all the exported API artifacts will be saved to; defaults to current directory', required=False )
        cmdargs = parser.parse_args()
        logging.info(type(cmdargs))
        logging.info(cmdargs)
        #Feature specific args parse
        serverargs = (cmdargs.configfile,)
        logging.info(serverargs) 
        destdir = cmdargs.destdir   #default CWD
    elif len(mainargs) in (1,2): #REPL
        serverargs = mainargs[0]
        destdir = mainargs[1] if (mainargs[1]) else './'
        #destdir = './'
        logging.info('Destination directory used for exportallapis = '+destdir)
        
    else:
        logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) # move here else will keep adding logger every loop
        #Feature specific args parse
        numargs = len(mainargs)
        logging.info(numargs)
        if numargs in  (3,4): pass
        else: raise TypeError("Number of arguments expected is 3 or 4 ; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        destdir = mainargs[3:4][0] if (numargs==4) else './'   #default CWD
        logging.info(destdir)
    
    apisvr = apipserver(serverargs)
    getallapis = apisvr.getall('api')
    getallapis(destdir)
    return 'success'
예제 #11
0
def main(*mainargs):
    logging.basicConfig(filename='logs/apip-session-{:%Y%m%d-%H%M%S}.log'.format(datetime.datetime.now()), filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG)    
    logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
    logging.info(sys.argv)
    item= None
    if len(mainargs) == 0 : 
        parser = argparse.ArgumentParser(description='Lists all Applications from APICS and writes to console. Only writes to the console, use exportallapps to persist details in File system')
        parser.add_argument('-cf','--configfile', dest='configfile', help='config file specifying server, auth, proxy and other details in json format;', default='apipcs_config.json', required=False)
        parser.add_argument('-i','--item', dest='item', help='type of artifacts (api, plan, application, gateway..) to be exported', required=True )

        cmdargs = parser.parse_args()
        logging.info(cmdargs)
        serverargs = (cmdargs.configfile,)
        item=cmdargs.item
    else:
        logging.info(mainargs)
        numargs = len(mainargs)
        if numargs==4: pass
        else: raise TypeError("Number of arguments expected is 4; got {} !".format(numargs)) 
        serverargs = mainargs[0:3]
        item = mainargs[3:4][0]
    apisvr = apipserver(serverargs)
    listitems = apisvr.listall(item)()
    return 'done'