Commit 4290c2cf1ebd9d86745b180d594b358592199925
1 parent
49805654
Exists in
dev
adding unit choice option when using start function in Pyros, refactoring method…
…s in ConfigPyros that used the unit (dict) paramater into using unit_name as a parameter
Showing
6 changed files
with
112 additions
and
67 deletions
Show diff stats
pyros.py
... | ... | @@ -521,7 +521,7 @@ def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only |
521 | 521 | def test(app): |
522 | 522 | print("Running tests") |
523 | 523 | os.environ["PATH_TO_OBSCONF_FOLDER"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"obsconfig/fixtures/") |
524 | - | |
524 | + os.environ["unit_name"] = "" | |
525 | 525 | #start_dir = os.getcwd() |
526 | 526 | if app == None: |
527 | 527 | #apps = ['obsconfig','scientific_program','common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] |
... | ... | @@ -622,10 +622,11 @@ def initdb(): |
622 | 622 | @click.argument('agent') |
623 | 623 | @click.option('--configfile', '-c', help='the configuration file to be used') |
624 | 624 | @click.option('--observatory', '-o', help='the observatory name to be used') |
625 | +@click.option('--unit', '-u', help='the unit name to be used') | |
625 | 626 | #@click.option('--format', '-f', type=click.Choice(['html', 'xml', 'text']), default='html', show_default=True) |
626 | 627 | #@click.option('--port', default=8000) |
627 | 628 | #def start(agent:str, configfile:str, test, verbosity): |
628 | -def start(agent:str, configfile:str,observatory:str): | |
629 | +def start(agent:str, configfile:str,observatory:str,unit:str): | |
629 | 630 | printd("Running start command") |
630 | 631 | if configfile: |
631 | 632 | printd("With config file", configfile) |
... | ... | @@ -652,6 +653,10 @@ def start(agent:str, configfile:str,observatory:str): |
652 | 653 | obs_config_file_path = os.path.join(path_to_obs_config_folder,obs_config_file_name) |
653 | 654 | os.environ["PATH_TO_OBSCONF_FILE"] = obs_config_file_path |
654 | 655 | os.environ["PATH_TO_OBSCONF_FOLDER"] = path_to_obs_config_folder |
656 | + if unit: | |
657 | + os.environ["unit_name"] = unit | |
658 | + else: | |
659 | + os.environ["unit_name"] = None | |
655 | 660 | # add path to pyros_django folder as the config class is supposed to work within this folder |
656 | 661 | #cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.configpyros import ConfigPyros\nConfigPyros('{os.path.join(PYROS_DJANGO_BASE_DIR,os.environ.get('PATH_TO_OBSCONF_FILE'))}')\"" |
657 | 662 | cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.configpyros import ConfigPyros\nConfigPyros('{obs_config_file_path}')\"" | ... | ... |
src/core/pyros_django/dashboard/views.py
... | ... | @@ -30,7 +30,7 @@ from django.conf import settings as pyros_settings |
30 | 30 | |
31 | 31 | sys.path.append("../../..") |
32 | 32 | #import utils.celme as celme |
33 | -import src.core.celme as celme | |
33 | +import src.core.guitastro as guitastro | |
34 | 34 | |
35 | 35 | |
36 | 36 | from collections import OrderedDict |
... | ... | @@ -41,10 +41,10 @@ MAX_LOGS_LINES = 100 |
41 | 41 | log = l.setupLogger("dashboard", "dashboard") |
42 | 42 | |
43 | 43 | def index(request): |
44 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
44 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
45 | 45 | observatory_name = config.get_obs_name() |
46 | - first_unit_name = config.get_units_name()[0] | |
47 | - request.session["obsname"] = observatory_name+" "+first_unit_name | |
46 | + unit_name = os.environ["unit_name"] | |
47 | + request.session["obsname"] = observatory_name+" "+unit_name | |
48 | 48 | |
49 | 49 | message = "" |
50 | 50 | if request.user.is_authenticated: |
... | ... | @@ -89,16 +89,16 @@ def retrieve_env(request): |
89 | 89 | |
90 | 90 | |
91 | 91 | ''' |
92 | - Function that call celme code to determine sun elevation, maybe it should be moved somewhere else ? | |
92 | + Function that call guitastro code to determine sun elevation, maybe it should be moved somewhere else ? | |
93 | 93 | ''' |
94 | 94 | |
95 | 95 | def get_sunelev(): |
96 | - date = celme.dates.Date("now") | |
97 | - site = celme.Site("MPC 244.5367 0.85792 +0.51292") # coords of san pedro martir site | |
96 | + date = guitastro.dates.Date("now") | |
97 | + site = guitastro.Site("MPC 244.5367 0.85792 +0.51292") # coords of san pedro martir site | |
98 | 98 | skyobj= {'planet':'Sun'} |
99 | 99 | outputs = ['name','ra','dec','elev'] |
100 | 100 | |
101 | - target = celme.Target() | |
101 | + target = guitastro.Target() | |
102 | 102 | target.define(skyobj) |
103 | 103 | output0s = ['ra','dec'] |
104 | 104 | results = target.ephem(date,site,output0s) | ... | ... |
src/core/pyros_django/obsconfig/configpyros.py
... | ... | @@ -455,7 +455,7 @@ class ConfigPyros: |
455 | 455 | exit(1) |
456 | 456 | #return None |
457 | 457 | |
458 | - def __init__(self,observatory_config_file:str) -> None: | |
458 | + def __init__(self,observatory_config_file:str,unit_name:str="") -> None: | |
459 | 459 | """ |
460 | 460 | Initiate class with the config file |
461 | 461 | set content attribute to a dictionary containing all values from the config file |
... | ... | @@ -464,6 +464,11 @@ class ConfigPyros: |
464 | 464 | config_file_name (str): path to the config file |
465 | 465 | """ |
466 | 466 | self.load(observatory_config_file) |
467 | + if unit_name == "": | |
468 | + # By default we will use the first unit | |
469 | + self.unit_name = self.get_units_name()[0] | |
470 | + else: | |
471 | + self.unit_name = unit_name | |
467 | 472 | |
468 | 473 | |
469 | 474 | def get_obs_name(self)->str: |
... | ... | @@ -475,13 +480,17 @@ class ConfigPyros: |
475 | 480 | """ |
476 | 481 | return self.obs_config["OBSERVATORY"]["name"] |
477 | 482 | |
478 | - def get_channels(self,unit)->dict: | |
483 | + def get_channels(self,unit_name:str)->dict: | |
484 | + | |
479 | 485 | """ |
480 | 486 | return dictionary of channels |
481 | 487 | |
488 | + Args: | |
489 | + unit_name (str): Name of the unit | |
482 | 490 | Returns: |
483 | 491 | dict: [description] |
484 | 492 | """ |
493 | + unit = self.get_unit_by_name(unit_name) | |
485 | 494 | channels = {} |
486 | 495 | |
487 | 496 | for channel_id in range(len(unit["TOPOLOGY"]["CHANNELS"])): |
... | ... | @@ -537,13 +546,17 @@ class ConfigPyros: |
537 | 546 | devices_names.append(device["DEVICE"]["name"]) |
538 | 547 | return devices_names |
539 | 548 | |
540 | - def get_agents(self,unit)->dict: | |
549 | + def get_agents(self,unit_name)->dict: | |
541 | 550 | """ |
542 | 551 | return dictionary of agents |
543 | 552 | |
553 | + Args: | |
554 | + unit_name (str): name of the unit | |
555 | + | |
544 | 556 | Returns: |
545 | 557 | dict: dictionary of agents. For each agents tell the name, computer, device, protocole, etc... |
546 | 558 | """ |
559 | + unit = self.get_unit_by_name(unit_name) | |
547 | 560 | if self.agents != None: |
548 | 561 | return self.agents |
549 | 562 | else: |
... | ... | @@ -557,15 +570,16 @@ class ConfigPyros: |
557 | 570 | agents[agent["name"]] = agent |
558 | 571 | return agents |
559 | 572 | |
560 | - def get_channel_groups(self,unit:dict)->dict: | |
573 | + def get_channel_groups(self,unit_name:str)->dict: | |
561 | 574 | """ |
562 | 575 | Return dictionary of channel groups, tell the logic between groups of channels and within a group of channels |
563 | 576 | |
564 | 577 | Args: |
565 | - unit (dict): dictonary contaning all values of a unit | |
578 | + unit_name (str): name of the unit | |
566 | 579 | Returns: |
567 | 580 | dict: dictionary of channel groups (tell the logic and groups of channels) |
568 | 581 | """ |
582 | + unit = self.get_unit_by_name(unit_name) | |
569 | 583 | info = {} |
570 | 584 | info["global_groups_logic"] = unit["TOPOLOGY"]["CHANNEL_GROUPS"]["logic"] |
571 | 585 | info["groups"] = {} |
... | ... | @@ -574,51 +588,52 @@ class ConfigPyros: |
574 | 588 | info["groups"][group_id] = group |
575 | 589 | return info |
576 | 590 | |
577 | - def get_channel_information(self,unit:dict,channel_name:str)->dict: | |
591 | + def get_channel_information(self,unit_name:str,channel_name:str)->dict: | |
578 | 592 | """ |
579 | 593 | Return information of the given channel name of a unit |
580 | 594 | |
581 | 595 | Args: |
582 | - unit (dict): dictionary representing the unit | |
596 | + unit_name (str): Name of the unit | |
583 | 597 | channel_name (str): name of the channel |
584 | 598 | |
585 | 599 | Returns: |
586 | 600 | dict: dictionary containing all values that define this channel |
587 | 601 | """ |
588 | - channels = self.get_channels(unit) | |
602 | + channels = self.get_channels(unit_name) | |
589 | 603 | return channels[channel_name] |
590 | 604 | |
591 | - def get_topology(self,unit:dict)->dict: | |
605 | + def get_topology(self,unit_name:str)->dict: | |
592 | 606 | """ |
593 | 607 | Return dictionary of the topology of the observatory |
594 | 608 | |
595 | 609 | Args: |
596 | - unit (dict): dictionary representing the unit | |
610 | + unit_name (str): Name of the unit | |
597 | 611 | Returns: |
598 | 612 | dict: dictionary representing the topology of an unit (security, mount, channels, channel_groups) |
599 | 613 | """ |
614 | + unit = self.get_unit_by_name(unit_name) | |
600 | 615 | topology = {} |
601 | 616 | for key in unit["TOPOLOGY"].keys(): |
602 | 617 | branch = unit["TOPOLOGY"][key] |
603 | 618 | if key == "CHANNELS": |
604 | - topology[key] = self.get_channels(unit) | |
619 | + topology[key] = self.get_channels(unit_name) | |
605 | 620 | elif key == "CHANNEL_GROUPS": |
606 | - topology[key] = self.get_channel_groups(unit) | |
621 | + topology[key] = self.get_channel_groups(unit_name) | |
607 | 622 | else: |
608 | 623 | topology[key] = branch |
609 | 624 | return topology |
610 | 625 | |
611 | - def get_active_agents(self,unit:dict)->list: | |
626 | + def get_active_agents(self,unit_name:str)->list: | |
612 | 627 | """ |
613 | 628 | Return the list of active agents (i.e. agents that have an association with a device) |
614 | 629 | |
615 | 630 | Args: |
616 | - unit (dict): dictionary representing the unit | |
631 | + unit_name (str): Name of the unit | |
617 | 632 | |
618 | 633 | Returns: |
619 | 634 | list: kist of the name of active agents |
620 | 635 | """ |
621 | - return list(self.get_agents(unit).keys()) | |
636 | + return list(self.get_agents(unit_name).keys()) | |
622 | 637 | |
623 | 638 | def get_units(self)->dict: |
624 | 639 | """ |
... | ... | @@ -634,18 +649,18 @@ class ConfigPyros: |
634 | 649 | result[unit["name"]] = unit |
635 | 650 | return result |
636 | 651 | |
637 | - def get_components_agents(self,unit:dict)->dict: | |
652 | + def get_components_agents(self,unit_name:str)->dict: | |
638 | 653 | """ |
639 | 654 | Return dictionary of component_agents of the given unit |
640 | 655 | |
641 | 656 | Args: |
642 | - unit (dict): dictionary representing the unit | |
657 | + unit_name (str): Name of the unit | |
643 | 658 | |
644 | 659 | Returns: |
645 | 660 | dict: dictionary sort by component name giving the associated agent (agent name) |
646 | 661 | """ |
647 | 662 | components_agents = {} |
648 | - topology = self.get_topology(unit) | |
663 | + topology = self.get_topology(unit_name) | |
649 | 664 | for element in topology: |
650 | 665 | if element in ("SECURITY","MOUNT","CHANNELS"): |
651 | 666 | if(element != "CHANNELS"): |
... | ... | @@ -680,19 +695,19 @@ class ConfigPyros: |
680 | 695 | """ |
681 | 696 | return self.get_units()[name] |
682 | 697 | |
683 | - def get_agents_per_computer(self,unit:dict)->dict: | |
698 | + def get_agents_per_computer(self,unit_name:str)->dict: | |
684 | 699 | """ |
685 | 700 | Return dictionary that give for each computer, what are the associated agents to it as a list |
686 | 701 | |
687 | 702 | Args: |
688 | - unit (dict): dictonary representing the unit | |
703 | + unit_name (str): Name of the unit | |
689 | 704 | |
690 | 705 | Returns: |
691 | 706 | dict: dictionary that give for each computer, what are the associated agents to it as a list |
692 | 707 | |
693 | 708 | """ |
694 | 709 | agents_per_computer = {} |
695 | - agents = self.get_agents(unit) | |
710 | + agents = self.get_agents(unit_name) | |
696 | 711 | for agent in agents: |
697 | 712 | computer_name = agents[agent]["computer"] |
698 | 713 | if(agents[agent]["computer"] not in agents_per_computer.keys()): |
... | ... | @@ -702,19 +717,19 @@ class ConfigPyros: |
702 | 717 | return agents_per_computer |
703 | 718 | |
704 | 719 | |
705 | - def get_agents_per_device(self,unit:dict)->dict: | |
720 | + def get_agents_per_device(self,unit_name:str)->dict: | |
706 | 721 | """ |
707 | 722 | Return dictionary that give for each device, what are the associated agents to it as a list |
708 | 723 | |
709 | 724 | Args: |
710 | - unit (dict): dictonary representing the unit | |
725 | + unit_name (str): Name of the unit | |
711 | 726 | |
712 | 727 | Returns: |
713 | 728 | dict: dictionary that give for each device, what are the associated agents to it as a list |
714 | 729 | |
715 | 730 | """ |
716 | 731 | agents_per_device = {} |
717 | - agents = self.get_agents(unit) | |
732 | + agents = self.get_agents(unit_name) | |
718 | 733 | for agent in agents: |
719 | 734 | if("device" in agents[agent].keys()): |
720 | 735 | device_name = agents[agent]["device"] |
... | ... | @@ -737,8 +752,7 @@ class ConfigPyros: |
737 | 752 | """ |
738 | 753 | active_devices = [] |
739 | 754 | for unit_name in self.get_units(): |
740 | - unit = self.get_unit_by_name(unit_name) | |
741 | - for device in self.get_agents_per_device(unit): | |
755 | + for device in self.get_agents_per_device(unit_name): | |
742 | 756 | active_devices.append(device) |
743 | 757 | return active_devices |
744 | 758 | |
... | ... | @@ -752,11 +766,11 @@ class ConfigPyros: |
752 | 766 | active_computers = [] |
753 | 767 | for unit_name in self.get_units(): |
754 | 768 | unit = self.get_unit_by_name(unit_name) |
755 | - for computer in self.get_agents_per_computer(unit): | |
769 | + for computer in self.get_agents_per_computer(unit_name): | |
756 | 770 | active_computers.append(computer) |
757 | 771 | return active_computers |
758 | 772 | |
759 | - def get_agent_information(self,unit:dict,agent_name:str)->dict: | |
773 | + def get_agent_information(self,unit_name:str,agent_name:str)->dict: | |
760 | 774 | """ |
761 | 775 | Give the dictionary of attributes of the agent for an unit. |
762 | 776 | |
... | ... | @@ -767,7 +781,7 @@ class ConfigPyros: |
767 | 781 | Returns: |
768 | 782 | dict: dictionary containing attributes of the agent |
769 | 783 | """ |
770 | - return self.get_agents(unit)[agent_name] | |
784 | + return self.get_agents(unit_name)[agent_name] | |
771 | 785 | |
772 | 786 | def get_device_information(self,device_name:str)->dict: |
773 | 787 | """ |
... | ... | @@ -793,7 +807,7 @@ class ConfigPyros: |
793 | 807 | """ |
794 | 808 | return self.get_unit_by_name(unit_name)["DATABASE"] |
795 | 809 | |
796 | - def get_device_for_agent(self,unit:dict,agent_name:str)->str: | |
810 | + def get_device_for_agent(self,unit_name:str,agent_name:str)->str: | |
797 | 811 | """ |
798 | 812 | Return device name associated to the agent |
799 | 813 | |
... | ... | @@ -804,7 +818,7 @@ class ConfigPyros: |
804 | 818 | Returns: |
805 | 819 | str: device name associated to this agent |
806 | 820 | """ |
807 | - agents_per_device = self.get_agents_per_device(unit) | |
821 | + agents_per_device = self.get_agents_per_device(unit_name) | |
808 | 822 | for device in agents_per_device: |
809 | 823 | if agent_name in agents_per_device[device]: |
810 | 824 | return self.get_device_information(device) |
... | ... | @@ -819,8 +833,7 @@ class ConfigPyros: |
819 | 833 | str: unit name |
820 | 834 | """ |
821 | 835 | for unit_name in self.get_units(): |
822 | - unit = self.get_unit_by_name(unit_name) | |
823 | - if(computer_name in self.get_agents_per_computer(unit)): | |
836 | + if(computer_name in self.get_agents_per_computer(unit_name)): | |
824 | 837 | return unit_name |
825 | 838 | |
826 | 839 | def get_unit_of_device(self,device_name:str)->str: |
... | ... | @@ -834,8 +847,7 @@ class ConfigPyros: |
834 | 847 | str: unit name |
835 | 848 | """ |
836 | 849 | for unit_name in self.get_units(): |
837 | - unit = self.get_unit_by_name(unit_name) | |
838 | - if(device_name in self.get_agents_per_device(unit)): | |
850 | + if(device_name in self.get_agents_per_device(unit_name)): | |
839 | 851 | return unit_name |
840 | 852 | |
841 | 853 | def get_device_power(self,device_name:str)->dict: |
... | ... | @@ -894,18 +906,46 @@ class ConfigPyros: |
894 | 906 | return self.get_computers()[computer_name]["computer_config"].get("power") |
895 | 907 | |
896 | 908 | def getDeviceControllerNameForAgent(self,unit_name:str,agent_name:str)->tuple: |
897 | - unit = self.get_unit_by_name(unit_name) | |
898 | - agent = self.get_agent_information(unit,agent_name) | |
909 | + agent = self.get_agent_information(unit_name,agent_name) | |
899 | 910 | return (agent["device"],"DeviceController"+agent["device"]) |
900 | 911 | |
901 | 912 | def getDeviceConfigForDeviceController(self,device_name:str)->dict: |
902 | 913 | return self.get_devices()[device_name]["device_config"] |
903 | 914 | |
915 | + def getCommParamsForAgentDevice(self,unit_name:str,agent_name:str)->tuple: | |
916 | + agent = self.get_agent_information(unit_name,agent_name) | |
917 | + device_config = self.getDeviceConfigForDeviceController(agent["device"]) | |
918 | + comm_access = agent.get("comm_access",None) | |
919 | + comm = device_config["comm"] | |
920 | + return (comm_access,comm) | |
921 | + | |
922 | + def getChannelCapabilities(self,unit_name:str,channel_name:str)->list: | |
923 | + channel = self.get_channel_information(unit_name,channel_name) | |
924 | + result = [] | |
925 | + for component_agent in channel["COMPONENT_AGENTS"]: | |
926 | + component = list(component_agent.keys())[0] | |
927 | + agent = component_agent[component] | |
928 | + device = self.getDeviceControllerNameForAgent(unit_name,agent)[0] | |
929 | + device_capabilities = self.get_device_capabilities(device) | |
930 | + for capability in device_capabilities: | |
931 | + if capability["component"] == component: | |
932 | + result.append(capability) | |
933 | + return result | |
934 | + | |
935 | + def getEditableAttributesOfCapability(self,capability:dict)->dict: | |
936 | + editable_fields = {} | |
937 | + attributes = capability.get("attributes") | |
938 | + for attribute in attributes: | |
939 | + print(attribute) | |
904 | 940 | def main(): |
905 | - config = ConfigPyros("../../../../privatedev/config/tnc/observatory_tnc.yml") | |
941 | + config = ConfigPyros("../../../../privatedev/config/guitalens/observatory_guitalens.yml") | |
906 | 942 | unit_name = config.get_units_name()[0] |
907 | 943 | dc = config.getDeviceControllerNameForAgent(unit_name,"mount")[0] |
908 | - print(config.getDeviceConfigForDeviceController(dc)) | |
944 | + #print(config.getDeviceConfigForDeviceController(dc)) | |
945 | + #print(config.getCommParamsForAgentDevice(unit_name,"mount")) | |
946 | + print(config.getChannelCapabilities(unit_name,"OpticalChannel_up")) | |
947 | + print(config.get_channel_groups(unit_name)) | |
948 | + print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_up")[0])) | |
909 | 949 | #print(config.get_devices()["FLI-Kepler4040"]["device_config"]) |
910 | 950 | #print(config.get_devices()["FLI-Kepler4040"]["device_config"]["CAPABILITIES"][1]["attributes"]["manufacturer"]) |
911 | 951 | #print(config.get_devices()["FLI-Kepler4040"]["device_config"]["CAPABILITIES"]) | ... | ... |
src/core/pyros_django/obsconfig/tests.py
... | ... | @@ -23,8 +23,8 @@ class ObservatoryConfigurationTests(TestCase): |
23 | 23 | self.assertEqual(len(config.get_units()),1) |
24 | 24 | first_unit = config.get_units()["test-unit"] |
25 | 25 | self.assertEqual(first_unit["name"],"test-unit") |
26 | - self.assertEqual(len(config.get_channels(first_unit)),1) | |
27 | - self.assertEqual(len(config.get_agents_per_device(first_unit)),4) | |
26 | + self.assertEqual(len(config.get_channels(first_unit["name"])),1) | |
27 | + self.assertEqual(len(config.get_agents_per_device(first_unit["name"])),4) | |
28 | 28 | self.assertIn("AstroMecCA",config.get_devices().keys()) |
29 | 29 | self.assertIn("MainComputer",config.get_computers().keys()) |
30 | 30 | self.assertEqual(config.get_device_capabilities("AstroMecCA")[0]["component"],"MountPointing") | ... | ... |
src/core/pyros_django/obsconfig/views.py
... | ... | @@ -30,7 +30,7 @@ def get_nested_dictionaries_as_list(dic,result=[]): |
30 | 30 | @login_required |
31 | 31 | @level_required("Admin","Observer","Management","Operator","Unit-PI") |
32 | 32 | def obs_global_config(request): |
33 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
33 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
34 | 34 | units_names = list(config.get_units().keys()) |
35 | 35 | pickle_file_mtime = os.path.getmtime(config.CONFIG_PATH+config.pickle_file) |
36 | 36 | pickle_datetime = datetime.utcfromtimestamp(pickle_file_mtime).strftime("%Y/%m/%d %H:%M:%S") |
... | ... | @@ -52,7 +52,7 @@ def obs_global_config(request): |
52 | 52 | @login_required |
53 | 53 | @level_required("Admin","Unit-PI","Operator") |
54 | 54 | def obs_hardware_config(request): |
55 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
55 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
56 | 56 | devices = config.get_devices() |
57 | 57 | active_devices = config.get_active_devices() |
58 | 58 | computers = config.get_computers() |
... | ... | @@ -71,7 +71,7 @@ def obs_hardware_config(request): |
71 | 71 | @login_required |
72 | 72 | @level_required("Admin","Unit-PI","Operator") |
73 | 73 | def unit_hardware_configuration(request,unit_name): |
74 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
74 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
75 | 75 | devices = config.get_devices() |
76 | 76 | |
77 | 77 | return render(request, 'obsconfig/unit_hardware_configuration.html', {'config':config}) |
... | ... | @@ -79,7 +79,7 @@ def unit_hardware_configuration(request,unit_name): |
79 | 79 | @login_required |
80 | 80 | @level_required("Admin","Unit-PI","Operator") |
81 | 81 | def computer_details(request,computer_name): |
82 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
82 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
83 | 83 | computer_detail = yaml.dump(config.get_computers()[computer_name]) |
84 | 84 | """ |
85 | 85 | computer_detail = { re.sub("^_","",key):value for key,value in config.get_computers()[computer_name].items() } |
... | ... | @@ -101,7 +101,7 @@ def computer_details(request,computer_name): |
101 | 101 | @login_required |
102 | 102 | @level_required("Admin","Unit-PI","Unit-board","Operator","Observer") |
103 | 103 | def device_details(request,device_name): |
104 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
104 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
105 | 105 | # We're removing "_" at the beginning of each key : |
106 | 106 | device = config.get_devices()[device_name] |
107 | 107 | #device_detail = yaml.dump(device) |
... | ... | @@ -156,13 +156,13 @@ def device_details(request,device_name): |
156 | 156 | @login_required |
157 | 157 | @level_required("Admin","Observer","Management","Operator","Unit-PI","TAC") |
158 | 158 | def obs_astronomer_config(request): |
159 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
159 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
160 | 160 | units = config.get_units() |
161 | 161 | units_topologies = {} |
162 | 162 | # for each unit |
163 | 163 | for unit_name in units: |
164 | 164 | |
165 | - units_topologies[unit_name] = config.get_topology(units[unit_name]) | |
165 | + units_topologies[unit_name] = config.get_topology(unit_name) | |
166 | 166 | # removing channel_groups, not useful in this view |
167 | 167 | units_topologies[unit_name].pop("CHANNEL_GROUPS") |
168 | 168 | # for each category (security, mount, channels) |
... | ... | @@ -173,7 +173,7 @@ def obs_astronomer_config(request): |
173 | 173 | for component_agent in units_topologies[unit_name][category]["COMPONENT_AGENTS"]: |
174 | 174 | component_name = list(component_agent.keys())[0] |
175 | 175 | agent = component_agent[component_name] |
176 | - device_of_agent = config.get_device_for_agent(units[unit_name],agent) | |
176 | + device_of_agent = config.get_device_for_agent(unit_name,agent) | |
177 | 177 | # get the index of the current component, agent couple |
178 | 178 | index = units_topologies[unit_name][category]["COMPONENT_AGENTS"].index(component_agent) |
179 | 179 | units_topologies[unit_name][category]["COMPONENT_AGENTS"][index][component_name] = device_of_agent |
... | ... | @@ -183,7 +183,7 @@ def obs_astronomer_config(request): |
183 | 183 | for component_agent in units_topologies[unit_name]["CHANNELS"][channel_name]["COMPONENT_AGENTS"] : |
184 | 184 | component_name = list(component_agent.keys())[0] |
185 | 185 | agent = component_agent[component_name] |
186 | - device_of_agent = config.get_device_for_agent(units[unit_name],agent) | |
186 | + device_of_agent = config.get_device_for_agent(unit_name,agent) | |
187 | 187 | index = units_topologies[unit_name]["CHANNELS"][channel_name]["COMPONENT_AGENTS"].index(component_agent) |
188 | 188 | units_topologies[unit_name]["CHANNELS"][channel_name]["COMPONENT_AGENTS"][index][component_name] = device_of_agent |
189 | 189 | |
... | ... | @@ -193,17 +193,17 @@ def obs_astronomer_config(request): |
193 | 193 | @login_required |
194 | 194 | @level_required("Admin") |
195 | 195 | def obs_agents_config(request): |
196 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
196 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
197 | 197 | units = config.get_units() |
198 | 198 | units_topologies = {} |
199 | 199 | active_agents_by_unit = {} |
200 | 200 | # for each unit |
201 | 201 | for unit_name in units: |
202 | - agents = config.get_agents(units[unit_name]) | |
202 | + agents = config.get_agents(unit_name) | |
203 | 203 | # list of active agents of the current unit |
204 | - active_agents_by_unit[unit_name] = config.get_active_agents(config.get_unit_by_name(unit_name)) | |
204 | + active_agents_by_unit[unit_name] = config.get_active_agents(unit_name) | |
205 | 205 | # topology of the current unit |
206 | - units_topologies[unit_name] = config.get_topology(units[unit_name]) | |
206 | + units_topologies[unit_name] = config.get_topology(unit_name) | |
207 | 207 | # removing channel_groups, not useful in this view |
208 | 208 | units_topologies[unit_name].pop("CHANNEL_GROUPS") |
209 | 209 | for category in units_topologies[unit_name]: |
... | ... | @@ -232,7 +232,7 @@ def obs_agents_config(request): |
232 | 232 | @login_required |
233 | 233 | @level_required("Admin","Operator","Unit-PI","Unit-board") |
234 | 234 | def edit_config(request): |
235 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
235 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
236 | 236 | return render(request,"obsconfig/edit_config.html",{"config_file":config.raw_config}) |
237 | 237 | |
238 | 238 | @login_required | ... | ... |
src/core/pyros_django/user_manager/views.py
... | ... | @@ -107,7 +107,7 @@ def login_validation(request): |
107 | 107 | View called when the user log in (form submitted) |
108 | 108 | ''' |
109 | 109 | if request.user.is_authenticated: |
110 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
110 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
111 | 111 | observatory_name = config.get_obs_name() |
112 | 112 | first_unit_name = config.get_units_name()[0] |
113 | 113 | request.session["obsname"] = observatory_name+" "+first_unit_name |
... | ... | @@ -165,7 +165,7 @@ def user_logout(request): |
165 | 165 | ''' |
166 | 166 | |
167 | 167 | logout(request) |
168 | - config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) | |
168 | + config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) | |
169 | 169 | observatory_name = config.get_obs_name() |
170 | 170 | first_unit_name = config.get_units_name()[0] |
171 | 171 | request.session["obsname"] = observatory_name+" "+first_unit_name | ... | ... |