Changed syntax to support python2.4. Allow external_ids to be None.
This commit is contained in:
parent
fdec957d36
commit
24375f5d22
1 changed files with 29 additions and 23 deletions
|
@ -128,8 +128,9 @@ class OVSBridge(object):
|
||||||
##
|
##
|
||||||
# Check if external ids would change.
|
# Check if external ids would change.
|
||||||
current_external_ids = self.get_external_ids()
|
current_external_ids = self.get_external_ids()
|
||||||
items = self.module.params['external_ids'].items()
|
exp_external_ids = self.module.params['external_ids']
|
||||||
for (key, value) in items:
|
if exp_external_ids is not None:
|
||||||
|
for (key, value) in exp_external_ids:
|
||||||
if ((key in current_external_ids) and
|
if ((key in current_external_ids) and
|
||||||
(value != current_external_ids[key])):
|
(value != current_external_ids[key])):
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -137,7 +138,7 @@ class OVSBridge(object):
|
||||||
##
|
##
|
||||||
# Check if external ids would be removed.
|
# Check if external ids would be removed.
|
||||||
for (key, value) in current_external_ids.items():
|
for (key, value) in current_external_ids.items():
|
||||||
if key not in self.module.params['external_ids']:
|
if key not in exp_external_ids:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
elif self.state == 'absent' and self.exists():
|
elif self.state == 'absent' and self.exists():
|
||||||
|
@ -178,16 +179,19 @@ class OVSBridge(object):
|
||||||
|
|
||||||
##
|
##
|
||||||
# Change and add existing external ids.
|
# Change and add existing external ids.
|
||||||
items = self.module.params['external_ids'].items()
|
exp_external_ids = self.module.params['external_ids']
|
||||||
for (key, value) in items:
|
if exp_external_ids is not None:
|
||||||
if (value != current_external_ids.get(key, None)):
|
for (key, value) in exp_external_ids.items():
|
||||||
changed = self.set_external_id(key, value) or changed
|
if ((value != current_external_ids.get(key, None)) and
|
||||||
|
self.set_external_id(key, value)):
|
||||||
|
changed = True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Remove current external ids that are not passed in.
|
# Remove current external ids that are not passed in.
|
||||||
for (key, value) in current_external_ids.items():
|
for (key, value) in current_external_ids.items():
|
||||||
if key not in self.module.params['external_ids']:
|
if ((key not in exp_external_ids) and
|
||||||
changed = self.set_external_id(key, None) or changed
|
self.set_external_id(key, None)):
|
||||||
|
changed = True
|
||||||
|
|
||||||
except Exception, earg:
|
except Exception, earg:
|
||||||
self.module.fail_json(msg=str(earg))
|
self.module.fail_json(msg=str(earg))
|
||||||
|
@ -196,21 +200,23 @@ class OVSBridge(object):
|
||||||
|
|
||||||
def get_external_ids(self):
|
def get_external_ids(self):
|
||||||
""" Return the bridge's external ids as a dict. """
|
""" Return the bridge's external ids as a dict. """
|
||||||
|
results = {}
|
||||||
if self.exists():
|
if self.exists():
|
||||||
rtc, out, err = self._vsctl(['br-get-external-id', self.bridge])
|
rtc, out, err = self._vsctl(['br-get-external-id', self.bridge])
|
||||||
if rtc != 0:
|
if rtc != 0:
|
||||||
self.module.fail_json(msg=err)
|
self.module.fail_json(msg=err)
|
||||||
lines = out.split("\n")
|
lines = out.split("\n")
|
||||||
lines = [item.split("=") for item in lines if (len(item) > 0)]
|
lines = [item.split("=") for item in lines if len(item) > 0]
|
||||||
return {item[0]: item[1] for item in lines}
|
for item in lines:
|
||||||
|
results[item[0]] = item[1]
|
||||||
|
|
||||||
return {}
|
return results
|
||||||
|
|
||||||
def set_external_id(self, key, value):
|
def set_external_id(self, key, value):
|
||||||
""" Set external id. """
|
""" Set external id. """
|
||||||
if self.exists():
|
if self.exists():
|
||||||
cmd = ['br-set-external-id', self.bridge, key]
|
cmd = ['br-set-external-id', self.bridge, key]
|
||||||
if (value):
|
if value:
|
||||||
cmd += [value]
|
cmd += [value]
|
||||||
|
|
||||||
(rtc, _, err) = self._vsctl(cmd)
|
(rtc, _, err) = self._vsctl(cmd)
|
||||||
|
|
Loading…
Reference in a new issue