From: peusterm Date: Fri, 23 Jun 2017 13:00:21 +0000 (+0200) Subject: Fixed: OpenStack API now supports very long instance names X-Git-Tag: v3.1~17^2~6^2~10 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=0beb1e04c88653d940d1647a112a767e96e9afc7;p=osm%2Fvim-emu.git Fixed: OpenStack API now supports very long instance names --- diff --git a/src/emuvim/api/openstack/compute.py b/src/emuvim/api/openstack/compute.py index fd9b1ac..09957b7 100755 --- a/src/emuvim/api/openstack/compute.py +++ b/src/emuvim/api/openstack/compute.py @@ -480,9 +480,16 @@ class OpenstackCompute(object): if name_or_id in self.computeUnits: return self.computeUnits[name_or_id] + if self._shorten_server_name(name_or_id) in self.computeUnits: + return self.computeUnits[name_or_id] + for server in self.computeUnits.values(): if server.name == name_or_id or server.template_name == name_or_id or server.full_name == name_or_id: return server + if (server.name == self._shorten_server_name(name_or_id) + or server.template_name == self._shorten_server_name(name_or_id) + or server.full_name == self._shorten_server_name(name_or_id)): + return server return None def create_server(self, name, stack_operation=False): @@ -499,12 +506,25 @@ class OpenstackCompute(object): """ if self.find_server_by_name_or_id(name) is not None and not stack_operation: raise Exception("Server with name %s already exists." % name) - server = Server(name) + safe_name = self._shorten_server_name(name) + server = Server(safe_name) server.id = str(uuid.uuid4()) if not stack_operation: self.computeUnits[server.id] = server return server + def _shorten_server_name(self, name, char_limit=64): + """ + Docker does not like too long instance names. + This function provides a shorter name if needed + """ + LOG.debug("Long server name: {}".format(name)) + if len(name) > char_limit: + # construct a short name + name = name[-char_limit:].strip("-_ .") + LOG.debug("Short server name: {}".format(name)) + return name + def delete_server(self, server): """ Deletes the given server from the stack dictionary and the computeUnits dictionary.