def __init__(self, desc=False, name='MAINSERVER', parent=False, readLevel=-1, writeLevel=-1, kid_base='/'):
        self._lock = Lock()
        if not desc:
            desc = collections.OrderedDict({'self': {}})
        Scriptable.__init__(self)
        self.log = logging
        self.kid_base = kid_base
        Conf.__init__(self, desc['self'])
        if readLevel > 0:
            self._readLevel = readLevel
        if writeLevel > 0:
            self._writeLevel = writeLevel
        self.children = desc #.copy()
        """Child configuration dictionaries"""
        self.children_obj = {}
        """Instantiated children configuration proxies"""
        # Remove myself from children...
        del self.children['self']
        self.name = name
        self._parent = parent
        if not parent:
            self._Method__name = name
        else:
            self._Method__name = parent._Method__name + self.separator + name
#           if parent._parent:
#               self._Method__name=parent._Method__name+self.separator+name
#           else:
#               self._Method__name=name
        if self.has_key('devpath'):
            self['devpath'] = name
        self.autosort()
Exemple #2
0
    def __init__(self,
                 config=None,
                 verbose=False,
                 debug=False,
                 host=None,
                 db_name=None,
                 user=None,
                 password=None):
        """
        Reads the config file and sets up a connection to the database

        args
        config -- path to the config file
        verbose -- output useful messages
        debug -- set to debug mode
        host -- hostname or address (overrides the config file if given)
        db -- name of database on server (overrides the config file if given)
        user -- username to connect to database (overrides the config file if given)
        password -- password to connect to database (overrides the config file if given)
        """
        Conf.__init__(self)
        self.verbose = verbose
        self.debug = debug
        self.module_dir = os.path.dirname(os.path.abspath(__file__))
        if config is None:
            config = os.path.join(self.module_dir, "config.yaml")
        self.config = self.parse_config(yaml.safe_load(open(config)))
        print("Connecting to database")
        if host is None:
            host = self.config.db.host
        if db_name is None:
            db_name = self.config.db.dbname
        if user is None:
            user = self.config.db.user
        if password is None:
            password = self.config.db.password
        db_connection_string = " ".join([
            "dbname=" + db_name, "user="******"host=" + host,
            "password="******"DB connection: %s" % db_connection_string)
        DBUtils.__init__(self, db_connection_string, self.verbose, self.debug)
        self.sql_subs = self.make_bna_substitutions(self.config)

        # mi/km
        if "units" in self.config:
            if self.config.units == "mi":
                self.km = False
            elif self.config.units == "km":
                self.km = True
            else:
                raise ValueError("Invalid units \"{}\" in config".format(
                    self.config.units))
        else:
            self.km = False
Exemple #3
0
	def __init__(self,loghandler):
		"""
		"""
		Conf.__init__(self)

		self.__counterr = 0
		self.__countwarn = 0
		self.__notification_required = False

		self.__logger = logging.getLogger(loghandler)

		if not self.__logger.handlers:
			self.__hdlr = logging.FileHandler(self.logfile)
			self.__formatter = logging.Formatter('%(asctime)s [%(levelname)s] : %(message)s')
			self.__hdlr.setFormatter(self.__formatter)
			self.__logger.addHandler(self.__hdlr)
			self.__logger.setLevel(logging.INFO)
Exemple #4
0
	def __init__(self,hostaddr=None,noop='noop'):
		"""
		"""
		Conf.__init__(self)

		logfile = self.logfile

		c = Common()
		c.banner()
		c.client_hosts()

		self.__host=hostaddr
		self.__noop=noop
		self.__counter = 0
		self.__exclude = 0

		self.__reader = open(logfile)
		self.__startline = len(self.__reader.readlines())
		self.__reader.close()

		l = Logger('initiator')
		l.logx('-'*70)

		if self.__host=='all':
			l.logx('Update command on all hosts executed')
			self.update_all()
			l.event_counter(self.__startline)

		elif re.match(r'^\.\*$',self.__host):
			print '\n[-]--> please use \'all\' instead of \'.*\'\n'

		elif re.match(r'.*[\.\*\+\[\]]+.*',self.__host):
			l.logx('Update regex command (%s) executed' % self.__host)
			self.reget_host()
			l.event_counter(self.__startline)

		else:
			l.logx('Update command on %s executed' % self.__host)
			env.host_string=self.__host
			self.update_host()
			l.event_counter(self.__startline)

		l.logx('End of execution')
Exemple #5
0
	def __init__(self,hostAddr=None,choice=None):
		"""
		"""
		Conf.__init__(self)

		logfile = self.logfile

		self.__choice = choice
		self.__host = hostAddr
		self.__counter = 0

		env.host_string = self.__host

		if choice is None:
			print 'install or remove puppet ?'

		elif choice == 'install':
			self.install()

		elif choice == 'remove':
			self.remove()

		elif choice == 'restart':
			self.restart()
Exemple #6
0
    def __init__(self,
                 config=None,
                 force_net_build=False,
                 verbose=False,
                 debug=False,
                 host=None,
                 db_name=None,
                 user=None,
                 password=None):
        """Connects to the BNA database

        kwargs:
        config -- path to the config file, if not given use the default config.yaml
        force_net_build -- force a rebuild of the network even if an existing one is found
        verbose -- output useful messages
        debug -- set to debug mode
        host -- hostname or address (overrides the config file if given)
        db -- name of database on server (overrides the config file if given)
        user -- username to connect to database (overrides the config file if given)
        password -- password to connect to database (overrides the config file if given)

        return: pyBNA object
        """
        Destinations.__init__(self)
        Connectivity.__init__(self)
        Core.__init__(self)
        Conf.__init__(self)
        self.verbose = verbose
        self.debug = debug
        self.module_dir = os.path.dirname(os.path.abspath(__file__))
        if config is None:
            config = os.path.join(self.module_dir, "config.yaml")
        self.config = self.parse_config(yaml.safe_load(open(config)))
        self.config["bna"]["connectivity"]["max_detour"] = float(
            100 + self.config["bna"]["connectivity"]["max_detour"]) / 100
        self.db_connectivity_table = self.config["bna"]["connectivity"][
            "table"]
        self.net_config = self.config["bna"]["network"]

        # km/mi
        if "units" in self.config:
            if self.config.units == "mi":
                self.km = False
            elif self.config.units == "km":
                self.km = True
            else:
                raise ValueError("Invalid units \"{}\" in config".format(
                    self.config.units))
        else:
            self.km = False

        if self.verbose:
            print("")
            print("---------------pyBNA---------------")
            print("   Create and test BNA scenarios")
            print("-----------------------------------")
            print("")

        # set up db connection
        print("Connecting to database")
        if host is None:
            host = self.config["db"]["host"]
        if db_name is None:
            db_name = self.config["db"]["dbname"]
        if user is None:
            user = self.config["db"]["user"]
        if password is None:
            password = self.config["db"]["password"]
        db_connection_string = " ".join([
            "dbname=" + db_name, "user="******"host=" + host,
            "password="******"DB connection: %s" % db_connection_string)
        DBUtils.__init__(self, db_connection_string, self.verbose, self.debug)

        # srid
        if "srid" in self.config:
            self.srid = self.config["srid"]
        elif not self.debug:
            self.srid = self.get_srid(self.config.bna.blocks.table)

        # destinations
        self.destinations = dict()
        self.destination_blocks = set()
        if not self.debug:
            pass
            # self.set_destinations()

        self.sql_subs = self.make_bna_substitutions(self.config)

        if force_net_build:
            print("Building network tables in database")
            self.build_network()
        elif self.debug:
            pass
        elif not self.check_network():
            print("Network tables not found in database...building")
            self.build_network()
        elif self.verbose:
            print("Network tables found in database")
Exemple #7
0
    def __init__(self, config=None, create_lookups=True, verbose=False):
        """
        Reads the config file, sets up a connection

        args
        config -- path to the config file, if not given use the default config.yaml
        create_lookups -- creates lookup tables in the db if none are found
        verbose -- output useful messages
        """
        Conf.__init__(self)
        self.verbose = verbose
        self.module_dir = os.path.dirname(os.path.abspath(__file__))
        if config is None:
            config = os.path.join(self.module_dir, "config.yaml")
        self.config = self.parse_config(yaml.safe_load(open(config)))
        print("Connecting to database")
        host = self.config.db.host
        db_name = self.config.db.dbname
        user = self.config.db.user
        password = self.config.db.password
        db_connection_string = " ".join([
            "dbname=" + db_name, "user="******"host=" + host,
            "password="******"Checking lookup tables")
        missing = self._missing_lookup_tables()
        if create_lookups and len(missing) > 0:
            for t in missing:
                self._create_lookup_table(*t)

        # add functions to db
        self._run_sql_script("bna_CompareAzimuths.sql",
                             dict(),
                             dirs=["sql", "stress", "db_functions"])
        self._run_sql_script("bna_IsCorridor.sql",
                             dict(),
                             dirs=["sql", "stress", "db_functions"])
        self._run_sql_script("bna_MultiEndPoint.sql",
                             dict(),
                             dirs=["sql", "stress", "db_functions"])
        self._run_sql_script("bna_MultiStartPoint.sql",
                             dict(),
                             dirs=["sql", "stress", "db_functions"])

        # build SQL substitutions
        self.segment_subs = dict()
        for direction in [FORWARD_DIRECTION, BACKWARD_DIRECTION]:
            self.segment_subs[
                direction] = self._build_segment_sql_substitutions(direction)

        self.crossing_subs = dict()
        for direction in [FORWARD_DIRECTION, BACKWARD_DIRECTION]:
            self.crossing_subs[
                direction] = self._build_crossing_sql_substitutions(direction)
Exemple #8
0
	def __init__(self):
		"""
		"""
		Conf.__init__(self)
		threading.Thread.__init__(self)
Exemple #9
0
	def __init__(self):
		"""
		"""
		Conf.__init__(self)
 def __init__(self, path, read_only=False):
     self.read_only = read_only
     path = fullpath(path)
     parser = GitConfigParser(path, read_only=self.read_only)
     Conf.__init__(self, path=path, parser=parser)