當前位置: 首頁>>代碼示例>>Python>>正文


Python voluptuous.MultipleInvalid方法代碼示例

本文整理匯總了Python中voluptuous.MultipleInvalid方法的典型用法代碼示例。如果您正苦於以下問題:Python voluptuous.MultipleInvalid方法的具體用法?Python voluptuous.MultipleInvalid怎麽用?Python voluptuous.MultipleInvalid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在voluptuous的用法示例。


在下文中一共展示了voluptuous.MultipleInvalid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def validate(schema, data):
    """
    Wrap the call to voluptuous schema to raise the proper exception.

    Args:
        schema: The voluptuous Schema object
        data: The validation data for the schema object

    Raises:
        PicoException with 400 status code and the voluptuous error message

    """
    try:
        schema(data)
    except MultipleInvalid as error:
        raise PicoException(error.msg, 400) 
開發者ID:picoCTF,項目名稱:picoCTF,代碼行數:18,代碼來源:common.py

示例2: process_config_enviroment

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_config_enviroment(self):
        log.log(log.LOG_INFO, "Processing Environments")
        envlist = self.fm.environments.index(per_page=99999)['results']
        for env in self.get_config_section('environment'):
            try:
                self.validator.enviroment(env)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create Environment '{0}': YAML validation Error: {1}".format(env['name'], e))
                continue

            env_id = False
            # fm.media.show(name) does not work, we need to iterate over fm.media.index()
            for envc in envlist:
                if (env['name'] == envc['name']):
                    env_id = envc['id']
                    log.log(log.LOG_DEBUG, "Environment '{0}' (id={1}) already present.".format(env['name'], env_id))
                    continue
            if not env_id:
                log.log(log.LOG_INFO, "Create Environment '{0}'".format(env['name']))
                self.fm.environments.create( environment = { 'name': env['name'] } ) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:22,代碼來源:importer.py

示例3: process_config_model

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_config_model(self):
        log.log(log.LOG_INFO, "Processing Models")
        for model in self.get_config_section('model'):
            try:
                self.validator.model(model)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create Model '{0}': YAML validation Error: {1}".format(model['name'], e))
                continue
            try:
                model_id = self.fm.models.show(model['name'])['id']
                log.log(log.LOG_DEBUG, "Model '{0}' (id={1}) already present.".format(model['name'], model_id))
            except:
                log.log(log.LOG_INFO, "Create Model '{0}'".format(model['name']))
                model_tpl = {
                    'name':             model['name'],
                    'info':             model['info'],
                    'vendor_class':     model['vendor-class'],
                    'hardware_model':   model['hardware-model']
                }
                self.fm.models.create( model = model_tpl ) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:22,代碼來源:importer.py

示例4: process_config_medium

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_config_medium(self):
        log.log(log.LOG_INFO, "Processing Media")
        medialist = self.fm.media.index(per_page=99999)['results']
        for medium in self.get_config_section('medium'):
            try:
                self.validator.medium(medium)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create Media '{0}': YAML validation Error: {1}".format(medium['name'], e))
                continue

            medium_id = False
            # fm.media.show(name) does not work, we need to iterate over fm.media.index()
            for mediac in medialist:
                if (mediac['name'] == medium['name']):
                    medium_id = mediac['id']
                    log.log(log.LOG_DEBUG, "Medium '{0}' (id={1}) already present.".format(medium['name'], medium_id))
            if not medium_id:
                log.log(log.LOG_INFO, "Create Medium '{0}'".format(medium['name']))
                medium_tpl = {
                    'name':        medium['name'],
                    'path':        medium['path'],
                    'os_family':   medium['os-family']
                }
                self.fm.media.create( medium = medium_tpl ) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:26,代碼來源:importer.py

示例5: process_config_ptable

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_config_ptable(self):
        log.log(log.LOG_INFO, "Processing Partition Tables")
        for ptable in self.get_config_section('partition-table'):
            try:
                self.validator.ptable(ptable)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create Partition Table '{0}': YAML validation Error: {1}".format(ptable['name'], e))
                continue
            try:
                ptable_id = self.fm.ptables.show(ptable['name'])['id']
                log.log(log.LOG_DEBUG, "Partition Table '{0}' (id={1}) already present.".format(ptable['name'], ptable_id))
            except:
                log.log(log.LOG_INFO, "Create Partition Table '{0}'".format(ptable['name']))
                ptable_tpl = {
                    'name':             ptable['name'],
                    'layout':           ptable['layout'],
                    'snippet':          ptable['snippet'],
                    'audit_comment':    ptable['audit-comment'],
                    'locked':           ptable['locked'],
                    'os_family':        ptable['os-family']
                }
                self.fm.ptables.create( ptable = ptable_tpl ) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:24,代碼來源:importer.py

