Add MAC Address Configuration
This commit is contained in:
+25
-7
@@ -104,13 +104,20 @@ class Interface:
|
|||||||
route['dst_len'] = r['dst_len']
|
route['dst_len'] = r['dst_len']
|
||||||
self.routes.append(route)
|
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:
|
if self.ndb:
|
||||||
self.ndb.set('state', 'up').commit()
|
self.ndb.set('state', 'up').commit()
|
||||||
elif self.ipr:
|
elif self.ipr:
|
||||||
iproute.link("set", index=self.index, state="up")
|
iproute.link("set", index=self.index, state="up")
|
||||||
|
|
||||||
def down(self):
|
def Down(self):
|
||||||
if self.ndb:
|
if self.ndb:
|
||||||
self.ndb.set('state', 'down').commit()
|
self.ndb.set('state', 'down').commit()
|
||||||
elif self.ipr:
|
elif self.ipr:
|
||||||
@@ -161,6 +168,9 @@ def test_Variable(v1, v2, f):
|
|||||||
assert v1 == v2, "{} not equal ({}, {})".format(f, v1, v2)
|
assert v1 == v2, "{} not equal ({}, {})".format(f, v1, v2)
|
||||||
|
|
||||||
def test_Interface():
|
def test_Interface():
|
||||||
|
InitializeLibrary('NDB')
|
||||||
|
InitializeLibrary('IPR')
|
||||||
|
|
||||||
itf1 = GetInterface('NDB', 'br0')
|
itf1 = GetInterface('NDB', 'br0')
|
||||||
itf2 = GetInterface('IPR', 'br0')
|
itf2 = GetInterface('IPR', 'br0')
|
||||||
|
|
||||||
@@ -173,27 +183,35 @@ def test_Interface():
|
|||||||
#test_Interface()
|
#test_Interface()
|
||||||
|
|
||||||
def test_CreateInterface():
|
def test_CreateInterface():
|
||||||
|
InitializeLibrary('NDB')
|
||||||
|
InitializeLibrary('IPR')
|
||||||
|
|
||||||
CreateInterface('NDB', 'ndb0', 'veth', 'ndb1')
|
CreateInterface('NDB', 'ndb0', 'veth', 'ndb1')
|
||||||
CreateInterface('IPR', 'ipr0', 'veth', 'ipr1')
|
CreateInterface('IPR', 'ipr0', 'veth', 'ipr1')
|
||||||
|
|
||||||
itf1 = GetInterface('NDB', 'ndb0')
|
itf1 = GetInterface('NDB', 'ndb0')
|
||||||
itf2 = GetInterface('IPR', 'ipr0')
|
itf2 = GetInterface('IPR', 'ipr0')
|
||||||
|
|
||||||
itf1.up();
|
itf1.Up();
|
||||||
itf2.up();
|
itf2.Up();
|
||||||
|
|
||||||
itf3 = GetInterface('NDB', 'ndb1')
|
itf3 = GetInterface('NDB', 'ndb1')
|
||||||
itf4 = GetInterface('IPR', 'ipr1')
|
itf4 = GetInterface('IPR', 'ipr1')
|
||||||
|
|
||||||
itf3.up();
|
itf3.SetAddress('00:11:22:33:44:55')
|
||||||
itf4.up();
|
itf4.SetAddress('00:11:22:33:44:56')
|
||||||
|
|
||||||
|
itf3.Up();
|
||||||
|
itf4.Up();
|
||||||
|
|
||||||
AddPort('NDB', 'br0', 'ndb0')
|
AddPort('NDB', 'br0', 'ndb0')
|
||||||
AddPort('IPR', 'br0', 'ipr0')
|
AddPort('IPR', 'br0', 'ipr0')
|
||||||
|
|
||||||
#test_CreateInterface()
|
#test_CreateInterface()
|
||||||
|
|
||||||
def test_RemoveInterface():
|
def test_RemoveInterface():
|
||||||
|
InitializeLibrary('NDB')
|
||||||
|
InitializeLibrary('IPR')
|
||||||
|
|
||||||
DelPort('NDB', 'br0', 'ndb0')
|
DelPort('NDB', 'br0', 'ndb0')
|
||||||
DelPort('IPR', 'br0', 'ipr0')
|
DelPort('IPR', 'br0', 'ipr0')
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -143,14 +143,14 @@ def create_endpoint():
|
|||||||
if_host, if_container = veth_pair(endpoint_id)
|
if_host, if_container = veth_pair(endpoint_id)
|
||||||
logger.info('creating veth pair %s <=> %s', if_host, if_container)
|
logger.info('creating veth pair %s <=> %s', if_host, if_container)
|
||||||
if_host = interface.CreateInterface(LIBRARY, if_host, 'veth', if_container)
|
if_host = interface.CreateInterface(LIBRARY, if_host, 'veth', if_container)
|
||||||
if_host.up()
|
if_host.Up()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while isinstance(if_container, str) and time.time() - start < 10:
|
while isinstance(if_container, str) and time.time() - start < 10:
|
||||||
try:
|
try:
|
||||||
if_container = interface.GetInterface(LIBRARY, if_container)
|
if_container = interface.GetInterface(LIBRARY, if_container)
|
||||||
if_container.up()
|
if_container.Up()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
if isinstance(if_container, str):
|
if isinstance(if_container, str):
|
||||||
@@ -164,14 +164,9 @@ def create_endpoint():
|
|||||||
'AddressIPv6': ''
|
'AddressIPv6': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
# !!!
|
if 'MacAddress' in req_iface and req_iface['MacAddress']:
|
||||||
# if 'MacAddress' in req_iface and req_iface['MacAddress']:
|
if_container.SetAddress(req_iface['MacAddress'])
|
||||||
# (if_container
|
else:
|
||||||
# .set('address', req_iface['MacAddress'])
|
|
||||||
# .commit())
|
|
||||||
# else:
|
|
||||||
# res_iface['MacAddress'] = if_container['address']
|
|
||||||
# !!!
|
|
||||||
res_iface['MacAddress'] = if_container['address']
|
res_iface['MacAddress'] = if_container['address']
|
||||||
|
|
||||||
def try_addr(type_):
|
def try_addr(type_):
|
||||||
|
|||||||
Reference in New Issue
Block a user