Add MAC Address Configuration

This commit is contained in:
2021-01-26 21:16:46 +01:00
parent 42c1c5fa66
commit a260d2fedb
2 changed files with 31 additions and 18 deletions
+25 -7
View File
@@ -104,13 +104,20 @@ class Interface:
route['dst_len'] = r['dst_len']
self.routes.append(route)
def up(self):
def SetAddress(self, address):
self.address = address
if self.ndb:
self.ndb.set('address', self.address).commit()
elif self.ipr:
iproute.link('set', index=self.index, address=self.address)
def Up(self):
if self.ndb:
self.ndb.set('state', 'up').commit()
elif self.ipr:
iproute.link("set", index=self.index, state="up")
def down(self):
def Down(self):
if self.ndb:
self.ndb.set('state', 'down').commit()
elif self.ipr:
@@ -161,6 +168,9 @@ def test_Variable(v1, v2, f):
assert v1 == v2, "{} not equal ({}, {})".format(f, v1, v2)
def test_Interface():
InitializeLibrary('NDB')
InitializeLibrary('IPR')
itf1 = GetInterface('NDB', 'br0')
itf2 = GetInterface('IPR', 'br0')
@@ -173,27 +183,35 @@ def test_Interface():
#test_Interface()
def test_CreateInterface():
InitializeLibrary('NDB')
InitializeLibrary('IPR')
CreateInterface('NDB', 'ndb0', 'veth', 'ndb1')
CreateInterface('IPR', 'ipr0', 'veth', 'ipr1')
itf1 = GetInterface('NDB', 'ndb0')
itf2 = GetInterface('IPR', 'ipr0')
itf1.up();
itf2.up();
itf1.Up();
itf2.Up();
itf3 = GetInterface('NDB', 'ndb1')
itf4 = GetInterface('IPR', 'ipr1')
itf3.up();
itf4.up();
itf3.SetAddress('00:11:22:33:44:55')
itf4.SetAddress('00:11:22:33:44:56')
itf3.Up();
itf4.Up();
AddPort('NDB', 'br0', 'ndb0')
AddPort('IPR', 'br0', 'ipr0')
#test_CreateInterface()
def test_RemoveInterface():
InitializeLibrary('NDB')
InitializeLibrary('IPR')
DelPort('NDB', 'br0', 'ndb0')
DelPort('IPR', 'br0', 'ipr0')
+5 -10
View File
@@ -143,14 +143,14 @@ def create_endpoint():
if_host, if_container = veth_pair(endpoint_id)
logger.info('creating veth pair %s <=> %s', if_host, if_container)
if_host = interface.CreateInterface(LIBRARY, if_host, 'veth', if_container)
if_host.up()
if_host.Up()
try:
start = time.time()
while isinstance(if_container, str) and time.time() - start < 10:
try:
if_container = interface.GetInterface(LIBRARY, if_container)
if_container.up()
if_container.Up()
except KeyError:
time.sleep(0.5)
if isinstance(if_container, str):
@@ -164,14 +164,9 @@ def create_endpoint():
'AddressIPv6': ''
}
# !!!
# if 'MacAddress' in req_iface and req_iface['MacAddress']:
# (if_container
# .set('address', req_iface['MacAddress'])
# .commit())
# else:
# res_iface['MacAddress'] = if_container['address']
# !!!
if 'MacAddress' in req_iface and req_iface['MacAddress']:
if_container.SetAddress(req_iface['MacAddress'])
else:
res_iface['MacAddress'] = if_container['address']
def try_addr(type_):