update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / plugins / rwnsm / rift / tasklets / rwnsmtasklet / rwnsmplugin.py
1 #
2 # Copyright 2016 RIFT.IO Inc
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from . import nsmpluginbase
17 from . import openmano_nsm
18 import asyncio
19
20 class RwNsPlugin(nsmpluginbase.NsmPluginBase):
21 """
22 RW Implentation of the NsmPluginBase
23 """
24 def __init__(self, dts, log, loop, publisher, ro_account, project):
25 self._dts = dts
26 self._log = log
27 self._loop = loop
28 self._project = project
29
30 def set_state(self, nsr_id, state):
31 pass
32
33 def create_nsr(self, nsr_msg, nsd, key_pairs=None, ssh_key=None):
34 """
35 Create Network service record
36 """
37 pass
38
39 @asyncio.coroutine
40 def deploy(self, nsr):
41 pass
42
43 @asyncio.coroutine
44 def instantiate_ns(self, nsr, config_xact):
45 """
46 Instantiate NSR with the passed nsr id
47 """
48 yield from nsr.instantiate(config_xact)
49
50 @asyncio.coroutine
51 def instantiate_vnf(self, nsr, vnfr, scaleout=False):
52 """
53 Instantiate NSR with the passed nsr id
54 """
55 yield from vnfr.instantiate(nsr)
56
57 @asyncio.coroutine
58 def instantiate_vl(self, nsr, vlr):
59 """
60 Instantiate NSR with the passed nsr id
61 """
62 yield from vlr.instantiate()
63
64 @asyncio.coroutine
65 def terminate_ns(self, nsr):
66 """
67 Terminate the network service
68 """
69 pass
70
71 @asyncio.coroutine
72 def terminate_vnf(self, nsr, vnfr, scalein=False):
73 """
74 Terminate the VNF
75 """
76 yield from vnfr.terminate()
77
78 @asyncio.coroutine
79 def terminate_vl(self, vlr):
80 """
81 Terminate the virtual link
82 """
83 yield from vlr.terminate()
84
85 @asyncio.coroutine
86 def update_vnfr(self, vnfr):
87 """ Update the virtual network function record """
88 yield from vnfr.update_vnfm()
89
90 class NsmPlugins(object):
91 """ NSM Plugins """
92 def __init__(self):
93 self._plugin_classes = {
94 "openmano": openmano_nsm.OpenmanoNsPlugin,
95 }
96
97 @property
98 def plugins(self):
99 """ Plugin info """
100 return self._plugin_classes
101
102 def __getitem__(self, name):
103 """ Get item """
104 return self._plugin_classes[name]
105
106 def register(self, plugin_name, plugin_class, *args):
107 """ Register a plugin to this Nsm"""
108 self._plugin_classes[plugin_name] = plugin_class
109
110 def deregister(self, plugin_name, plugin_class, *args):
111 """ Deregister a plugin to this Nsm"""
112 if plugin_name in self._plugin_classes:
113 del self._plugin_classes[plugin_name]
114
115 def class_by_plugin_name(self, name):
116 """ Get class by plugin name """
117 return self._plugin_classes[name]