def initialsetup2(request): form = InitialDetectForm(data=request.POST) if form.is_valid(): taskid = form.cleaned_data['taskid'] task = get_object_or_404(Tasks, taskid=taskid) if task.status == 'F': dirname = form.cleaned_data['dirname'].encode('ascii', 'ignore') descr = form.cleaned_data['descr'] email = form.cleaned_data['email'] admpass = form.cleaned_data['admpass'] storage = form.cleaned_data['storage'].replace('tape', '') tapeinit = form.cleaned_data['tapeinit'] libs = detectlibs() libdata = None for l in libs: if l['id'] == storage: libdata = l tapelib = { 'Lib': libdata, 'Devices': ast.literal_eval(task.output) } try: stopallservices() createconfigfiles(dirname) address = detectip() with transaction.atomic(): # create config files initialize(name=dirname, descr=descr, email=email, password=admpass, stortype='tape', address=address, tapelib=tapelib) postinitial(request) startallservices() if tapeinit: prepareTask(name="Initializing tape library", proc=4, params='tape', log='Starting...') user = authenticate(username='******', password=admpass) auth_login(request, user) return redirect('home') except Exception as err: # redisplay initial message = """Initialize encountered an error: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str(err) traceback.print_exc() else: log = task.log.replace('\n', '<br>') message = """Error encountered during library detection:<hr>%s<hr> Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % log else: message = """Cannot parse parameters: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str(form.errors) storages = preparestorages() form = InitialForm(storages=storages) return render(request, 'initial/index.html', { 'displayalert': True, 'subject': 'Error during initialize.', 'form': form, 'message': message, })
def labeltape(request, storage): storageres = getDIRStorageinfo(name=storage) if storageres is None: raise Http404() logi = Log(jobid_id=0, logtext='User labeled tapes in "%s"' % storage) logi.save() taskid = prepareTask(name="Label tapes", proc=4, params=storage, log="Starting...") context = {'taskid': taskid} return JsonResponse(context, safe=False)
def tapedetectlib(request, tapeid): libs = detectlibs() tape = tapeid stname = 'Unknown' for l in libs: if l['id'] == tapeid: tape = 'tape' + str(tapeid) stname = l['name'] break taskid = prepareTask(name="Detecting tape library: " + str(stname) + ' ' + str(tapeid), proc=3, params=tape, log='Starting...') # TODO: change into {'taskid': taskid} context = [taskid] return JsonResponse(context, safe=False)
def libdetect(request): isconfigured = getDIRname(request) if isconfigured is not None: return redirect('initial') storages = preparestorages() forminitial = InitialForm(data=request.POST, storages=storages) if forminitial.is_valid(): st = forminitial.cleaned_data['storage'] storagename = 'Library' for (s, n) in storages: if s == st: storagename = n break taskid = prepareTask(name="Detecting tape library: " + storagename, proc=3, params=st, log='Starting...') data = { 'dirname': forminitial.cleaned_data['dirname'].encode('ascii', 'ignore'), 'descr': forminitial.cleaned_data['descr'], 'email': forminitial.cleaned_data['email'], 'admpass': forminitial.cleaned_data['admpass'], 'storage': st, 'taskid': taskid, 'tapeinit': True, } form = InitialDetectForm(initial=data) context = { 'form': form, 'storage': storagename, } return render(request, 'initial/libdetect.html', context) else: message = """Cannot parse parameters: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str( forminitial.errors) return render( request, 'initial/index.html', { 'displayalert': True, 'subject': 'Error during preinitialize.', 'form': forminitial, 'message': message, })
def taperescanlib(request, name, tapeid): storageres = getDIRStorageinfo(name=name) if storageres is None: raise Http404() storage = extractstorageparams(storageres) devices = getSDDevicesListex(component=storage['StorageComponent'], storage=storage['Device']) params = { 'tapeid': 'tape' + tapeid, 'storage': storage['Name'], 'devices': devices, } taskid = prepareTask(name="Rescan tape library: " + storage['StorageDirDevice'], proc=5, params=params, log='Starting...') context = {'taskid': taskid} return JsonResponse(context, safe=False)
def libdetect(request): isconfigured = getDIRname(request) if isconfigured is not None: return redirect('initial') storages = preparestorages() forminitial = InitialForm(data=request.POST, storages=storages) if forminitial.is_valid(): st = forminitial.cleaned_data['storage'] storagename = 'Library' for (s, n) in storages: if s == st: storagename = n break taskid = prepareTask(name="Detecting tape library: " + storagename, proc=3, params=st, log='Starting...') data = { 'dirname': forminitial.cleaned_data['dirname'].encode('ascii', 'ignore'), 'descr': forminitial.cleaned_data['descr'], 'email': forminitial.cleaned_data['email'], 'admpass': forminitial.cleaned_data['admpass'], 'storage': st, 'taskid': taskid, 'tapeinit': True, } form = InitialDetectForm(initial=data) context = { 'form': form, 'storage': storagename, } return render(request, 'initial/libdetect.html', context) else: message = """Cannot parse parameters: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str(forminitial.errors) return render(request, 'initial/index.html', { 'displayalert': True, 'subject': 'Error during preinitialize.', 'form': forminitial, 'message': message, })
def initialsetup2(request): form = InitialDetectForm(data=request.POST) if form.is_valid(): taskid = form.cleaned_data['taskid'] task = get_object_or_404(Tasks, taskid=taskid) if task.status == 'F': dirname = form.cleaned_data['dirname'].encode('ascii', 'ignore') descr = form.cleaned_data['descr'] email = form.cleaned_data['email'] admpass = form.cleaned_data['admpass'] storage = form.cleaned_data['storage'].replace('tape', '') tapeinit = form.cleaned_data['tapeinit'] libs = detectlibs() libdata = None for l in libs: if l['id'] == storage: libdata = l tapelib = { 'Lib': libdata, 'Devices': ast.literal_eval(task.output) } try: stopallservices() createconfigfiles(dirname) address = detectip() with transaction.atomic(): # create config files initialize(name=dirname, descr=descr, email=email, password=admpass, stortype='tape', address=address, tapelib=tapelib) postinitial(request) startallservices() if tapeinit: prepareTask(name="Initializing tape library", proc=4, params='tape', log='Starting...') user = authenticate(username='******', password=admpass) auth_login(request, user) return redirect('home') except Exception as err: # redisplay initial message = """Initialize encountered an error: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str( err) traceback.print_exc() else: log = task.log.replace('\n', '<br>') message = """Error encountered during library detection:<hr>%s<hr> Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % log else: message = """Cannot parse parameters: %s Try again later or contact <a href="https://inteos.freshservice.com">Inteos support</a>.""" % str( form.errors) storages = preparestorages() form = InitialForm(storages=storages) return render( request, 'initial/index.html', { 'displayalert': True, 'subject': 'Error during initialize.', 'form': form, 'message': message, })