blob: 10c2e33a14bb366553e4ef5cb3d2ec613780a094 [file] [log] [blame]
lloretgalleg1d2ff512020-08-01 06:05:58 +00001##
2# Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U.
3# This file is part of OSM
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15# implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19# For those usages not covered by the Apache License, Version 2.0 please
20# contact with: nfvlabs@tid.es
21##
22
23import asyncio
24import logging
25
26from osm_ee.exceptions import VnfException
27
28
29class VnfEE:
30
31 def __init__(self, config_params):
32 self.logger = logging.getLogger('osm_ee.vnf')
33 self.config_params = config_params
34
35 async def config(self, id, params):
36 self.logger.debug("Execute action config params: {}".format(params))
37 # Config action is special, params are merged with previous config calls
38 self.config_params.update(params)
39 yield "OK", "Configured"
40
41 async def sleep(self, id, params):
42 self.logger.debug("Execute action sleep, params: {}".format(params))
43
44 for i in range(3):
45 await asyncio.sleep(5)
46 self.logger.debug("Temporal result return, params: {}".format(params))
47 yield "PROCESSING", f"Processing {i} action id {id}"
48 yield "OK", f"Processed action id {id}"
49
50 @staticmethod
51 def _check_required_params(params, required_params):
52 for required_param in required_params:
53 if required_param not in params:
54 raise VnfException("Missing required param: {}".format(required_param))