def implement_show_running_config(context, data): """ Manager for the 'show running-config' command, which calls the specific detail functions for any of the parameters. """ # use the bigdb scoreboard to collect the running-config. global rc_scoreboard rc_scoreboard = BigDB_RC_scoreboard() context.rc_scoreboard = rc_scoreboard if len(data): # pick the word word = data['running-config'] choice = utif.full_word_from_choices(word, registry_items_enabled(context)) if choice: perform_running_config(choice, context, rc_scoreboard, data) else: yield context.error_msg("unknown running-config item: %s" % word) return # config[:-1] removes the last trailing newline # display any erros associated with the generation of the running config for item in rc_scoreboard.generate_errors(): print 'Warning; \n' + item yield '!\n' yield '! Warning: \n' + item else: # Create the order based on the registration value running_config_order = sorted( registry_items_enabled(context), key=lambda item: running_config_registry[item]['order']) # Since the scoreboard defines the ouutput order, the # running-config generators can be run in any order. for rc in running_config_order: perform_running_config(rc, context, rc_scoreboard, data) # display any erros associated with the generation of the running config for item in rc_scoreboard.generate_errors(): print 'Warning: \n' + item yield '!\n' yield '! Warning: \n' + item yield "!\n" yield "! %s" % 'NEED VERSION STRING\n' # context.do_show_version yield "! Current Time: %s\n" % \ datetime.datetime.now().strftime("%Y-%m-%d.%H:%M:%S %Z") yield "!\n" yield "version 1.0\n" # need a better determination of command syntax version for item in rc_scoreboard.generate(): yield item rc_scoreboard = None context.rc_scoreboard = None
def implement_show_running_config(context, data): """ Manager for the 'show running-config' command, which calls the specific detail functions for any of the parameters. """ # use the bigdb scoreboard to collect the running-config. global rc_scoreboard rc_scoreboard = BigDB_RC_scoreboard() context.rc_scoreboard = rc_scoreboard if len(data): # pick the word word = data['running-config'] choice = utif.full_word_from_choices(word, registry_items_enabled(context)) if choice: perform_running_config(choice, context, rc_scoreboard, data) else: yield context.error_msg("unknown running-config item: %s" % word) return # config[:-1] removes the last trailing newline # display any erros associated with the generation of the running config for item in rc_scoreboard.generate_errors(): print 'Warning; \n' + item yield '!\n' yield '! Warning: \n' + item else: # Create the order based on the registration value running_config_order = sorted(registry_items_enabled(context), key=lambda item: running_config_registry[item]['order']) # Since the scoreboard defines the ouutput order, the # running-config generators can be run in any order. for rc in running_config_order: perform_running_config(rc, context, rc_scoreboard, data) # display any erros associated with the generation of the running config for item in rc_scoreboard.generate_errors(): print 'Warning: \n' + item yield '!\n' yield '! Warning: \n' + item yield "!\n" yield "! %s" % 'NEED VERSION STRING\n' # context.do_show_version yield "! Current Time: %s\n" % \ datetime.datetime.now().strftime("%Y-%m-%d.%H:%M:%S %Z") yield "!\n" yield "version 1.0\n" # need a better determination of command syntax version for item in rc_scoreboard.generate(): yield item rc_scoreboard = None context.rc_scoreboard = None
def perform_running_config(name, context, scoreboard, data, with_errors = None): """ Callout to append to config """ global rc_scoreboard rc_scoreboard = scoreboard if scoreboard == None: rc_scoreboard = BigDB_RC_scoreboard(with_errors = with_errors) context.rc_scoreboard = rc_scoreboard if name in running_config_registry: try: running_config_registry[name]['proc'](context, rc_scoreboard, data) except urllib2.HTTPError, e: if context.description: print 'perform_running_config: rest error', e rc_scoreboard.add_error(e.code)
def perform_running_config(name, context, scoreboard, data, with_errors=None): """ Callout to append to config """ global rc_scoreboard rc_scoreboard = scoreboard if scoreboard == None: rc_scoreboard = BigDB_RC_scoreboard(with_errors=with_errors) context.rc_scoreboard = rc_scoreboard if name in running_config_registry: try: running_config_registry[name]['proc'](context, rc_scoreboard, data) except urllib2.HTTPError, e: if context.description: print 'perform_running_config: rest error', e rc_scoreboard.add_error(e.code)