From: Thierry Parmentelat Date: Thu, 17 Jul 2014 11:14:15 +0000 (+0200) Subject: huge cleanup for removing mutables used as default X-Git-Tag: sfa-3.1-9~5 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=d59f8e0b663b71d8c349017d0ecb37cb6bc527a1 huge cleanup for removing mutables used as default http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument --- diff --git a/sfa/cortexlab/cortexlabaggregate.py b/sfa/cortexlab/cortexlabaggregate.py index d9cddf3b..24a53106 100644 --- a/sfa/cortexlab/cortexlabaggregate.py +++ b/sfa/cortexlab/cortexlabaggregate.py @@ -292,7 +292,7 @@ class CortexlabAggregate: return rspec_node - def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = {}): + def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations=None): """Makes a geni sliver structure from all the nodes allocated to slivers in the sliver_allocations dictionary. Returns the states of the sliver. @@ -312,6 +312,8 @@ class CortexlabAggregate: .. seealso:: node_to_rspec_node """ + if sliver_allocations is None: sliver_allocations={} + if rspec_node['sliver_id'] in sliver_allocations: # set sliver allocation and operational status sliver_allocation = sliver_allocations[rspec_node['sliver_id']] @@ -555,7 +557,7 @@ class CortexlabAggregate: - def get_slivers(self, urns, options={}): + def get_slivers(self, urns, options=None): """Get slivers of the given slice urns. Slivers contains slice, node and user information. @@ -569,7 +571,7 @@ class CortexlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ - + if options is None: options={} slice_ids = set() node_ids = [] @@ -667,7 +669,7 @@ class CortexlabAggregate: return slivers - def list_resources(self, version = None, options={}): + def list_resources(self, version = None, options=None): """ Returns an advertisement Rspec of available resources at this aggregate. This Rspec contains a resource listing along with their @@ -688,6 +690,8 @@ class CortexlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources """ + if options is None: options={} + version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version(version.type, @@ -722,7 +726,7 @@ class CortexlabAggregate: return rspec.toxml() - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): """ Retrieve a manifest RSpec describing the resources contained by the named entities, e.g. a single slice or a set of the slivers in a slice. @@ -752,6 +756,7 @@ class CortexlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version( diff --git a/sfa/cortexlab/cortexlabdriver.py b/sfa/cortexlab/cortexlabdriver.py index bc674f76..c5ad4e6a 100644 --- a/sfa/cortexlab/cortexlabdriver.py +++ b/sfa/cortexlab/cortexlabdriver.py @@ -1081,7 +1081,7 @@ class CortexlabDriver(Driver): - def delete(self, slice_urns, options={}): + def delete(self, slice_urns, options=None): """ Deletes the lease associated with the slice hrn and the credentials if the slice belongs to iotlab. Answer to DeleteSliver. @@ -1099,6 +1099,7 @@ class CortexlabDriver(Driver): .. note:: creds are unused, and are not used either in the dummy driver delete_sliver . """ + if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = CortexlabAggregate(self) @@ -1390,17 +1391,20 @@ class CortexlabDriver(Driver): # first 2 args are None in case of resource discovery - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} aggregate = CortexlabAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec - def describe(self, urns, version, options={}): + def describe(self, urns, version, options=None): + if options is None: options={} aggregate = CortexlabAggregate(self) return aggregate.describe(urns, version=version, options=options) - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} aggregate = CortexlabAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = {'geni_urn': desc['geni_urn'], @@ -1408,7 +1412,8 @@ class CortexlabDriver(Driver): return status - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} xrn = Xrn(urn) aggregate = CortexlabAggregate(self) @@ -1488,7 +1493,8 @@ class CortexlabDriver(Driver): return aggregate.describe([xrn.get_urn()], version=rspec.version) - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} # update users slices = CortexlabSlices(self) aggregate = CortexlabAggregate(self) diff --git a/sfa/cortexlab/cortexlabslices.py b/sfa/cortexlab/cortexlabslices.py index ee160d43..888d7dbe 100644 --- a/sfa/cortexlab/cortexlabslices.py +++ b/sfa/cortexlab/cortexlabslices.py @@ -351,7 +351,7 @@ class CortexlabSlices: return sfa_slice - def verify_persons(self, slice_hrn, slice_record, users, options={}): + def verify_persons(self, slice_hrn, slice_record, users, options=None): """Ensures the users in users list exist and are enabled in LDAP. Adds person if needed(AddPerson). @@ -378,6 +378,7 @@ class CortexlabSlices: """ + if options is None: options={} logger.debug("CortexlabSlices \tverify_persons \tslice_hrn %s \ \t slice_record %s\r\n users %s \t " @@ -525,10 +526,11 @@ class CortexlabSlices: return added_persons - def verify_keys(self, persons, users, peer, options={}): + def verify_keys(self, persons, users, peer, options=None): """ .. warning:: unused """ + if options is None: options={} # existing keys key_ids = [] for person in persons: diff --git a/sfa/dummy/dummy_testbed_api.py b/sfa/dummy/dummy_testbed_api.py index 2673166d..f553e40e 100644 --- a/sfa/dummy/dummy_testbed_api.py +++ b/sfa/dummy/dummy_testbed_api.py @@ -12,7 +12,12 @@ for i in range(1,11): slices_list = [] for i in range(1,3): - slice = {'slice_name': 'slice'+str(i), 'user_ids': range(i,4,2), 'slice_id': i, 'node_ids': range(i,10,2), 'enabled': True, 'expires': int(time.time())+60*60*24*30} + slice = {'slice_name': 'slice'+str(i), + 'user_ids': range(i,4,2), + 'slice_id': i, + 'node_ids': range(i,10,2), + 'enabled': True, + 'expires': int(time.time())+60*60*24*30} slices_list.append(slice) users_list = [] @@ -43,7 +48,8 @@ def FilterList(myfilter, mylist): def GetTestbedInfo(): return {'name': 'dummy', 'longitude': 123456, 'latitude': 654321, 'domain':'dummy-testbed.org'} -def GetNodes(filter={}): +def GetNodes(filter=None): + if filter is None: filter={} global DB result = [] result.extend(DB['nodes_list']) @@ -55,7 +61,8 @@ def GetNodes(filter={}): result = FilterList(filter, result) return result -def GetSlices(filter={}): +def GetSlices(filter=None): + if filter is None: filter={} global DB result = [] result.extend(DB['slices_list']) @@ -69,7 +76,8 @@ def GetSlices(filter={}): return result -def GetUsers(filter={}): +def GetUsers(filter=None): + if filter is None: filter={} global DB result = [] result.extend(DB['users_list']) diff --git a/sfa/dummy/dummyaggregate.py b/sfa/dummy/dummyaggregate.py index 576ccd58..c5b4d10c 100644 --- a/sfa/dummy/dummyaggregate.py +++ b/sfa/dummy/dummyaggregate.py @@ -52,12 +52,14 @@ class DummyAggregate: return (slice, slivers) - def get_nodes(self, options={}): + def get_nodes(self, options=None): + if options is None: options={} filter = {} nodes = self.driver.shell.GetNodes(filter) return nodes - def get_slivers(self, urns, options={}): + def get_slivers(self, urns, options=None): + if options is None: options={} slice_names = set() slice_ids = set() node_ids = [] @@ -122,7 +124,8 @@ class DummyAggregate: slivers.append(node) return slivers - def node_to_rspec_node(self, node, options={}): + def node_to_rspec_node(self, node, options=None): + if options is None: options={} rspec_node = NodeElement() site=self.driver.testbedInfo rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['name'], node['hostname']) @@ -163,7 +166,8 @@ class DummyAggregate: }) return rspec_node - def get_slice_nodes(self, slice, options={}): + def get_slice_nodes(self, slice, options=None): + if options is None: options={} nodes_dict = {} filter = {} if slice and slice.get('node_ids'): @@ -176,7 +180,8 @@ class DummyAggregate: nodes_dict[node['node_id']] = node return nodes_dict - def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = {}): + def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = None): + if sliver_allocations is None: sliver_allocations={} if rspec_node['sliver_id'] in sliver_allocations: # set sliver allocation and operational status sliver_allocation = sliver_allocations[rspec_node['sliver_id']] @@ -202,7 +207,8 @@ class DummyAggregate: } return geni_sliver - def list_resources(self, version = None, options={}): + def list_resources(self, version = None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) @@ -224,7 +230,8 @@ class DummyAggregate: return rspec.toxml() - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version(version.type, version.version, 'manifest') diff --git a/sfa/dummy/dummydriver.py b/sfa/dummy/dummydriver.py index 4d7f7a38..a69662e1 100644 --- a/sfa/dummy/dummydriver.py +++ b/sfa/dummy/dummydriver.py @@ -412,16 +412,19 @@ class DummyDriver (Driver): def aggregate_version (self): return {} - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} aggregate = DummyAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec - def describe(self, urns, version, options={}): + def describe(self, urns, version, options=None): + if options is None: options={} aggregate = DummyAggregate(self) return aggregate.describe(urns, version=version, options=options) - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} aggregate = DummyAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = {'geni_urn': desc['geni_urn'], @@ -429,7 +432,8 @@ class DummyDriver (Driver): return status - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} xrn = Xrn(urn) aggregate = DummyAggregate(self) slices = DummySlices(self) @@ -453,7 +457,8 @@ class DummyDriver (Driver): return aggregate.describe([xrn.get_urn()], version=rspec.version) - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} # update users slices = DummySlices(self) aggregate = DummyAggregate(self) @@ -469,7 +474,8 @@ class DummyDriver (Driver): rspec_version = version_manager.get_version(options['geni_rspec_version']) return self.describe(urns, rspec_version, options=options) - def delete(self, urns, options={}): + def delete(self, urns, options=None): + if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = DummyAggregate(self) @@ -504,7 +510,8 @@ class DummyDriver (Driver): 'geni_expires': datetime_to_string(utcparse(sliver['expires']))}) return geni_slivers - def renew (self, urns, expiration_time, options={}): + def renew (self, urns, expiration_time, options=None): + if options is None: options={} aggregate = DummyAggregate(self) slivers = aggregate.get_slivers(urns) if not slivers: @@ -516,7 +523,8 @@ class DummyDriver (Driver): description = self.describe(urns, 'GENI 3', options) return description['geni_slivers'] - def perform_operational_action (self, urns, action, options={}): + def perform_operational_action (self, urns, action, options=None): + if options is None: options={} # Dummy doesn't support operational actions. Lets pretend like it # supports start, but reject everything else. action = action.lower() @@ -535,7 +543,8 @@ class DummyDriver (Driver): geni_slivers = self.describe(urns, 'GENI 3', options)['geni_slivers'] return geni_slivers - def shutdown (self, xrn, options={}): + def shutdown (self, xrn, options=None): + if options is None: options={} xrn = DummyXrn(xrn=xrn, type='slice') slicename = xrn.pl_slicename() slices = self.shell.GetSlices({'name': slicename}, ['slice_id']) diff --git a/sfa/dummy/dummyslices.py b/sfa/dummy/dummyslices.py index cf5a6da9..7ab94ba2 100644 --- a/sfa/dummy/dummyslices.py +++ b/sfa/dummy/dummyslices.py @@ -110,7 +110,8 @@ class DummySlices: return resulting_nodes - def verify_slice(self, slice_hrn, slice_record, expiration, options={}): + def verify_slice(self, slice_hrn, slice_record, expiration, options=None): + if options is None: options={} slicename = hrn_to_dummy_slicename(slice_hrn) parts = slicename.split("_") login_base = parts[0] @@ -130,7 +131,8 @@ class DummySlices: return slice - def verify_users(self, slice_hrn, slice_record, users, options={}): + def verify_users(self, slice_hrn, slice_record, users, options=None): + if options is None: options={} slice_name = hrn_to_dummy_slicename(slice_hrn) users_by_email = {} for user in users: @@ -162,7 +164,8 @@ class DummySlices: pass - def verify_keys(self, old_users, new_users, options={}): + def verify_keys(self, old_users, new_users, options=None): + if options is None: options={} # existing keys existing_keys = [] for user in old_users: diff --git a/sfa/iotlab/iotlabaggregate.py b/sfa/iotlab/iotlabaggregate.py index 34eb38fa..56e40e4f 100644 --- a/sfa/iotlab/iotlabaggregate.py +++ b/sfa/iotlab/iotlabaggregate.py @@ -306,7 +306,7 @@ class IotlabAggregate: return rspec_node - def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = {}): + def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = None): """Makes a geni sliver structure from all the nodes allocated to slivers in the sliver_allocations dictionary. Returns the states of the sliver. @@ -326,6 +326,7 @@ class IotlabAggregate: .. seealso:: node_to_rspec_node """ + if sliver_allocations is None: sliver_allocations={} if rspec_node['sliver_id'] in sliver_allocations: # set sliver allocation and operational status sliver_allocation = sliver_allocations[rspec_node['sliver_id']] @@ -400,7 +401,8 @@ class IotlabAggregate: return rspec_node - def get_leases(self, slice=None, options={}): + def get_leases(self, slice=None, options=None): + if options is None: options={} filter={} if slice: filter.update({'name':slice['slice_name']}) @@ -598,7 +600,7 @@ class IotlabAggregate: FINAL RSPEC %s \r\n" % (rspec.toxml())) return rspec.toxml() - def get_slivers(self, urns, options={}): + def get_slivers(self, urns, options=None): """Get slivers of the given slice urns. Slivers contains slice, node and user information. @@ -613,7 +615,7 @@ class IotlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ - + if options is None: options={} slice_ids = set() node_ids = [] for urn in urns: @@ -709,7 +711,7 @@ class IotlabAggregate: slivers.append(node) return slivers - def list_resources(self, version = None, options={}): + def list_resources(self, version = None, options=None): """ Returns an advertisement Rspec of available resources at this aggregate. This Rspec contains a resource listing along with their @@ -730,6 +732,7 @@ class IotlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources """ + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version(version.type, @@ -764,7 +767,7 @@ class IotlabAggregate: return rspec.toxml() - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): """ Retrieve a manifest RSpec describing the resources contained by the named entities, e.g. a single slice or a set of the slivers in a slice. @@ -794,6 +797,7 @@ class IotlabAggregate: .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns """ + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version( diff --git a/sfa/iotlab/iotlabdriver.py b/sfa/iotlab/iotlabdriver.py index eb055d93..797f156a 100644 --- a/sfa/iotlab/iotlabdriver.py +++ b/sfa/iotlab/iotlabdriver.py @@ -1088,7 +1088,7 @@ class IotlabDriver(Driver): - def delete(self, slice_urns, options={}): + def delete(self, slice_urns, options=None): """ Deletes the lease associated with the slice hrn and the credentials if the slice belongs to iotlab. Answer to DeleteSliver. @@ -1106,6 +1106,7 @@ class IotlabDriver(Driver): .. note:: creds are unused, and are not used either in the dummy driver delete_sliver . """ + if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = IotlabAggregate(self) @@ -1398,16 +1399,19 @@ class IotlabDriver(Driver): 'geni_ad_rspec_versions': ad_rspec_versions} # first 2 args are None in case of resource discovery - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} aggregate = IotlabAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec - def describe(self, urns, version, options={}): + def describe(self, urns, version, options=None): + if options is None: options={} aggregate = IotlabAggregate(self) return aggregate.describe(urns, version=version, options=options) - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} aggregate = IotlabAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = {'geni_urn': desc['geni_urn'], @@ -1415,7 +1419,8 @@ class IotlabDriver(Driver): return status - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} xrn = Xrn(urn) aggregate = IotlabAggregate(self) @@ -1529,7 +1534,8 @@ class IotlabDriver(Driver): return aggregate.describe([xrn.get_urn()], version=rspec.version) - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} # update users slices = IotlabSlices(self) aggregate = IotlabAggregate(self) diff --git a/sfa/iotlab/iotlabslices.py b/sfa/iotlab/iotlabslices.py index e4866247..966a26b6 100644 --- a/sfa/iotlab/iotlabslices.py +++ b/sfa/iotlab/iotlabslices.py @@ -356,7 +356,7 @@ class IotlabSlices: return sfa_slice - def verify_persons(self, slice_hrn, slice_record, users, options={}): + def verify_persons(self, slice_hrn, slice_record, users, options=None): """Ensures the users in users list exist and are enabled in LDAP. Adds person if needed (AddPerson). @@ -382,7 +382,7 @@ class IotlabSlices: """ - + if options is None: options={} logger.debug("IOTLABSLICES \tverify_persons \tslice_hrn %s \ \t slice_record %s\r\n users %s \t " % (slice_hrn, slice_record, users)) @@ -528,10 +528,11 @@ class IotlabSlices: return added_persons - def verify_keys(self, persons, users, peer, options={}): + def verify_keys(self, persons, users, peer, options=None): """ .. warning:: unused """ + if options is None: options={} # existing keys key_ids = [] for person in persons: diff --git a/sfa/managers/aggregate_manager.py b/sfa/managers/aggregate_manager.py index 15211035..8b736444 100644 --- a/sfa/managers/aggregate_manager.py +++ b/sfa/managers/aggregate_manager.py @@ -29,7 +29,8 @@ class AggregateManager: 'geni_ad_rspec_versions': ad_rspec_versions, } - def get_rspec_version_string(self, rspec_version, options={}): + def get_rspec_version_string(self, rspec_version, options=None): + if options is None: options={} version_string = "rspec_%s" % (rspec_version) #panos adding the info option to the caching key (can be improved) @@ -149,12 +150,14 @@ class AggregateManager: return api.driver.renew(xrns, expiration_time, options) - def PerformOperationalAction(self, api, xrns, creds, action, options={}): + def PerformOperationalAction(self, api, xrns, creds, action, options=None): + if options is None: options={} call_id = options.get('call_id') if Callids().already_handled(call_id): return True return api.driver.perform_operational_action(xrns, action, options) - def Shutdown(self, api, xrn, creds, options={}): + def Shutdown(self, api, xrn, creds, options=None): + if options is None: options={} call_id = options.get('call_id') if Callids().already_handled(call_id): return True return api.driver.shutdown(xrn, options) diff --git a/sfa/managers/driver.py b/sfa/managers/driver.py index 0e8b71dc..1985e0ee 100644 --- a/sfa/managers/driver.py +++ b/sfa/managers/driver.py @@ -78,7 +78,8 @@ class Driver: # answer to ListResources # returns : advertisment rspec (xml string) - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} return "dummy Driver.list_resources needs to be redefined" # the answer to Describe on a slice or a set of the slivers in a slice @@ -97,40 +98,48 @@ class Driver: # ... # ] #} - def describe (self, urns, version, options={}): + def describe (self, urns, version, options=None): + if options is None: options={} return "dummy Driver.describe needs to be redefined" # the answer to Allocate on a given slicei or a set of the slivers in a slice # returns: same struct as for describe. - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} return "dummy Driver.allocate needs to be redefined" # the answer to Provision on a given slice or a set of the slivers in a slice # returns: same struct as for describe. - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} return "dummy Driver.provision needs to be redefined" # the answer to PerformOperationalAction on a given slice or a set of the slivers in a slice # returns: struct containing "geni_slivers" list of the struct returned by describe. - def perform_operational_action (self, urns, action, options={}): + def perform_operational_action (self, urns, action, options=None): + if options is None: options={} return "dummy Driver.perform_operational_action needs to be redefined" # the answer to Status on a given slice or a set of the slivers in a slice # returns: struct containing "geni_urn" and "geni_slivers" list of the struct returned by describe. - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} return "dummy Driver.status needs to be redefined" # the answer to Renew on a given slice or a set of the slivers in a slice # returns: struct containing "geni_slivers" list of the struct returned by describe. - def renew (self, urns, expiration_time, options={}): + def renew (self, urns, expiration_time, options=None): + if options is None: options={} return "dummy Driver.renew needs to be redefined" # the answer to Delete on a given slice # returns: struct containing "geni_slivers" list of the struct returned by describe. - def delete(self, urns, options={}): + def delete(self, urns, options=None): + if options is None: options={} return "dummy Driver.delete needs to be redefined" # the answer to Shutdown on a given slice # returns: boolean - def shutdown (self, xrn, options={}): + def shutdown (self, xrn, options=None): + if options is None: options={} return False diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 7306380d..5a49d479 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -237,7 +237,8 @@ class RegistryManager: return records - def List (self, api, xrn, origin_hrn=None, options={}): + def List (self, api, xrn, origin_hrn=None, options=None): + if options is None: options={} dbsession=api.dbsession() # load all know registry names into a prefix tree and attempt to find # the longest matching prefix diff --git a/sfa/managers/slice_manager.py b/sfa/managers/slice_manager.py index 05b0f1ee..2a99b6f4 100644 --- a/sfa/managers/slice_manager.py +++ b/sfa/managers/slice_manager.py @@ -508,7 +508,8 @@ class SliceManager: multiclient.get_results() return 1 - def Shutdown(self, api, xrn, creds, options={}): + def Shutdown(self, api, xrn, creds, options=None): + if options is None: options={} xrn = Xrn(xrn) # get the callers hrn valid_cred = api.auth.checkCredentials(creds, 'stopslice', xrn.hrn)[0] diff --git a/sfa/methods/GetVersion.py b/sfa/methods/GetVersion.py index cb682e44..f043992e 100644 --- a/sfa/methods/GetVersion.py +++ b/sfa/methods/GetVersion.py @@ -15,6 +15,7 @@ class GetVersion(Method): returns = Parameter(dict, "Version information") # API v2 specifies options is optional, so.. - def call(self, options={}): + def call(self, options=None): + if options is None: options={} self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name)) return self.api.manager.GetVersion(self.api, options) diff --git a/sfa/methods/List.py b/sfa/methods/List.py index d53a0a5e..83d7a6e0 100644 --- a/sfa/methods/List.py +++ b/sfa/methods/List.py @@ -25,7 +25,8 @@ class List(Method): # xxx used to be [SfaRecord] returns = [Parameter(dict, "registry record")] - def call(self, xrn, creds, options={}): + def call(self, xrn, creds, options=None): + if options is None: options={} hrn, type = urn_to_hrn(xrn) valid_creds = self.api.auth.checkCredentials(creds, 'list') diff --git a/sfa/methods/Resolve.py b/sfa/methods/Resolve.py index f3a6e671..dc34f759 100644 --- a/sfa/methods/Resolve.py +++ b/sfa/methods/Resolve.py @@ -30,7 +30,8 @@ class Resolve(Method): # xxx used to be [SfaRecord] returns = [Parameter(dict, "registry record")] - def call(self, xrns, creds, options={}): + def call(self, xrns, creds, options=None): + if options is None: options={} # use details=False by default, only when explicitly specified do we want # to mess with the testbed details if 'details' in options: details=options['details'] diff --git a/sfa/nitos/nitosaggregate.py b/sfa/nitos/nitosaggregate.py index bb7c56d6..832a2c7c 100644 --- a/sfa/nitos/nitosaggregate.py +++ b/sfa/nitos/nitosaggregate.py @@ -68,7 +68,9 @@ class NitosAggregate: - def get_nodes(self, slice_xrn, slice=None,slivers={}, options={}): + def get_nodes(self, slice_xrn, slice=None,slivers=None, options=None): + if slivers is None: slivers={} + if options is None: options={} # if we are dealing with a slice that has no node just return # and empty list if slice_xrn: @@ -126,8 +128,9 @@ class NitosAggregate: rspec_nodes.append(rspec_node) return rspec_nodes - def get_leases_and_channels(self, slice=None, slice_xrn=None, options={}): - + def get_leases_and_channels(self, slice=None, slice_xrn=None, options=None): + + if options is None: options={} slices = self.driver.shell.getSlices({}, []) nodes = self.driver.shell.getNodes({}, []) leases = self.driver.shell.getReservedNodes({}, []) @@ -216,8 +219,9 @@ class NitosAggregate: return (rspec_leases, rspec_channels) - def get_channels(self, slice=None, options={}): - + def get_channels(self, slice=None, options=None): + if options is None: options={} + all_channels = self.driver.shell.getChannels({}, []) channels = [] if slice: @@ -245,7 +249,8 @@ class NitosAggregate: - def get_rspec(self, slice_xrn=None, version = None, options={}): + def get_rspec(self, slice_xrn=None, version = None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) diff --git a/sfa/nitos/nitosslices.py b/sfa/nitos/nitosslices.py index 3eac8aa3..875a5a90 100644 --- a/sfa/nitos/nitosslices.py +++ b/sfa/nitos/nitosslices.py @@ -153,7 +153,8 @@ class NitosSlices: - def verify_slice(self, slice_hrn, slice_record, sfa_peer, options={}): + def verify_slice(self, slice_hrn, slice_record, sfa_peer, options=None): + if options is None: options={} slicename = hrn_to_nitos_slicename(slice_hrn) slices = self.driver.shell.getSlices({}, []) slices = self.driver.filter_nitos_results(slices, {'slice_name': slicename}) @@ -168,7 +169,8 @@ class NitosSlices: return slice - def verify_users(self, slice_hrn, slice_record, users, sfa_peer, options={}): + def verify_users(self, slice_hrn, slice_record, users, sfa_peer, options=None): + if options is None: options={} # get slice info slicename = hrn_to_nitos_slicename(slice_hrn) slices = self.driver.shell.getSlices({}, []) @@ -204,7 +206,8 @@ class NitosSlices: return added_users - def verify_keys(self, persons, users, options={}): + def verify_keys(self, persons, users, options=None): + if options is None: options={} # existing keys key_ids = [] for person in persons: diff --git a/sfa/openstack/image.py b/sfa/openstack/image.py index 54aaf502..555b1b9b 100644 --- a/sfa/openstack/image.py +++ b/sfa/openstack/image.py @@ -4,7 +4,8 @@ from sfa.rspecs.elements.disk_image import DiskImage class Image: - def __init__(self, image={}): + def __init__(self, image=None): + if image is None: image={} self.id = None self.container_format = None self.kernel_id = None diff --git a/sfa/openstack/nova_driver.py b/sfa/openstack/nova_driver.py index e36946e6..39ea2f91 100644 --- a/sfa/openstack/nova_driver.py +++ b/sfa/openstack/nova_driver.py @@ -355,23 +355,27 @@ class NovaDriver(Driver): return {} # first 2 args are None in case of resource discovery - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} aggregate = OSAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): + if options is None: options={} aggregate = OSAggregate(self) return aggregate.describe(urns, version=version, options=options) - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} aggregate = OSAggregate(self) desc = aggregate.describe(urns) status = {'geni_urn': desc['geni_urn'], 'geni_slivers': desc['geni_slivers']} return status - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} xrn = Xrn(urn) aggregate = OSAggregate(self) @@ -401,7 +405,8 @@ class NovaDriver(Driver): return aggregate.describe(urns=[urn], version=rspec.version) - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} # update sliver allocation states and set them to geni_provisioned aggregate = OSAggregate(self) instances = aggregate.get_instances(urns) @@ -415,7 +420,8 @@ class NovaDriver(Driver): rspec_version = version_manager.get_version(options['geni_rspec_version']) return self.describe(urns, rspec_version, options=options) - def delete (self, urns, options={}): + def delete (self, urns, options=None): + if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = OSAggregate(self) @@ -441,11 +447,13 @@ class NovaDriver(Driver): 'geni_expires': None}) return geni_slivers - def renew (self, urns, expiration_time, options={}): + def renew (self, urns, expiration_time, options=None): + if options is None: options={} description = self.describe(urns, None, options) return description['geni_slivers'] - def perform_operational_action (self, urns, action, options={}): + def perform_operational_action (self, urns, action, options=None): + if options is None: options={} aggregate = OSAggregate(self) action = action.lower() if action == 'geni_start': @@ -474,7 +482,8 @@ class NovaDriver(Driver): geni_slivers = self.describe(urns, None, options)['geni_slivers'] return geni_slivers - def shutdown(self, xrn, options={}): + def shutdown(self, xrn, options=None): + if options is None: options={} xrn = OSXrn(xrn=xrn, type='slice') tenant_name = xrn.get_tenant_name() name = xrn.get_slicename() diff --git a/sfa/openstack/osaggregate.py b/sfa/openstack/osaggregate.py index f31891b8..2b653997 100644 --- a/sfa/openstack/osaggregate.py +++ b/sfa/openstack/osaggregate.py @@ -58,7 +58,8 @@ class OSAggregate: zones = [zone.name for zone in zones] return zones - def list_resources(self, version=None, options={}): + def list_resources(self, version=None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version(version.type, version.version, 'ad') @@ -67,7 +68,8 @@ class OSAggregate: rspec.version.add_nodes(nodes) return rspec.toxml() - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): + if options is None: options={} # update nova connection tenant_name = OSXrn(xrn=urns[0], type='slice').get_tenant_name() self.driver.shell.nova_manager.connect(tenant=tenant_name) @@ -211,7 +213,8 @@ class OSAggregate: 'storage': str(instance.disk)}) return sliver - def instance_to_geni_sliver(self, instance, sliver_allocations = {}): + def instance_to_geni_sliver(self, instance, sliver_allocations=None): + if sliver_allocations is None: sliver_allocations={} sliver_hrn = '%s.%s' % (self.driver.hrn, instance.id) sliver_id = Xrn(sliver_hrn, type='sliver').urn @@ -302,7 +305,8 @@ class OSAggregate: return key_name - def create_security_group(self, slicename, fw_rules=[]): + def create_security_group(self, slicename, fw_rules=None): + if fw_rules is None: fw_rules=[] # use default group by default group_name = 'default' if isinstance(fw_rules, list) and fw_rules: diff --git a/sfa/planetlab/plaggregate.py b/sfa/planetlab/plaggregate.py index cae6495b..28766948 100644 --- a/sfa/planetlab/plaggregate.py +++ b/sfa/planetlab/plaggregate.py @@ -31,7 +31,8 @@ class PlAggregate: def __init__(self, driver): self.driver = driver - def get_nodes(self, options={}): + def get_nodes(self, options=None): + if options is None: options={} filter = {'peer_id': None} geni_available = options.get('geni_available') if geni_available == True: @@ -40,13 +41,15 @@ class PlAggregate: return nodes - def get_sites(self, filter={}): + def get_sites(self, filter=None): + if filter is None: filter={} sites = {} for site in self.driver.shell.GetSites(filter): sites[site['site_id']] = site return sites - def get_interfaces(self, filter={}): + def get_interfaces(self, filter=None): + if filter is None: filter={} interfaces = {} for interface in self.driver.shell.GetInterfaces(filter): iface = Interface() @@ -98,20 +101,23 @@ class PlAggregate: return links - def get_node_tags(self, filter={}): + def get_node_tags(self, filter=None): + if filter is None: filter={} node_tags = {} for node_tag in self.driver.shell.GetNodeTags(filter): node_tags[node_tag['node_tag_id']] = node_tag return node_tags - def get_pl_initscripts(self, filter={}): + def get_pl_initscripts(self, filter=None): + if filter is None: filter={} pl_initscripts = {} filter.update({'enabled': True}) for initscript in self.driver.shell.GetInitScripts(filter): pl_initscripts[initscript['initscript_id']] = initscript return pl_initscripts - def get_slivers(self, urns, options={}): + def get_slivers(self, urns, options=None): + if options is None: options={} names = set() slice_ids = set() node_ids = [] @@ -193,7 +199,9 @@ class PlAggregate: slivers.append(node) return slivers - def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=[], grain=None, options={}): + def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=None, grain=None, options=None): + if pl_initscripts is None: pl_initscripts=[] + if options is None: options={} rspec_node = NodeElement() # xxx how to retrieve site['login_base'] site=sites[node['site_id']] @@ -286,7 +294,8 @@ class PlAggregate: tags_dict[tag['node_id']] = tag return tags_dict - def get_slice_nodes(self, slice, options={}): + def get_slice_nodes(self, slice, options=None): + if options is None: options={} nodes_dict = {} filter = {'peer_id': None} tags_filter = {} @@ -304,7 +313,8 @@ class PlAggregate: nodes_dict[node['node_id']] = node return nodes_dict - def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations = {}): + def rspec_node_to_geni_sliver(self, rspec_node, sliver_allocations=None): + if sliver_allocations is None: sliver_allocations={} if rspec_node['sliver_id'] in sliver_allocations: # set sliver allocation and operational status sliver_allocation = sliver_allocations[rspec_node['sliver_id']] @@ -333,7 +343,8 @@ class PlAggregate: } return geni_sliver - def get_leases(self, slice=None, options={}): + def get_leases(self, slice=None, options=None): + if options is None: options={} now = int(time.time()) filter={} @@ -370,7 +381,8 @@ class PlAggregate: return rspec_leases - def list_resources(self, version = None, options={}): + def list_resources(self, version = None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) @@ -410,7 +422,8 @@ class PlAggregate: return rspec.toxml() - def describe(self, urns, version=None, options={}): + def describe(self, urns, version=None, options=None): + if options is None: options={} version_manager = VersionManager() version = version_manager.get_version(version) rspec_version = version_manager._get_version(version.type, version.version, 'manifest') diff --git a/sfa/planetlab/pldriver.py b/sfa/planetlab/pldriver.py index 1c59fc9e..53f12563 100644 --- a/sfa/planetlab/pldriver.py +++ b/sfa/planetlab/pldriver.py @@ -627,23 +627,27 @@ class PlDriver (Driver): return {} # first 2 args are None in case of resource discovery - def list_resources (self, version=None, options={}): + def list_resources (self, version=None, options=None): + if options is None: options={} aggregate = PlAggregate(self) rspec = aggregate.list_resources(version=version, options=options) return rspec - def describe(self, urns, version, options={}): + def describe(self, urns, version, options=None): + if options is None: options={} aggregate = PlAggregate(self) return aggregate.describe(urns, version=version, options=options) - def status (self, urns, options={}): + def status (self, urns, options=None): + if options is None: options={} aggregate = PlAggregate(self) desc = aggregate.describe(urns, version='GENI 3') status = {'geni_urn': desc['geni_urn'], 'geni_slivers': desc['geni_slivers']} return status - def allocate (self, urn, rspec_string, expiration, options={}): + def allocate (self, urn, rspec_string, expiration, options=None): + if options is None: options={} xrn = Xrn(urn) aggregate = PlAggregate(self) slices = PlSlices(self) @@ -680,7 +684,8 @@ class PlDriver (Driver): return aggregate.describe([xrn.get_urn()], version=rspec.version) - def provision(self, urns, options={}): + def provision(self, urns, options=None): + if options is None: options={} # update users slices = PlSlices(self) aggregate = PlAggregate(self) @@ -715,7 +720,8 @@ class PlDriver (Driver): rspec_version = version_manager.get_version(options['geni_rspec_version']) return self.describe(urns, rspec_version, options=options) - def delete(self, urns, options={}): + def delete(self, urns, options=None): + if options is None: options={} # collect sliver ids so we can update sliver allocation states after # we remove the slivers. aggregate = PlAggregate(self) @@ -754,7 +760,8 @@ class PlDriver (Driver): 'geni_expires': datetime_to_string(utcparse(sliver['expires']))}) return geni_slivers - def renew (self, urns, expiration_time, options={}): + def renew (self, urns, expiration_time, options=None): + if options is None: options={} aggregate = PlAggregate(self) slivers = aggregate.get_slivers(urns) if not slivers: @@ -767,7 +774,8 @@ class PlDriver (Driver): return description['geni_slivers'] - def perform_operational_action (self, urns, action, options={}): + def perform_operational_action (self, urns, action, options=None): + if options is None: options={} # MyPLC doesn't support operational actions. Lets pretend like it # supports start, but reject everything else. action = action.lower() @@ -787,7 +795,8 @@ class PlDriver (Driver): return geni_slivers # set the 'enabled' tag to 0 - def shutdown (self, xrn, options={}): + def shutdown (self, xrn, options=None): + if options is None: options={} hrn, _ = urn_to_hrn(xrn) top_auth_hrn = top_auth(hrn) site_hrn = '.'.join(hrn.split('.')[:-1]) diff --git a/sfa/planetlab/plslices.py b/sfa/planetlab/plslices.py index b6cec880..1226f12f 100644 --- a/sfa/planetlab/plslices.py +++ b/sfa/planetlab/plslices.py @@ -322,7 +322,9 @@ class PlSlices: - def verify_site(self, slice_xrn, slice_record={}, sfa_peer=None, options={}): + def verify_site(self, slice_xrn, slice_record=None, sfa_peer=None, options=None): + if slice_record is None: slice_record={} + if options is None: options={} (slice_hrn, type) = urn_to_hrn(slice_xrn) top_auth_hrn = top_auth(slice_hrn) site_hrn = '.'.join(slice_hrn.split('.')[:-1]) @@ -367,7 +369,8 @@ class PlSlices: return site - def verify_slice(self, slice_hrn, slice_record, sfa_peer, expiration, options={}): + def verify_slice(self, slice_hrn, slice_record, sfa_peer, expiration, options=None): + if options is None: options={} top_auth_hrn = top_auth(slice_hrn) site_hrn = '.'.join(slice_hrn.split('.')[:-1]) slice_part = slice_hrn.split('.')[-1] @@ -416,7 +419,8 @@ class PlSlices: return self.driver.shell.GetSlices(int(slice['slice_id']))[0] - def verify_persons(self, slice_hrn, slice_record, users, sfa_peer, options={}): + def verify_persons(self, slice_hrn, slice_record, users, sfa_peer, options=None): + if options is None: options={} top_auth_hrn = top_auth(slice_hrn) site_hrn = '.'.join(slice_hrn.split('.')[:-1]) slice_part = slice_hrn.split('.')[-1] @@ -504,7 +508,8 @@ class PlSlices: return persons_to_add - def verify_keys(self, persons_to_verify_keys, options={}): + def verify_keys(self, persons_to_verify_keys, options=None): + if options is None: options={} # we only add keys that comes from sfa to persons in PL for person_id in persons_to_verify_keys: person_sfa_keys = persons_to_verify_keys[person_id].get('keys', []) @@ -518,7 +523,8 @@ class PlSlices: self.driver.shell.AddPersonKey(int(person_id), key) - def verify_slice_attributes(self, slice, requested_slice_attributes, options={}, admin=False): + def verify_slice_attributes(self, slice, requested_slice_attributes, options=None, admin=False): + if options is None: options={} append = options.get('append', True) # get list of attributes users ar able to manage filter = {'category': '*slice*'} diff --git a/sfa/rspecs/elements/element.py b/sfa/rspecs/elements/element.py index 7f79e810..36ad12f7 100644 --- a/sfa/rspecs/elements/element.py +++ b/sfa/rspecs/elements/element.py @@ -2,7 +2,8 @@ class Element(dict): fields = {} - def __init__(self, fields={}, element=None, keys=None): + def __init__(self, fields=None, element=None, keys=None): + if fields is None: fields={} self.element = element dict.__init__(self, dict.fromkeys(self.fields)) if not keys: diff --git a/sfa/rspecs/elements/versions/iotlabv1Lease.py b/sfa/rspecs/elements/versions/iotlabv1Lease.py index eebb1ae2..bfc503aa 100644 --- a/sfa/rspecs/elements/versions/iotlabv1Lease.py +++ b/sfa/rspecs/elements/versions/iotlabv1Lease.py @@ -29,7 +29,8 @@ class Iotlabv1Lease: @staticmethod - def get_leases(xml, filter={}): + def get_leases(xml, filter=None): + if filter is None: filter={} xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) lease_elems = xml.xpath(xpath) return Iotlabv1Lease.get_lease_objs(lease_elems) diff --git a/sfa/rspecs/elements/versions/iotlabv1Node.py b/sfa/rspecs/elements/versions/iotlabv1Node.py index af6fe2a4..49f7cfd2 100644 --- a/sfa/rspecs/elements/versions/iotlabv1Node.py +++ b/sfa/rspecs/elements/versions/iotlabv1Node.py @@ -160,14 +160,16 @@ class Iotlabv1Node: return node_elems @staticmethod - def get_nodes(xml, filter={}): + def get_nodes(xml, filter=None): + if filter is None: filter={} xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), \ XpathFilter.xpath(filter)) node_elems = xml.xpath(xpath) return Iotlabv1Node.get_node_objs(node_elems) @staticmethod - def get_nodes_with_slivers(xml, sliver_filter={}): + def get_nodes_with_slivers(xml, sliver_filter=None): + if sliver_filter is None: sliver_filter={} xpath = '//node[count(sliver)>0] | \ //default:node[count(default:sliver) > 0]' diff --git a/sfa/rspecs/elements/versions/iotlabv1Sliver.py b/sfa/rspecs/elements/versions/iotlabv1Sliver.py index f26ace6b..0f9fb014 100644 --- a/sfa/rspecs/elements/versions/iotlabv1Sliver.py +++ b/sfa/rspecs/elements/versions/iotlabv1Sliver.py @@ -35,7 +35,8 @@ class Iotlabv1Sliver: for (key, value) in attrib_dict.items(): attrib_elem.set(key, value) @staticmethod - def get_slivers(xml, filter={}): + def get_slivers(xml, filter=None): + if filter is None: filter={} xpath = './default:sliver | ./sliver' sliver_elems = xml.xpath(xpath) @@ -54,5 +55,6 @@ class Iotlabv1Sliver: return slivers @staticmethod - def get_sliver_attributes(xml, filter={}): - return [] \ No newline at end of file + def get_sliver_attributes(xml, filter=None): + if filter is None: filter={} + return [] diff --git a/sfa/rspecs/elements/versions/nitosv1Channel.py b/sfa/rspecs/elements/versions/nitosv1Channel.py index 60582e35..cf4a5f61 100644 --- a/sfa/rspecs/elements/versions/nitosv1Channel.py +++ b/sfa/rspecs/elements/versions/nitosv1Channel.py @@ -54,7 +54,8 @@ class NITOSv1Channel: @staticmethod - def get_channels(xml, filter={}): + def get_channels(xml, filter=None): + if filter is None: filter={} xpath = '//channel%s | //default:channel%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) channel_elems = xml.xpath(xpath) return NITOSv1Channel.get_channel_objs(channel_elems) diff --git a/sfa/rspecs/elements/versions/nitosv1Lease.py b/sfa/rspecs/elements/versions/nitosv1Lease.py index 99e815a5..dd3041c5 100644 --- a/sfa/rspecs/elements/versions/nitosv1Lease.py +++ b/sfa/rspecs/elements/versions/nitosv1Lease.py @@ -73,7 +73,8 @@ class NITOSv1Lease: @staticmethod - def get_leases(xml, filter={}): + def get_leases(xml, filter=None): + if filter is None: filter={} xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) lease_elems = xml.xpath(xpath) return NITOSv1Lease.get_lease_objs(lease_elems) diff --git a/sfa/rspecs/elements/versions/nitosv1Node.py b/sfa/rspecs/elements/versions/nitosv1Node.py index 44b9b523..ea59b3d5 100644 --- a/sfa/rspecs/elements/versions/nitosv1Node.py +++ b/sfa/rspecs/elements/versions/nitosv1Node.py @@ -135,7 +135,8 @@ class NITOSv1Node: node.element.remove(sliver.element) @staticmethod - def get_nodes(xml, filter={}): + def get_nodes(xml, filter=None): + if filter is None: filter={} xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) node_elems = xml.xpath(xpath) return NITOSv1Node.get_node_objs(node_elems) diff --git a/sfa/rspecs/elements/versions/nitosv1PLTag.py b/sfa/rspecs/elements/versions/nitosv1PLTag.py index 7d03fe06..ea34ff4e 100644 --- a/sfa/rspecs/elements/versions/nitosv1PLTag.py +++ b/sfa/rspecs/elements/versions/nitosv1PLTag.py @@ -9,7 +9,8 @@ class NITOSv1PLTag: pl_tag_elem.set_text(value) @staticmethod - def get_pl_tags(xml, ignore=[]): + def get_pl_tags(xml, ignore=None): + if ignore is None: ignore=[] pl_tags = [] for elem in xml.iterchildren(): if elem.tag not in ignore: diff --git a/sfa/rspecs/elements/versions/nitosv1Sliver.py b/sfa/rspecs/elements/versions/nitosv1Sliver.py index 0f40211d..feac8879 100644 --- a/sfa/rspecs/elements/versions/nitosv1Sliver.py +++ b/sfa/rspecs/elements/versions/nitosv1Sliver.py @@ -43,7 +43,8 @@ class NITOSv1Sliver: return attribs @staticmethod - def get_slivers(xml, filter={}): + def get_slivers(xml, filter=None): + if filter is None: filter={} xpath = './default:sliver | ./sliver' sliver_elems = xml.xpath(xpath) slivers = [] diff --git a/sfa/rspecs/elements/versions/ofeliav1Port.py b/sfa/rspecs/elements/versions/ofeliav1Port.py index 07520ef3..f4cf74dc 100644 --- a/sfa/rspecs/elements/versions/ofeliav1Port.py +++ b/sfa/rspecs/elements/versions/ofeliav1Port.py @@ -39,7 +39,8 @@ class Ofeliav1Port: return attribs @staticmethod - def get_ports(xml, filter={}): + def get_ports(xml, filter=None): + if filter is None: filter={} xpath = './openflow:port | ./port' port_elems = xml.xpath(xpath) ports = [] diff --git a/sfa/rspecs/elements/versions/ofeliav1datapath.py b/sfa/rspecs/elements/versions/ofeliav1datapath.py index 86a38002..a1849735 100644 --- a/sfa/rspecs/elements/versions/ofeliav1datapath.py +++ b/sfa/rspecs/elements/versions/ofeliav1datapath.py @@ -21,7 +21,8 @@ from sfa.rspecs.elements.versions.ofeliav1Port import Ofeliav1Port class Ofeliav1Datapath: @staticmethod - def get_datapaths(xml, filter={}): + def get_datapaths(xml, filter=None): + if filter is None: filter={} #xpath = '//datapath%s | //default:datapath%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) xpath = '//datapath%s | //openflow:datapath%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) datapath_elems = xml.xpath(xpath) @@ -144,7 +145,8 @@ class Ofeliav1Datapath: # node.element.remove(sliver.element) # # @staticmethod -# def get_nodes(xml, filter={}): +# def get_nodes(xml, filter=None): +# if filter is None: filter={} # xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) # node_elems = xml.xpath(xpath) # return SFAv1Node.get_node_objs(node_elems) diff --git a/sfa/rspecs/elements/versions/ofeliav1link.py b/sfa/rspecs/elements/versions/ofeliav1link.py index 3fc2eb24..83a20969 100644 --- a/sfa/rspecs/elements/versions/ofeliav1link.py +++ b/sfa/rspecs/elements/versions/ofeliav1link.py @@ -8,7 +8,8 @@ from sfa.rspecs.elements.link import Link class Ofeliav1Link: @staticmethod - def get_links(xml, filter={}): + def get_links(xml, filter=None): + if filter is None: filter={} xpath = '//link%s | //openflow:link%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) link_elems = xml.xpath(xpath) return Ofeliav1Link.get_link_objs(link_elems) diff --git a/sfa/rspecs/elements/versions/pgv2DiskImage.py b/sfa/rspecs/elements/versions/pgv2DiskImage.py index 51363de3..4a6df82e 100644 --- a/sfa/rspecs/elements/versions/pgv2DiskImage.py +++ b/sfa/rspecs/elements/versions/pgv2DiskImage.py @@ -13,7 +13,8 @@ class PGv2DiskImage: xml.add_instance('disk_image', image, DiskImage.fields) @staticmethod - def get_images(xml, filter={}): + def get_images(xml, filter=None): + if filter is None: filter={} xpath = './default:disk_image | ./disk_image' image_elems = xml.xpath(xpath) images = [] diff --git a/sfa/rspecs/elements/versions/pgv2Lease.py b/sfa/rspecs/elements/versions/pgv2Lease.py index 68c44f0c..b04f7dc2 100644 --- a/sfa/rspecs/elements/versions/pgv2Lease.py +++ b/sfa/rspecs/elements/versions/pgv2Lease.py @@ -51,7 +51,8 @@ class PGv2Lease: @staticmethod - def get_leases(xml, filter={}): + def get_leases(xml, filter=None): + if filter is None: filter={} xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) lease_elems = xml.xpath(xpath) return PGv2Lease.get_lease_objs(lease_elems) diff --git a/sfa/rspecs/elements/versions/pgv2Node.py b/sfa/rspecs/elements/versions/pgv2Node.py index d553d219..60447b03 100644 --- a/sfa/rspecs/elements/versions/pgv2Node.py +++ b/sfa/rspecs/elements/versions/pgv2Node.py @@ -82,13 +82,15 @@ class PGv2Node: @staticmethod - def get_nodes(xml, filter={}): + def get_nodes(xml, filter=None): + if filter is None: filter={} xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) node_elems = xml.xpath(xpath) return PGv2Node.get_node_objs(node_elems) @staticmethod - def get_nodes_with_slivers(xml, filter={}): + def get_nodes_with_slivers(xml, filter=None): + if filter is None: filter={} xpath = '//node[count(sliver_type)>0] | //default:node[count(default:sliver_type) > 0]' node_elems = xml.xpath(xpath) return PGv2Node.get_node_objs(node_elems) diff --git a/sfa/rspecs/elements/versions/pgv2SliverType.py b/sfa/rspecs/elements/versions/pgv2SliverType.py index 1f3ec0c7..3ad687f8 100644 --- a/sfa/rspecs/elements/versions/pgv2SliverType.py +++ b/sfa/rspecs/elements/versions/pgv2SliverType.py @@ -40,7 +40,8 @@ class PGv2SliverType: for (key, value) in attrib_dict.items(): attrib_elem.set(key, value) @staticmethod - def get_slivers(xml, filter={}): + def get_slivers(xml, filter=None): + if filter is None: filter={} xpath = './default:sliver_type | ./sliver_type' sliver_elems = xml.xpath(xpath) slivers = [] @@ -56,5 +57,6 @@ class PGv2SliverType: return slivers @staticmethod - def get_sliver_attributes(xml, filter={}): + def get_sliver_attributes(xml, filter=None): + if filter is None: filter={} return [] diff --git a/sfa/rspecs/elements/versions/sfav1Lease.py b/sfa/rspecs/elements/versions/sfav1Lease.py index 039d2d13..0c7cb26b 100644 --- a/sfa/rspecs/elements/versions/sfav1Lease.py +++ b/sfa/rspecs/elements/versions/sfav1Lease.py @@ -72,7 +72,8 @@ class SFAv1Lease: @staticmethod - def get_leases(xml, filter={}): + def get_leases(xml, filter=None): + if filter is None: filter={} xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) lease_elems = xml.xpath(xpath) return SFAv1Lease.get_lease_objs(lease_elems) diff --git a/sfa/rspecs/elements/versions/sfav1Node.py b/sfa/rspecs/elements/versions/sfav1Node.py index 51076985..1931a584 100644 --- a/sfa/rspecs/elements/versions/sfav1Node.py +++ b/sfa/rspecs/elements/versions/sfav1Node.py @@ -125,7 +125,8 @@ class SFAv1Node: node.element.remove(sliver.element) @staticmethod - def get_nodes(xml, filter={}): + def get_nodes(xml, filter=None): + if filter is None: filter={} xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) node_elems = xml.xpath(xpath) return SFAv1Node.get_node_objs(node_elems) diff --git a/sfa/rspecs/elements/versions/sfav1PLTag.py b/sfa/rspecs/elements/versions/sfav1PLTag.py index b523124f..907c962a 100644 --- a/sfa/rspecs/elements/versions/sfav1PLTag.py +++ b/sfa/rspecs/elements/versions/sfav1PLTag.py @@ -9,7 +9,8 @@ class SFAv1PLTag: pl_tag_elem.set_text(value) @staticmethod - def get_pl_tags(xml, ignore=[]): + def get_pl_tags(xml, ignore=None): + if ignore is None: ignore=[] pl_tags = [] for elem in xml.iterchildren(): if elem.tag not in ignore: diff --git a/sfa/rspecs/elements/versions/sfav1Sliver.py b/sfa/rspecs/elements/versions/sfav1Sliver.py index a2b07a13..7e9282f2 100644 --- a/sfa/rspecs/elements/versions/sfav1Sliver.py +++ b/sfa/rspecs/elements/versions/sfav1Sliver.py @@ -39,7 +39,8 @@ class SFAv1Sliver: return attribs @staticmethod - def get_slivers(xml, filter={}): + def get_slivers(xml, filter=None): + if filter is None: filter={} xpath = './default:sliver | ./sliver' sliver_elems = xml.xpath(xpath) slivers = [] diff --git a/sfa/rspecs/rspec.py b/sfa/rspecs/rspec.py index 8a66ff35..0f61e905 100755 --- a/sfa/rspecs/rspec.py +++ b/sfa/rspecs/rspec.py @@ -10,7 +10,8 @@ from sfa.rspecs.version_manager import VersionManager class RSpec: - def __init__(self, rspec="", version=None, user_options={}): + def __init__(self, rspec="", version=None, user_options=None): + if user_options is None: user_options={} self.header = '\n' self.template = """""" self.version = None @@ -72,15 +73,17 @@ class RSpec: raise InvalidRSpecElement(element_type, extra=msg) return self.elements[element_type] - def get(self, element_type, filter={}, depth=0): + def get(self, element_type, filter=None, depth=0): + if filter is None: filter={} elements = self.get_elements(element_type, filter) elements = [self.xml.get_element_attributes(elem, depth=depth) for elem in elements] return elements - def get_elements(self, element_type, filter={}): + def get_elements(self, element_type, filter=None): """ search for a registered element """ + if filter is None: filter={} if element_type not in self.elements: msg = "Unable to search for element %s in rspec, expath expression not found." % \ element_type diff --git a/sfa/rspecs/versions/iotlabv1.py b/sfa/rspecs/versions/iotlabv1.py index 9d8045f7..ad491571 100644 --- a/sfa/rspecs/versions/iotlabv1.py +++ b/sfa/rspecs/versions/iotlabv1.py @@ -139,7 +139,8 @@ class Iotlabv1(RSpecVersion): def add_default_sliver_attribute(self, name, value, network=None): pass - def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): + def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False): + if attributes is None: attributes=[] # all nodes hould already be present in the rspec. Remove all # nodes that done have slivers print>>sys.stderr, "\r\n \r\n \r\n \t\t\t Iotlabv1.PY add_slivers ----->get_node " diff --git a/sfa/rspecs/versions/nitosv1.py b/sfa/rspecs/versions/nitosv1.py index af60d8ed..3288b48b 100644 --- a/sfa/rspecs/versions/nitosv1.py +++ b/sfa/rspecs/versions/nitosv1.py @@ -60,7 +60,8 @@ class NITOSv1(RSpecVersion): # Slivers - def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): + def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False): + if attributes is None: attributes=[] # add slice name to network tag network_tags = self.xml.xpath('//network') if network_tags: diff --git a/sfa/rspecs/versions/ofeliav1.py b/sfa/rspecs/versions/ofeliav1.py index cd206ffc..d074694b 100755 --- a/sfa/rspecs/versions/ofeliav1.py +++ b/sfa/rspecs/versions/ofeliav1.py @@ -86,7 +86,8 @@ class Ofelia(RSpecVersion): # Slivers - def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): + def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False): + if attributes is None: attributes=[] # add slice name to network tag network_tags = self.xml.xpath('//network') if network_tags: diff --git a/sfa/rspecs/versions/pgv2.py b/sfa/rspecs/versions/pgv2.py index 80febc90..21183bf7 100644 --- a/sfa/rspecs/versions/pgv2.py +++ b/sfa/rspecs/versions/pgv2.py @@ -103,7 +103,8 @@ class PGv2(RSpecVersion): def add_default_sliver_attribute(self, name, value, network=None): pass - def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): + def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False): + if attributes is None: attributes=[] # all nodes hould already be present in the rspec. Remove all # nodes that done have slivers for hostname in hostnames: diff --git a/sfa/rspecs/versions/sfav1.py b/sfa/rspecs/versions/sfav1.py index 4ee8a4c8..6e973e7e 100644 --- a/sfa/rspecs/versions/sfav1.py +++ b/sfa/rspecs/versions/sfav1.py @@ -59,7 +59,8 @@ class SFAv1(RSpecVersion): # Slivers - def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): + def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False): + if attributes is None: attributes=[] # add slice name to network tag network_tags = self.xml.xpath('//network') if network_tags: diff --git a/sfa/storage/model.py b/sfa/storage/model.py index d50d3b6d..7c749773 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -410,7 +410,8 @@ def drop_tables(engine): ############################## # create a record of the right type from either a dict or an xml string -def make_record (dict={}, xml=""): +def make_record (dict=None, xml=""): + if dict is None: dict={} if dict: return make_record_dict (dict) elif xml: return make_record_xml (xml) else: raise Exception("make_record has no input") diff --git a/sfa/storage/record.py b/sfa/storage/record.py index 812efdeb..9fcab19f 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -35,7 +35,8 @@ class Record: # it may be important to exclude relationships, which fortunately # - def todict (self, exclude_types=[]): + def todict (self, exclude_types=None): + if exclude_types is None: exclude_types=[] d=self.__dict__ def exclude (k,v): if k.startswith('_'): return True diff --git a/sfa/util/config.py b/sfa/util/config.py index c25ec442..797bed73 100644 --- a/sfa/util/config.py +++ b/sfa/util/config.py @@ -194,7 +194,8 @@ DO NOT EDIT. This file was automatically generated at return False - def dump(self, sections = []): + def dump(self, sections=None): + if sections is None: sections=[] sys.stdout.write(output_python()) def output_python(self, encoding = "utf-8"): diff --git a/sfa/util/storage.py b/sfa/util/storage.py index 793a38eb..89a25099 100644 --- a/sfa/util/storage.py +++ b/sfa/util/storage.py @@ -9,8 +9,8 @@ class SimpleStorage(dict): db_filename = None type = 'dict' - def __init__(self, db_filename, db = {}): - + def __init__(self, db_filename, db = None): + if db is None: db={} dict.__init__(self, db) self.db_filename = db_filename diff --git a/sfa/util/version.py.in b/sfa/util/version.py.in index 46b31d39..97ae6c40 100644 --- a/sfa/util/version.py.in +++ b/sfa/util/version.py.in @@ -3,7 +3,8 @@ version_tag="@VERSIONTAG@" scm_url="@SCMURL@" import socket -def version_core (more={}): +def version_core (more=None): + if more is None: more={} core = { 'code_tag' : version_tag, 'code_url' : scm_url, 'hostname' : socket.gethostname(), diff --git a/sfa/util/xml.py b/sfa/util/xml.py index d6734e63..ba324c7b 100755 --- a/sfa/util/xml.py +++ b/sfa/util/xml.py @@ -20,7 +20,8 @@ class XpathFilter: return xpath @staticmethod - def xpath(filter={}): + def xpath(filter=None): + if filter is None: filter={} xpath = "" if filter: filter_list = [] @@ -78,11 +79,12 @@ class XmlElement: def getparent(self): return XmlElement(self.element.getparent(), self.namespaces) - def get_instance(self, instance_class=None, fields=[]): + def get_instance(self, instance_class=None, fields=None): """ Returns an instance (dict) of this xml element. The instance holds a reference to this xml element. """ + if fields is None: fields=[] if not instance_class: instance_class = Element if not fields and hasattr(instance_class, 'fields'): @@ -97,11 +99,12 @@ class XmlElement: instance[field] = self.attrib[field] return instance - def add_instance(self, name, instance, fields=[]): + def add_instance(self, name, instance, fields=None): """ Adds the specifed instance(s) as a child element of this xml element. """ + if fields is None: fields=[] if not fields and hasattr(instance, 'keys'): fields = instance.keys() elem = self.add_element(name) diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index b0db4c1d..b16ea511 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -110,7 +110,8 @@ class Xrn: return Xrn.urn_meaningful(urn).split('+') @staticmethod - def filter_type(urns=[], type=None): + def filter_type(urns=None, type=None): + if urns is None: urns=[] urn_list = [] if not type: return urns