当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.InvalidInput方法代码示例

本文整理汇总了Python中neutron_lib.exceptions.InvalidInput方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.InvalidInput方法的具体用法?Python exceptions.InvalidInput怎么用?Python exceptions.InvalidInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neutron_lib.exceptions的用法示例。


在下文中一共展示了exceptions.InvalidInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_port_mask

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def get_port_mask(min_port, max_port):
    """get port/mask serial by port range."""
    if min_port < 1 or max_port > 0xffff or min_port > max_port:
        msg = _("the port range is invalid")
        raise exceptions.InvalidInput(error_message=msg)
    masks = []
    while min_port <= max_port:
        mask = 0xffff
        while mask != 0:
            next_mask = (mask << 1) & 0xffff
            port_start = min_port & next_mask
            port_end = min_port + (next_mask ^ 0xffff)
            if port_start == min_port and port_end <= max_port:
                mask = next_mask
            else:
                break
        masks.append('0x%x/0x%x' % (min_port, mask))
        min_port = min_port + (mask ^ 0xffff) + 1

    return masks 
开发者ID:openstack,项目名称:networking-sfc,代码行数:22,代码来源:ovs_ext_lib.py

示例2: convert_to_positive_float_or_none

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def convert_to_positive_float_or_none(val):
    """Converts a value to a python float if the value is positive.

    :param val: The value to convert to a positive python float.
    :returns: The value as a python float. If the val is None, None is
        returned.
    :raises ValueError, InvalidInput: A ValueError is raised if the 'val'
        is a float, but is negative. InvalidInput is raised if 'val' can't be
        converted to a python float.
    """
    # NOTE(salv-orlando): This conversion function is currently used by
    # a vendor specific extension only at the moment  It is used for
    # port's RXTX factor in neutron.plugins.vmware.extensions.qos.
    # It is deemed however generic enough to be in this module as it
    # might be used in future for other API attributes.
    if val is None:
        return
    try:
        val = float(val)
        if val < 0:
            raise ValueError()
    except (ValueError, TypeError):
        msg = _("'%s' must be a non negative decimal") % val
        raise n_exc.InvalidInput(error_message=msg)
    return val 
开发者ID:openstack,项目名称:neutron-lib,代码行数:27,代码来源:converters.py

示例3: convert_kvp_list_to_dict

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def convert_kvp_list_to_dict(kvp_list):
    """Convert a list of 'key=value' strings to a dict.

    :param kvp_list: A list of key value pair strings. For more info on the
        format see; convert_kvp_str_to_list().
    :returns: A dict who's key value pairs are populated by parsing 'kvp_list'.
    :raises InvalidInput: If any of the key value strings are malformed.
    """
    if kvp_list == ['True']:
        # No values were provided (i.e. '--flag-name')
        return {}
    kvp_map = {}
    for kvp_str in kvp_list:
        key, value = convert_kvp_str_to_list(kvp_str)
        kvp_map.setdefault(key, set())
        kvp_map[key].add(value)
    return dict((x, list(y)) for x, y in kvp_map.items()) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:19,代码来源:converters.py

示例4: validate_any_key_specs_or_none

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def validate_any_key_specs_or_none(data, key_specs=None):
    """Validate each dict in a list matches at least 1 key_spec.

    :param data: The list of dicts to validate.
    :param key_specs: An iterable collection of key spec dicts that is used
        to check each dict in data.
    :returns: None.
    :raises InvalidInput: If any of the dicts in data do not match at least
        1 of the key_specs given.
    """
    if data is None:
        return

    def dict_validator(data_dict):
        msg = _validate_any_key_spec(data_dict, key_specs=key_specs)
        if msg:
            raise n_exc.InvalidInput(error_message=msg)

    msg = _validate_list_of_items(dict_validator, data)
    if msg:
        raise n_exc.InvalidInput(error_message=msg) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:23,代码来源:__init__.py

示例5: test_validate_no_whitespace

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_validate_no_whitespace(self):
        data = 'no_white_space'
        result = validators.validate_no_whitespace(data)
        self.assertEqual(data, result)

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i have whitespace')

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i\thave\twhitespace')

        for ws in string.whitespace:
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              '%swhitespace-at-head' % ws)
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              'whitespace-at-tail%s' % ws) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:22,代码来源:test_validators.py

示例6: do_action_groups

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def do_action_groups(self, action, kwargs_list):
        group_strs = [_build_group_expr_str(kw, action) for kw in kwargs_list]
        if action == 'add' or action == 'del':
            cmd = '%s-groups' % action
        elif action == 'mod':
            cmd = '%s-group' % action
        else:
            msg = _("Action is illegal")
            raise exceptions.InvalidInput(error_message=msg)
        self.run_ofctl(cmd, ['-'], '\n'.join(group_strs)) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:12,代码来源:ovs_ext_lib.py

