X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Fsonata%2Fdummygatekeeper.py;h=770bae6fa345c130ec101db1049f9f4277dbfbab;hb=8d4290a88dc41173832490d4bd20097f929f397c;hp=f9ff50667ad29e586b0d7ed0727982f1a878023f;hpb=a5a0ea08373c54e0855efad1dcc83d67ba577943;p=osm%2Fvim-emu.git diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index f9ff506..770bae6 100755 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -45,6 +45,7 @@ import flask_restful as fr from collections import defaultdict import pkg_resources from subprocess import Popen +import tempfile logging.basicConfig() LOG = logging.getLogger("sonata-dummy-gatekeeper") @@ -345,7 +346,23 @@ class Service(object): mem_lim = int(mem_limit) cpu_period, cpu_quota = self._calculate_cpu_cfs_values(float(cpu_bw)) - # 4. do the dc.startCompute(name="foobar") call to run the container + # 4. generate the volume paths for the docker container + volumes=list() + # a volume to extract log files + #tempfile.mkdtemp(dir="/tmp/results/%s/%s"%(self.uuid,vnf_name)) + docker_log_path = "/tmp/results/%s/%s"%(self.uuid,vnf_name) + LOG.debug("LOG path for vnf %s is %s."%(vnf_name,docker_log_path)) + #docker_log_path = tempfile.mkdtemp(dir=docker_log_path) + if not os.path.exists(docker_log_path): + os.makedirs(docker_log_path) + with open(docker_log_path+"/testfile", "w") as tf: + tf.write("placeholder") + tf.close() + + volumes.append(docker_log_path+":/mnt/share/") + + + # 5. do the dc.startCompute(name="foobar") call to run the container # TODO consider flavors, and other annotations intfs = vnfd.get("connection_points") @@ -361,8 +378,16 @@ class Service(object): LOG.info("Starting %r as %r in DC %r" % (vnf_name, self.vnf_name2docker_name[vnf_name], vnfd.get("dc"))) LOG.debug("Interfaces for %r: %r" % (vnf_name, intfs)) - vnfi = target_dc.startCompute(self.vnf_name2docker_name[vnf_name], network=intfs, image=docker_name, flavor_name="small", - cpu_quota=cpu_quota, cpu_period=cpu_period, cpuset=cpu_list, mem_limit=mem_lim) + vnfi = target_dc.startCompute( + self.vnf_name2docker_name[vnf_name], + network=intfs, + image=docker_name, + flavor_name="small", + cpu_quota=cpu_quota, + cpu_period=cpu_period, + cpuset=cpu_list, + mem_limit=mem_lim, + volumes=volumes) return vnfi def _stop_vnfi(self, vnfi): @@ -652,12 +677,14 @@ class Packages(fr.Resource): """ try: # get file contents - print(request.files) + LOG.info("POST /packages called") # lets search for the package in the request + is_file_object = False # make API more robust: file can be in data or in files field if "package" in request.files: son_file = request.files["package"] - # elif "file" in request.files: - # son_file = request.files["file"] + is_file_object = True + elif len(request.data) > 0: + son_file = request.data else: return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed. file not found."}, 500 # generate a uuid to reference this package @@ -667,7 +694,11 @@ class Packages(fr.Resource): ensure_dir(UPLOAD_FOLDER) upload_path = os.path.join(UPLOAD_FOLDER, "%s.son" % service_uuid) # store *.son file to disk - son_file.save(upload_path) + if is_file_object: + son_file.save(upload_path) + else: + with open(upload_path, 'wb') as f: + f.write(son_file) size = os.path.getsize(upload_path) # create a service object and register it s = Service(service_uuid, file_hash, upload_path) @@ -695,15 +726,15 @@ class Instantiations(fr.Resource): Will return a new UUID to identify the running service instance. :return: UUID """ + LOG.info("POST /instantiations (or /reqeusts) called") # try to extract the service uuid from the request json_data = request.get_json(force=True) service_uuid = json_data.get("service_uuid") # lets be a bit fuzzy here to make testing easier - if service_uuid is None and len(GK.services) > 0: + if (service_uuid is None or service_uuid=="latest") and len(GK.services) > 0: # if we don't get a service uuid, we simple start the first service in the list service_uuid = list(GK.services.iterkeys())[0] - if service_uuid in GK.services: # ok, we have a service uuid, lets start the service service_instance_uuid = GK.services.get(service_uuid).start_service() @@ -764,8 +795,8 @@ app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 512 * 1024 * 1024 # 512 MB max upload api = fr.Api(app) # define endpoints -api.add_resource(Packages, '/packages') -api.add_resource(Instantiations, '/instantiations') +api.add_resource(Packages, '/packages', '/api/v2/packages') +api.add_resource(Instantiations, '/instantiations', '/api/v2/instantiations', '/api/v2/requests') api.add_resource(Exit, '/emulator/exit')