示例6: process_auth_sources_ldap

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_auth_sources_ldap(self):
        log.log(log.LOG_INFO, "Processing LDAP auth sources")
        for auth in self.get_config_section('auth-source-ldap'):
            # validate yaml
            try:
                self.validator.auth_source_ldaps(auth)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create LDAP source '{0}': YAML validation Error: {1}".format(auth['name'], e))
                continue
            try:
                as_id   = self.fm.auth_source_ldaps.show(auth['name'])['id']
                log.log(log.LOG_WARN, "LDAP source {0} allready exists".format(auth['name']))
                continue
            except TypeError:
                pass
            ldap_auth_obj = self.dict_underscore(auth)
            try:
                self.fm.auth_source_ldaps.create( auth_source_ldap=ldap_auth_obj )
            except:
                log.log(log.LOG_ERROR, "Something went wrong creating LDAP source {0}".format(auth['name'])) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:22,代碼來源:importer.py

示例7: process_cleanup_computeprfl

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_cleanup_computeprfl(self):
        log.log(log.LOG_INFO, "Processing Cleanup of Compute profiles")
        for computeprfl in self.get_config_section('cleanup-compute-profile'):
            try:
                self.validator.cleanup_computeprfl(computeprfl)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot delete Compute profile '{0}': YAML validation Error: {1}".format(computeprfl['name'], e))
                continue

            try:
                self.fm.compute_profiles.show(computeprfl['name'])['id']
                log.log(log.LOG_INFO, "Delete Compute profile '{0}'".format(computeprfl['name']))

                self.fm.compute_profiles.destroy( computeprfl['name'] )
            except:
                log.log(log.LOG_WARN, "Compute profile '{0}' already absent.".format(computeprfl['name'])) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:18,代碼來源:cleanup.py

示例8: process_cleanup_medium

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_cleanup_medium(self):
        log.log(log.LOG_INFO, "Processing Cleanup of Media")
        medialist = self.fm.media.index(per_page=99999)['results']
        for medium in self.get_config_section('cleanup-medium'):
            try:
                self.validator.cleanup_medium(medium)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot delete Medium '{0}': YAML validation Error: {1}".format(medium['name'], e))
                continue

            medium_deleted = False
            # fm.media.show(name) does not work, we need to iterate over fm.media.index()
            for mediac in medialist:
                if (mediac['name'] == medium['name']):
                    medium_deleted = True
                    log.log(log.LOG_INFO, "Delete Medium '{0}'".format(medium['name']))

                    self.fm.media.destroy( medium['name'] )
                    continue
            if not medium_deleted:
                log.log(log.LOG_WARN, "Medium '{0}' already absent.".format(medium['name'])) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:23,代碼來源:cleanup.py

示例9: process_cleanup_ptable

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def process_cleanup_ptable(self):
        log.log(log.LOG_INFO, "Processing Cleanup of Partition Tables")
        for ptable in self.get_config_section('cleanup-partition-table'):
            try:
                self.validator.cleanup_ptable(ptable)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot delete Partition Table '{0}': YAML validation Error: {1}".format(ptable['name'], e))
                continue

            try:
                self.fm.ptables.show(ptable['name'])['id']
                log.log(log.LOG_INFO, "Delete Partition Table '{0}'".format(ptable['name']))

                self.fm.ptables.destroy( ptable['name'] )
            except:
                log.log(log.LOG_WARN, "Partition Table '{0}' already absent.".format(ptable['name'])) 
開發者ID:adfinis-sygroup,項目名稱:foreman-yml,代碼行數:18,代碼來源:cleanup.py

