• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python machine.start_machine_imaging函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中service.tasks.machine.start_machine_imaging函数的典型用法代码示例。如果您正苦于以下问题:Python start_machine_imaging函数的具体用法?Python start_machine_imaging怎么用?Python start_machine_imaging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: post

 def post(self, request, provider_id, identity_id):
     """
     Sends an e-mail to the admins to start
     the create_image process.
     """
     #request.DATA is r/o
     #Copy allows for editing
     data = copy.deepcopy(request.DATA)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis','public') != 'public':
         user_list  = re.split(', | |\n', data.get('shared_with',""))
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user] # Skips blanks
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         #Add parent machine to request
         machine_request = serializer.object
         machine_request.parent_machine = machine_request.instance.provider_machine
         serializer.save()
         #Object now has an ID for links..
         machine_request_id = serializer.object.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.has_trait("Auto-Imaging")
         requestImaging(request, machine_request_id,
                        auto_approve=auto_approve)
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data,
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
开发者ID:420reich,项目名称:atmosphere,代码行数:35,代码来源:machine_request.py


示例2: get

    def get(self, request,
            machine_request_id, action=None):
        """
        OPT 1 for approval: via GET with /approve or /deny
        This is a convenient way to approve requests remotely
        """

        user = request.user
        try:
            machine_request = CoreMachineRequest.objects.get(
                instance__source__provider__cloudadministrator__user=user,
                id=machine_request_id)
        except CoreMachineRequest.DoesNotExist:
            return Response('No machine request with id %s'
                            % machine_request_id,
                            status=status.HTTP_404_NOT_FOUND)

        if not action:
            serializer = MachineRequestSerializer(machine_request)
            return Response(serializer.data, status=status.HTTP_200_OK)

        # Don't update the request unless its pending or error
        # Otherwise use the existing status to 'start machine imaging'
        if machine_request.status in ['error', 'pending']:
            machine_request.status = action
            machine_request.save()

        # Only run task if status is 'approve'
        if machine_request.status == 'approve':
            start_machine_imaging(machine_request)

        serializer = MachineRequestSerializer(machine_request)
        return Response(serializer.data, status=status.HTTP_200_OK)
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:33,代码来源:cloud_admin.py


示例3: get

    def get(self, request, machine_request_id, action=None):
        """
        OPT 1 for approval: via GET with /approve or /deny
        This is a convenient way to approve requests remotely
        """
        if not request.user.is_staff:
            raise NotAuthenticated("Must be a staff user to view requests "
                                   "directly")

        try:
            machine_request = CoreMachineRequest.objects.get(
                id=machine_request_id)
        except CoreMachineRequest.DoesNotExist:
            return Response('No machine request with id %s'
                            % machine_request_id,
                            status=status.HTTP_404_NOT_FOUND)

        serializer = MachineRequestSerializer(machine_request)
        if not action:
            return Response(serializer.data, status=status.HTTP_200_OK)

        machine_request = serializer.object
        #Don't update the request unless its pending
        if machine_request.status in ['error','pending']:
            machine_request.status = action
            machine_request.save()

        #Only run task if status is 'approve'
        if machine_request.status == 'approve':
            start_machine_imaging(machine_request)

        serializer = MachineRequestSerializer(machine_request)
        return Response(serializer.data, status=status.HTTP_200_OK)
开发者ID:420reich,项目名称:atmosphere,代码行数:33,代码来源:machine_request.py


示例4: patch

    def patch(self, request, machine_request_id, action=None):
        """
        OPT2 for approval: sending a PATCH to the machine request with
          {"status":"approve/deny"}
        
        Modfiy attributes on a machine request
        """
        if not request.user.is_staff:
            raise NotAuthenticated("Must be a staff user to view requests "
                                   "directly")

        try:
            machine_request = CoreMachineRequest.objects.get(
                id=machine_request_id)
        except CoreMachineRequest.DoesNotExist:
            return Response('No machine request with id %s'
                            % machine_request_id,
                            status=status.HTTP_404_NOT_FOUND)

        data = request.DATA
        serializer = MachineRequestSerializer(machine_request, data=data,
                partial=True)
        if serializer.is_valid():
            #Only run task if status is 'approve'
            if machine_request.status == 'approve':
                start_machine_imaging(machine_request)
            machine_request.save()
        #Object may have changed
        serializer = MachineRequestSerializer(machine_request)
        return Response(serializer.data, status=status.HTTP_200_OK)
开发者ID:420reich,项目名称:atmosphere,代码行数:30,代码来源:machine_request.py