示例7: _build_group_expr_str

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def _build_group_expr_str(group_dict, cmd):
    group_expr_arr = []
    buckets = None
    group_id = None

    if cmd != 'del':
        if "group_id" not in group_dict:
            msg = _("Must specify one group Id on group addition"
                    " or modification")
            raise exceptions.InvalidInput(error_message=msg)
        group_id = "group_id=%s" % group_dict.pop('group_id')

        if "buckets" not in group_dict:
            msg = _("Must specify one or more buckets on group addition"
                    " or modification")
            raise exceptions.InvalidInput(error_message=msg)
        buckets = "%s" % group_dict.pop('buckets')

    if group_id:
        group_expr_arr.append(group_id)

    for key, value in group_dict.items():
        group_expr_arr.append("%s=%s" % (key, value))

    if buckets:
        group_expr_arr.append(buckets)

    return ','.join(group_expr_arr) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:30,代码来源:ovs_ext_lib.py

示例8: test_invalid_min_port

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_invalid_min_port(self):
        self.assertRaises(
            exceptions.InvalidInput,
            ovs_ext_lib.get_port_mask,
            0, 100
        ) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:8,代码来源:test_ovs_ext_lib.py

示例9: test_invalid_max_port

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_invalid_max_port(self):
        self.assertRaises(
            exceptions.InvalidInput,
            ovs_ext_lib.get_port_mask,
            100, 65536
        ) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:8,代码来源:test_ovs_ext_lib.py

示例10: validate_network_mapping_list

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def validate_network_mapping_list(network_mapping, check_vlan):
    """Validate network mapping list in connection."""
    if network_mapping.get('segmentation_id'):
        if check_vlan:
            raise exceptions.InvalidInput(
                error_message=_("default segmentation_id should not be"
                                " provided when segmentation_id is assigned"
                                " during l2gateway creation"))
        seg_id = network_mapping.get(constants.SEG_ID)
        is_valid_vlan_id(seg_id)

    if not network_mapping.get('segmentation_id'):
        if check_vlan is False:
            raise exceptions.InvalidInput(
                error_message=_("Segmentation id must be specified in create "
                                "l2gateway connections"))
    network_id = network_mapping.get(constants.NETWORK_ID)
    if not network_id:
        raise exceptions.InvalidInput(
            error_message=_("A valid network identifier must be specified "
                            "when connecting a network to a network "
                            "gateway. Unable to complete operation"))
    connection_attrs = set(network_mapping.keys())
    if not connection_attrs.issubset(ALLOWED_CONNECTION_ATTRIBUTES):
        raise exceptions.InvalidInput(
            error_message=(_("Invalid keys found among the ones provided "
                             "in request : %(connection_attrs)s."),
                           connection_attrs))
    return network_id 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:31,代码来源:l2gw_validators.py

示例11: is_valid_vlan_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def is_valid_vlan_id(seg_id):
    try:
        int_seg_id = int(seg_id)
    except ValueError:
        msg = _("Segmentation id must be a valid integer")
        raise exceptions.InvalidInput(error_message=msg)
    if int_seg_id < 0 or int_seg_id >= 4095:
        msg = _("Segmentation id is out of range")
        raise exceptions.InvalidInput(error_message=msg) 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:11,代码来源:l2gw_validators.py

示例12: test_validate_network_mapping_list_with_seg_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_validate_network_mapping_list_with_seg_id(self):
        network_mapping = {'segmentation_id': 67}
        check_vlan = True
        self.assertRaises(exceptions.InvalidInput,
                          l2gw_validators.validate_network_mapping_list,
                          network_mapping, check_vlan) 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:8,代码来源:test_l2gw_validators.py

示例13: test_validate_network_mapping_list_without_seg_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_validate_network_mapping_list_without_seg_id(self):
        network_mapping = {'segmentation_id': ''}
        check_vlan = False
        self.assertRaises(exceptions.InvalidInput,
                          l2gw_validators.validate_network_mapping_list,
                          network_mapping, check_vlan) 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:8,代码来源:test_l2gw_validators.py

示例14: test_validate_network_mapping_list_for_empty_network_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_validate_network_mapping_list_for_empty_network_id(self):
        network_mapping = {'segmentation_id': '', 'network_id': ''}
        check_vlan = True
        self.assertRaises(exceptions.InvalidInput,
                          l2gw_validators.validate_network_mapping_list,
                          network_mapping, check_vlan) 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:8,代码来源:test_l2gw_validators.py

示例15: test_is_valid_vlan_id_for_value_less_than_0

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import InvalidInput [as 别名]
def test_is_valid_vlan_id_for_value_less_than_0(self):
        seg_id = -1
        self.assertRaises(exceptions.InvalidInput,
                          l2gw_validators.is_valid_vlan_id,
                          seg_id) 
开发者ID:openstack,项目名称:networking-l2gw,代码行数:7,代码来源:test_l2gw_validators.py


注:本文中的neutron_lib.exceptions.InvalidInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。