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
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')]
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
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
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
def __init__(self, junos, name=None, **kvargs): if name is None: # resource-manager Resource.__init__(self, junos, name, **kvargs) return self.rule = NatSrcRule(junos, M=self, parent=self) self._manages = ['rule'] Resource.__init__(self, junos, name, **kvargs)
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')]
def __init__(self, junos, name=None, **kvargs): if name is None: # resource-manager Resource.__init__(self, junos, name, **kvargs) return self.ifs = ZoneInterface(junos, parent=self) self.ab = ZoneAddrBook(junos, name, parent=self) self._manages = ['ifs', 'ab'] Resource.__init__(self, junos, name, **kvargs)
def __init__(self, junos, name=None, **kvargs): if name is None: # resource-manager Resource.__init__(self, junos, name, **kvargs) return self.addr = ZoneAddrBookAddr(junos, parent=self) self.set = ZoneAddrBookSet(junos, parent=self) self._manages = ['addr', 'set'] Resource.__init__(self, junos, name, **kvargs)
def __init__(self, junos, name=None, **kvargs): if name is None: # resource-manager Resource.__init__(self, junos, name, **kvargs) return # specific instance will manage policy rules self.rule = PolicyRule(junos, M=self, parent=self) self._manages = ['rule'] self._name_from_zone = name[0] self._name_to_zone = name[1] Resource.__init__(self, junos, name, **kvargs)
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
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 ]
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'])
def _xml_change_log_close(self, xml): xml.append(E.then(E.log( Resource.xmltag_set_or_del( 'session-close', self.should['log_close']) ))) return True
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)
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)
def _xml_change_appset_list(self, xml): if None == self.should.get('appset_list'): self['appset_list'] = [] (adds, dels) = Resource.diff_list( self.has.get('appset_list', []), self.should['appset_list']) for this in adds: xml.append(E('application-set', E.name(this))) for this in dels: xml.append(E('application-set', JXML.DEL, E.name(this))) return True
def _xml__change__hit(self, xml, prop, ele_name): (adds, dels) = Resource.diff_list(self.has[prop], self.should[prop]) if not adds and not dels: return False hit = E('host-inbound-traffic') for this in adds: hit.append(E(ele_name, E.name(this))) for this in dels: hit.append(E(ele_name, JXML.DEL, E.name(this))) xml.append(hit) return True
def _xml_change_match_srcs(self, xml): adds, dels = Resource.diff_list( self.has['match_srcs'], self.should['match_srcs']) if len(adds): x_match = E.match() xml.append(x_match) for this in adds: x_match.append(E('source-address', E.name(this))) if len(dels): x_match = E.match() xml.append(x_match) for this in dels: x_match.append(E('source-address', JXML.DEL, E.name(this))) return True
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 ]
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]
def _xml_change_count(self, xml): xml.append(E.then( Resource.xmltag_set_or_del('count', self.should['count']) )) return True
def _xml_change_duplex(self, xml): value = self.PORT_DUPLEX.get(self.duplex) Resource.xml_set_or_delete(self._ethopts, 'link-mode', value) return True
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]
def _xml_change_loopback(self, xml): self._ethopts.append( Resource.xmltag_set_or_del( 'loopback', self.loopback)) return True
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')]
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'])
def _xml_to_py(self, has_xml, has_py): Resource._r_has_xml_status(has_xml, has_py)
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'])
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
def _xml_to_py(self, as_xml, to_py): Resource._r_has_xml_status(as_xml, to_py)