"""clean host installing progress."""
        self.host_provider_.clean_host_installing_progress(hostid)

    def clean_cluster_installing_progress(self, clusterid):
        """clean cluster installing progress."""
        self.host_provider_.clean_cluster_installing_progress(clusterid)

    def clean_cluster_config(self, clusterid):
        """clean cluster config."""
        self.host_provider_.clean_cluster_config(clusterid)

    def get_cluster_hosts(self, clusterid):
        """get cluster hosts."""
        return self.host_provider_.get_cluster_hosts(clusterid)

    def get_clusters(self):
        """get clusters."""
        return self.host_provider_.get_clusters()

    def get_switch_and_machines(self):
        """get switch and machines."""
        return self.host_provider_.get_switch_and_machines()

    def update_switch_and_machines(self, switches, switch_machines):
        """update siwtch and machines."""
        self.host_provider_.update_switch_and_machines(
            switches, switch_machines)


config_provider.register_provider(MixProvider)
            logging.error('failed to read file %s', filename)
            logging.exception(error)
            return {}

        if cls._config_format_python(config_format):
            try:
                exec(content, config_globals, config_locals)
            except Exception as error:
                logging.error('failed to exec %s', content)
                logging.exception(error)
                return {}

        elif cls._config_format_json(config_format):
            try:
                config_locals = json.loads(content)
            except Exception as error:
                logging.error('failed to load json data %s', content)
                logging.exception(error)
                return {}

        return config_locals

    def get_global_config(self):
        """read global config from file."""
        return self._read_config_from_file(
            self._global_config_filename(),
            self._config_format())


config_provider.register_provider(FileProvider)
            })
            switch_machines_data[switch.ip] = []
            for machine in switch.machines:
                switch_machines_data[switch.ip].append({
                    'mac': machine.mac,
                    'port': machine.port,
                    'vlan': machine.vlan,
                })

        return switches_data, switch_machines_data

    def update_switch_and_machines(
        self, switches, switch_machines
    ):
        """update switches and machines."""
        session = database.current_session()
        session.query(Switch).delete(synchronize_session='fetch')
        session.query(Machine).delete(synchronize_session='fetch')
        for switch_data in switches:
            switch = Switch(**switch_data)
            logging.info('add switch %s', switch)
            session.add(switch)
            for machine_data in switch_machines.get(switch.ip, []):
                machine = Machine(**machine_data)
                logging.info('add machine %s under %s', machine, switch)
                machine.switch = switch
                session.add(machine)


config_provider.register_provider(DBProvider)
Exemple #4
0
        """clean host installing progress."""
        self.host_provider_.clean_host_installing_progress(hostid)

    def clean_cluster_installing_progress(self, clusterid):
        """clean cluster installing progress."""
        self.host_provider_.clean_cluster_installing_progress(clusterid)

    def clean_cluster_config(self, clusterid):
        """clean cluster config."""
        self.host_provider_.clean_cluster_config(clusterid)

    def get_cluster_hosts(self, clusterid):
        """get cluster hosts."""
        return self.host_provider_.get_cluster_hosts(clusterid)

    def get_clusters(self):
        """get clusters."""
        return self.host_provider_.get_clusters()

    def get_switch_and_machines(self):
        """get switch and machines."""
        return self.host_provider_.get_switch_and_machines()

    def update_switch_and_machines(self, switches, switch_machines):
        """update siwtch and machines."""
        self.host_provider_.update_switch_and_machines(switches,
                                                       switch_machines)


config_provider.register_provider(MixProvider)
Exemple #5
0
                'credential': switch.credential,
                'state': switch.state,
            })
            switch_machines_data[switch.ip] = []
            for machine in switch.machines:
                switch_machines_data[switch.ip].append({
                    'mac': machine.mac,
                    'port': machine.port,
                    'vlan': machine.vlan,
                })

        return switches_data, switch_machines_data

    def update_switch_and_machines(self, switches, switch_machines):
        """update switches and machines."""
        session = database.current_session()
        session.query(Switch).delete(synchronize_session='fetch')
        session.query(Machine).delete(synchronize_session='fetch')
        for switch_data in switches:
            switch = Switch(**switch_data)
            logging.info('add switch %s', switch)
            session.add(switch)
            for machine_data in switch_machines.get(switch.ip, []):
                machine = Machine(**machine_data)
                logging.info('add machine %s under %s', machine, switch)
                machine.switch = switch
                session.add(machine)


config_provider.register_provider(DBProvider)
 def test_found_provider(self):
     config_provider.register_provider(DummyProvider)
     provider = config_provider.get_provider_by_name(
         DummyProvider.NAME)
     self.assertIsInstance(provider, DummyProvider)
 def test_multi_registered_provider(self):
     config_provider.register_provider(DummyProvider)
     self.assertRaises(KeyError, config_provider.register_provider,
                       Dummy2Provider)
Exemple #8
0
        except Exception as error:
            logging.error('failed to read file %s', filename)
            logging.exception(error)
            return {}

        if cls._config_format_python(config_format):
            try:
                exec(content, config_globals, config_locals)
            except Exception as error:
                logging.error('failed to exec %s', content)
                logging.exception(error)
                return {}

        elif cls._config_format_json(config_format):
            try:
                config_locals = json.loads(content)
            except Exception as error:
                logging.error('failed to load json data %s', content)
                logging.exception(error)
                return {}

        return config_locals

    def get_global_config(self):
        """read global config from file."""
        return self._read_config_from_file(self._global_config_filename(),
                                           self._config_format())


config_provider.register_provider(FileProvider)
 def test_multi_registered_provider(self):
     """tst register multi provider with the same name."""
     config_provider.register_provider(DummyProvider)
     self.assertRaises(KeyError, config_provider.register_provider,
                       Dummy2Provider)
 def test_found_provider(self):
     """test found provider."""
     config_provider.register_provider(DummyProvider)
     provider = config_provider.get_provider_by_name(DummyProvider.NAME)
     self.assertIsInstance(provider, DummyProvider)
Exemple #11
0
 def test_multi_registered_provider(self):
     config_provider.register_provider(DummyProvider)
     self.assertRaises(KeyError, config_provider.register_provider,
                       Dummy2Provider)
 def test_multi_registered_provider(self):
     """tst register multi provider with the same name."""
     config_provider.register_provider(DummyProvider)
     self.assertRaises(KeyError, config_provider.register_provider,
                       Dummy2Provider)