summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2018-06-09 10:44:47 +0200
committerOlivier Gayot <olivier.gayot@sigexec.com>2018-06-09 10:50:17 +0200
commitbde5321c4993a90f972389623a2ced9a0499f5c5 (patch)
tree716b72d7206a94c2ba2c7e390e61e50cc1490b27
parent759bd8222be51f70dad6449addc2b035bd8c98d3 (diff)
Add the MACVLAN creation
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rwxr-xr-xip-link-add-menu.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/ip-link-add-menu.py b/ip-link-add-menu.py
index 4d04908..cc9ab05 100755
--- a/ip-link-add-menu.py
+++ b/ip-link-add-menu.py
@@ -37,6 +37,22 @@ class VLAN():
vlan_id=self.vid
).commit()
+class MACVLAN():
+ def __init__(self, name, master, mode):
+ self.name = name
+ self.master = master
+ self.mode = mode
+
+ def create(self):
+ global ipdb
+ underlying = ipdb.interfaces[self.master]
+ ipdb.create(
+ kind='macvlan',
+ ifname=self.name,
+ link=underlying,
+ mode=self.mode
+ ).commit()
+
def create_bridge():
choices = [(str(i), '', False) for i in ipdb.by_name.keys()]
@@ -78,12 +94,40 @@ def create_vlan():
vlan.create()
+def create_macvlan():
+ choices = [(str(i), '') for i in ipdb.by_name.keys()]
+
+ code, master = d.menu('Select the master interface to use.', choices=choices)
+
+ if code == d.ESC or code == d.CANCEL:
+ return
+
+ code, name = d.inputbox('Please name your new MACVLAN interface.')
+
+ if code == d.ESC or code == d.CANCEL:
+ return
+
+ choices = [
+ ('private', 'Private'),
+ ('vepa', 'VEPA'),
+ ('bridge', 'Bridge'),
+ ('passthru', 'Passthrough'),
+ ('source', 'Source'),
+ ]
+
+ code, mode = d.menu('Select the mode of MACVLAN interface.', choices=choices)
+
+ macvlan = MACVLAN(name, master, mode)
+
+ macvlan.create()
+
def main():
d.set_background_title('ip-link add menu')
choices = (
('bridge', 'Create a Bridge'),
('vlan', 'Create a VLAN'),
+ ('macvlan', 'Create a MACVLAN'),
)
code, tag = d.menu('Select the type of interface you want to create.', choices=choices)
@@ -95,6 +139,8 @@ def main():
create_bridge()
elif tag == 'vlan':
create_vlan()
+ elif tag == 'macvlan':
+ create_macvlan()
if __name__ == '__main__':
main()