]>
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 peer node ip',
25 'example': ['vxlan-peernodeip 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 peernodeips
=ifaceobj
.get_attr_value('vxlan-peernodeip'),
48 learning
=ifaceobj
.get_attr_value_first('vxlan-learning'))
49 if ifaceobj
.addr_method
== 'manual':
50 rtnetlink_api
.rtnl_api
.link_set(ifaceobj
.name
, "up")
52 def _down(self
, ifaceobj
):
54 self
.ipcmd
.link_delete(ifaceobj
.name
)
58 def _query_check_n_update(self
, ifaceobjcurr
, attrname
, attrval
,
60 if running_attrval
and attrval
== running_attrval
:
61 ifaceobjcurr
.update_config_with_status(attrname
, attrval
, 0)
63 ifaceobjcurr
.update_config_with_status(attrname
, running_attrval
, 1)
65 def _query_check_n_update_addresses(self
, ifaceobjcurr
, attrname
,
66 addresses
, running_addresses
):
69 if a
in running_addresses
:
70 ifaceobjcurr
.update_config_with_status(attrname
, a
, 0)
72 ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
73 running_addresses
= Set(running_addresses
).difference(
75 [ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
76 for a
in running_addresses
]
78 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
79 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
82 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobj
.name
)
84 ifaceobjcurr
.check_n_update_config_with_status_many(ifaceobj
,
85 self
.get_mod_attrs(), -1)
87 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-id',
88 ifaceobj
.get_attr_value_first('vxlan-id'),
89 vxlanattrs
.get('vxlanid'))
91 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-local-tunnelip',
92 ifaceobj
.get_attr_value_first('vxlan-local-tunnelip'),
93 vxlanattrs
.get('local'))
95 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-svcnodeip',
96 ifaceobj
.get_attr_value('vxlan-svcnodeip'),
97 vxlanattrs
.get('svcnode', []))
99 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-peernodeip',
100 ifaceobj
.get_attr_value('vxlan-peernodeip'),
101 vxlanattrs
.get('peernode', []))
103 learning
= ifaceobj
.get_attr_value_first('vxlan-learning')
104 running_learning
= vxlanattrs
.get('learning')
105 if learning
== running_learning
:
106 ifaceobjcurr
.update_config_with_status('vxlan-learning',
109 ifaceobjcurr
.update_config_with_status('vxlan-learning',
112 def _query_running(self
, ifaceobjrunning
):
113 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobjrunning
.name
)
116 attrval
= vxlanattrs
.get('vxlanid')
118 ifaceobjrunning
.update_config('vxlan-id', vxlanattrs
.get('vxlanid'))
119 attrval
= vxlanattrs
.get('local')
121 ifaceobjrunning
.update_config('vxlan-local-tunnelip', attrval
)
122 attrval
= vxlanattrs
.get('svcnode')
124 [ifaceobjrunning
.update_config('vxlan-svcnode', a
)
126 attrval
= vxlanattrs
.get('peernode')
128 [ifaceobjrunning
.update_config('vxlan-peernode', a
)
130 attrval
= vxlanattrs
.get('learning')
131 if attrval
and attrval
== 'on':
132 ifaceobjrunning
.update_config('vxlan-learning', 'on')
135 _run_ops
= {'pre-up' : _up
,
137 'query-checkcurr' : _query_check
,
138 'query-running' : _query_running
}
141 return self
._run
_ops
.keys()
143 def _init_command_handlers(self
):
145 self
.ipcmd
= iproute2(**self
.get_flags())
147 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, **extra_args
):
148 op_handler
= self
._run
_ops
.get(operation
)
151 if (operation
!= 'query-running' and
152 not self
._is
_vxlan
_device
(ifaceobj
)):
154 self
._init
_command
_handlers
()
155 if operation
== 'query-checkcurr':
156 op_handler(self
, ifaceobj
, query_ifaceobj
)
158 op_handler(self
, ifaceobj
)