def addtape(request): departments = getUserDepartmentsList(request, default=False) st = getStorageNames() storages = () for s in st: storages += ((s, s),) libs = detectlibs() tapelibs = () tlavl = False stortapeids = getDIRStorageTapeids() for l in libs: if l['id'] not in stortapeids: tapelibs += ((l['id'], l['name'] + l['id']),) tlavl = True if request.method == 'GET': form = StorageTapeForm(storages=storages, tapelibs=tapelibs, departments=departments) form.fields['address'].disabled = True context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Add', 'Tape storage'], 'form': form, 'tlavl': tlavl} updateMenuNumbers(request, context) messages.info(request, """Here <b>IBAdmin</b> will detect a storage you select. It will require to execute tape load/unload operations which will take some time to complete. You should check the operation progress below.<br> By default IBAdmin will automatically <u>initialize</u> all tapes found in library for future use. If you want to make this initialization later you have to deselect the checkbox below.""", extra_tags="noslide:Info") return render(request, 'storage/addtape.html', context) else: # print (request.POST) cancel = request.POST.get('cancel', 0) if not cancel: form = StorageTapeForm(data=request.POST, storages=storages, tapelibs=tapelibs, departments=departments) if form.is_valid(): taskid = form.cleaned_data['taskid'] task = get_object_or_404(Tasks, taskid=taskid) if task.status == 'F': storname = form.cleaned_data['name'].encode('ascii', 'ignore') descr = form.cleaned_data['descr'] storage = form.cleaned_data['storagelist'] # address = form.cleaned_data['address'] tapelist = form.cleaned_data['tapelist'] libdata = None for l in libs: if l['id'] == tapelist: libdata = l tapelib = { 'Lib': libdata, 'Devices': ast.literal_eval(task.output) } # create a Storage resource with transaction.atomic(): extendStoragetape(storname=storname, descr=descr, sdcomponent=storage, tapelib=tapelib) directorreload() response = redirect('storageinfo', storname) response['Location'] += '?n=1' return response else: messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error') return redirect('storagedefined')
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 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 edittape(request, name): storageres = getDIRStorageinfo(name=name) if storageres is None: raise Http404() departments = getUserDepartmentsList(request, default=False) storage = extractstorageparams(storageres) storageid = storage.get("StorageDirTapeid") if storageid is None: return redirect('storagedefined') st = getStorageNames() storages = () for s in st: storages += ((s, s),) libs = detectlibs() tapelibs = () tlavl = False if len(libs) > 0: tlavl = True for l in libs: tapelibs += ((l['id'], l['name'] + l['id']),) data = makeinitialdata(name, storage) data['taskid'] = 0 data['tapelist'] = storageid if request.method == 'GET': form = StorageTapeForm(storages=storages, departments=departments, tapelibs=tapelibs, initial=data) form.fields['name'].disabled = True form.fields['address'].disabled = True form.fields['storagelist'].disabled = True form.fields['tapelist'].disabled = True context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Edit', 'Tape storage'], 'form': form, 'Storage': storage, 'tlavl': tlavl, 'StorageId': storageid} updateMenuNumbers(request, context) return render(request, 'storage/edittape.html', context) else: # print request.POST cancel = request.POST.get('cancel', 0) if not cancel: post = request.POST.copy() post['name'] = name post['address'] = storage['Address'] post['storagelist'] = storage['StorageComponent'] post['tapelist'] = storageid form = StorageTapeForm(data=post, storages=storages, departments=departments, initial=data, tapelibs=tapelibs) if form.is_valid(): response = redirect('storageinfo', name) descr = form.cleaned_data['descr'] departs = form.cleaned_data['departments'] if form.has_changed(): with transaction.atomic(): # print "form valid and changed ... " if 'descr' in form.changed_data: # update description updateDIRStorageDescr(request, name=name, descr=descr) if 'departments' in form.changed_data: # update departments updateDIRStorageDepartments(request, name=name, departments=departs) if 'taskid' in form.changed_data: # rescan was performed taskid = form.cleaned_data['taskid'] tasks = Tasks.objects.filter(taskid=taskid) if len(tasks) != 0: task = tasks[0] else: messages.error(request, "Something goes wrong and I cannot find TaskId: %s" % taskid, extra_tags="Error") return redirect('storagedefined') if task.status == 'F': libdata = None for l in libs: if l['id'] == storageid: libdata = l tapelib = { 'Lib': libdata, 'Devices': ast.literal_eval(task.output) } with transaction.atomic(): updateStorageTapelib(storname=name, tapelib=tapelib) response['Location'] += '?n=2' directorreload() return response else: messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error') return redirect('storagedefined')
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, })