示例10: validate

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def validate(self, config: dict) -> dict:
        """Validates a given voluptuous schema

        Args:
            config: Takeoff configuration

        Returns:
            The validated schema

        Raises:
            MultipleInvalid
            Invalid
        """
        try:
            return self.schema()(config)
        except (vol.MultipleInvalid, vol.Invalid) as e:
            logger.error(e)
            logger.error(pprint.pformat(config))
            raise e 
開發者ID:schipholgroup,項目名稱:takeoff,代碼行數:21,代碼來源:step.py

示例11: test_root_schema_invalid

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def test_root_schema_invalid(self):

        test_data = {
            'kind': 'RootCA',
            'metadata': {
                'name': 'test-root-ca',
                'description': 'Test Root CA'
            },
            'spec': {
                'key_type': 'rsa',
                'key_bits': 4096,
            }
        }

        with self.assertRaises(voluptuous.MultipleInvalid):
            self.assertIsInstance(schemas.RootCASchema(test_data), dict) 
開發者ID:bincyber,項目名稱:pkictl,代碼行數:18,代碼來源:test_schemas.py

示例12: test_intermediate_schema_invalid

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def test_intermediate_schema_invalid(self):

        test_data = {
            'kind': 'IntermediateCA',
            'metadata': {
                'name': 'test-intermediate-ca',
                'description': 'Test Intermediate CA',
                'issuer': 'test-root-ca'
            },
            'spec': {
                'type': 'internal',
                'key_type': 'ec',
                'key_bits': 8192
            }
        }

        with self.assertRaises(voluptuous.MultipleInvalid):
            self.assertIsInstance(schemas.IntermediateCASchema(test_data), dict) 
開發者ID:bincyber,項目名稱:pkictl,代碼行數:20,代碼來源:test_schemas.py

示例13: _check_certificate

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def _check_certificate(cert):
    _errors = []
    cert = load_certificate(cert)
    is_expired = verify_certificate_expiration(cert)
    has_supported_alg = verify_certificate_algorithm(cert)
    no_sha1 = verify_bad_certificate_algorithm(cert)
    if is_expired:
        _errors.append(
            Invalid('Il certificato è scaduto.')
        )
    if not has_supported_alg:
        _errors.append(
            Invalid('Il certificato deve essere firmato con un algoritmo valido.')
        )
    if not no_sha1:
        _errors.append(
            Invalid('Il certificato non deve essere firmato tramite algoritmo SHA1 (deprecato).')
        )
    if _errors:
        raise MultipleInvalid(errors=_errors)
    return cert 
開發者ID:italia,項目名稱:spid-testenv2,代碼行數:23,代碼來源:validators.py

示例14: get_all_metrics

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def get_all_metrics():
    try:
        metrics_conf = collector.validate_conf(
            ck_utils.load_conf(CONF.collect.metrics_conf))
    except (voluptuous.Invalid, voluptuous.MultipleInvalid):
        msg = 'Invalid endpoint: no metrics in current configuration.'
        pecan.abort(405, msg)

    policy.authorize(pecan.request.context, 'info:list_metrics_info', {})
    metrics_info_list = []
    for metric_name, metric in metrics_conf.items():
        info = metric.copy()
        info['metric_id'] = info['alt_name']
        metrics_info_list.append(
            info_models.CloudkittyMetricInfo(**info))
    return info_models.CloudkittyMetricInfoCollection(
        metrics=metrics_info_list) 
開發者ID:openstack,項目名稱:cloudkitty,代碼行數:19,代碼來源:info.py

示例15: validate

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import MultipleInvalid [as 別名]
def validate(logger, data, schema, where):
    """
    Generic validation of a data structure against schema
    using Voluptuous data validation library
    Parameters:
     - logger: valid logger reference
     - data: structure to validate
     - schema: a valid Voluptuous schema
     - where: string for debugging purposes to identity the policy location
    """
    logger.debug("validating data=%s", data)
    try:
        #*** Check correctness of data against schema with Voluptuous:
        schema(data)
    except MultipleInvalid as exc:
        #*** There was a problem with the data:
        logger.critical("Voluptuous detected a problem where=%s, exception=%s",
                                                                    where, exc)
        sys.exit("Exiting nmeta. Please fix error in main_policy.yaml")
    return 1 
開發者ID:mattjhayes,項目名稱:nmeta,代碼行數:22,代碼來源:policy.py


注:本文中的voluptuous.MultipleInvalid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。