1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Telefonica
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 This WIM does nothing and allows using it for testing and when no WIM is needed
23 from http
import HTTPStatus
25 from uuid
import uuid4
27 from osm_ro_plugin
.sdnconn
import SdnConnectorBase
, SdnConnectorError
30 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
33 class SdnDummyConnector(SdnConnectorBase
):
34 """Abstract base class for all the WIM connectors
37 wim (dict): WIM record, as stored in the database
38 wim_account (dict): WIM account record, as stored in the database
39 config (dict): optional persistent information related to an specific
40 connector. Inside this dict, a special key,
41 ``service_endpoint_mapping`` provides the internal endpoint
43 logger (logging.Logger): optional logger object. If none is passed
44 ``openmano.wim.wimconn`` is used.
46 The arguments of the constructor are converted to object attributes.
47 An extra property, ``service_endpoint_mapping`` is created from ``config``.
50 def __init__(self
, wim
, wim_account
, config
=None, logger
=None):
51 self
.logger
= logger
or logging
.getLogger("ro.sdn.dummy")
52 super(SdnDummyConnector
, self
).__init
__(wim
, wim_account
, config
, self
.logger
)
53 self
.logger
.debug("__init: wim='{}' wim_account='{}'".format(wim
, wim_account
))
57 def check_credentials(self
):
58 """Check if the connector itself can access the WIM.
61 SdnConnectorError: Issues regarding authorization, access to
62 external URLs, etc are detected.
64 self
.logger
.debug("check_credentials")
68 def get_connectivity_service_status(self
, service_uuid
, conn_info
=None):
69 """Monitor the status of the connectivity service established
72 service_uuid (str): UUID of the connectivity service
73 conn_info (dict or None): Information returned by the connector
74 during the service creation/edition and subsequently stored in
78 dict: JSON/YAML-serializable dict that contains a mandatory key
79 ``sdn_status`` associated with one of the following values::
81 Additionally ``error_msg``(**str**) and ``sdn_info``(**dict**)
82 keys can be used to provide additional status explanation or
83 new information available for the connectivity service.
86 "get_connectivity_service_status: service_uuid='{}' conn_info='{}'".format(
87 service_uuid
, conn_info
91 return {"sdn_status": "ACTIVE", "sdn_info": self
.connections
.get(service_uuid
)}
93 def create_connectivity_service(self
, service_type
, connection_points
, **kwargs
):
94 """Establish WAN connectivity between the endpoints"""
96 "create_connectivity_service: service_type='{}' connection_points='{}', kwargs='{}'".format(
97 service_type
, connection_points
, kwargs
101 self
.connections
[_id
] = connection_points
.copy()
106 def delete_connectivity_service(self
, service_uuid
, conn_info
=None):
107 """Disconnect multi-site endpoints previously connected"""
109 "delete_connectivity_service: service_uuid='{}' conn_info='{}'".format(
110 service_uuid
, conn_info
114 if service_uuid
not in self
.connections
:
115 raise SdnConnectorError(
116 "connectivity {} not found".format(service_uuid
),
117 http_code
=HTTPStatus
.NOT_FOUND
.value
,
120 self
.connections
.pop(service_uuid
, None)
124 def edit_connectivity_service(
125 self
, service_uuid
, conn_info
=None, connection_points
=None, **kwargs
127 """Change an existing connectivity service.
129 This method's arguments and return value follow the same convention as
130 :meth:`~.create_connectivity_service`.
133 "edit_connectivity_service: service_uuid='{}' conn_info='{}', connection_points='{}'"
134 "kwargs='{}'".format(service_uuid
, conn_info
, connection_points
, kwargs
)
137 if service_uuid
not in self
.connections
:
138 raise SdnConnectorError(
139 "connectivity {} not found".format(service_uuid
),
140 http_code
=HTTPStatus
.NOT_FOUND
.value
,
143 self
.connections
[service_uuid
] = connection_points
.copy()
147 def clear_all_connectivity_services(self
):
148 """Delete all WAN Links in a WIM.
150 This method is intended for debugging only, and should delete all the
151 connections controlled by the WIM, not only the WIM connections that
152 a specific RO is aware of.
155 self
.logger
.debug("clear_all_connectivity_services")
156 self
.connections
.clear()
160 def get_all_active_connectivity_services(self
):
161 """Provide information about all active connections provisioned by a
165 SdnConnectorException: In case of error.
167 self
.logger
.debug("get_all_active_connectivity_services")
169 return self
.connections