From: peusterm Date: Wed, 16 Mar 2016 19:14:22 +0000 (+0100) Subject: Added placement interface and a dumb placement algorithm that always uses the first... X-Git-Tag: v3.1~161^2~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=082378b8e883bb531c745c5ecc8da06d475648b2;p=osm%2Fvim-emu.git Added placement interface and a dumb placement algorithm that always uses the first DC in the list. --- diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index 71fb559..c3694e5 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -28,7 +28,7 @@ class Gatekeeper(object): def __init__(self): self.services = dict() - self.dcs = list() + self.dcs = dict() LOG.info("Create SONATA dummy gatekeeper.") def register_service_package(self, service_uuid, service): @@ -63,19 +63,6 @@ class Service(object): self.local_docker_files = dict() self.instances = dict() - def start_service(self): - # TODO implement method - instance_uuid = str(uuid.uuid4()) - # 1. parse descriptors and get name of each docker container - for vnfd in self.vnfds.itervalues(): - for u in vnfd.get("virtual_deployment_units"): - docker_name = u.get("vm_image") - # 2. do the corresponding dc.startCompute(name="foobar") calls - print "start %r" % docker_name - print "available dcs: %r " % GK.dcs - # 3. store references to the compute objects in self.instantiations - return instance_uuid - def onboard(self): """ Do all steps to prepare this service to be instantiated @@ -94,6 +81,21 @@ class Service(object): LOG.info("On-boarded service: %r" % self.manifest.get("package_name")) + def start_service(self): + # TODO implement method + # each service instance gets a new uuid to identify it + instance_uuid = str(uuid.uuid4()) + # compute placement of this service instance (adds DC names to VNFDs) + self._calculate_placement(FirstDcPlacement) + # 1. parse descriptors and get name of each docker container + for vnfd in self.vnfds.itervalues(): + for u in vnfd.get("virtual_deployment_units"): + docker_name = u.get("vm_image") + # 2. do the corresponding dc.startCompute(name="foobar") calls + print "start %r" % docker_name + # 3. store references to the compute objects in self.instantiations + return instance_uuid + def _unpack_service_package(self): """ unzip *.son file and store contents in CATALOG_FOLDER/services// @@ -170,6 +172,36 @@ class Service(object): # TODO implement pass + def _calculate_placement(self, algorithm): + """ + Do placement by adding the a field "dc" to + each VNFD that points to one of our + data center objects known to the gatekeeper. + """ + assert(len(self.vnfds) > 0) + assert(len(GK.dcs) > 0) + # instantiate algorithm an place + p = algorithm() + p.place(self.nsd, self.vnfds, GK.dcs) + LOG.info("Using placement algorithm: %r" % p.__class__.__name__) + # lets print the placement result + for name, vnfd in self.vnfds.iteritems(): + LOG.info("Placed VNF %r on DC %r" % (name, str(vnfd.get("dc")))) + + +""" +Some (simple) placement algorithms +""" + + +class FirstDcPlacement(object): + """ + Placement: Always use one and the same data center from the GK.dcs dict. + """ + def place(self, nsd, vnfds, dcs): + for name, vnfd in vnfds.iteritems(): + vnfd["dc"] = list(dcs.itervalues())[0] + """ Resource definitions and API endpoints @@ -252,7 +284,7 @@ api.add_resource(Packages, '/api/packages') api.add_resource(Instantiations, '/api/instantiations') -def start_rest_api(host, port, datacenters=list()): +def start_rest_api(host, port, datacenters=dict()): GK.dcs = datacenters # start the Flask server (not the best performance but ok for our use case) app.run(host=host,