Esempio n. 1
0
#
# dhcpd_leases_parser.py
#
# Copyright 2008, Paul McGuire
#
# Sample parser to parse a dhcpd.leases file to extract leases
# and lease attributes
#
# format ref: http://www.linuxmanpages.com/man5/dhcpd.leases.5.php
#
import os
from pyparsing import *
import datetime, time
from knight.common import logger

LOG = logger.get_logger(__name__)

LBRACE, RBRACE, SEMI, QUOTE = map(Suppress, '{};"')
ipAddress = Combine(Word(nums) + ('.' + Word(nums)) * 3)
hexint = Word(hexnums, exact=2)
macAddress = Combine(hexint + (':' + hexint) * 5)
hdwType = Word(alphanums)

yyyymmdd = Combine((Word(nums, exact=4) | Word(nums, exact=2)) +
                   ('/' + Word(nums, exact=2)) * 2)
hhmmss = Combine(Word(nums, exact=2) + (':' + Word(nums, exact=2)) * 2)
dateRef = oneOf(list("0123456"))("weekday") + yyyymmdd("date") + \
                                                        hhmmss("time")


def utcToLocalTime(tokens):
Esempio n. 2
0
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import scoped_session

from knight.common import cfg
from knight.common import logger


core_opts = [
    cfg.StrOpt('sql_conn', default='mysql://*****:*****@localhost/battery',
                help=('The knight server listen address')),
]

CONF = cfg.CONF
CONF.register_opts(core_opts)

LOG = logger.get_logger(__name__)

def get_engine(echo=True):

    engine = None

    if engine is None:
        engine = create_engine(CONF.sql_conn, echo=echo)

    return engine

def get_session(autocommit=True, expire_on_commit=False,
                sqlite_fk=False):

    engine = get_engine()
    return scoped_session(sessionmaker(bind=engine,