]> git.proxmox.com Git - mirror_ifupdown2.git/blame - addons/vxlan.py
Fix missing import due to merge
[mirror_ifupdown2.git] / addons / vxlan.py
CommitLineData
15ef32ea
RP
1#!/usr/bin/python
2
3from ifupdown.iface import *
4from ifupdownaddons.modulebase import moduleBase
5from ifupdownaddons.iproute2 import iproute2
6import logging
7
8class vxlan(moduleBase):
9 _modinfo = {'mhelp' : 'vxlan module configures vxlan interfaces.',
10 'attrs' : {
11 'vxlan-id' :
12 {'help' : 'vxlan id',
13 'required' : True,
14 'example': ['vxlan-id 100']},
15 'vxlan-local-tunnelip' :
16 {'help' : 'vxlan local tunnel ip',
17 'example': ['vxlan-local-tunnelip 172.16.20.103']},
18 'vxlan-svcnodeip' :
19 {'help' : 'vxlan id',
20 'example': ['vxlan-svcnodeip 172.16.22.125']},
21 'vxlan-peernodeip' :
22 {'help' : 'vxlan peer node ip',
23 'example': ['vxlan-peernodeip 172.16.22.127']},
24 'vxlan-learning' :
25 {'help' : 'vxlan learning on/off',
26 'example': ['vxlan-learning on']},
27 }}
28
29 def __init__(self, *args, **kargs):
30 moduleBase.__init__(self, *args, **kargs)
31 self.ipcmd = None
32
33 def _is_vxlan_device(self, ifaceobj):
34 if ifaceobj.get_attr_value_first('vxlan-id'):
35 return True
36 return False
37
38 def _up(self, ifaceobj):
39 vxlanid = ifaceobj.get_attr_value_first('vxlan-id')
40 if vxlanid:
41 self.ipcmd.link_create_vxlan(ifaceobj.name, vxlanid,
42 localtunnelip=ifaceobj.get_attr_value_first('vxlan-local-tunnelip'),
43 svcnodeips=ifaceobj.get_attr_value('vxlan-svcnodeip'),
44 peernodeips=ifaceobj.get_attr_value('vxlan-peernodeip'),
45 learning=ifaceobj.get_attr_value_first('vxlan-learning'))
46
47 def _down(self, ifaceobj):
48 try:
49 self.ipcmd.link_delete(ifaceobj.name)
50 except Exception, e:
51 self.log_warn(str(e))
52
53 def _query_check(self, ifaceobj, ifaceobjcurr):
54 if not self.ipcmd.link_exists(ifaceobj.name):
55 ifaceobjcurr.status = ifaceStatus.NOTFOUND
56 return
57
58 # Update vxlan object
59
60 def _query_running(self, ifaceobjrunning):
61 # Not implemented
62 return
63
64 _run_ops = {'pre-up' : _up,
65 'post-down' : _down,
66 'query-checkcurr' : _query_check,
67 'query-running' : _query_running}
68
69 def get_ops(self):
70 return self._run_ops.keys()
71
72 def _init_command_handlers(self):
73 if not self.ipcmd:
74 self.ipcmd = iproute2(**self.get_flags())
75
76 def run(self, ifaceobj, operation, query_ifaceobj=None):
77 op_handler = self._run_ops.get(operation)
78 if not op_handler:
79 return
80 if (operation != 'query-running' and
81 not self._is_vxlan_device(ifaceobj)):
82 return
83 self._init_command_handlers()
84 if operation == 'query-checkcurr':
85 op_handler(self, ifaceobj, query_ifaceobj)
86 else:
87 op_handler(self, ifaceobj)