예제 #1
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     Resource.copyifexists(as_xml, 'description', to_py)
     to_py['addr_list'] = [
         name.text for name in as_xml.xpath('address/name')]
     to_py['set_list'] = [
         name.text for name in as_xml.xpath('address-set/name')]
예제 #2
0
    def _xml_to_py(self, as_xml, to_py):
        Resource._r_has_xml_status(as_xml, to_py)
        Resource.copyifexists(as_xml, 'description', to_py)

        x_match = as_xml.find('match')
        x_then = as_xml.find('then')

        # collect up the 'match' criteria

        to_py['match_srcs'] = [
            this.text for this in x_match.findall('source-address')]
        to_py['match_dsts'] = [
            this.text for this in x_match.findall('destination-address')]
        to_py['match_apps'] = [
            this.text for this in x_match.findall('application')]

        # collect up the 'then' criteria

        to_py['action'] = x_then.xpath('permit | reject | deny')[0].tag

        if x_then.find('count') is not None:
            to_py['count'] = True
        if x_then.find('log/session-init') is not None:
            to_py['log_init'] = True
        if x_then.find('log/session-close') is not None:
            to_py['log_close'] = True
예제 #3
0
 def _xml_to_py(self, as_xml, to_py):
     """
     converts Junos XML to native Python
     """
     Resource._r_has_xml_status(as_xml, to_py)
     Resource.copyifexists(as_xml, 'description', to_py)
     e = as_xml.find('static-nat-rule-match')
     to_py['match_dst_addr'] = e.find('destination-address').text
예제 #4
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     Resource.copyifexists(as_xml, 'description', to_py)
     e = as_xml.xpath('host-inbound-traffic/system-services/name')
     to_py['services'] = [n.text for n in e]
     e = as_xml.xpath('host-inbound-traffic/protocols/name')
     to_py['protocols'] = [n.text for n in e]
     to_py['$ifs_list'] = [
         name.text for name in as_xml.xpath('interfaces/name')]
예제 #5
0
    def _xml_to_py(self, has_xml, has_py):
        Resource._r_has_xml_status(has_xml, has_py)
        Resource.copyifexists(has_xml, 'description', has_py)

        # each of the <application> elements
        app_list = [this.findtext('name')
                    for this in has_xml.xpath('application')]
        set_list = [this.findtext('name')
                    for this in has_xml.xpath('application-set')]

        if len(app_list):
            has_py['app_list'] = app_list
        if len(set_list):
            has_py['appset_list'] = set_list
예제 #6
0
    def _xml_to_py(self, has_xml, has_py):
        PhyPortBase._xml_to_py(self, has_xml, has_py)

        # speed, duplex, loopback are all under 'ether-options'
        ethopts = has_xml.find('ether-options')
        if ethopts is None:
            return

        if ethopts.find('loopback') is not None:
            has_py['loopback'] = True

        speed = ethopts.find('speed')
        if speed is not None:
            # take the first child element
            has_py['speed'] = speed[0].tag
            PhyPortBase._set_invert(has_py, 'speed', self.PORT_SPEED)

        Resource.copyifexists(ethopts, 'link-mode', has_py, 'duplex')
        if 'duplex' in has_py:
            PhyPortBase._set_invert(has_py, 'duplex', self.PORT_DUPLEX)
예제 #7
0
    def _xml_to_py(self, has_xml, has_py):
        PhyPortBase._xml_to_py(self, has_xml, has_py)

        # speed, duplex, loopback are all under 'ether-options'
        ethopts = has_xml.find("ether-options")
        if ethopts is None:
            return

        if ethopts.find("loopback") is not None:
            has_py["loopback"] = True

        speed = ethopts.find("speed")
        if speed is not None:
            # take the first child element
            has_py["speed"] = speed[0].tag
            PhyPortBase._set_invert(has_py, "speed", self.PORT_SPEED)

        Resource.copyifexists(ethopts, "link-mode", has_py, "duplex")
        if "duplex" in has_py:
            PhyPortBase._set_invert(has_py, "duplex", self.PORT_DUPLEX)
예제 #8
0
파일: user.py 프로젝트: ARD92/py-junos-eznc
    def _xml_to_py(self, has_xml, has_py):
        Resource._r_has_xml_status(has_xml, has_py)

        has_py['userclass'] = has_xml.findtext('class')

        Resource.copyifexists(has_xml, 'full-name', has_py, 'fullname')

        Resource.copyifexists(has_xml, 'uid', has_py)
        if 'uid' in has_py:
            has_py['uid'] = int(has_py['uid'])

        auth = has_xml.find('authentication')
        if auth is not None:
            # plain-text password
            Resource.copyifexists(
                auth,
                'encrypted-password',
                has_py,
                '$password')

            # ssh-keys
            sshkeys = auth.xpath('ssh-rsa | ssh-dsa')
            if sshkeys is not None:
                has_py['$sshkeys'] = [(sshkey.tag,
                                       sshkey.findtext('name').strip())
                                      for sshkey in sshkeys
                                      ]
예제 #9
0
파일: app.py 프로젝트: dgjnpr/py-junos-eznc
 def _xml_to_py(self, has_xml, has_py):
     Resource._r_has_xml_status(has_xml, has_py)
     Resource.copyifexists(has_xml, 'description', has_py)
     has_py['protocol'] = has_xml.findtext('protocol')
     Resource.copyifexists(has_xml, 'destination-port', has_py, 'dest_port')
     Resource.copyifexists(has_xml, 'inactivity-timeout', has_py, 'timeout')
     if 'timeout' in has_py and has_py['timeout'] != 'never':
         has_py['timeout'] = int(has_py['timeout'])
예제 #10
0
파일: user.py 프로젝트: yggdr/py-junos-eznc
    def _xml_to_py(self, has_xml, has_py):
        Resource._r_has_xml_status(has_xml, has_py)

        has_py["userclass"] = has_xml.findtext("class")

        Resource.copyifexists(has_xml, "full-name", has_py, "fullname")

        Resource.copyifexists(has_xml, "uid", has_py)
        if "uid" in has_py:
            has_py["uid"] = int(has_py["uid"])

        auth = has_xml.find("authentication")
        if auth is not None:
            # plain-text password
            Resource.copyifexists(auth, "encrypted-password", has_py, "$password")

            # ssh-keys
            sshkeys = auth.xpath("ssh-rsa | ssh-dsa")
            if sshkeys is not None:
                has_py["$sshkeys"] = [
                    (sshkey.tag, sshkey.findtext("name").strip()) for sshkey in sshkeys
                ]
예제 #11
0
    def _xml_to_py(self, has_xml, has_py):
        Resource._r_has_xml_status(has_xml, has_py)

        has_py['userclass'] = has_xml.findtext('class')

        Resource.copyifexists(has_xml, 'full-name', has_py, 'fullname')

        Resource.copyifexists(has_xml, 'uid', has_py)
        if 'uid' in has_py:
            has_py['uid'] = int(has_py['uid'])

        auth = has_xml.find('authentication')
        if auth is not None:
            # plain-text password
            Resource.copyifexists(auth, 'encrypted-password', has_py,
                                  '$password')

            # ssh-keys
            sshkeys = auth.xpath('ssh-rsa | ssh-dsa')
            if sshkeys is not None:
                has_py['$sshkeys'] = [(sshkey.tag,
                                       sshkey.findtext('name').strip())
                                      for sshkey in sshkeys]
예제 #12
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     Resource.copyifexists(as_xml, 'description', to_py)
     to_py['ip_prefix'] = as_xml.find('ip-prefix').text