本文整理汇总了Python中networkapi.vlan.models.TipoRede.save方法的典型用法代码示例。如果您正苦于以下问题:Python TipoRede.save方法的具体用法?Python TipoRede.save怎么用?Python TipoRede.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.vlan.models.TipoRede
的用法示例。
在下文中一共展示了TipoRede.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_post
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import save [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Treat POST requests to add new network types.
URL: /net_type/
"""
try:
# Check permission
if not has_perm(user, AdminPermission.NETWORK_TYPE_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Get request XML data
xml_map, attrs_map = loads(request.raw_post_data)
# Get networkapi tag map
networkapi_map = xml_map.get('networkapi')
if networkapi_map is None:
return self.response_error(3, u'There is no networkapi tag from request XML.')
# Get net_type tag map
net_type_map = networkapi_map.get('net_type')
if net_type_map is None:
return self.response_error(3, u'There is no tipo_rede tag from request XML.')
# Valid name attribute
name = net_type_map.get('name')
if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 100):
self.log.error(
u'Parameter %s is invalid. Value: %s.', 'name', name)
raise InvalidValueError(None, 'name', name)
net_type = TipoRede(tipo_rede=name)
try:
TipoRede.get_by_name(net_type.tipo_rede)
raise NetworkTypeNameDuplicatedError(
None, u'Network type with name %s already exist' % net_type.tipo_rede)
except NetworkTypeNotFoundError:
pass
try:
net_type.save(user)
except Exception, e:
self.log.error(u'Failed to insert network type.')
raise VlanError(e, u'Failed to insert network type.')
net_type_map = dict()
net_type_map['id'] = net_type.id
return self.response(dumps_networkapi({'net_type': net_type_map}))