Пример #1
0
    def create(self, request, *args, **kwargs):
        data2 = {}
        for key in request.data:
            data2[key] = request.data[key]
        data2[u'user'] = request.user.username

        # Retrieve site information with the Appliance Registry API (check for existence)
        appliance = remote.appliances_name(data2[u'appliance'])

        serializer = self.get_serializer(data=data2)
        serializer.is_valid(raise_exception=True)

        cluster = Cluster()
        cluster.appliance = appliance.name
        cluster.user = request.user
        cluster.name = "%s_%s" % (appliance.name, uuid.uuid4())
        cluster.hints = data2["hints"]
        if "targeted_slaves_count" in data2:
            cluster.targeted_slaves_count = data2["targeted_slaves_count"]
        cluster.save()

        if cluster.targeted_slaves_count > 0:
            mister_cluster = MisterClusterImplementation()
            mister_cluster.resize_cluster(cluster, new_size=cluster.targeted_slaves_count)

        serializer = ClusterSerializer(cluster)
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Пример #2
0
    def destroy(self, request, *args, **kwargs):
        if "pk" in kwargs:
            cluster_id = kwargs["pk"]
            candidates = Cluster.objects.filter(id=cluster_id)
            if len(candidates) > 0:
                cluster = candidates[0]
                # Remove all cluster's host
                for host in cluster.host_set.all():
                    host.delete()
                mister_cluster = MisterClusterImplementation()
                try:
                    mister_cluster.delete_cluster(cluster)
                except:
                    logging.error("an error occured while deleting resources of cluster %s. It seems that this cluster was non functional." % (cluster.id))
                    pass

        # clusters = Cluster.objects.all()
        # serializer = ClusterSerializer(clusters)
        # return Response(serializer.data, status=status.HTTP_201_CREATED)
        return viewsets.ModelViewSet.destroy(self, request, args, kwargs)
Пример #3
0
def remove_host(cluster):
    mister_cluster = MisterClusterImplementation()
    cluster.targeted_slaves_count -= 1
    cluster.save()
    result = mister_cluster.resize_cluster(cluster, new_size=cluster.targeted_slaves_count)
    return result