http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument
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.
.. 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']]
- 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.
.. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
"""
-
+ if options is None: options={}
slice_ids = set()
node_ids = []
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
.. 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,
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.
.. 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(
- 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.
.. 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)
# 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'],
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)
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)
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).
"""
+ if options is None: options={}
logger.debug("CortexlabSlices \tverify_persons \tslice_hrn %s \
\t slice_record %s\r\n users %s \t "
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:
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 = []
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'])
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'])
return result
-def GetUsers(filter={}):
+def GetUsers(filter=None):
+ if filter is None: filter={}
global DB
result = []
result.extend(DB['users_list'])
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 = []
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'])
})
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'):
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']]
}
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)
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')
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'],
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)
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)
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)
'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:
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()
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'])
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]
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:
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:
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.
.. 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']]
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']})
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.
.. 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:
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
.. 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,
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.
.. 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(
- 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.
.. 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)
'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'],
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)
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)
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).
"""
-
+ 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))
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:
'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)
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)
# 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
# ...
# ]
#}
- 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
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
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]
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)
# 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')
# 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']
- 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:
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({}, [])
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:
- 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)
- 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})
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({}, [])
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:
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
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)
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)
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)
'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':
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()
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')
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)
'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
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:
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:
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()
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 = []
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']]
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 = {}
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']]
}
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={}
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)
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')
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)
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)
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)
'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:
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()
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])
- 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])
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]
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]
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', [])
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*'}
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:
@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)
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]'
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)
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 []
@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)
@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)
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)
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:
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 = []
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 = []
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)
# 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)
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)
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 = []
@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)
@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)
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 = []
return slivers
@staticmethod
- def get_sliver_attributes(xml, filter={}):
+ def get_sliver_attributes(xml, filter=None):
+ if filter is None: filter={}
return []
@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)
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)
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:
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 = []
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 = '<?xml version="1.0"?>\n'
self.template = """<RSpec></RSpec>"""
self.version = None
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
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 "
# 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:
# 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:
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:
# 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:
##############################
# 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")
# 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
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"):
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
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(),
return xpath
@staticmethod
- def xpath(filter={}):
+ def xpath(filter=None):
+ if filter is None: filter={}
xpath = ""
if filter:
filter_list = []
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'):
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)
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