# Copyright (C) 2013 INRIA
#
# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
log.debug("Package sfa-common not installed.\
Could not import sfa.rspecs.rspec and sfa.util.xrn")
-from types import StringTypes, ListType
-
-
class SfaRSpecProcessing(object):
"""
Class to process SFA RSpecs, parse the RSpec replies such as Advertisement RSpecs,
self.config = config
def make_dict_rec(self, obj):
- if not obj or isinstance(obj, (StringTypes, bool)):
+ if not obj or isinstance(obj, (str, bool)):
return obj
if isinstance(obj, list):
objcopy = []
return objcopy
# We thus suppose we have a child of dict
objcopy = {}
- for k, v in obj.items():
+ for k, v in list(obj.items()):
objcopy[k] = self.make_dict_rec(v)
return objcopy
try:
nodes = rspec.version.get_nodes()
- except Exception, e:
+ except Exception as e:
self._log.warn("Could not retrieve nodes in RSpec: %s" % e)
try:
leases = rspec.version.get_leases()
- except Exception, e:
+ except Exception as e:
self._log.warn("Could not retrieve leases in RSpec: %s" % e)
try:
links = rspec.version.get_links()
- except Exception, e:
+ except Exception as e:
self._log.warn("Could not retrieve links in RSpec: %s" % e)
try:
channels = rspec.version.get_channels()
- except Exception, e:
+ except Exception as e:
self._log.warn("Could not retrieve channels in RSpec: %s" % e)
resources = []
# }
- def build_sfa_rspec(self, slice_id, resources, leases):
+ def build_sfa_rspec(self, slice_id, resources, properties, leases):
"""
Build the XML RSpec from list of resources' urns.
eg. resources = ["urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it"]
nodes = []
channels = []
links = []
- self._log.info("Building RSpec for resources %s" % resources)
+ self._log.debug("Building RSpec for resources %s" % resources)
+ cardinal = 0
+ wilab = False
for urn in resources:
# XXX TO BE CORRECTED, this handles None values
if not urn:
continue
- self._log.info(urn)
+ self._log.debug(urn)
resource = dict()
# TODO: take into account the case where we send a dict of URNs without keys
#resource['component_id'] = resource.pop('urn')
if resource_type == 'node':
# XXX dirty hack WiLab !!!
- if self.config:
- if 'wilab2' in self.config['sm']:
- resource['client_id'] = "PC"
- resource['sliver_type'] = "raw-pc"
+# Commented Lucia, doesn't work for wilabt
+# if self.config:
+# if 'wilab2' in self.config['sm']:
+# resource['client_id'] = "PC"
+# resource['sliver_type'] = "raw-pc"
+ if 'wilab2' in urn:
+ wilab = True
+ resource['client_id'] = "node%s" % cardinal
+ resource['sliver_type'] = "raw-pc"
+ resource['disk_image'] = "hola"
+ top_auth = resource_hrn.replace("\\", "").split('.')
+ top_auth.pop()
+ top_auth = '.'.join(top_auth)
+ cm = urn.split("+")
+ resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth)
+ cardinal += 1
nodes.append(resource)
elif resource_type == 'link':
links.append(resource)
elif resource_type == 'channel':
channels.append(resource)
else:
- raise Exception, "Not supported type of resource"
+ raise Exception("Not supported type of resource")
rspec.version.add_nodes(nodes, rspec_content_type="request")
#rspec.version.add_leases(leases)
#rspec.version.add_links(links)
#rspec.version.add_channels(channels)
-
- self._log.info("request rspec: %s"%rspec.toxml())
- return rspec.toxml()
+
+ #self._log.debug("request rspec: %s"%rspec.toxml())
+ string = rspec.toxml()
+ if wilab and properties is not None:
+ ## dirty hack for the f4f demo
+ b = string.split('\n')
+ for i, n in enumerate(b):
+ if 'sliver_type name="raw-pc"' in n:
+ b[i] = '<sliver_type name="raw-pc">'
+ b.insert(i+1, '<disk_image name="urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//%s"/>' % properties['disk_image'])
+ #b.insert(i+1, '<disk_image name="urn:publicid:IDN+wilab2.ilabt.iminds.be+image+nepi:%s"/>' % properties['disk_image'])
+ b.insert(i+2, '</sliver_type>')
+ string = ''.join(b)
+ self._log.debug("request rspec : %s" % string)
+ return string