Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN
LOGGER = logging.getLogger(__name__)
class MockOSM:
def __init__(self, url, mapping, username, password):
wim = {'wim_url': url}
wim_account = {'user': username, 'password': password}
config = {'mapping_not_needed': False, 'service_endpoint_mapping': mapping}
self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config)
self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors
def create_connectivity_service(self, service_type, connection_points):
LOGGER.info('[create_connectivity_service] service_type={:s}'.format(str(service_type)))
LOGGER.info('[create_connectivity_service] connection_points={:s}'.format(str(connection_points)))
self.wim.check_credentials()
result = self.wim.create_connectivity_service(service_type, connection_points)
LOGGER.info('[create_connectivity_service] result={:s}'.format(str(result)))
service_uuid, conn_info = result
self.conn_info[service_uuid] = conn_info
return service_uuid
def get_connectivity_service_status(self, service_uuid):
LOGGER.info('[get_connectivity_service] service_uuid={:s}'.format(str(service_uuid)))
conn_info = self.conn_info.get(service_uuid)
if conn_info is None: raise Exception('ServiceId({:s}) not found'.format(str(service_uuid)))
LOGGER.info('[get_connectivity_service] conn_info={:s}'.format(str(conn_info)))
self.wim.check_credentials()
result = self.wim.get_connectivity_service_status(service_uuid, conn_info=conn_info)
LOGGER.info('[get_connectivity_service] result={:s}'.format(str(result)))
return result
def edit_connectivity_service(self, service_uuid, connection_points):
LOGGER.info('[edit_connectivity_service] service_uuid={:s}'.format(str(service_uuid)))
LOGGER.info('[edit_connectivity_service] connection_points={:s}'.format(str(connection_points)))
conn_info = self.conn_info.get(service_uuid)
if conn_info is None: raise Exception('ServiceId({:s}) not found'.format(str(service_uuid)))
LOGGER.info('[edit_connectivity_service] conn_info={:s}'.format(str(conn_info)))
self.wim.edit_connectivity_service(service_uuid, conn_info=conn_info, connection_points=connection_points)
def delete_connectivity_service(self, service_uuid):
LOGGER.info('[delete_connectivity_service] service_uuid={:s}'.format(str(service_uuid)))
conn_info = self.conn_info.get(service_uuid)
if conn_info is None: raise Exception('ServiceId({:s}) not found'.format(str(service_uuid)))
LOGGER.info('[delete_connectivity_service] conn_info={:s}'.format(str(conn_info)))
self.wim.check_credentials()
self.wim.delete_connectivity_service(service_uuid, conn_info=conn_info)