X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fng_ro.py;h=03819c850bd3b27e2f60875a2f2f4bb813f59f84;hb=refs%2Fchanges%2F84%2F11984%2F12;hp=0acccc4a97cd95d0afc8136992c9f44ee40c5b62;hpb=07f4e4cc95d17c613f5557e65781b8d4599ed20f;p=osm%2FLCM.git diff --git a/osm_lcm/ng_ro.py b/osm_lcm/ng_ro.py index 0acccc4..03819c8 100644 --- a/osm_lcm/ng_ro.py +++ b/osm_lcm/ng_ro.py @@ -156,6 +156,42 @@ class NgRoClient: except asyncio.TimeoutError: raise NgRoException("Timeout", http_code=504) + async def operate(self, nsr_id, target, operation_type): + """ + Performs start/stop/rebuil of VNFs + :param nsr_id: NS Instance Id + :param target: payload data for migrate operation + :param operation_type: start/stop/rebuil of VNFs + :return: dictionary with the information or raises NgRoException on Error + """ + try: + if isinstance(target, str): + target = self._parse_yaml(target) + payload_req = yaml.safe_dump(target) + + url = "{}/ns/v1/{operation_type}/{nsr_id}".format( + self.endpoint_url, operation_type=operation_type, nsr_id=nsr_id + ) + async with aiohttp.ClientSession(loop=self.loop) as session: + self.logger.debug("NG-RO POST %s %s", url, payload_req) + # timeout = aiohttp.ClientTimeout(total=self.timeout_large) + async with session.post( + url, headers=self.headers_req, data=payload_req + ) as response: + response_text = await response.read() + self.logger.debug( + "POST {} [{}] {}".format( + url, response.status, response_text[:100] + ) + ) + if response.status >= 300: + raise NgRoException(response_text, http_code=response.status) + return self._parse_yaml(response_text, response=True) + except (aiohttp.ClientOSError, aiohttp.ClientError) as e: + raise NgRoException(e, http_code=504) + except asyncio.TimeoutError: + raise NgRoException("Timeout", http_code=504) + async def status(self, nsr_id, action_id): try: url = "{}/ns/v1/deploy/{nsr_id}/{action_id}".format( @@ -299,6 +335,38 @@ class NgRoClient: except asyncio.TimeoutError: raise NgRoException("Timeout", http_code=504) + async def vertical_scale(self, nsr_id, target): + """ + Performs migration of VNFs + :param nsr_id: NS Instance Id + :param target: payload data for migrate operation + :return: dictionary with the information or raises NgRoException on Error + """ + try: + if isinstance(target, str): + target = self._parse_yaml(target) + payload_req = yaml.safe_dump(target) + + url = "{}/ns/v1/verticalscale/{nsr_id}".format(self.endpoint_url, nsr_id=nsr_id) + async with aiohttp.ClientSession(loop=self.loop) as session: + self.logger.debug("NG-RO POST %s %s", url, payload_req) + async with session.post( + url, headers=self.headers_req, data=payload_req + ) as response: + response_text = await response.read() + self.logger.debug( + "POST {} [{}] {}".format( + url, response.status, response_text[:100] + ) + ) + if response.status >= 300: + raise NgRoException(response_text, http_code=response.status) + return self._parse_yaml(response_text, response=True) + except (aiohttp.ClientOSError, aiohttp.ClientError) as e: + raise NgRoException(e, http_code=504) + except asyncio.TimeoutError: + raise NgRoException("Timeout", http_code=504) + @staticmethod def _parse_yaml(descriptor, response=False): try: