Esempio n. 1
0
    def parse_template(str_xml):
        """ Parse a line of local template into structured comamand and device info
        """
        dev_info = DevInfo()
        cmd = Command()

        root = ElementTree.fromstring(str_xml)
        if root.tag == 'Template':
            for element in root:
                if element.tag == 'Command':
                    for sub_element in element:
                        if sub_element.tag == 'AbsCmd':
                            cmd.abs_cmd = sub_element.text
                        elif sub_element.tag == 'ActCmd':
                            cmd.act_cmd = sub_element.text
                        elif sub_element.tag == 'ExpResult':
                            for field in sub_element:
                                cmd.exp_result.append((field.tag, field.text))
                        else:
                            setattr(cmd, sub_element.tag, sub_element.text)
                if element.tag == 'DevInfo':
                    for sub_element in element:
                        if sub_element.tag == 'Type':
                            dev_info.dev_type = sub_element.text
                        elif sub_element.tag == 'Factory':
                            dev_info.dev_factory = sub_element.text
                        elif sub_element.tag == 'Model':
                            dev_info.dev_model = sub_element.text
                        else:
                            setattr(cmd, sub_element.tag, sub_element.text)
        return cmd, dev_info
Esempio n. 2
0
def tutorial_cfg_cmd():
    """ Configure some command templates.
    """
    master = Master()
    cmd = Command()
    cmd.abs_cmd = 'hwinfo'
    cmd.act_cmd = 'lscpu'
    master.cfg_cmd('10.65.7.131', cmd)
    cmd.abs_cmd = 'hwinfo'
    cmd.act_cmd = 'lscpu'
    master.cfg_cmd('10.137.59.22', cmd)
    cmd.abs_cmd = 'networkinfo'
    cmd.act_cmd = 'ifconfig'
    master.cfg_cmd('10.65.7.131', cmd)
    cmd.abs_cmd = 'networkinfo'
    cmd.act_cmd = 'ifconfig'
    master.cfg_cmd('10.137.59.22', cmd)
Esempio n. 3
0
def tutorial_exec_cmd():
    """ Configure one command and execute it to show network interface information on device(here we use linux server
        instead of real device)
    """
    master = Master()
    cmd = Command()

    cmd.abs_cmd = 'networkinfo'
    cmd.act_cmd = 'ifconfig'
    master.cfg_cmd('10.137.59.22', cmd)

    para_list = []
    identity1 = Identity()
    identity1.ip = '10.137.59.22'
    identity1.dev_id = 'tianyi.dty'
    identity1.dev_pw = 'Mtfbwy626488'
    telnetPro = ('telnet_server_control', 'TelnetServerControl')
    para_list.append(('cmd', 'networkinfo', identity1, telnetPro))
    result = master.execute(para_list)
    print 'result:'
    print result
Esempio n. 4
0
def tutorial_exec_script():
    """ Configure two types of comamands, then execute a script to show hardware and network information on device
        (here we use linux server instead of real device)
    """
    master = Master()
    cmd = Command()

    cmd.abs_cmd = 'hwinfo'
    cmd.act_cmd = 'lscpu'
    master.cfg_cmd('10.65.7.131', cmd)
    cmd.abs_cmd = 'hwinfo'
    cmd.act_cmd = 'lscpu'
    master.cfg_cmd('10.137.59.22', cmd)
    cmd.abs_cmd = 'networkinfo'
    cmd.act_cmd = 'ifconfig'
    master.cfg_cmd('10.65.7.131', cmd)

    para_list = [('script', 'script-linux.py')]
    result = master.execute(para_list)
    print 'result:'
    print result
Esempio n. 5
0
def tutorial_exec_script2():
    """ Configure two commands which have the same abstract command on different devices. Then execute a script which
        contains both these commands to show network interface information on device(here we use linux server instead
        of real device)
    """
    master = Master()
    cmd = Command()

    cmd.abs_cmd = 'show'
    cmd.act_cmd = 'show -hw'
    master.cfg_cmd('1.1.1.1', cmd)
    cmd.abs_cmd = 'ps'
    cmd.act_cmd = 'ps -hw'
    master.cfg_cmd('1.1.1.1', cmd)
    cmd.abs_cmd = 'show'
    cmd.act_cmd = 'show -cisco'
    master.cfg_cmd('192.168.0.1', cmd)

    para_list = [('script', 'script-diffdev.py')]
    result = master.execute(para_list)
    print 'result:'
    print result