示例5: put

    def put(self, request, provider_uuid, identity_uuid, machine_request_id):
        """
        Authentication Required, update information on a pending request.
        """
        # Meta data changes in 'pending' are OK
        # Status change 'pending' --> 'cancel' are OK
        data = request.DATA
        try:
            machine_request = CoreMachineRequest.objects.get(
                id=machine_request_id)
        except CoreMachineRequest.DoesNotExist:
            return Response('No machine request with id %s'
                            % machine_request_id,
                            status=status.HTTP_404_NOT_FOUND)

        serializer = MachineRequestSerializer(machine_request,
                                              data=data, partial=True)
        if serializer.is_valid():
            # Only run task if status is 'approve'
            machine_request = serializer.object
            if machine_request.status == 'approve':
                start_machine_imaging(machine_request)
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:miquelcie,项目名称:atmosphere,代码行数:25,代码来源:machine_request.py


示例6: _create_image

 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     # request.DATA is r/o
     # Copy allows for editing
     data = copy.deepcopy(request.DATA)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis', 'public') != 'public':
         user_list = data.get('shared_with', '')
         if type(user_list) == str:
             user_list = re.split(', | |\n', user_list)
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user]  # Skips blanks
         # TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         # Add parent machine to request
         instance = serializer.validated_data['instance']
         parent_machine = instance.source.providermachine
         serializer.validated_data['parent_machine'] = parent_machine
         user = serializer.validated_data['new_machine_owner']
         identity_member = IdentityMembership.objects.get(
                 identity__provider=serializer.validated_data['new_machine_provider'],
                 identity__created_by=user)
         serializer.validated_data['membership'] = identity_member
         serializer.validated_data['created_by'] = user
         self._permission_to_image(identity_uuid, instance)
         machine_request = serializer.save()
         instance = machine_request.instance
         # NOTE: THIS IS A HACK -- While we enforce all images
         #       to go to iPlant Cloud - Tucson.
         # THIS CODE SHOULD BE REMOVED
         try:
             tucson_provider = Provider.objects.get(
                 location='iPlant Cloud - Tucson')
             if machine_request.new_machine_provider.location\
                != tucson_provider.location:
                 machine_request.new_machine_provider = tucson_provider
         except:
             # Will skip this step if no provider is named
             # iPlant Cloud - Tucson.
             pass
         serializer.save()
         # Object now has an ID for links..
         machine_request_id = machine_request.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(request, machine_request_id,
                        auto_approve=auto_approve)
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data,
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
开发者ID:singkorn,项目名称:atmosphere,代码行数:58,代码来源:machine_request.py


示例7: _create_image

 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     # request.data is r/o
     # Copy allows for editing
     data = copy.deepcopy(request.data)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis', 'public') != 'public':
         user_list = data.get('shared_with', '')
         if type(user_list) == str:
             user_list = re.split(', | |\n', user_list)
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user]    # Skips blanks
         # TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         # Add parent machine to request
         instance = serializer.validated_data['instance']
         parent_machine = instance.source.providermachine
         serializer.validated_data['parent_machine'] = parent_machine
         user = serializer.validated_data['new_machine_owner']
         identity_member = IdentityMembership.objects.get(
             identity__provider=serializer.
             validated_data['new_machine_provider'],
             identity__created_by=user
         )
         serializer.validated_data['membership'] = identity_member
         serializer.validated_data['created_by'] = user
         self._permission_to_image(identity_uuid, instance)
         pending_status, _ = StatusType.objects.get_or_create(name='pending')
         machine_request = serializer.save(status=pending_status)
         instance = machine_request.instance
         if getattr(settings, 'REPLICATION_PROVIDER_LOCATION'):
             try:
                 replication_provider = Provider.objects.get(
                     location=settings.REPLICATION_PROVIDER_LOCATION
                 )
                 if machine_request.new_machine_provider.location\
                    != replication_provider.location:
                     machine_request.new_machine_provider = replication_provider
             except:
                 # Will skip this step if no provider is named
                 # as the REPLICATION_PROVIDER_LOCATION
                 pass
         # Object now has an ID for links..
         machine_request_id = machine_request.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(
             request, machine_request_id, auto_approve=auto_approve
         )
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return bad_request(serializer.errors, prefix="Invalid value for ")
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:58,代码来源:machine_request.py


