Example #1
0
 def __init__(self):
     """The Constructor for NetworkConfiguration class"""
     self._couch_db = CouchDatabase()
     self.postgresql_query = PostgreSQL()
     self.couch_query = Queries()
     self.epoch_default = 26763
     super(NetworkConfiguration, self).__init__()
Example #2
0
 def __init__(self):
     """The Constructor for Failover class"""
     self._couch_db = CouchDatabase()
     self.postgresql_query = PostgreSQL()
     self.couch_query = Queries()
     self.epoch_default = 26763
     super(Failover, self).__init__()
Example #3
0
    def __init__(self):
        """The Constructor for CreateSubCategory class"""

        self.postgresql_query = PostgreSQL()
        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        super(CreateSubCategory, self).__init__()
Example #4
0
    def __init__(self):
        """The Constructor for UpdateModuleState class"""

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        super(UpdateModuleState, self).__init__()
Example #5
0
 def __init__(self):
     """The Constructor for UpdateCompany class"""
     self.postgres = PostgreSQL()
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     self.log = Log()
     super(UpdateCompany, self).__init__()
Example #6
0
    def __init__(self):
        """The Constructor for Invite class"""

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        self.epoch_default = 26763

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']
        super(Invite, self).__init__()

        if self.vpn_db_build.upper() == 'TRUE':
            self.my_ip = config_section_parser(self.config, "IPS")['my']
            self.my_protocol = config_section_parser(self.config,
                                                     "IPS")['my_protocol']

            self.user_vpn = config_section_parser(self.config,
                                                  "IPS")['user_vpn']
            self.user_protocol = config_section_parser(self.config,
                                                       "IPS")['user_protocol']

            self.vessel_vpn = config_section_parser(self.config,
                                                    "IPS")['vessel_vpn']
            self.vessel_protocol = config_section_parser(
                self.config, "IPS")['vessel_protocol']

            self.vpn_token = '269c2c3706886d94aeefd6e7f7130ab08346590533d4c5b24ccaea9baa5211ec'
Example #7
0
 def __init__(self):
     """The Constructor for Vessel class"""
     # self._my_db = MySQLDatabase()
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     self.postgres = PostgreSQL()
     self.epoch_default = 26763
     self.aws3 = AwsS3()
     super(Vessel, self).__init__()
Example #8
0
    def __init__(self):
        """The Constructor for RemoteCommand class"""
        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        self.epoch_default = 26763
        super(RemoteCommand, self).__init__()
Example #9
0
    def __init__(self):
        """The Constructor for Device class"""
        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.aws3 = AwsS3()
        self.epoch_default = 26763
        self.db_host = config_section_parser(self.config, "COUCHDB")['host']
        self.db_port = config_section_parser(self.config, "COUCHDB")['port']
        super(Device, self).__init__()
Example #10
0
    def __init__(self):
        """The Constructor for Vessels class"""
        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        self.epoch_default = 26763
        self.vessel_name = ""
        self.aws3 = AwsS3()

        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self.vpn_db_build = config_section_parser(self.config, "VPNDB")['build']

        super(MapVessels, self).__init__()
Example #11
0
    def __init__(self):
        """The Constructor for UpdateINIFiles class"""
        # INIT CONFIG
        self.config = ConfigParser()

        # CONFIG FILE
        self.config.read("config/config.cfg")

        self._couch_db = CouchDatabase()
        self.couch_query = Queries()
        self.postgres = PostgreSQL()
        super(UpdateINIFiles, self).__init__()

        self.vpn_db_build = config_section_parser(self.config,
                                                  "VPNDB")['build']

        self.vessel_vpn = config_section_parser(self.config,
                                                "IPS")['vessel_vpn']
        self.vessel_protocol = config_section_parser(self.config,
                                                     "IPS")['vessel_protocol']

        self.vpn_token = '269c2c3706886d94aeefd6e7f7130ab08346590533d4c5b24ccaea9baa5211ec'
Example #12
0
 def __init__(self):
     """The Constructor for PortForwarding class"""
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     self.epoch_default = 26763
     super(PortForwarding, self).__init__()
Example #13
0
 def __init__(self):
     """The Constructor for Report class"""
     self.postgresql_query = PostgreSQL()
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     super(Report, self).__init__()
Example #14
0
 def __init__(self):
     """The Constructor for GeneralInfo class"""
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     self.epoch_default = 26763
     super(GeneralInfo, self).__init__()
