add interface of opt vim resources
[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 import json
15 import logging
16 import threading
17 import traceback
18 import sys
19
20 from lcm.pub.vimapi import adaptor
21
22 logger = logging.getLogger(__name__)
23
24 class ResCreateThread(threading.Thread):
25     """
26     Create resource
27     """
28     def __init__(self, req_data):
29         threading.Thread.__init__(self)
30         self.data = req_data
31
32     def run(self):
33         try:
34             adaptor.create_vim_res(self.data, self.do_notify)
35         except:
36             logger.error(traceback.format_exc())
37             logger.error(str(sys.exc_info()))
38             
39     def do_notify(self, res_type, ret):
40         logger.debug('ret of [%s] is %s', res_type, str(ret))
41
42 class ResDeleteThread(threading.Thread):
43     """
44     Delete resource
45     """
46     def __init__(self, req_data):
47         threading.Thread.__init__(self)
48         self.data = req_data
49
50     def run(self):
51         try:
52             adaptor.delete_vim_res(self.data, self.do_notify)
53         except:
54             logger.error(traceback.format_exc())
55             logger.error(str(sys.exc_info()))
56             
57     def do_notify(self, res_type, res_id):
58         logger.debug('Delete %s(%s)', res_type, res_id)