<commit_before>#!/usr/bin/env python2.6
# coding=utf8
# vi:ts=4:

"""Package containing interfaces to Magdb"""

import sys
import prettytable
import ConfigParser

config = ConfigParser.ConfigParser()
config.read(['/etc/magdb/magdb.conf'])

DEFAULT_DOMAIN = config.get("defaults", "domain")
CS = config.get("database", "sqlalchemy")

class MagdbRecord:
    """Class defining a complete host network record"""
    def __init__(self, id, mac, ip, fqdn):
        """Create and return a Magdb network object, aliases can be added by appending to the aliases property"""
        self.id = id
        self.mac = mac
        self.ip = ip
        self.fqdn = fqdn
        self.aliases = []

    def __str__(self):
        t = prettytable.PrettyTable(("SystemID", "MAC", "IP", "FQDN", "Aliases"))
        als = ""
        for a in self.aliases:
            als += "%s\n%s" % (als, a)

        t.add_row((self.id, self.mac, self.ip, self.fqdn, als))

        result = t.printt()

        if t is not None:
            return(result)
        else:
            return("Nada")

    def __repr__(self):
        return("__ not implemented")


class MagdbError(Exception):
    """Exception class for all Magdb Errors"""
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Magdb:
    """Class defining an interface to MagDB"""
    def __init__(self, conn_string):
        """Create and return a connected Magdb interface object"""
        from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String
        self.engine = create_engine(conn_string, echo=False)

        self.metadata = MetaData()
        self.metadata.reflect(bind=self.engine)

        self.view = Table("vNetwork2", self.metadata, Column("systemId", Integer), Column("macAddress", Integer), Column("ipAddress", Integer, primary_key=True), Column("fqdn", Integer), autoload_with=self.engine)
        self.view_aliases = Table("vAliases", self.metadata, Column("hostnameId", Integer, primary_key=True), Column("aliasId", Integer, primary_key=True), Column("alias", String), Column("aliasDomian", String), Column("host", String), Column("hostDomain", String), autoload_with=self.engine)

        self.tables = self.metadata.tables
        self.hostnames = Table('hostnames', self.metadata, autoload=True)

        self.aliases = self.tables["aliases"]
        self.systems = self.tables["systems"]
        self.domains = self.tables["domains"]
        self.hostAddresses = self.tables["hostAddresses"]
        self.hostnames = self.tables["hostnames"]
        self.hostnameAliases = self.tables["hostnamesAliases"]
        self.networkInterfaces = self.tables["networkInterfaces"]
        self.networkSubnets = self.tables["networkSubnets"]
        self.vendors = self.tables["vendors"]
        self.racks = self.tables["racks"]
        self.categories = self.tables["categories"]
        self.manufacturers = self.tables["manufacturers"]
        self.ipSurvey = self.tables["ipSurvey"]

        from sqlalchemy.orm import sessionmaker
        Session = sessionmaker(bind=self.engine)

        self.session = Session()

    def split_fqdn(self, fqdn):
        """Split fqdn into a tuple containing (hostname, domain). If domain not present, appends DEFAULT_DOMAIN"""
        result = fqdn.split('.', 1)
        if len(result) == 1:<commit_msg>Reflect storageSystems table<commit_after>#!/usr/bin/env python2.6
# coding=utf8
# vi:ts=4:

"""Package containing interfaces to Magdb"""

import sys
import prettytable
import ConfigParser

config = ConfigParser.ConfigParser()
config.read(['/etc/magdb/magdb.conf'])

DEFAULT_DOMAIN = config.get("defaults", "domain")
CS = config.get("database", "sqlalchemy")

class MagdbRecord:
    """Class defining a complete host network record"""
    def __init__(self, id, mac, ip, fqdn):
        """Create and return a Magdb network object, aliases can be added by appending to the aliases property"""
        self.id = id
        self.mac = mac
        self.ip = ip
        self.fqdn = fqdn
        self.aliases = []

    def __str__(self):
        t = prettytable.PrettyTable(("SystemID", "MAC", "IP", "FQDN", "Aliases"))
        als = ""
        for a in self.aliases:
            als += "%s\n%s" % (als, a)

        t.add_row((self.id, self.mac, self.ip, self.fqdn, als))

        result = t.printt()

        if t is not None:
            return(result)
        else:
            return("Nada")

    def __repr__(self):
        return("__ not implemented")


class MagdbError(Exception):
    """Exception class for all Magdb Errors"""
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Magdb:
    """Class defining an interface to MagDB"""
    def __init__(self, conn_string):
        """Create and return a connected Magdb interface object"""
        from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String
        self.engine = create_engine(conn_string, echo=False)

        self.metadata = MetaData()
        self.metadata.reflect(bind=self.engine)

        self.view = Table("vNetwork2", self.metadata, Column("systemId", Integer), Column("macAddress", Integer), Column("ipAddress", Integer, primary_key=True), Column("fqdn", Integer), autoload_with=self.engine)
        self.view_aliases = Table("vAliases", self.metadata, Column("hostnameId", Integer, primary_key=True), Column("aliasId", Integer, primary_key=True), Column("alias", String), Column("aliasDomian", String), Column("host", String), Column("hostDomain", String), autoload_with=self.engine)

        self.tables = self.metadata.tables
        self.hostnames = Table('hostnames', self.metadata, autoload=True)

        self.aliases = self.tables["aliases"]
        self.systems = self.tables["systems"]
        self.domains = self.tables["domains"]
        self.hostAddresses = self.tables["hostAddresses"]
        self.hostnames = self.tables["hostnames"]
        self.hostnameAliases = self.tables["hostnamesAliases"]
        self.networkInterfaces = self.tables["networkInterfaces"]
        self.networkSubnets = self.tables["networkSubnets"]
        self.vendors = self.tables["vendors"]
        self.racks = self.tables["racks"]
        self.categories = self.tables["categories"]
        self.manufacturers = self.tables["manufacturers"]
        self.ipSurvey = self.tables["ipSurvey"]
        self.storageSystems = self.tables["storageSystems"]

        from sqlalchemy.orm import sessionmaker
        Session = sessionmaker(bind=self.engine)

        self.session = Session()

    def split_fqdn(self, fqdn):
        """Split fqdn into a tuple containing (hostname, domain). If domain not present, appends DEFAULT_DOMAIN"""
        result = fqdn.split('.', 1)
        if len(result) == 1:
{'fraction_non_alphanumeric': 0.13215278794087518, 'fraction_numerical': 0.002048880433191863, 'mean_word_length': 3.161997563946407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773977', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1993, 'n_words': 497}