#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
:Mod: config.py

:Synopsis:

:Author:
    servilla

:Created:
    3/16/18
"""


class Config(object):

    USER = 'USER'
    KEY_PATH = 'SSH_KEY_PATH'
    KEY_PASS = 'SSH_KEY_PASSWORD'

    LOCK_FILE = "LOCK_FILE_LOCATION"
    STATUS_FILE = "STATUS_FILE_LOCATION"

    # Database
    db = 'soh_db.sqlite'

    UP = 0
    DOWN = 1

    # Servers
    servers = {
        'PASTA': 'pasta.lternet.edu',
        'PACKAGE': 'package.lternet.edu',
        'AUDIT': 'audit.lternet.edu',
        'SOLR': 'solr.lternet.edu',
        'PASTA_S': 'pasta-s.lternet.edu',
        'PACKAGE_S': 'package-s.lternet.edu',
        'AUDIT_S': 'audit-s.lternet.edu',
        'SOLR_S': 'solr-s.lternet.edu',
        'PASTA_D': 'pasta-d.lternet.edu',
        'PACKAGE_D': 'package-d.lternet.edu',
        'AUDIT_D': 'audit-d.lternet.edu',
        'SOLR_D': 'solr-d.lternet.edu',
        'PORTAL_EDI': 'portal.edirepository.org',
        'PORTAL_S_EDI': 'portal-s.edirepository.org',
        'PORTAL_D_EDI': 'portal-d.edirepository.org',
        'GMN_LTER': 'gmn.lternet.edu',
        'GMN_S_LTER': 'gmn-s.lternet.edu',
        'GMN_EDI': 'gmn.edirepository.org',
        'GMN_S_EDI': 'gmn-s.edirepository.org',
        'AUTH': 'auth.edirepository.org',
        'AUTH_D': 'auth-d.edirepository.org',
        'LDAP_EDI': 'ldap.edirepository.org',
        'LDAP2_EDI': 'ldap2.edirepository.org',
        'LDAP_D': 'ldap-d.edirepository.org',
        'EZEML': 'ezeml.edirepository.org',
        'EZEML_S': 'ezeml-s.edirepository.org',
        'EZEML_D': 'ezeml-d.edirepository.org',
        'UNIT': 'unit.lternet.edu',
        'VOCAB': 'vocab.lternet.edu',
        'SEO': 'seo.edirepository.org',
        'DEX': 'dex.edirepository.org',
        'TWEETER': 'tweeter.edirepository.org',
        'SPACE': 'space.lternet.edu',
        'JOSH': 'josh.edirepository.org',
        'WEBX': 'web-x.edirepository.org',
        'SCHEMA': 'nis.lternet.edu',
}

    server_types = {
        'APACHE':
            ['vocab.lternet.edu',
             'seo.edirepository.org',
             'dex.edirepository.org',
             'ezeml.edirepository.org',
             'ezeml-s.edirepository.org',
             'ezeml-d.edirepository.org',
             'tweeter.edirepository.org',
             'web-x.edirepository.org',
             'nis.lternet.edu'],
        'APACHE_TOMCAT':
            [],
        'AUDIT':
            ['audit.lternet.edu',
             'audit-s.lternet.edu',
             'audit-d.lternet.edu', ],
        'AUTH':
            ['auth.edirepository.org',
             'auth-d.edirepository.org'],
        'GMN':
            ['gmn.edirepository.org',
             'gmn-s.edirepository.org',
             'gmn.lternet.edu',
             'gmn-s.lternet.edu'],
        'JETTY':
            ['pasta.lternet.edu',
             'pasta-s.lternet.edu',
             'pasta-d.lternet.edu'],
        'LDAP':
            ['ldap.edirepository.org',
             'ldap2.edirepository.org',
             'ldap-d.edirepository.org'],
        'PORTAL':
            ['portal.edirepository.org',
             'portal-s.edirepository.org',
             'portal-d.edirepository.org'],
        'PACKAGE':
            ['package.lternet.edu',
             'package-s.lternet.edu',
             'package-d.lternet.edu'],
        'SERVER':
            ['space.lternet.edu',
             'josh.edirepository.org'],
        'SOLR':
            ['solr.lternet.edu',
             'solr-s.lternet.edu',
             'solr-d.lternet.edu'],
        'TOMCAT':
            [],
    }

    gmn_pasta_mapping = {
        'gmn.edirepository.org': 'pasta.lternet.edu',
        'gmn-s.edirepository.org': 'pasta-s.lternet.edu',
        'gmn.lternet.edu': 'pasta.lternet.edu',
        'gmn-s.lternet.edu': 'pasta-s.lternet.edu'
    }

    # SOH anti-assertions and corresponding identifiers
    assertions = {
        'SERVER_DOWN': 1,        # 000000000000001
        'JETTY_DOWN': 2,         # 000000000000010
        'TOMCAT_DOWN': 4,        # 000000000000100
        'SOLR_DOWN': 8,          # 000000000001000
        'LDAP_DOWN': 16,         # 000000000010000
        'APACHE_DOWN': 32,       # 000000000100000
        'GMN_DOWN': 64,          # 000000001000000
        'PORTAL_DOWN': 128,      # 000000010000000
        'PACKAGE_DOWN': 256,     # 000000100000000
        'GATEKEEPER_DOWN': 512,  # 000001000000000
        'AUDIT_DOWN': 1024,      # 000010000000000
        'AUTH_DOWN': 2048,       # 000100000000000
        'SYNC_DOWN': 4096,       # 001000000000000
        'LOAD_HIGH': 8192,       # 010000000000000
        'READ_ONLY': 16384,      # 100000000000000
    }

    server_assertions = {
        'SERVER': ['SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'APACHE': ['APACHE_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'JETTY': ['JETTY_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'TOMCAT': ['TOMCAT_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'SOLR': ['SOLR_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'LDAP': ['LDAP_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'APACHE_TOMCAT': ['APACHE_DOWN', 'TOMCAT_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'GMN': ['SYNC_DOWN', 'GMN_DOWN', 'APACHE_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'PORTAL': ['PORTAL_DOWN', 'TOMCAT_DOWN', 'APACHE_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'PACKAGE': ['PACKAGE_DOWN', 'TOMCAT_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'AUDIT': ['AUDIT_DOWN', 'TOMCAT_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY'],
        'AUTH': ['AUTH_DOWN', 'APACHE_DOWN', 'SERVER_DOWN', 'LOAD_HIGH', 'READ_ONLY']
    }

    # Email configuration
    RELAY_HOST = 'RELAY_HOST'
    RELAY_PASSWORD = 'RELAY_PASSWORD'
    RELAY_USER = 'RELAY_USER'
    RELAY_TLS_PORT = 587
    TO = 'admin@edirepository.org'
    TO_NAME = 'Admin'
    FROM = 'dashboard@edirepository.org'
    FROM_NAME = "Dashboard"

    # PASTA database connection
    DB_USER = 'DB_USER'
    DB_PW = 'SECRET_PASSWORD'
    DB_DB = 'pasta'
    DB_DRIVER = 'postgresql+psycopg2'

    gmn_pasta_db_host_mapping = {
        'gmn.edirepository.org': 'DB_HOST',
        'gmn-s.edirepository.org': 'DB_HOST',
        'gmn.lternet.edu': 'DB_HOST',
        'gmn-s.lternet.edu': 'DB_HOST'
    }

    TIMEOUT = 1.0
    LOAD1_MAX = 5.00
    SLEEP = 4
