Add MAC Address Configuration
This commit is contained in:
+25
-7
@@ -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')
|
||||
|
||||
|
||||
+6
-11
@@ -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,15 +164,10 @@ 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']
|
||||
# !!!
|
||||
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_):
|
||||
addr = None
|
||||
|
||||
Reference in New Issue
Block a user