本文整理匯總了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}))