示例8: patch

    def patch(self, request, cloud_admin_uuid, machine_request_id, action=None):
        """
        OPT2 for approval: sending a PATCH to the machine request with
          {"status":"approve/deny"}

        Modfiy attributes on a machine request
        """
        user = request.user
        try:
            machine_request = CoreMachineRequest.objects.get(
                instance__source__provider__cloudadministrator__user=user,
                id=machine_request_id
            )
        except CoreMachineRequest.DoesNotExist:
            return Response(
                'No machine request with id %s' % machine_request_id,
                status=status.HTTP_404_NOT_FOUND
            )

        data = request.data
        # Behavior will remove 'status' if its being updated.
        # Status should only be updated if denied or skipped.
        # Status of 'approve','continue' will use the machine_request.status
        # to allow restarting the request at the correct point in time.
        start_request = False
        if 'status' in data:
            _status = data['status'].lower()
            if machine_request.old_status == 'completed':
                return Response(
                    "Cannot update status of 'completed' request",
                    status=status.HTTP_409_conflict
                )
            elif _status in ['approve', 'continue']:
                data.pop('status')
                start_request = True
            elif _status not in ['deny', 'skip']:
                return Response(
                    "Bad Status Value: %s. "
                    "Available choices for a status update are: "
                    "approve, continue, deny, skip"
                )
        serializer = MachineRequestSerializer(
            machine_request, data=data, partial=True
        )
        if not serializer.is_valid():
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST
            )
        # Only run task if status is 'approve'
        machine_request = serializer.save()
        mr_data = serializer.data
        if start_request:
            start_machine_imaging(machine_request)
        return Response(mr_data, status=status.HTTP_200_OK)
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:54,代码来源:cloud_admin.py


示例9: _create_image

 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     #request.DATA is r/o
     #Copy allows for editing
     data = copy.deepcopy(request.DATA)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis','public') != 'public':
         user_list  = re.split(', | |\n', data.get('shared_with',""))
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user] # Skips blanks
         #TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         #Add parent machine to request
         machine_request = serializer.object
         instance = machine_request.instance
         if instance.source.is_machine():
             machine_request.parent_machine = machine_request.instance\
                     .source.providermachine
         elif instance.source.is_volume():
             raise Exception(
                     "Instance of booted volume can NOT be imaged."
                     "Contact your Administrator for more information.")
         else:
             raise Exception(
                     "Instance source type cannot be determined."
                     "Contact your Administrator for more information.")
         #NOTE: THIS IS A HACK -- While we enforce all images to go to iPlant Cloud - Tucson.
         # THIS CODE SHOULD BE REMOVED 
         try:
             tucson_provider = Provider.objects.get(location='iPlant Cloud - Tucson')
             if machine_request.new_machine_provider.location != tucson_provider.location:
                 machine_request.new_machine_provider = tucson_provider
         except:
             pass
         serializer.save()
         #Object now has an ID for links..
         machine_request_id = serializer.object.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(request, machine_request_id,
                        auto_approve=auto_approve)
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data,
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
开发者ID:MMontgomeryII,项目名称:atmosphere,代码行数:52,代码来源:machine_request.py


示例10: submit_action

 def submit_action(self, instance):
     """
     Submits a resource request email
     """
     provider = instance.active_provider()
     pre_approved = provider.auto_imaging
     requestImaging(self.request, instance.id, auto_approve=pre_approved)
     
     if pre_approved:
         status, _ = StatusType.objects.get_or_create(name="approved")
         instance.status = status
         instance.save()
         start_machine_imaging(instance)
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:13,代码来源:machine_request.py


示例11: submit_action

    def submit_action(self, instance):
        """
        Submits a resource request email
        """
        #NOTE/FIXME: This should be considered when locking down "Imaging Strategy" for a "Provider Grouping"
        new_provider = self._get_new_provider()
        pre_approved = new_provider.auto_imaging
        requestImaging(self.request, instance.id, auto_approve=pre_approved)

        if pre_approved:
            status, _ = StatusType.objects.get_or_create(name="approved")
            instance.status = status
            instance.save()
            start_machine_imaging(instance)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:14,代码来源:machine_request.py


示例12: patch

    def patch(self, request, provider_id, identity_id, machine_request_id):
        """
        Meta data changes in 'pending' are OK
        Status change 'pending' --> 'cancel' are OK
        All other changes should FAIL
        """
        data = request.DATA
        try:
            machine_request = CoreMachineRequest.objects.get(id=machine_request_id)
        except CoreMachineRequest.DoesNotExist:
            return Response("No machine request with id %s" % machine_request_id, status=status.HTTP_404_NOT_FOUND)

        serializer = MachineRequestSerializer(machine_request, data=data, partial=True)
        if serializer.is_valid():
            machine_request = serializer.object
            if machine_request.status == "approve":
                start_machine_imaging(machine_request)
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:nickeddy,项目名称:atmosphere,代码行数:20,代码来源:machine_request.py


示例13: approve_action

 def approve_action(self, instance):
     """
     Updates the resource for the request
     """
     start_machine_imaging(instance)
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:5,代码来源:machine_request.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python service_api.ServiceApi类代码示例发布时间:2022-05-27
下一篇:
Python settings.SettingsProvider类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap