Bug fixed Arista SDN plugin
[osm/RO.git] / RO-SDN-arista / osm_rosdn_arista / aristaConfigLet.py
diff --git a/RO-SDN-arista/osm_rosdn_arista/aristaConfigLet.py b/RO-SDN-arista/osm_rosdn_arista/aristaConfigLet.py
new file mode 100644 (file)
index 0000000..bceaa3c
--- /dev/null
@@ -0,0 +1,106 @@
+# -*- coding: utf-8 -*-\r
+##\r
+# Copyright 2019 Atos - CoE Telco NFV Team\r
+# All Rights Reserved.\r
+#\r
+# Contributors: Oscar Luis Peral, Atos\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+# not use this file except in compliance with the License. You may obtain\r
+# a copy of the License at\r
+#\r
+#         http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+# License for the specific language governing permissions and limitations\r
+# under the License.\r
+#\r
+# For those usages not covered by the Apache License, Version 2.0 please\r
+# contact with: <oscarluis.peral@atos.net>\r
+#\r
+# Neither the name of Atos nor the names of its\r
+# contributors may be used to endorse or promote products derived from\r
+# this software without specific prior written permission.\r
+#\r
+# This work has been performed in the context of Arista Telefonica OSM PoC.\r
+##\r
+\r
+\r
+class AristaSDNConfigLet:\r
+    _configLet_SRIOV = """\r
+!# service: {}\r
+interface {}\r
+   switchport\r
+   switchport mode trunk\r
+   switchport trunk group {}{}\r
+!\r
+"""\r
+\r
+    def _get_sriov(self, uuid, interface, vlan_id, s_type, index):\r
+        return self._configLet_SRIOV.format(uuid, interface, s_type, vlan_id)\r
+\r
+    def getElan_sriov(self, uuid, interface, vlan_id, index):\r
+        return self._get_sriov(uuid, interface, vlan_id, "ELAN", index)\r
+\r
+    def getEline_sriov(self, uuid, interface, vlan_id, index):\r
+        return self._get_sriov(uuid, interface, vlan_id, "ELINE", index)\r
+\r
+    _configLet_PASSTROUGH = """\r
+!# service: {}\r
+interface {}\r
+   switchport\r
+   switchport mode access\r
+   switchport access vlan {}\r
+!\r
+"""\r
+\r
+    def _get_passthrough(self, uuid, interface, vlan_id, s_type, index):\r
+        return self._configLet_PASSTROUGH.format(uuid, interface, vlan_id)\r
+\r
+    def getElan_passthrough(self, uuid, interface, vlan_id, index):\r
+        return self._get_passthrough(uuid, interface, vlan_id, "ELAN", index)\r
+\r
+    def getEline_passthrough(self, uuid, interface, vlan_id, index):\r
+        return self._get_passthrough(uuid, interface, vlan_id, "ELINE", index)\r
+\r
+    _configLet_VLAN = """\r
+!## service: {service} {vlan} {uuid}\r
+vlan {vlan}\r
+   name {service}{vlan}\r
+   trunk group {service}{vlan}\r
+   trunk group MLAGPEER\r
+\r
+interface VXLAN1\r
+   VXLAN vlan {vlan} vni {vni}\r
+!\r
+"""\r
+\r
+    def _get_vlan(self, uuid, vlan_id, vni_id, s_type):\r
+        return self._configLet_VLAN.format(service=s_type, vlan=vlan_id, uuid=uuid, vni=vni_id)\r
+\r
+    def getElan_vlan(self, uuid, vlan_id, vni_id):\r
+        return self._get_vlan(uuid, vlan_id, vni_id, "ELAN")\r
+\r
+    def getEline_vlan(self, uuid, vlan_id, vni_id):\r
+        return self._get_vlan(uuid, vlan_id, vni_id, "ELINE")\r
+\r
+    _configLet_BGP = """\r
+!# service: {uuid}\r
+router bgp {bgp}\r
+    vlan {vlan}\r
+        rd {loopback}:{vni}\r
+        route-target both {vni}:{vni}\r
+        redistribute learned\r
+!\r
+"""\r
+\r
+    def _get_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp, s_type):\r
+        return self._configLet_BGP.format(uuid=uuid, bgp=bgp, vlan=vlan_id, loopback=loopback0, vni=vni_id)\r
+\r
+    def getElan_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp):\r
+        return self._get_bgp(uuid, vlan_id, vni_id, loopback0, bgp, "ELAN")\r
+\r
+    def getEline_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp):\r
+        return self._get_bgp(uuid, vlan_id, vni_id, loopback0, bgp, "ELINE")\r