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
24 from uuid
import uuid4
25 from .wimconn
import WimConnector
27 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
30 class FakeConnector(WimConnector
):
31 """Abstract base class for all the WIM connectors
34 wim (dict): WIM record, as stored in the database
35 wim_account (dict): WIM account record, as stored in the database
36 config (dict): optional persistent information related to an specific
37 connector. Inside this dict, a special key,
38 ``service_endpoint_mapping`` provides the internal endpoint
40 logger (logging.Logger): optional logger object. If none is passed
41 ``openmano.wim.wimconn`` is used.
43 The arguments of the constructor are converted to object attributes.
44 An extra property, ``service_endpoint_mapping`` is created from ``config``.
46 def __init__(self
, wim
, wim_account
, config
=None, logger
=None):
47 self
.logger
= logging
.getLogger('openmano.wimconn.fake')
48 super(FakeConnector
, self
).__init
__(wim
, wim_account
, config
, logger
)
49 self
.logger
.debug("__init: wim='{}' wim_account='{}'".format(wim
, wim_account
))
53 def check_credentials(self
):
54 """Check if the connector itself can access the WIM.
57 WimConnectorError: Issues regarding authorization, access to
58 external URLs, etc are detected.
60 self
.logger
.debug("check_credentials")
63 def get_connectivity_service_status(self
, service_uuid
, conn_info
=None):
64 """Monitor the status of the connectivity service established
67 service_uuid (str): UUID of the connectivity service
68 conn_info (dict or None): Information returned by the connector
69 during the service creation/edition and subsequently stored in
73 dict: JSON/YAML-serializable dict that contains a mandatory key
74 ``wim_status`` associated with one of the following values::
76 Additionally ``error_msg``(**str**) and ``wim_info``(**dict**)
77 keys can be used to provide additional status explanation or
78 new information available for the connectivity service.
80 self
.logger
.debug("get_connectivity_service_status: service_uuid='{}' conn_info='{}'".format(service_uuid
,
82 return {'wim_status': 'ACTIVE', 'wim_info': self
.connectivity
.get(service_uuid
)}
84 def create_connectivity_service(self
, service_type
, connection_points
,
87 Stablish WAN connectivity between the endpoints
90 self
.logger
.debug("create_connectivity_service: service_type='{}' connection_points='{}', kwargs='{}'".
91 format(service_type
, connection_points
, kwargs
))
93 self
.connectivity
[_id
] = {"nb": self
.counter
}
95 return _id
, self
.connectivity
[_id
]
97 def delete_connectivity_service(self
, service_uuid
, conn_info
=None):
98 """Disconnect multi-site endpoints previously connected
101 self
.logger
.debug("delete_connectivity_service: service_uuid='{}' conn_info='{}'".format(service_uuid
,
103 self
.connectivity
.pop(service_uuid
, None)
106 def edit_connectivity_service(self
, service_uuid
, conn_info
=None,
107 connection_points
=None, **kwargs
):
108 """Change an existing connectivity service.
110 This method's arguments and return value follow the same convention as
111 :meth:`~.create_connectivity_service`.
113 self
.logger
.debug("edit_connectivity_service: service_uuid='{}' conn_info='{}', connection_points='{}'"
114 "kwargs='{}'".format(service_uuid
, conn_info
, connection_points
, kwargs
))
117 def clear_all_connectivity_services(self
):
118 """Delete all WAN Links in a WIM.
120 This method is intended for debugging only, and should delete all the
121 connections controlled by the WIM, not only the WIM connections that
122 a specific RO is aware of.
125 self
.logger
.debug("clear_all_connectivity_services")
126 self
.connectivity
.clear()
129 def get_all_active_connectivity_services(self
):
130 """Provide information about all active connections provisioned by a
134 WimConnectorException: In case of error.
136 self
.logger
.debug("get_all_active_connectivity_services")
137 return self
.connectivity