Commit 97505e28 by Bach Dániel Committed by Your Name

improve ovs code

parent 2e48479d
...@@ -15,15 +15,16 @@ class Interface(object): ...@@ -15,15 +15,16 @@ class Interface(object):
self.is_veth = data.get('type', 'external') == 'internal' self.is_veth = data.get('type', 'external') == 'internal'
try: try:
self.untagged = int(data['tag'])
except (TypeError, KeyError):
self.untagged = None
try:
self.tagged = frozenset(int(i) for i in data['trunks']) self.tagged = frozenset(int(i) for i in data['trunks'])
except (TypeError, KeyError): except (TypeError, KeyError):
self.tagged = frozenset() self.tagged = frozenset()
untagged = data.get('tag')
if (untagged and not self.tagged and unicode(untagged).isdecimal()):
self.untagged = int(untagged)
else:
self.untagged = None
if with_show: if with_show:
data['addresses'] = self.show() data['addresses'] = self.show()
try: try:
...@@ -41,9 +42,8 @@ class Interface(object): ...@@ -41,9 +42,8 @@ class Interface(object):
return self.__dict__ == other.__dict__ return self.__dict__ == other.__dict__
def __hash__(self): def __hash__(self):
r = reduce(lambda acc, x: acc ^ hash(x), return reduce(lambda acc, x: acc ^ hash(x),
(self.name, self.is_veth, self.untagged, self.tagged), 0) self.__dict__.values(), 0)
return r
@property @property
def external_name(self): def external_name(self):
...@@ -143,7 +143,7 @@ class Switch(object): ...@@ -143,7 +143,7 @@ class Switch(object):
def add_port(self, interface): def add_port(self, interface):
params = ['add-port', self.brname, interface.external_name] params = ['add-port', self.brname, interface.external_name]
if interface.untagged and not interface.tagged: if interface.untagged:
params.append('tag=%d' % int(interface.untagged)) params.append('tag=%d' % int(interface.untagged))
if interface.tagged: if interface.tagged:
params.append('trunks=%s' % list(interface.tagged)) params.append('trunks=%s' % list(interface.tagged))
...@@ -171,11 +171,6 @@ class Switch(object): ...@@ -171,11 +171,6 @@ class Switch(object):
new_interfaces = [Interface(port, data) new_interfaces = [Interface(port, data)
for port, data in new_ports.items()] for port, data in new_ports.items()]
add = [i for i in new_interfaces
if i not in old_interfaces]
delete = [i for i in old_interfaces
if i not in new_interfaces]
add = list(set(new_interfaces).difference(set(old_interfaces))) add = list(set(new_interfaces).difference(set(old_interfaces)))
delete = list(set(old_interfaces).difference(set(new_interfaces))) delete = list(set(old_interfaces).difference(set(new_interfaces)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment