<gh_stars>0
#from settings import APPS, APP_STAGES
#APP_SAAS_ODOO12_KEY, APP_SAAS_ODOO13_KEY, APP_SAAS_ODOO14_KEY, APP_MAOREDEV_BUSINESS_KEY, APP_SAAS_ENTERPRISE_ODOO13_KEY, APP_SAAS_ENTERPRISE_ODOO14_KEY
#from fabric_common.common.deploy_python import DeployPython

from operations.core.db import Operations
from fabric_common.common.monitor import Monitoring
from fabric_common.common.monitor import PGSQLMonitoring
#from odoo.instances import ODOO_INSTANCE_STAGES

from fabric_common.common.deploy_python import DeployPython
import csv


class ClusterUtils():
    def __init__(self, sequence, params):
        
        self.operations = Operations()
        command         = self.operations.pjcommandbyid(id = sequence)
        cluster         = self.operations.clusterbyname(cluster_name = command.get('param'))
        method          = command.get('method')
        self.monitoring      = Monitoring(cluster = cluster, params = None)
        
        print(command)

        if method == 'certbot renew':
            self.renewcertbot()
        
        elif method == 'reload nginx':
            self.reloadnginx()

        elif method == "purge odoo":
            self.purge_odoo()
        else:
            print("no method ...")
        

    def purge_odoo(self):
        self.monitoring.rc.sudo(cmd = "rm -rf /home/odoobackup/*")
        print("removing /home/odoobackup/* ...")
        self.monitoring.rc.sudo(cmd = "rm -rf /home/odoorestore/*")
        print("removing /home/odoorestore/* ...")


    def renewcertbot(self):
        print("renew certbot ...")
        self.monitoring.rc.sudo(cmd = "certbot renew")

    def reloadnginx(self):
        print("reloading nginx ...")
        self.monitoring.rc.sudo(cmd = "systemctl reload nginx")





    def ls(self):
        print("salut")

    def instantiate(self):
        print("\n\n==> backup =  ")




#from settings import APPS, APP_STAGES
#APP_SAAS_ODOO12_KEY, APP_SAAS_ODOO13_KEY, APP_SAAS_ODOO14_KEY, APP_MAOREDEV_BUSINESS_KEY, APP_SAAS_ENTERPRISE_ODOO13_KEY, APP_SAAS_ENTERPRISE_ODOO14_KEY
#from fabric_common.common.deploy_python import DeployPython

from operations.core.db import Operations
from fabric_common.common.monitor import Monitoring
from fabric_common.common.monitor import PGSQLMonitoring
#from odoo.instances import ODOO_INSTANCE_STAGES

from fabric_common.common.deploy_python import DeployPython
import csv


class ClusterUtils():
    def __init__(self, sequence, params):
        
        self.operations = Operations()
        command         = self.operations.pjcommandbyid(id = sequence)
        cluster         = self.operations.clusterbyname(cluster_name = command.get('param'))
        method          = command.get('method')
        self.monitoring      = Monitoring(cluster = cluster, params = None)
        
        print(command)

        if method == 'certbot renew':
            self.renewcertbot()
        
        elif method == 'reload nginx':
            self.reloadnginx()

        elif method == "purge odoo":
            self.purge_odoo()
        else:
            print("no method ...")
        

    def purge_odoo(self):
        self.monitoring.rc.sudo(cmd = "rm -rf /home/odoobackup/*")
        print("removing /home/odoobackup/* ...")
        self.monitoring.rc.sudo(cmd = "rm -rf /home/odoorestore/*")
        print("removing /home/odoorestore/* ...")


    def renewcertbot(self):
        print("renew certbot ...")
        self.monitoring.rc.sudo(cmd = "certbot renew")

    def reloadnginx(self):
        print("reloading nginx ...")
        self.monitoring.rc.sudo(cmd = "systemctl reload nginx")





    def ls(self):
        print("salut")

    def instantiate(self):
        print("\n\n==> backup =  ")
#from settings import APPS, APP_STAGES #APP_SAAS_ODOO12_KEY, APP_SAAS_ODOO13_KEY, APP_SAAS_ODOO14_KEY, APP_MAOREDEV_BUSINESS_KEY, APP_SAAS_ENTERPRISE_ODOO13_KEY, APP_SAAS_ENTERPRISE_ODOO14_KEY #from fabric_common.common.deploy_python import DeployPython #from odoo.instances import ODOO_INSTANCE_STAGES