本文整理汇总了Python中neutron.api.v2.attributes._validate_dict_or_empty函数的典型用法代码示例。如果您正苦于以下问题:Python _validate_dict_or_empty函数的具体用法?Python _validate_dict_or_empty怎么用?Python _validate_dict_or_empty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_validate_dict_or_empty函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_portinfo
def _validate_portinfo(self, profile):
key_specs = {
'portinfo:datapath_id': {'type:string': None, 'required': True},
'portinfo:port_no': {'type:non_negative': None, 'required': True,
'convert_to': attrs.convert_to_int}
}
msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs)
if msg:
raise q_exc.InvalidInput(error_message=msg)
datapath_id = profile.get('portinfo:datapath_id')
port_no = profile.get('portinfo:port_no')
try:
dpid = int(datapath_id, 16)
except ValueError:
raise nexc.ProfilePortInfoInvalidDataPathId()
if dpid > 0xffffffffffffffffL:
raise nexc.ProfilePortInfoInvalidDataPathId()
# Make sure dpid is a hex string beginning with 0x.
dpid = hex(dpid)
if int(port_no) > 65535:
raise nexc.ProfilePortInfoInvalidPortNo()
return {'datapath_id': dpid, 'port_no': port_no}
示例2: test_validate_dict_or_empty
def test_validate_dict_or_empty(self):
dictionary, constraints = self._construct_dict_and_constraints()
# Check whether an empty dictionary is valid.
msg = attributes._validate_dict_or_empty({}, constraints)
self.assertIsNone(msg, 'Validation of a None dictionary failed.')
# Check validation of a regular dictionary.
msg = attributes._validate_dict_or_none(dictionary, constraints)
self.assertIsNone(msg, 'Validation of a valid dictionary failed.')
self.assertIsNone(msg, 'Validation of a valid dictionary failed.')
示例3: _validate_service_context_list
def _validate_service_context_list(data, valid_values=None):
if not isinstance(data, list):
msg = _("invalid data format for service context list: '%s'") % data
LOG.debug(msg)
return msg
key_specs = {
'network_id': {'type:uuid': None},
'subnet_id': {'type:uuid': None},
'port_id': {'type:uuid': None},
'router_id': {'type:uuid': None},
'role': {'type:string': None},
'index': {'type:non_negative': None,
'convert_to': attr.convert_to_int},
}
for sc_entry in data:
msg = attr._validate_dict_or_empty(sc_entry, key_specs=key_specs)
if msg:
LOG.debug(msg)
return msg
示例4: _validate_portinfo
def _validate_portinfo(self, profile):
key_specs = {
"datapath_id": {"type:string": None, "required": True},
"port_no": {"type:non_negative": None, "required": True, "convert_to": attrs.convert_to_int},
}
msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs)
if msg:
raise n_exc.InvalidInput(error_message=msg)
datapath_id = profile.get("datapath_id")
port_no = profile.get("port_no")
try:
dpid = int(datapath_id, 16)
except ValueError:
raise nexc.ProfilePortInfoInvalidDataPathId()
if dpid > 0xFFFFFFFFFFFFFFFFL:
raise nexc.ProfilePortInfoInvalidDataPathId()
# Make sure dpid is a hex string beginning with 0x.
dpid = hex(dpid)
if int(port_no) > 65535:
raise nexc.ProfilePortInfoInvalidPortNo()
return {"datapath_id": dpid, "port_no": port_no}