示例#1
0
def run(op_str, args):
    try:
        full_cmd = os.getenv('USER_COMMAND', None)
        if full_cmd is not None:
            pipestr().write(full_cmd.split())
        resp = request_handlers[op_str](args)
        response_handlers[op_str](resp, args)
    except Exception as e:
        print("%Error: {}".format(str(e)))

    return
示例#2
0
def show_cli_output(template_file, response):
    # Create the jinja2 environment.
    # Notice the use of trim_blocks, which greatly helps control whitespace.

    template_path = os.getenv("RENDERER_TEMPLATE_PATH")
    #template_path = os.path.abspath(os.path.join(THIS_DIR, "../render-templates"))

    j2_env = Environment(loader=FileSystemLoader(template_path),extensions=['jinja2.ext.do','jinja2.ext.loopcontrols'])
    j2_env.trim_blocks = True
    j2_env.lstrip_blocks = True
    j2_env.rstrip_blocks = True

    def datetimeformat(time):
        return datetime.datetime.fromtimestamp(int(time)).strftime('%Y-%m-%d %H:%M:%S')

    j2_env.globals.update(datetimeformat=datetimeformat)

    full_cmd = os.getenv('USER_COMMAND', None)
    if full_cmd is not None:
        pipestr().write(full_cmd.split())

    if response:
        t_str = (j2_env.get_template(template_file).render(json_output=response))
        write(t_str)
示例#3
0
def write(t_str):
    global line_count
    line_count = 0
    q = False

    render_init(0)
    if t_str != "":
        pipelst = pipestr().read()
        for s_str in t_str.split('\n'):
            if pipelst:
                if pipelst.process_pipes(s_str):
                    q = _write(s_str, pipelst.is_page_disabled())
            else:
                q = _write(s_str)
            if q:
                break
示例#4
0
        #print("Exception when calling OpenconfigInterfacesApi->%s : %s\n" %(func.__name__, e))
        if e.body != "":
            body = json.loads(e.body)
            if "ietf-restconf:errors" in body:
                err = body["ietf-restconf:errors"]
                if "error" in err:
                    errList = err["error"]

                    errDict = {}
                    for dict in errList:
                        for k, v in dict.iteritems():
                            errDict[k] = v

                    if "error-message" in errDict:
                        print "%Error: " + errDict["error-message"]
                        return
                    print "%Error: Transaction Failure"
                    return
            print "%Error: Transaction Failure"
        else:
            print "Failed"


if __name__ == '__main__':

    pipestr().write(sys.argv)
    func = eval(sys.argv[1], globals(),
                openconfig_interfaces_client.OpenconfigInterfacesApi.__dict__)

    run(func, sys.argv[2:])