def index(self, request, extra_context=None): """ Modify the index view to add controllers for the web services (blockUnblock and applyChanges) since the administration panel """ try: block_status = Configuration.objects.get(setting='BLOCK') except: block_status = Configuration(setting='BLOCK', value=False) block_status.save() requester_group = Group.objects.filter(name='Requester') if not requester_group: requester_group = Group(name='Requester') requester_group.save() consistent = checkConsistencyService.check() == "SUCCESS" # are passed the read_only status and the consistency status to the # template extra_context = {'read_only': block_status.value, 'consistent': consistent} return super(CustomAdminSite, self).index(request, extra_context=extra_context)
def update_antennas_view(self, request): """ view that allows update the antennas in the db from the cfg file """ error = "" antennas = [] changes = [] default_ste = 'VENDOR' if error == '': file_lines = open(settings.CONFIGURATION_DIR + 'antennas.cfg') file_lines = file_lines.readlines() for line_string in file_lines: line_string.strip() is_comment = line_string[0:2] == "//" if line_string and not is_comment: name_antenna, vendor = line_string.split() vendor = vendor.replace('-', ' ') if Antenna.objects.filter(name=name_antenna): antenna = Antenna.objects.get(name=name_antenna) if antenna.vendor != vendor: antenna.vendor = vendor antenna.save() changes.append("The vendor of %s was updated." % antenna) antennas.append(antenna) else: new_antenna = Antenna(name=name_antenna) new_antenna.current_ste = default_ste new_antenna.vendor = vendor new_antenna.save() antennas.append(new_antenna) changes.append("The Antenna %s was added." % new_antenna) for antenna in Antenna.objects.all(): if antenna not in antennas: changes.append("The Antenna %s was deleted." % antenna) antenna.delete() consistent = checkConsistencyService.check() == "SUCCESS" ctx = {'title': 'Update Antennas', 'changes': changes, 'error': error, 'consistent': consistent } return TemplateResponse(request, "admin/update_configuration.html", ctx)
def update_pads_view(self, request): """ View that allows update the PAD configurations from pads.cfg """ error = '' pads = [] changes = [] file_lines = open(settings.CONFIGURATION_DIR + 'pads.cfg') file_lines = file_lines.readlines() for line_string in file_lines: line_string = line_string.strip() is_comment = line_string[0:2] == "//" if line_string and not is_comment: pad_name, location = line_string.split() if PAD.objects.filter(name=pad_name): pad = PAD.objects.get(name=pad_name) if pad.location != location: changes.append("The %s location was updated." % pad) pad.location = location pad.save() pads.append(pad) else: new_pad = PAD(name=pad_name) new_pad.location = location new_pad.save() pads.append(new_pad) changes.append("The %s was added." % new_pad) for pad in PAD.objects.all(): if pad not in pads: changes.append("The %s was deleted." % pad) pad.delete() consistent = checkConsistencyService.check() == "SUCCESS" ctx = {'title': 'Update PADs', 'changes': changes, 'error': error, 'consistent': consistent } return TemplateResponse(request, "admin/update_configuration.html", ctx)
def update_configurations_view(self, request): error = '' holos = [] changes = [] file_lines = open(settings.CONFIGURATION_DIR + 'holography.cfg') file_lines = file_lines.readlines() for line_string in file_lines: line_string = line_string.strip() is_comment = line_string[0:2] == "//" if line_string and not is_comment: holo_name = line_string if HolographyConfiguration.objects.filter(name=holo_name): holo = HolographyConfiguration.objects.get(name=holo_name) holos.append(holo) else: new_holo = HolographyConfiguration(name=holo_name) new_holo.save() holos.append(new_holo) changes.append("The %s was added." % new_holo) for holo in HolographyConfiguration.objects.all(): if holo not in holos: changes.append("The %s was deleted." % holo) holo.delete() consistent = checkConsistencyService.check() == "SUCCESS" ctx = {'title': 'Update Holography Receptors', 'changes': changes, 'error': error, 'consistent': consistent } return TemplateResponse(request, "admin/update_configuration.html", ctx)
def apply(): """ Method that apply the requested changes permanently to the database i.e. pass the requested configurations to current configurations Also this method stores the request text in the DB The method return a string, *FAILURE* if exist consistency errors and return *SUCCESS* if the method apply the changes with successfully """ # if exist consistency errors the method return *FAILURE* if checkConsistencyService.check() != 'SUCCESS': return 'FAILURE' _request_text = "" # is applied the changes for the Antennas for antenna in Antenna.objects.all(): # if exist a request and the if (antenna.active and antenna.is_requested()): for status in antenna.text_status(): _request_text += "%s\n" % status # is saved the requested ste to current ste if antenna.is_ste_request(): antenna.current_ste = antenna.requested_ste if antenna.is_band_request(): if antenna.requested_band == "[-1]": antenna.requested_band = "[]" antenna.current_band = antenna.requested_band # is cleaned the request data antenna.requested_band = "[]" antenna.requested_ste = None antenna.requester = None antenna.request_date = None # is saved the information antenna.save() # is applied the changes for the PADs for pad in PAD.objects.all(): # if exist a request if pad.active and pad.is_requested(): for status in pad.text_status(): _request_text += "%s\n" % status pad.current_antenna = pad.requested_antenna pad.requested_antenna = None pad.assigned = True pad.requester = None pad.request_date = None pad.save() # is applied the changes for the Correlator Configurations for corr_conf in CorrelatorConfiguration.objects.all(): if corr_conf.active and corr_conf.is_requested(): for status in corr_conf.text_status(): _request_text += "%s\n" % status corr_conf.current_antenna = corr_conf.requested_antenna corr_conf.requested_antenna = None corr_conf.assigned = True corr_conf.requester = None corr_conf.request_date = None corr_conf.save() # is applied the changes for the CentralLO Configurations for clo_conf in CentralloConfiguration.objects.all(): if clo_conf.active and clo_conf.is_requested(): for status in clo_conf.text_status(): _request_text += "%s\n" % status clo_conf.current_antenna = clo_conf.requested_antenna clo_conf.requested_antenna = None clo_conf.assigned = True clo_conf.requester = None clo_conf.request_date = None clo_conf.save() # is applied the changes for the Holography Receptors for holo in HolographyConfiguration.objects.all(): if holo.active and holo.is_requested(): for status in holo.text_status(): _request_text += "%s\n" % status holo.current_antenna = holo.requested_antenna holo.requested_antenna = None holo.assigned = True holo.requester = None holo.request_date = None holo.save() #is saved the request in the DB _request_history = History() _request_history.date_time = datetime.now() _request_history.request = _request_text _request_history.save() return 'SUCCESS'
def update_configurations_view(self, request): """ Allows update the CentralLO Configurations from the clo_configs file """ error = '' changes = [] clo_confs = [] header = None file_lines = open(settings.CONFIGURATION_DIR + 'clo_configs.cfg') file_lines = file_lines.readlines() for line_string in file_lines: line_string = line_string.strip() is_comment = line_string[0:2] == "//" if line_string and not is_comment: line_list = line_string.split() line_list[0:-1] = [x.replace('-', ' ') for x in line_list[0:-1]] if line_string[0] == "#": line_list[0:-1] = [x.replace('#', '') for x in line_list[0:-1]] # if the table header not exist this is created if TableHeader.objects.filter( resource=line_list[-1]): header = TableHeader.objects.get( resource=line_list[-1]) header.text = str(line_list[0:-1]) header.save() else: new_header = TableHeader(text=str(line_list[0:-1]), resource=line_list[-1]) new_header.save() else: # is used the element in the first column as identifier identifier = line_list[0] configuration = line_list[1:-1] centrallo = line_list[-1] header = TableHeader.objects.get(resource=centrallo) if CentralloConfiguration.objects.filter( identifier=identifier, centrallo=centrallo): clo_config = CentralloConfiguration.objects.get( identifier=identifier, centrallo=centrallo) if clo_config.configuration != unicode(configuration): clo_config.configuration = unicode(configuration) clo_config.save() changes.append("The %s was updated." % clo_config) clo_confs.append(clo_config) else: new_clo_config = CentralloConfiguration( identifier=identifier, centrallo=centrallo) new_clo_config.configuration = unicode(configuration) new_clo_config.header = header new_clo_config.save() changes.append("The %s was added." % new_clo_config) clo_confs.append(new_clo_config) # the configurations that not appears in the cfg file are deleted for clo_config in CentralloConfiguration.objects.all(): if clo_config not in clo_confs: changes.append("The %s was deleted." % clo_config) clo_config.delete() consistent = checkConsistencyService.check() == "SUCCESS" ctx = {'title': 'Update CentralLO Configurations', 'changes': changes, 'error': error, 'consistent': consistent } return TemplateResponse(request, "admin/update_configuration.html", ctx)
def update_configurations_view(self, request): "View that update the corr configs from corr_configs file" error = '' changes = [] corr_confs = [] header = None file_lines = open(settings.CONFIGURATION_DIR + 'corr_configs.cfg') file_lines = file_lines.readlines() for line_string in file_lines: line_string = line_string.strip() #the comments are ignored is_comment = line_string[0:2] == "//" if line_string and not is_comment: line_list = line_string.split() # the - are replaced to spaces line_list[0:-1] = [x.replace('-', ' ') for x in line_list[0:-1]] if line_string[0] == "#": line_list[0:-1] = [x.replace('#', '') for x in line_list[0:-1]] # if the table header exist is added to the object, # if not is created if TableHeader.objects.filter(resource=line_list[-1]): header = TableHeader.objects.get( resource=line_list[-1]) header.text = str(line_list[0:-1]) header.save() else: new_header = TableHeader(text=str(line_list[0:-1]), resource=line_list[-1]) new_header.save() else: caimap = line_list[0] configuration = line_list[1:-1] correlator = line_list[-1] header = TableHeader.objects.get(resource=correlator) if CorrelatorConfiguration.objects.filter( caimap=caimap, correlator=correlator): corr_config = CorrelatorConfiguration.objects.get( caimap=caimap, correlator=correlator) if corr_config.configuration != unicode(configuration): corr_config.configuration = unicode(configuration) corr_config.save() changes.append("The %s was updated." % corr_config) corr_confs.append(corr_config) else: new_corr_config = CorrelatorConfiguration( caimap=caimap, correlator=correlator) new_corr_config.configuration = unicode(configuration) new_corr_config.header = header new_corr_config.save() changes.append("The %s was added." % new_corr_config) corr_confs.append(new_corr_config) for corr_config in CorrelatorConfiguration.objects.all(): if corr_config not in corr_confs: changes.append("The %s was deleted." % corr_config) corr_config.delete() consistent = checkConsistencyService.check() == "SUCCESS" ctx = {'title': 'Update Correlator Configurations', 'changes': changes, 'error': error, 'consistent': consistent } return TemplateResponse(request, "admin/update_configuration.html", ctx)
def status_json(ctx): """ Return a String with the current status of the request in JSON format """ if checkConsistencyService.check() != 'SUCCESS': return ('FAILURE: The current status of the system ' 'is not consistent.') result = {'ste': {}} antennas = {} for antenna in Antenna.objects.all(): show_antenna = False antenna_data = {'show_antenna': False, 'ste': None, 'drxbbpr0': None, 'drxbbpr1': None, 'drxbbpr2': None, 'drxbbpr3': None, 'dtsrbbpr0': None, 'dtsrbbpr1': None, 'dtsrbbpr2': None, 'dtsrbbpr3': None, 'cai': None, 'acacai': None, 'bands': None, 'sas': None, 'llc': None, 'pad': None } ste = antenna.current_ste if antenna.is_requested(): show_antenna = True if antenna.is_ste_request(): ste = antenna.requested_ste if antenna.current_ste != 'VENDOR': if antenna.current_ste not in result['ste']: result['ste'].setdefault(antenna.current_ste, []) result['ste'][antenna.current_ste].append( {"%s" % antenna: None}) # is added the bands information antenna_data['bands'] = antenna.current_band if antenna.is_band_request(): antenna_data['bands'] = antenna.requested_band antenna_data['ste'] = ste antenna_data['show_antenna'] = show_antenna antennas.setdefault("%s" % antenna, antenna_data) # PAD Information for pad in PAD.objects.all(): if pad.is_requested(): if pad.requested_antenna is not None: antenna = antennas["%s" % pad.requested_antenna] antenna['show_antenna'] = True antenna['pad'] = ("%s" % pad.name) elif pad.current_antenna is not None: antennas["%s" % pad.current_antenna]['show_antenna'] = True elif pad.current_antenna is not None: antennas["%s" % pad.current_antenna]['pad'] = ("%s" % pad.name) # Corr Conf Information for corr_conf in CorrelatorConfiguration.objects.all(): if corr_conf.is_requested(): if corr_conf.requested_antenna is not None: antenna = antennas["%s" % corr_conf.requested_antenna] antenna['show_antenna'] = True if corr_conf.correlator != 'ACA-Corr': (antenna['drxbbpr0'], antenna['drxbbpr1'], antenna['drxbbpr2'], antenna['drxbbpr3']) = corr_conf.drx_data() antenna['cai'] = corr_conf.cai_data() else: (antenna['dtsrbbpr0'], antenna['dtsrbbpr1'], antenna['dtsrbbpr2'], antenna['dtsrbbpr3']) = corr_conf.dtsr_data() antenna['acacai'] = corr_conf.acacai_data() elif corr_conf.current_antenna is not None: antenna = antennas["%s" % corr_conf.current_antenna] antenna['show_antenna'] = True elif corr_conf.current_antenna is not None: antenna = antennas["%s" % corr_conf.current_antenna] if corr_conf.correlator != 'ACA-Corr': (antenna['drxbbpr0'], antenna['drxbbpr1'], antenna['drxbbpr2'], antenna['drxbbpr3']) = corr_conf.drx_data() antenna['cai'] = corr_conf.cai_data() else: (antenna['dtsrbbpr0'], antenna['dtsrbbpr1'], antenna['dtsrbbpr2'], antenna['dtsrbbpr3']) = corr_conf.dtsr_data() antenna['acacai'] = corr_conf.acacai_data() # CentralLO information for clo_conf in CentralloConfiguration.objects.all(): if clo_conf.is_requested(): if clo_conf.requested_antenna is not None: antenna = antennas["%s" % clo_conf.requested_antenna] antenna['show_antenna'] = True antenna['sas'] = "%s-%s" % ( clo_conf.sas_ch(), clo_conf.sas_node()) antenna['llc'] = "%s-%s" % ( clo_conf.llc_ch(), clo_conf.llc_node()) elif clo_conf.current_antenna is not None: antenna = antennas["%s" % clo_conf.current_antenna] antenna['show_antenna'] = True elif clo_conf.current_antenna is not None: antenna = antennas["%s" % clo_conf.current_antenna] antenna['sas'] = "%s-%s" % ( clo_conf.sas_ch(), clo_conf.sas_node()) antenna['llc'] = "%s-%s" % ( clo_conf.llc_ch(), clo_conf.llc_node()) # ----------------------------------- # Holography Receptor Information # # Not included # # ----------------------------------- for antenna_name, antenna_data in antennas.iteritems(): if antenna_data['ste'] == 'VENDOR': continue if antenna_data['show_antenna']: ste = antenna_data['ste'] if ste not in result['ste']: result['ste'].setdefault(ste, []) del antenna_data['show_antenna'] del antenna_data['ste'] result['ste'][ste].append({"%s" % antenna_name: antenna_data}) if result['ste'] != {}: return json.dumps(result) else: return 'DOES NOT EXIST CHANGES.'