def pxe_config_script():
    parser = argparse.ArgumentParser(description='Edit BMM PXE configurations', epilog=epilog)

    parser.add_argument('--active', action='store_true', dest='active', default=None, help='PXE config is active')
    parser.add_argument('--inactive', action='store_false', dest='active', help='PXE config is not active')
    parser.add_argument('--description', '-m', help='description of the PXE config')
    parser.add_argument('--config', '-c', help='file containing configuration data; - for stdin')
    parser.add_argument('action', nargs=1, help='action to perform: add, list, show, modify')
    parser.add_argument('name', nargs='?', help='name of the PXE config')

    args = parser.parse_args()

    args.action = args.action[0]
    if args.action != 'list' and not args.name:
        parser.error("name is required")
    elif args.action == 'list' and args.name:
        parser.error("name is not allowed with 'list'")

    db = setup()

    def get_config():
        if not args.config:
            parser.error('--config is required')
        if args.config == '-':
            if os.isatty(0):
                print "Enter config contents:"
            return sys.stdin.read()
        else:
            return open(args.config).read()

    def show_details(name):
        deets = db.pxe_configs.get(name)
        print "** Name:", deets['name'], '(inactive)' if not deets['active'] else ''
        print "** Description:", deets['description']
        print "** Contents:"
        print deets['contents'].strip()

    if args.action == 'add':
        if args.active is None:
            args.active = True
        if not args.description:
            parser.error('--description is required for --add')
        config = get_config()
        db.pxe_configs.add(args.name, args.description, args.active, config)
        show_details(args.name)

    elif args.action == 'modify':
        config = None if args.config is None else get_config()
        db.pxe_configs.update(args.name, args.description, args.active, config)
        show_details(args.name)

    elif args.action == 'show':
        if args.active or args.config or args.description:
            parser.error('show does not take any additional options')
        show_details(args.name)

    elif args.action == 'list':
        active_arg = {'active_only':True} if args.active else {}
        for name in db.pxe_configs.list(**active_arg):
            show_details(name)
Exemple #2
0
def db_script():
    # Basic commandline interface for testing the relay module.
    def usage():
        print "Usage: %s create-schema -- create the DB schema in the configured DB" % sys.argv[0]
        print "Usage: %s run mydata.py -- run mydata.py with an open connection `conn`" % sys.argv[0]
        sys.exit(1)
    if len(sys.argv) < 2:
        usage()
    if sys.argv[1] == 'create-schema':
        db = setup()
        model.metadata.create_all(bind=db.pool.engine)
    elif sys.argv[1] == 'run':
        db = setup()
        execfile(sys.argv[2], dict(conn=db.pool.engine.connect(), args=sys.argv[3:]))
    else:
        usage()
    sys.exit(0)
Exemple #3
0
def main():
    parser = argparse.ArgumentParser(description='Sync BMM with inventory.')
    parser.add_argument('--verbose', action='store_true',
                        default=False,
                        help='verbose output')
    args = parser.parse_args()

    db = setup()
    sync(db, verbose=args.verbose)
Exemple #4
0
    def setUpMixin(self):
        # note that we can't use an in-memory DB, as that is not usable
        # from multiple threads.
        self.dbfile = os.path.join(self.tempdir, 'db.sqlite3')
        self.db = db.setup('sqlite:///' + self.dbfile)
        model.metadata.create_all(bind=self.db.pool.engine)

        # reset the local "fake" stuff
        self.inventory_id = 1
Exemple #5
0
    def setUpMixin(self):
        # note that we can't use an in-memory DB, as that is not usable
        # from multiple threads.
        self.dbfile = os.path.join(self.tempdir, 'db.sqlite3')
        self.db = db.setup('sqlite:///' + self.dbfile)
        model.metadata.create_all(bind=self.db.pool.engine)

        # reset the local "fake" stuff
        self.inventory_id = 1
Exemple #6
0
def main():
    parser = argparse.ArgumentParser(description='Sync BMM with inventory.')
    parser.add_argument('--verbose', action='store_true',
                        default=False,
                        help='verbose output')
    parser.add_argument('--ship-it', action='store_true',
                        default=False,
                        help="Make large changes; don't use this flag in a crontask!")
    args = parser.parse_args()

    db = setup()
    sync(db, verbose=args.verbose, ship_it=args.ship_it)
def main():
    parser = argparse.ArgumentParser(description='Sync BMM with inventory.')
    parser.add_argument('--verbose',
                        action='store_true',
                        default=False,
                        help='verbose output')
    parser.add_argument(
        '--ship-it',
        action='store_true',
        default=False,
        help="Make large changes; don't use this flag in a crontask!")
    args = parser.parse_args()

    db = setup()
    sync(db, verbose=args.verbose, ship_it=args.ship_it)