Example #15
0
 def __init__(self):
     """The constructor for Indexing class"""
     self._couch_db = CouchDatabase()
Example #16
0
 def __init__(self):
     """The Constructor for Vessels class"""
     self._couch_db = CouchDatabase()
     super(Queries, self).__init__()
Example #17
0
#!/usr/bin/env python3
# coding: utf-8
# pylint: disable=bare-except
"""Delete Vessel"""
import sys
import time
import json
import requests

from library.couch_database import CouchDatabase
from library.postgresql_queries import PostgreSQL

COUCHDB = CouchDatabase()
POSTGRES = PostgreSQL()

# couch_query = COUCHDB.couch_db_link()

def single_delete(doc_id, rev):
    """Single Delete"""
    url = COUCHDB.couch_db_link()
    url += '/' + doc_id + '?' + 'rev=' + rev
    headers = {"Content-Type" : "application/json"}
    response = requests.delete(url, headers=headers)
    response = response.json()

    return response

def bulk_delete(query):
    """Bulk Delete"""
    count = 1
Example #18
0
 def __init__(self):
     """The Constructor for Graph class"""
     self.postgres = PostgreSQL()
     self._couch_db = CouchDatabase()
     self.couch_query = Queries()
     super(Graph, self).__init__()
Example #19
0
class Queries(Common):
    """Class for Queries"""

    # INITIALIZE
    def __init__(self):
        """The Constructor for Vessels class"""
        self._couch_db = CouchDatabase()
        super(Queries, self).__init__()

    def get_device(self, vessel_id):
        """Return Device by Vessel ID"""
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/device/_view/get_device?'
        couch_query += 'startkey=["' + vessel_id + '"]&'
        couch_query += 'endkey=["' + vessel_id + '",{}]'
        couch_query += '&include_docs=true'

        res = requests.get(couch_query)
        json_data = res.json()
        rows = json_data['rows']

        data = []
        for row in rows:

            data.append(row['doc'])

        return data

    def get_by_id(self, couch_id):
        """Get By ID"""

        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/' + str(couch_id)

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()

        if json_data:

            return json_data

        return {}

    def get_vessels(self, vessel_number=None, limit=None, page=None):
        """Return Vessels"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/vessel/_view/get_vessels?'
        if vessel_number:
            couch_query += 'startkey="' + vessel_number + '"'
            couch_query += '&endkey="' + vessel_number + '"&'

        couch_query += 'include_docs=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()

        if limit and page:

            rows = json_data['rows']
            device_list = self.limits(rows, limit, page)

        else:

            device_list = json_data['rows']

        return device_list

    def get_system(self, vessel_id):
        """Return System"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/system/_view/get_system?'

        if vessel_id:

            couch_query += 'startkey=["' + vessel_id + '",9999999999]&'
            couch_query += 'endkey=["' + vessel_id + '",0]&'

        couch_query += 'include_docs=true&limit=1&descending=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()

        # RETURN
        return json_data

    # JUST FOR INDEXING THE DATE - WILL DELETE SOON
    def get_system1(self, limit=10, page=None):
        """Return System1"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/system/_view/get_system?limit=' + str(limit)

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()

        if limit and page:

            rows = json_data['rows']
            device_list = self.limits(rows, limit, page)

        else:

            device_list = json_data['rows']

        # RETURN
        return device_list

    def get_all_devices(self, vessel_id):
        """Return All Devices"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/device/_view/get_device?'
        couch_query += 'startkey=["' + vessel_id + '"]&'
        couch_query += 'endkey=["' + vessel_id + '",{}]&'
        couch_query += 'include_docs=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()
        device_list = json_data['rows']

        return device_list

    def get_complete_values(self,
                            vessel_id,
                            device,
                            start=None,
                            end=None,
                            flag='one',
                            descending=True):
        """Return Complete Values"""
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/value/_view/get_value?'

        if start and end:
            couch_query += 'startkey=["' + vessel_id + '", "' + device + '",' + end + ']&'
            couch_query += 'endkey=["' + vessel_id + '", "' + device + '",' + start + ']'

            if flag == 'all':
                couch_query += '&include_docs=true&descending=true'
            else:
                if descending:

                    couch_query += '&include_docs=true&limit=1&descending=true'

                else:

                    couch_query += '&include_docs=true&limit=1'

        else:
            couch_query += 'startkey=["' + vessel_id + '", "' + device + '",9999999999]&'
            couch_query += 'endkey=["' + vessel_id + '", "' + device + '",0]'

            if flag == 'all':
                couch_query += '&include_docs=true&descending=true'
            else:
                couch_query += '&include_docs=true&limit=1&descending=true'

        res = requests.get(couch_query)
        json_data = res.json()

        data = []
        if 'rows' not in json_data.keys():
            print("Error: {0} Reason: {1}".format(json_data['error'],
                                                  json_data['reason']))
        else:
            rows = json_data['rows']

            if rows:

                if flag == 'one':

                    if rows:
                        data = rows[0]['doc']['value']

                if flag == 'one_doc':

                    if rows:
                        data = rows[0]['doc']

                elif flag == 'all':

                    data = []
                    for row in rows:

                        data.append(row['doc'])

        return data

    def get_devices(self):
        """Return Devices from CouchDB"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/device/_view/get_device'
        couch_query += '?include_docs=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()
        rows = json_data['rows']

        data = []
        for row in rows:
            data.append(row['doc'])

        return data

    def get_modules(self):
        """Return Modules from CouchDB"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/module/_view/get_module'
        couch_query += '?include_docs=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()
        rows = json_data['rows']

        data = []
        for row in rows:
            data.append(row['doc'])

        return data

    def get_options(self):
        """Return Options from CouchDB"""
        # COUCH QUERY - GET VESSELS
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/option/_view/get_option'
        couch_query += '?include_docs=true'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()
        rows = json_data['rows']

        data = []
        for row in rows:
            data.append(row['doc'])

        return data

    def get_coredata(self, vessel_id, start=None, end=None, flag=None):
        """Return Corevalues Data"""
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/value/_view/get_value?'

        #if start and end:
        couch_query += 'startkey=["' + vessel_id + '", "COREVALUES",' + str(
            end) + ']&'
        couch_query += 'endkey=["' + vessel_id + '", "COREVALUES",' + str(
            start) + ']'
        couch_query += '&descending=true'

        if flag == "limit":
            couch_query += '&limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)
        json_data = res.json()

        rows = json_data['rows']
        data = []

        for row in rows:
            data.append(row['key'][2])

        # RETURN
        return data

    def get_last_ini(self, vessel_id):
        """ GET LAST INI FILE DATA """

        couch_query = self._couch_db.couch_db_link()
        couch_query += "/_design/ini/_view/get_ini?"
        couch_query += "startkey=[\"{0}\", 9999999999]".format(vessel_id)
        couch_query += "&endkey=[\"{0}\", 0]".format(vessel_id)
        couch_query += "&include_docs=true&limit=1&descending=true"
        res = requests.get(couch_query)
        json_data = res.json()

        if 'rows' in json_data.keys():

            return json_data['rows']

        return 0
