Ejemplo n.º 1
0
    def get_active_deployments():
        active_deployments = []
        env_list = [folder.lower() for folder in IOUtils.get_list_dir(f"{EnvInit.init.get(EnvConstants.DEPLOY_PATH)}")]
        for item in env_list:
            container_list = DockerUtils.ps(item).get('out').split("\n")[1:]
            for container in container_list:
                if item in container:
                    active_deployments.append(ActiveDeployment.docker_deployment(item.strip(), container_list))
                    break

        return active_deployments
Ejemplo n.º 2
0
    def folder_clean_up(path=EnvInit.init.get(EnvConstants.DEPLOY_PATH), delete_period=60):
        deleted_folders = []
        active_deployments = [item.get('id') for item in DockerUtils.get_active_deployments()]

        full_deployments_list = map(lambda x: x.rstrip(), IOUtils.get_list_dir(f"{path}"))
        for item in full_deployments_list:
            if item not in active_deployments and (datetime.datetime.now() - datetime.datetime.fromtimestamp(
                    os.path.getmtime(f"{path}/{item}"))) > datetime.timedelta(minutes=delete_period):
                shutil.rmtree(f"{path}/{item}")
                deleted_folders.append(item)

        return deleted_folders