def _query_state_rci(state):
    """\
    Parse an RCI response via ElementTree.
    
    Present limitations:
    
        o Only returns tags in the first level below "state".

        o Appends any tag attributes to the tag name, but the order may
            change since ElementTree sorts them.  Best to use only one
            attribute per tag.
    """

    query_string = """\
<rci_request version="1.1">
    <query_state>
        <%s/>
    </query_state>
</rci_request>""" % state


    state_tree = ElementTree().parsestring("<"+state+" />")
    
    state_xml = simple_rci_query(query_string)
    tree = ElementTree().parsestring(state_xml)    
    root_list = tree.findall(state_tree.tag)
    return root_list
def get_device_id():
    """\
        Retrieves the Device ID from the Digi device.
    """
    value = ""
    query_base = '<rci_request version="1.1"><%s><%s/>' \
                 '</%s></rci_request>'
    try:
        query = query_base % ('query_setting', 'mgmtglobal', 'query_setting')
        raw_data = process_rci_request(query)
        setting_tree = ElementTree().parsestring(raw_data)
        device_id = setting_tree.find('deviceId')
        value = device_id.text
    except AttributeError:
        # PLATFORM: this might be an x2e
        query = query_base % ('query_state', 'device_info', 'query_state')
        raw_data = process_rci_request(query)
        setting_tree = ElementTree().parsestring(raw_data)
        device_id = setting_tree.find('deviceid')
        value = device_id.text

        # normalize to the old NDS format
        if not value.startswith('0x'):
            value = ''.join(('0x', value))
        value = value.replace('-', '')
    except:
        _tracer.error("get_device_id(): Unable to retrieve Device ID")
        raise

    return value
Example #3
0
def _query_state_rci(state):
    """\
    Parse an RCI response via ElementTree.

    Present limitations:

        o Only returns tags in the first level below "state".

        o Appends any tag attributes to the tag name, but the order may
            change since ElementTree sorts them.  Best to use only one
            attribute per tag.
    """

    query_string = """\
<rci_request version="1.1">
    <query_state>
        <%s/>
    </query_state>
</rci_request>""" % state

    state_tree = ElementTree().parsestring("<" + state + " />")

    state_xml = simple_rci_query(query_string)
    tree = ElementTree().parsestring(state_xml)
    root_list = tree.findall(state_tree.tag)
    return root_list
Example #4
0
def get_ethernet_mac_string():
    """\
        Returns the Ethernet MAC address as a string, using RCI 'device_info'
        
        Example: "00:40:9D:6A:72:F6"
    """

    if sys.platform == 'digiconnect':
        # in Connect/ConnectPort, looking for:
        # <device_info>
        #    <mac>00:40:9d:52:1d:6e</mac>
        # </device_info>
        info = query_state("device_info")
        for item in info:
            mac = item.find('mac')
            if mac != None:
                return mac.text

    elif sys.platform == 'linux2':
        # in X2e ZB/3G, looking for
        # <interface_info name="eth0">
        #    <mac>00:40:9d:52:1d:6e</mac>
        # </interface_info>

        response = process_rci_request(
            '<rci_request version="1.1"><query_state /></rci_request>')

        # there may be a cleaner method, but we have multiple possible nodes
        # like <interface_info name="eth0"> and <interface_info name="wlan0">
        # I couldn't find a cleaner way to find <interface_info name="eth0"> if
        # it is NOT the first interface_info
        root = ElementTree().parsestring(response)
        inf_list = root.findall('interface_info')

        interface_node = None
        for node in inf_list:
            if interface_node is None:
                # save the very first 'interface_info' we find, but keep going
                interface_node = node

            if node.attrib['name'] in ('eth0'):
                # break and use this one
                interface_node = node
                break

        # this will return string like '00:40:9d:5c:1b:05" or None
        if interface_node is not None:
            return interface_node.findtext('mac')

    return None
 def get_address(self):
     """\
         Retrieves the current iDigi SMS phone number from the Digi device.
     """
     phnum = ""
     try:
         query = '<rci_request version="1.1"><query_setting><idigisms/>' \
             '</query_setting></rci_request>'
         raw_data = process_rci_request(query)
         setting_tree = ElementTree().parsestring(raw_data)
         phnum = setting_tree.find("phnum")
         phnum = phnum.text
     except Exception, e:
         self.__tracer.error(e)
         pass
Example #6
0
 def get_address(self):
     """\
         Retrieves the current SMS phone number from the Digi device.
     """
     phnum = ""
     try:
         query = '<rci_request version="1.1"><query_setting><idigisms/>' \
             '</query_setting></rci_request>'
         raw_data = process_rci_request(query)
         setting_tree = ElementTree().parsestring(raw_data)
         phnum = setting_tree.find("phnum")
         phnum = phnum.text
     except Exception, e:
         sms_idigi_client_tracer.error(e)
         pass
def get_device_id():
    """\
        Retrieves the Device ID from the Digi device.
    """
    value = ""
    try:
        query = '<rci_request version="1.1"><query_setting><mgmtglobal/>' \
                '</query_setting></rci_request>'
        raw_data = process_rci_request(query)
        setting_tree = ElementTree().parsestring(raw_data)
        device_id = setting_tree.find("deviceId")
        value = device_id.text
    except:
        _tracer.error("get_device_id(): Unable to retrieve Device ID")
        raise

    return value
Example #8
0
def get_device_id():
    """\
        Retrieves the Device ID from the Digi device.
    """
    value = ""
    query_base = '<rci_request version="1.1"><%s><%s/>' \
                 '</%s></rci_request>'
    try:
        query = query_base % ('query_setting', 'mgmtglobal', 'query_setting')
        raw_data = process_rci_request(query)
        setting_tree = ElementTree().parsestring(raw_data)
        device_id = setting_tree.find('deviceId')
        value = device_id.text
    except AttributeError:
        # PLATFORM: this might be an x2e
        query = query_base % ('query_state', 'device_info', 'query_state')
        raw_data = process_rci_request(query)
        setting_tree = ElementTree().parsestring(raw_data)
        device_id = setting_tree.find('deviceid')
        value = device_id.text

        # normalize to the old NDS format
        if not value.startswith('0x'):
            value = ''.join(('0x', value))
        value = value.replace('-', '')
    except:
        _tracer.error("get_device_id(): Unable to retrieve Device ID")
        raise

    return value