Example #20
0
class Indexing():
    """Indexing"""

    # INITIALIZE
    def __init__(self):
        """The constructor for Indexing class"""
        self._couch_db = CouchDatabase()

    def index_device(self):
        """Index Device"""
        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/device/_view/get_device?'
        couch_query += 'limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)

        json_data = res.json()
        if json_data['rows']:
            value = json_data['rows']
            return value
        return 0

    def index_module(self):
        """Index Module"""
        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/module/_view/get_module?'
        couch_query += 'limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)

        json_data = res.json()
        if json_data['rows']:
            value = json_data['rows']
            return value
        return 0

    def index_option(self):
        """Index Option"""
        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/option/_view/get_option?'
        couch_query += 'limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)

        json_data = res.json()
        if json_data['rows']:
            value = json_data['rows']
            return value
        return 0

    def index_value(self):
        """Index Value"""
        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/value/_view/get_value?'
        couch_query += 'limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)

        json_data = res.json()
        if json_data['rows']:
            value = json_data['rows']
            return value
        return 0

    def index_vessel(self):
        """Vessel Index"""
        # GET MODULE
        couch_query = self._couch_db.couch_db_link()
        couch_query += '/_design/vessel/_view/get_vessels?'
        couch_query += 'limit=1'

        # EXECUTE COUCH QUERY
        res = requests.get(couch_query)

        json_data = res.json()
        if json_data['rows']:
            value = json_data['rows']
            return value
        return 0