]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/addons/vxlan.py
3 from ifupdown
.iface
import *
4 from ifupdownaddons
.modulebase
import moduleBase
5 from ifupdownaddons
.iproute2
import iproute2
6 import ifupdown
.rtnetlink_api
as rtnetlink_api
10 class vxlan(moduleBase
):
11 _modinfo
= {'mhelp' : 'vxlan module configures vxlan interfaces.',
16 'example': ['vxlan-id 100']},
17 'vxlan-local-tunnelip' :
18 {'help' : 'vxlan local tunnel ip',
19 'example': ['vxlan-local-tunnelip 172.16.20.103']},
22 'example': ['vxlan-svcnodeip 172.16.22.125']},
24 {'help' : 'vxlan remote ip',
25 'example': ['vxlan-remoteip 172.16.22.127']},
27 {'help' : 'vxlan learning on/off',
28 'example': ['vxlan-learning off'],
32 def __init__(self
, *args
, **kargs
):
33 moduleBase
.__init
__(self
, *args
, **kargs
)
36 def _is_vxlan_device(self
, ifaceobj
):
37 if ifaceobj
.get_attr_value_first('vxlan-id'):
41 def _up(self
, ifaceobj
):
42 vxlanid
= ifaceobj
.get_attr_value_first('vxlan-id')
44 self
.ipcmd
.link_create_vxlan(ifaceobj
.name
, vxlanid
,
45 localtunnelip
=ifaceobj
.get_attr_value_first('vxlan-local-tunnelip'),
46 svcnodeips
=ifaceobj
.get_attr_value('vxlan-svcnodeip'),
47 remoteips
=ifaceobj
.get_attr_value('vxlan-remoteip'),
48 learning
=ifaceobj
.get_attr_value_first('vxlan-learning'),
49 ageing
=ifaceobj
.get_attr_value_first('vxlan-ageing'))
50 if ifaceobj
.addr_method
== 'manual':
51 rtnetlink_api
.rtnl_api
.link_set(ifaceobj
.name
, "up")
53 def _down(self
, ifaceobj
):
55 self
.ipcmd
.link_delete(ifaceobj
.name
)
59 def _query_check_n_update(self
, ifaceobjcurr
, attrname
, attrval
,
61 if running_attrval
and attrval
== running_attrval
:
62 ifaceobjcurr
.update_config_with_status(attrname
, attrval
, 0)
64 ifaceobjcurr
.update_config_with_status(attrname
, running_attrval
, 1)
66 def _query_check_n_update_addresses(self
, ifaceobjcurr
, attrname
,
67 addresses
, running_addresses
):
70 if a
in running_addresses
:
71 ifaceobjcurr
.update_config_with_status(attrname
, a
, 0)
73 ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
74 running_addresses
= Set(running_addresses
).difference(
76 [ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
77 for a
in running_addresses
]
79 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
80 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
83 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobj
.name
)
85 ifaceobjcurr
.check_n_update_config_with_status_many(ifaceobj
,
86 self
.get_mod_attrs(), -1)
88 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-id',
89 ifaceobj
.get_attr_value_first('vxlan-id'),
90 vxlanattrs
.get('vxlanid'))
92 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-local-tunnelip',
93 ifaceobj
.get_attr_value_first('vxlan-local-tunnelip'),
94 vxlanattrs
.get('local'))
96 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-svcnodeip',
97 ifaceobj
.get_attr_value('vxlan-svcnodeip'),
98 vxlanattrs
.get('svcnode', []))
100 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-remoteip',
101 ifaceobj
.get_attr_value('vxlan-remoteip'),
102 vxlanattrs
.get('remote', []))
104 learning
= ifaceobj
.get_attr_value_first('vxlan-learning')
107 running_learning
= vxlanattrs
.get('learning')
108 if learning
== running_learning
:
109 ifaceobjcurr
.update_config_with_status('vxlan-learning',
112 ifaceobjcurr
.update_config_with_status('vxlan-learning',
115 def _query_running(self
, ifaceobjrunning
):
116 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobjrunning
.name
)
119 attrval
= vxlanattrs
.get('vxlanid')
121 ifaceobjrunning
.update_config('vxlan-id', vxlanattrs
.get('vxlanid'))
122 attrval
= vxlanattrs
.get('local')
124 ifaceobjrunning
.update_config('vxlan-local-tunnelip', attrval
)
125 attrval
= vxlanattrs
.get('svcnode')
127 [ifaceobjrunning
.update_config('vxlan-svcnode', a
)
129 attrval
= vxlanattrs
.get('remote')
131 [ifaceobjrunning
.update_config('vxlan-remoteip', a
)
133 attrval
= vxlanattrs
.get('learning')
134 if attrval
and attrval
== 'on':
135 ifaceobjrunning
.update_config('vxlan-learning', 'on')
138 _run_ops
= {'pre-up' : _up
,
140 'query-checkcurr' : _query_check
,
141 'query-running' : _query_running
}
144 return self
._run
_ops
.keys()
146 def _init_command_handlers(self
):
148 self
.ipcmd
= iproute2(**self
.get_flags())
150 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, **extra_args
):
151 op_handler
= self
._run
_ops
.get(operation
)
154 if (operation
!= 'query-running' and
155 not self
._is
_vxlan
_device
(ifaceobj
)):
157 self
._init
_command
_handlers
()
158 if operation
== 'query-checkcurr':
159 op_handler(self
, ifaceobj
, query_ifaceobj
)
161 op_handler(self
, ifaceobj
)