2a4fa4ec25bcea22013be786201b1731afe61fb6
[vfc/gvnfm/vnflcm.git] / lcm / lcm / samples / resources.py
1 # Copyright 2017 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import json
16 import logging
17 import threading
18 import traceback
19 import sys
20
21 from lcm.pub.vimapi import adaptor
22
23 logger = logging.getLogger(__name__)
24
25 class ResCreateThread(threading.Thread):
26     """
27     Create resource
28     """
29     def __init__(self, req_data):
30         threading.Thread.__init__(self)
31         self.data = req_data
32
33     def run(self):
34         try:
35             adaptor.create_vim_res(self.data, self.do_notify)
36         except:
37             logger.error(traceback.format_exc())
38             logger.error(str(sys.exc_info()))
39             
40     def do_notify(self, res_type, ret):
41         logger.debug('ret of [%s] is %s', res_type, ret)
42
43 class ResDeleteThread(threading.Thread):
44     """
45     Delete resource
46     """
47     def __init__(self, req_data):
48         threading.Thread.__init__(self)
49         self.data = req_data
50
51     def run(self):
52         try:
53             adaptor.delete_vim_res(self.data, self.do_notify)
54         except:
55             logger.error(traceback.format_exc())
56             logger.error(str(sys.exc_info()))
57             
58     def do_notify(self, res_type, res_id):
59         logger.debug('Delete %s(%s)', res_type, res_id)