예제 #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 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