Debian Codegraph @

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

raw
1 # 3rd-party
2 from lxml.builder import E
3
4 # local module
5 from jnpr.junos.cfg.resource import Resource
6
7
8 class PhyPortBase(Resource):
9 """
10 [edit interfaces <name>]
11
12 Resource name: str
13 <name> is the interface-name (IFD), e.g. 'ge-0/0/0'
14 """
15
16 PROPERTIES = [
17 "admin", # True
18 "description", # str
19 "speed", # ['10m','100m','1g','10g']
20 "duplex", # ['full','half']
21 "mtu", # int
22 "loopback", # True
23 "$unit_count", # number of units defined
24 ]
25
26 PORT_DUPLEX = {"full": "full-duplex", "half": "half-duplex"}
27
28 @classmethod
29 def _set_invert(cls, in_this, item, from_this):
30 from_item = in_this[item]
31 in_this[item] = [_k for _k, _v in from_this.items() if _v == from_item][0]
32
33 # -----------------------------------------------------------------------
34 # XML readers
35 # -----------------------------------------------------------------------
36
37 def _xml_at_top(self):
38 return E.interfaces(E.interface(E.name(self._name)))
39
40 def _xml_at_res(self, xml):
41 return xml.find(".//interface")
42
43 def _xml_to_py(self, has_xml, has_py):
44 # common to all subclasses
45 Resource._r_has_xml_status(has_xml, has_py)
46 has_py["admin"] = bool(has_xml.find("disable") is None)
47 Resource.copyifexists(has_xml, "description", has_py)
48 Resource.copyifexists(has_xml, "mtu", has_py)
49 has_py["$unit_count"] = len(has_xml.findall("unit"))
50
51 # -----------------------------------------------------------------------
52 # XML writers
53 # -----------------------------------------------------------------------
54
55 # description handed by Resource
56
57 def _xml_change_admin(self, xml):
58 xml.append(Resource.xmltag_set_or_del("disable", (self.admin is False)))
59 return True
60
61 def _xml_change_mtu(self, xml):
62 Resource.xml_set_or_delete(xml, "mtu", self.mtu)
63 return True
64
65 # -----------------------------------------------------------------------
66 # Manager List, Catalog
67 # -----------------------------------------------------------------------
68
69 def _r_list(self):
70 got = self.R.get_interface_information(
71 media=True, interface_name="[efgx][et]-*"
72 )
73 self._rlist = [
74 name.text.strip() for name in got.xpath("physical-interface/name")
75 ]