Beispiel #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')]
Beispiel #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
Beispiel #3
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
                                      ]
Beispiel #4
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)
     to_py['addr_from'] = as_xml.find('address/name').text
     to_py['addr_to'] = as_xml.find('address/to/ipaddr').text
Beispiel #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)
     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'])
Beispiel #6
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
Beispiel #7
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)
     e = as_xml.find('src-nat-rule-match')
     to_py['match_src_addr'] = e.find('source-address').text
     to_py['match_dst_addr'] = e.find('destination-address').text
     to_py['pool'] = as_xml.find('.//pool-name').text
Beispiel #8
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')]
Beispiel #9
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
Beispiel #10
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
                ]
Beispiel #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]
Beispiel #12
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, 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]
Beispiel #13
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     to_py['$addrs'] = [name.text for name in as_xml.xpath('address/name')]
     to_py['$sets'] = [
         name.text for name in as_xml.xpath('address-set/name')]
Beispiel #14
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     to_py['$rules'] = [
         policy.text for policy in as_xml.xpath('.//policy/name')]
     to_py['$rules_count'] = len(to_py['$rules'])
Beispiel #15
0
 def _xml_to_py(self, has_xml, has_py):
     Resource._r_has_xml_status(has_xml, has_py)
Beispiel #16
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)
     to_py['zone_from'] = as_xml.find('from/zone').text
     to_py['zone_to'] = as_xml.find('to/zone').text
     to_py['$rules'] = [rule.text for rule in as_xml.xpath('.//rule/name')]
     to_py['$rules_count'] = len(to_py['$rules'])
Beispiel #17
0
 def _xml_to_py(self, has_xml, has_py):
     Resource._r_has_xml_status(has_xml, has_py)
Beispiel #18
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
Beispiel #19
0
 def _xml_to_py(self, as_xml, to_py):
     Resource._r_has_xml_status(as_xml, to_py)