Exemplo n.º 1
0
    def process_order_item(self, user):
        resource = self.get_resource()
        if not resource:
            raise serializers.ValidationError('Resource is not found.')

        view = self.get_viewset().as_view({'delete': 'destroy'})
        delete_attributes = self.order_item.attributes
        response = common_utils.delete_request(view,
                                               user,
                                               uuid=resource.uuid.hex,
                                               query_params=delete_attributes)

        if response.status_code == status.HTTP_204_NO_CONTENT:
            with transaction.atomic():
                self.order_item.resource.set_state_terminated()
                self.order_item.resource.save(update_fields=['state'])

                self.order_item.state = models.OrderItem.States.DONE
                self.order_item.save(update_fields=['state'])

        elif response.status_code == status.HTTP_202_ACCEPTED:
            with transaction.atomic():
                self.order_item.resource.set_state_terminating()
                self.order_item.resource.save(update_fields=['state'])
        else:
            raise serializers.ValidationError(response.data)
Exemplo n.º 2
0
 def send_request(self, user, resource):
     view = self.get_viewset().as_view({'delete': 'destroy'})
     delete_attributes = self.order_item.attributes
     response = common_utils.delete_request(view,
                                            user,
                                            uuid=resource.uuid.hex,
                                            query_params=delete_attributes)
     if response.status_code not in (
             status.HTTP_204_NO_CONTENT,
             status.HTTP_202_ACCEPTED,
     ):
         raise serializers.ValidationError(response.data)
     return response.status_code == status.HTTP_204_NO_CONTENT
Exemplo n.º 3
0
    def execute(self, instance, user_id):
        node = instance
        user = auth.get_user_model().objects.get(pk=user_id)

        if node.instance:
            view = InstanceViewSet.as_view({'delete': 'force_destroy'})
            response = common_utils.delete_request(
                view,
                user,
                uuid=node.instance.uuid.hex,
                query_params={'delete_volumes': True},
            )

            if response.status_code != status.HTTP_202_ACCEPTED:
                raise exceptions.RancherException(response.data)
        else:
            backend = node.cluster.get_backend()
            backend.delete_node(node)