]>
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 get_dependent_ifacenames(self
, ifaceobj
, ifaceobjs_all
=None):
37 if not self
._is
_vxlan
_device
(ifaceobj
):
39 ifaceobj
.link_kind |
= ifaceLinkKind
.VXLAN
42 def _is_vxlan_device(self
, ifaceobj
):
43 if ifaceobj
.get_attr_value_first('vxlan-id'):
47 def _up(self
, ifaceobj
):
48 vxlanid
= ifaceobj
.get_attr_value_first('vxlan-id')
50 self
.ipcmd
.link_create_vxlan(ifaceobj
.name
, vxlanid
,
51 localtunnelip
=ifaceobj
.get_attr_value_first('vxlan-local-tunnelip'),
52 svcnodeips
=ifaceobj
.get_attr_value('vxlan-svcnodeip'),
53 remoteips
=ifaceobj
.get_attr_value('vxlan-remoteip'),
54 learning
=ifaceobj
.get_attr_value_first('vxlan-learning'),
55 ageing
=ifaceobj
.get_attr_value_first('vxlan-ageing'))
56 if ifaceobj
.addr_method
== 'manual':
57 rtnetlink_api
.rtnl_api
.link_set(ifaceobj
.name
, "up")
59 def _down(self
, ifaceobj
):
61 self
.ipcmd
.link_delete(ifaceobj
.name
)
65 def _query_check_n_update(self
, ifaceobjcurr
, attrname
, attrval
,
67 if running_attrval
and attrval
== running_attrval
:
68 ifaceobjcurr
.update_config_with_status(attrname
, attrval
, 0)
70 ifaceobjcurr
.update_config_with_status(attrname
, running_attrval
, 1)
72 def _query_check_n_update_addresses(self
, ifaceobjcurr
, attrname
,
73 addresses
, running_addresses
):
76 if a
in running_addresses
:
77 ifaceobjcurr
.update_config_with_status(attrname
, a
, 0)
79 ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
80 running_addresses
= Set(running_addresses
).difference(
82 [ifaceobjcurr
.update_config_with_status(attrname
, a
, 1)
83 for a
in running_addresses
]
85 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
86 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
89 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobj
.name
)
91 ifaceobjcurr
.check_n_update_config_with_status_many(ifaceobj
,
92 self
.get_mod_attrs(), -1)
94 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-id',
95 ifaceobj
.get_attr_value_first('vxlan-id'),
96 vxlanattrs
.get('vxlanid'))
98 self
._query
_check
_n
_update
(ifaceobjcurr
, 'vxlan-local-tunnelip',
99 ifaceobj
.get_attr_value_first('vxlan-local-tunnelip'),
100 vxlanattrs
.get('local'))
102 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-svcnodeip',
103 ifaceobj
.get_attr_value('vxlan-svcnodeip'),
104 vxlanattrs
.get('svcnode', []))
106 self
._query
_check
_n
_update
_addresses
(ifaceobjcurr
, 'vxlan-remoteip',
107 ifaceobj
.get_attr_value('vxlan-remoteip'),
108 vxlanattrs
.get('remote', []))
110 learning
= ifaceobj
.get_attr_value_first('vxlan-learning')
113 running_learning
= vxlanattrs
.get('learning')
114 if learning
== running_learning
:
115 ifaceobjcurr
.update_config_with_status('vxlan-learning',
118 ifaceobjcurr
.update_config_with_status('vxlan-learning',
121 def _query_running(self
, ifaceobjrunning
):
122 vxlanattrs
= self
.ipcmd
.get_vxlandev_attrs(ifaceobjrunning
.name
)
125 attrval
= vxlanattrs
.get('vxlanid')
127 ifaceobjrunning
.update_config('vxlan-id', vxlanattrs
.get('vxlanid'))
128 attrval
= vxlanattrs
.get('local')
130 ifaceobjrunning
.update_config('vxlan-local-tunnelip', attrval
)
131 attrval
= vxlanattrs
.get('svcnode')
133 [ifaceobjrunning
.update_config('vxlan-svcnode', a
)
135 attrval
= vxlanattrs
.get('remote')
137 [ifaceobjrunning
.update_config('vxlan-remoteip', a
)
139 attrval
= vxlanattrs
.get('learning')
140 if attrval
and attrval
== 'on':
141 ifaceobjrunning
.update_config('vxlan-learning', 'on')
144 _run_ops
= {'pre-up' : _up
,
146 'query-checkcurr' : _query_check
,
147 'query-running' : _query_running
}
150 return self
._run
_ops
.keys()
152 def _init_command_handlers(self
):
154 self
.ipcmd
= iproute2(**self
.get_flags())
156 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, **extra_args
):
157 op_handler
= self
._run
_ops
.get(operation
)
160 if (operation
!= 'query-running' and
161 not self
._is
_vxlan
_device
(ifaceobj
)):
163 self
._init
_command
_handlers
()
164 if operation
== 'query-checkcurr':
165 op_handler(self
, ifaceobj
, query_ifaceobj
)
167 op_handler(self
, ifaceobj
)