Exemple #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
Exemple #2
0
 def get_devinfo(ip):
     devinfo = DevInfo()
     if ip == '1.1.1.1':
         devinfo.dev_type = 'switch'
         devinfo.dev_factory = 'HW'
         devinfo.dev_model = '150'
         agent_ip = '127.0.0.1'
     elif ip == '192.168.0.1':
         devinfo.dev_type = 'switch'
         devinfo.dev_factory = 'CISCO'
         devinfo.dev_model = '200'
         agent_ip = '127.0.0.1'
     elif ip == '10.65.7.131':  #taobao test device
         devinfo.dev_type = 'server'
         devinfo.dev_factory = 'ALIBABA'
         devinfo.dev_model = 'taobao_test'
         agent_ip = '127.0.0.1'
     elif ip == '10.137.59.22':  # springboard
         devinfo.dev_type = 'server'
         devinfo.dev_factory = 'ALIBABA'
         devinfo.dev_model = 'springboard'
         agent_ip = '127.0.0.1'
     else:
         devinfo.dev_type = 'switch'
         devinfo.dev_factory = 'HW'
         devinfo.dev_model = '150'
         agent_ip = '127.0.0.1'
     return agent_ip, devinfo