Debian Codegraph @

lib/jnpr/junos/cfg/phyport/classic.py

raw
1 # 3rd-party
2 from lxml.builder import E
3
4 # local
5 from jnpr.junos.cfg.resource import Resource
6 from jnpr.junos import JXML
7 from jnpr.junos.cfg.phyport.base import PhyPortBase
8
9
10 class PhyPortClassic(PhyPortBase):
11 # -----------------------------------------------------------------------
12 # XML readers
13 # -----------------------------------------------------------------------
14
15 def _xml_to_py(self, has_xml, has_py):
16 PhyPortBase._xml_to_py(self, has_xml, has_py)
17
18 Resource.copyifexists(has_xml, "speed", has_py)
19 Resource.copyifexists(has_xml, "link-mode", has_py, "duplex")
20 if has_xml.find("gigether-options/loopback") is not None:
21 has_py["loopback"] = True
22 has_py["$unit_count"] = len(has_xml.findall("unit"))
23
24 # normalizers
25 if "duplex" in has_py:
26 PhyPortBase._set_invert(has_py, "duplex", self.PORT_DUPLEX)
27
28 # -----------------------------------------------------------------------
29 # XML writers
30 # -----------------------------------------------------------------------
31
32 def _xml_change_speed(self, xml):
33 Resource.xml_set_or_delete(xml, "speed", self.speed)
34 return True
35
36 def _xml_change_duplex(self, xml):
37 value = self.PORT_DUPLEX.get(self.duplex)
38 Resource.xml_set_or_delete(xml, "link-mode", value)
39 return True
40
41 def _xml_change_loopback(self, xml):
42 opts = E("gigether-options")
43 opts.append(Resource.xmltag_set_or_del("loopback", self.loopback))
44 xml.append(opts)
45 return True