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


Python Serializer.keys方法代码示例

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


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

示例1: post

# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import keys [as 别名]
 def post(self, request, *args, **kwargs):
     from ralph.urls import LATEST_API
     try:
         actor = User.objects.get(
             username=ApiKeyAuthentication().get_identifier(request)
         )
     except User.DoesNotExist:
         actor = None
     if not (actor and actor.profile.has_perm(Perm.has_core_access)):
         return HttpResponse(
             unicode(_('You cannot create new devices')),
             status=401
         )
     data = Serializer().deserialize(
         request.body,
         format=request.META.get('CONTENT_TYPE', 'application/json')
     )
     missing_keys = {
         'mac',
         'network',
         'management-ip',
         'venture',
         'venture-role'
     } - set(data.keys())
     if missing_keys:
         return HttpResponse(
             _('Missing data: {}').format(', '.join(missing_keys)),
             status=400,
         )
     mac = MACAddressField.normalize(data['mac'])
     existing_mac = DHCPEntry.objects.filter(mac=mac).count()
     if existing_mac:
         return HttpResponse(unicode(_('MAC already exists')), status=400)
     parent = self.get_parent_device(data)
     try:
         ip_addr = get_first_free_ip(data['network'])
     except Network.DoesNotExist:
         raise Http404('No network with such name exists')
     hostname = self.get_hostname(parent)
     venture = get_object_or_404(
         Venture,
         symbol=data['venture']
     )
     role_name = data.get('venture-role')
     role = role_name and get_object_or_404(
         VentureRole,
         venture=venture,
         name=role_name,
     )
     ethernets = [Eth(
         'DEPLOYMENT MAC',
         mac,
         EthernetSpeed.unknown,
     )]
     device = Device.create(
         ethernets=ethernets,
         model_type=DeviceType.unknown,
         model_name='Unknown',
         verified=True,
     )
     device.name = hostname
     device.parent = parent
     device.venture = venture
     device.venture_role = role
     device.rack = parent.rack
     device.dc = parent.dc
     device.save()
     IPAddress.objects.create(
         address=ip_addr,
         device=device,
         hostname=hostname,
     )
     reset_dns(hostname, ip_addr)
     reset_dhcp(ip_addr, data['mac'])
     resp = HttpResponse('', status=201)
     resp['Location'] = LATEST_API.canonical_resource_for(
         'dev'
     ).get_resource_uri(device)
     return resp
开发者ID:4i60r,项目名称:ralph,代码行数:81,代码来源:deploy.py


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