Beispiel #1
0
class AutoScalerDestroyer(object):
    """
    AutoScalerDestroyer is to destroy autoscaler instance when deleting
    application.
    """
    def __init__(self, application):
        self.application = application
        self.application_name = get_application_instance_name(self.application)
        self.namespace = self.application.image.project.name

        self.kubeclient = KubeClient("http://{}:{}{}".format(settings.MASTER_IP,
            settings.K8S_PORT, settings.K8S_V1BETA1_API_PATH))

    def delete_autoscaler(self):
        """
        Destroy autoscaler for application instance by multiple threading.
        """
        deleting_thread = Thread(target=self._delete_autoscaler_instance)
        deleting_thread.start()

    def _delete_autoscaler_instance(self):
        scalers = AutoScaler.objects.filter(app=self.application)
        for scaler in scalers:
            scaler.delete()

        ok = self.kubeclient.delete_autoscaler(namespace=self.namespace,
            name=self.application_name)
        if not ok:
            logger.error("Delete autoscaler {} failed.".format(
                self.application_name))
        else:
            logger.debug("Delete autoscaler {} successfully.".format(
                self.application_name))
Beispiel #2
0
class AutoScalerDestroyer(object):
    """
    AutoScalerDestroyer is to destroy autoscaler instance when deleting
    application.
    """
    def __init__(self, application):
        self.application = application
        self.application_name = get_application_instance_name(self.application)
        self.namespace = self.application.image.project.name

        self.kubeclient = KubeClient("http://{}:{}{}".format(
            settings.MASTER_IP, settings.K8S_PORT,
            settings.K8S_V1BETA1_API_PATH))

    def delete_autoscaler(self):
        """
        Destroy autoscaler for application instance by multiple threading.
        """
        deleting_thread = Thread(target=self._delete_autoscaler_instance)
        deleting_thread.start()

    def _delete_autoscaler_instance(self):
        scalers = AutoScaler.objects.filter(app=self.application)
        for scaler in scalers:
            scaler.delete()

        ok = self.kubeclient.delete_autoscaler(namespace=self.namespace,
                                               name=self.application_name)
        if not ok:
            logger.error("Delete autoscaler {} failed.".format(
                self.application_name))
        else:
            logger.debug("Delete autoscaler {} successfully.".format(
                self.application_name))
Beispiel #3
0
 def test_delete_autoscaler(self):
     beta_client = KubeClient(
         "http://192.168.0.10:8080/apis/extensions/v1beta1/")
     res = beta_client.delete_autoscaler('user', 'project0-nginx-test')
     print(res)
Beispiel #4
0
 def test_delete_autoscaler(self):
     beta_client = KubeClient("http://192.168.0.10:8080/apis/extensions/v1beta1/")
     res = beta_client.delete_autoscaler('user', 'project0-nginx-test')
     print(res)