コード例 #1
0
ファイル: apicommands.py プロジェクト: chbatey/saboteur
def build_add_fault_command(shell, params):
    if not params.has_key('type') or params['type'] not in FAULT_TYPES.keys():
        message = 'must be present and one of ' + str(alphabetical_keys(FAULT_TYPES))
        exception=MultipleInvalid()
        exception.add(Invalid(message, ['type'], message))
        raise exception
    return FAULT_TYPES[params['type']](shell, params)
コード例 #2
0
ファイル: apicommands.py プロジェクト: wontruefree/saboteur
def build_add_fault_command(shell, params):
    if not params.has_key('type') or params['type'] not in FAULT_TYPES.keys():
        message = 'must be present and one of ' + str(
            alphabetical_keys(FAULT_TYPES))
        exception = MultipleInvalid()
        exception.add(Invalid(message, ['type'], message))
        raise exception
    return FAULT_TYPES[params['type']](shell, params)
コード例 #3
0
ファイル: conf.py プロジェクト: mbookman/elasticluster
    def read_config(self):
        """Reads the configuration properties from the ini file and links the
        section to comply with the cluster config dictionary format.

        :return: dictionary containing all configuration properties from the
         ini file in compliance to the cluster config format
        :raises: :py:class:`voluptuous.MultipleInvalid` if not all sections
                 present or broken links between secitons
        """
        clusters = dict((key, value) for key, value in self.conf.iteritems() if
                        re.search(ConfigReader.cluster_section + "/(.*)", key)
                        and key.count("/") == 1)

        conf_values = dict()

        errors = MultipleInvalid()
        # FIXME: to be refactored:
        # we should check independently each one of the sections, and raise errors accordingly.

        for cluster in clusters:
            # Get the name of the cluster
            name = re.search(ConfigReader.cluster_section + "/(.*)",
                             cluster).groups()[0]
            if not name:
                errors.add("Invalid section name `%s`" % cluster)
                continue

            cluster_conf = dict(self.conf[cluster])

            try:
                self.schemas['cluster'](cluster_conf)
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add("Section `%s`: %s" % (cluster, error))
                continue

            cloud_name = ConfigReader.cloud_section + "/" + cluster_conf[
                'cloud']
            login_name = ConfigReader.login_section + "/" + cluster_conf[
                'login']
            setup_name = ConfigReader.setup_section + "/" + cluster_conf[
                'setup_provider']

            values = dict()
            values['cluster'] = cluster_conf
            try:
                values['setup'] = dict(self.conf[setup_name])
                self.schemas['setup'](values['setup'])
            except KeyError, ex:
                errors.add(
                    "cluster `%s` setup section `%s` does not exists" % (
                        cluster, setup_name))
            except MultipleInvalid, ex:
                for error in ex.errors:
                    errors.add(error)
コード例 #4
0
ファイル: conf.py プロジェクト: riccardomurri/elasticluster
    def read_config(self):
        """Reads the configuration properties from the ini file and links the
        section to comply with the cluster config dictionary format.

        :return: tuple of dictionaries (clusters, storage) containing
         all configuration properties from the ini file in compliance
         to the cluster config format, and global configuration options for the storage.

        :raises: :py:class:`voluptuous.MultipleInvalid` if not all sections
                 present or broken links between secitons

        """
        storage_section = self.conf.get('storage', {
            'storage_path': Configurator.default_storage_path,
            'storage_type': Configurator.default_storage_type})

        clusters = dict((key, value) for key, value in self.conf.iteritems() if
                        re.search(ConfigReader.cluster_section + "/(.*)", key)
                        and key.count("/") == 1)

        conf_values = dict()

        errors = MultipleInvalid()
        # FIXME: to be refactored:
        # we should check independently each one of the sections, and raise errors accordingly.

        for cluster in clusters:
            # Get the name of the cluster
            name = re.search(ConfigReader.cluster_section + "/(.*)",
                             cluster).groups()[0]
            if not name:
                errors.add("Invalid section name `%s`" % cluster)
                continue

            cluster_conf = dict(self.conf[cluster])

            try:
                self.schemas['cluster'](cluster_conf)
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add("Section `%s`: %s" % (cluster, error))
                continue

            cloud_name = ConfigReader.cloud_section + "/" + cluster_conf[
                'cloud']
            login_name = ConfigReader.login_section + "/" + cluster_conf[
                'login']
            setup_name = ConfigReader.setup_section + "/" + cluster_conf[
                'setup_provider']

            values = dict()
            values['cluster'] = cluster_conf
            try:
                values['setup'] = dict(self.conf[setup_name])
                self.schemas['setup'](values['setup'])
            except KeyError as ex:
                errors.add(
                    "cluster `%s` setup section `%s` does not exists" % (
                        cluster, setup_name))
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add(error)

            try:
                values['login'] = dict(self.conf[login_name])
                self.schemas['login'](values['login'])
            except KeyError as ex:
                errors.add(
                    "cluster `%s` login section `%s` does not exists" % (
                        cluster, login_name))
            except MultipleInvalid as ex:
                errors.add(Invalid("Error in login section `%s`: %s" % (
                    login_name, str.join(', ', [str(e) for e in ex.errors]))))

            try:
                values['cloud'] = dict(self.conf[cloud_name])
                self.schemas['cloud'](values['cloud'])
            except KeyError as ex:
                errors.add(
                    "cluster `%s` cloud section `%s` does not exists" % (
                        cluster, cloud_name))
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add(Invalid("section %s: %s" % (cloud_name, error)))

            try:
                # nodes can inherit the properties of cluster or overwrite them
                nodes = dict((key, value) for key, value in
                             values['cluster'].items() if
                             key.endswith('_nodes'))
                values['nodes'] = dict()
                for node in nodes.iterkeys():
                    node_name = re.search("(.*)_nodes", node).groups()[0]
                    property_name = "%s/%s/%s" % (ConfigReader.cluster_section,
                                                  name, node_name)
                    if property_name in self.conf:
                        node_values = dict(
                            (key, value.strip("'").strip('"')) for key, value
                            in self.conf[property_name].iteritems())
                        node_values = dict(
                            values['cluster'].items() + node_values.items())
                        values['nodes'][node_name] = node_values
                    else:
                        values['nodes'][node_name] = values['cluster']

                if errors.errors:
                    log.error("Ignoring cluster `%s`: %s" % (
                        name, str.join(", ", [str(e) for e in errors.errors])))
                else:
                    conf_values[name] = values
            except KeyError as ex:
                errors.add("Error in section `%s`" % cluster)

        # FIXME: do we really need to raise an exception if we cannot
        # parse *part* of the configuration files? We should just
        # ignore those with errors and return both the parsed
        # configuration values _and_ a list of errors
        if errors.errors:
            raise errors
        return (conf_values, storage_section)
コード例 #5
0
ファイル: conf.py プロジェクト: sternshus/elasticluster
    def read_config(self):
        """Reads the configuration properties from the ini file and links the
        section to comply with the cluster config dictionary format.

        :return: tuple of dictionaries (clusters, storage) containing
         all configuration properties from the ini file in compliance
         to the cluster config format, and global configuration options for the storage.

        :raises: :py:class:`voluptuous.MultipleInvalid` if not all sections
                 present or broken links between secitons

        """
        storage_section = self.conf.get(
            'storage', {
                'storage_path': Configurator.default_storage_path,
                'storage_type': Configurator.default_storage_type
            })

        clusters = dict((key, value) for key, value in self.conf.items()
                        if re.search(ConfigReader.cluster_section +
                                     "/(.*)", key) and key.count("/") == 1)

        conf_values = dict()

        errors = MultipleInvalid()
        # FIXME: to be refactored:
        # we should check independently each one of the sections, and raise errors accordingly.

        for cluster in clusters:
            # Get the name of the cluster
            name = re.search(ConfigReader.cluster_section + "/(.*)",
                             cluster).groups()[0]
            if not name:
                errors.add("Invalid section name `%s`" % cluster)
                continue

            cluster_conf = dict(self.conf[cluster])

            try:
                self.schemas['cluster'](cluster_conf)
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add("Section `%s`: %s" % (cluster, error))
                continue

            cloud_name = ConfigReader.cloud_section + "/" + cluster_conf[
                'cloud']
            login_name = ConfigReader.login_section + "/" + cluster_conf[
                'login']
            setup_name = ConfigReader.setup_section + "/" + cluster_conf[
                'setup_provider']

            values = dict()
            values['cluster'] = cluster_conf
            try:
                values['setup'] = dict(self.conf[setup_name])
                self.schemas['setup'](values['setup'])
            except KeyError as ex:
                errors.add("cluster `%s` setup section `%s` does not exists" %
                           (cluster, setup_name))
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add(error)

            try:
                values['login'] = dict(self.conf[login_name])
                self.schemas['login'](values['login'])
            except KeyError as ex:
                errors.add("cluster `%s` login section `%s` does not exists" %
                           (cluster, login_name))
            except MultipleInvalid as ex:
                errors.add(
                    Invalid("Error in login section `%s`: %s" %
                            (login_name,
                             str.join(', ', [str(e) for e in ex.errors]))))

            try:
                values['cloud'] = dict(self.conf[cloud_name])
                self.schemas['cloud'](values['cloud'])
            except KeyError as ex:
                errors.add("cluster `%s` cloud section `%s` does not exists" %
                           (cluster, cloud_name))
            except MultipleInvalid as ex:
                for error in ex.errors:
                    errors.add(Invalid("section %s: %s" % (cloud_name, error)))

            try:
                # nodes can inherit the properties of cluster or overwrite them
                nodes = dict((key, value)
                             for key, value in values['cluster'].items()
                             if key.endswith('_nodes'))
                values['nodes'] = dict()
                for node in nodes.keys():
                    node_name = re.search("(.*)_nodes", node).groups()[0]
                    property_name = "%s/%s/%s" % (ConfigReader.cluster_section,
                                                  name, node_name)
                    if property_name in self.conf:
                        node_values = dict(
                            (key, value.strip("'").strip('"'))
                            for key, value in self.conf[property_name].items())
                        node_values = dict(values['cluster'].items() +
                                           node_values.items())
                        values['nodes'][node_name] = node_values
                    else:
                        values['nodes'][node_name] = values['cluster']

                if errors.errors:
                    log.error(
                        "Ignoring cluster `%s`: %s" %
                        (name, str.join(", ", [str(e)
                                               for e in errors.errors])))
                else:
                    conf_values[name] = values
            except KeyError as ex:
                errors.add("Error in section `%s`" % cluster)

        # FIXME: do we really need to raise an exception if we cannot
        # parse *part* of the configuration files? We should just
        # ignore those with errors and return both the parsed
        # configuration values _and_ a list of errors
        if errors.errors:
            raise errors
        return (conf_values, storage_section)