| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | ## |
| tierno | 9202102 | 2018-09-12 16:29:23 +0200 | [diff] [blame] | 4 | # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 5 | # This file is part of openmano |
| 6 | # All Rights Reserved. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | # not use this file except in compliance with the License. You may obtain |
| 10 | # a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 17 | # License for the specific language governing permissions and limitations |
| 18 | # under the License. |
| 19 | # |
| 20 | # For those usages not covered by the Apache License, Version 2.0 please |
| 21 | # contact with: nfvlabs@tid.es |
| 22 | ## |
| 23 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 24 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 25 | vimconn implement an Abstract class for the vim connector plugins |
| 26 | with the definition of the method to be implemented. |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 27 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 28 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 29 | import logging |
| gcalvino | e580c7d | 2017-09-22 14:09:51 +0200 | [diff] [blame] | 30 | import paramiko |
| 31 | import socket |
| tierno | 7d782ef | 2019-10-04 12:56:31 +0000 | [diff] [blame] | 32 | from io import StringIO |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 33 | import yaml |
| gcalvino | 51757e9 | 2017-10-03 11:31:31 +0200 | [diff] [blame] | 34 | import sys |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 35 | from email.mime.multipart import MIMEMultipart |
| 36 | from email.mime.text import MIMEText |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 37 | from http import HTTPStatus |
| 38 | import warnings |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 39 | |
| 40 | __author__ = "Alfonso Tierno, Igor D.C." |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 41 | __date__ = "$14-aug-2017 23:59:59$" |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 42 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 43 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 44 | def deprecated(message): |
| 45 | def deprecated_decorator(func): |
| 46 | def deprecated_func(*args, **kwargs): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 47 | warnings.warn( |
| 48 | "{} is a deprecated function. {}".format(func.__name__, message), |
| 49 | category=DeprecationWarning, |
| 50 | stacklevel=2, |
| 51 | ) |
| 52 | warnings.simplefilter("default", DeprecationWarning) |
| 53 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 54 | return func(*args, **kwargs) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 55 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 56 | return deprecated_func |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 57 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 58 | return deprecated_decorator |
| 59 | |
| 60 | |
| 61 | # Error variables |
| 62 | HTTP_Bad_Request = HTTPStatus.BAD_REQUEST.value |
| 63 | HTTP_Unauthorized = HTTPStatus.UNAUTHORIZED.value |
| 64 | HTTP_Not_Found = HTTPStatus.NOT_FOUND.value |
| 65 | HTTP_Method_Not_Allowed = HTTPStatus.METHOD_NOT_ALLOWED.value |
| 66 | HTTP_Request_Timeout = HTTPStatus.REQUEST_TIMEOUT.value |
| 67 | HTTP_Conflict = HTTPStatus.CONFLICT.value |
| 68 | HTTP_Not_Implemented = HTTPStatus.NOT_IMPLEMENTED.value |
| 69 | HTTP_Service_Unavailable = HTTPStatus.SERVICE_UNAVAILABLE.value |
| 70 | HTTP_Internal_Server_Error = HTTPStatus.INTERNAL_SERVER_ERROR.value |
| 71 | |
| 72 | |
| 73 | class VimConnException(Exception): |
| 74 | """Common and base class Exception for all VimConnector exceptions""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 75 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 76 | def __init__(self, message, http_code=HTTP_Bad_Request): |
| 77 | Exception.__init__(self, message) |
| 78 | self.http_code = http_code |
| 79 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 80 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 81 | class VimConnConnectionException(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 82 | """Connectivity error with the VIM""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 83 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 84 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 85 | VimConnException.__init__(self, message, http_code) |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 86 | |
| 87 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 88 | class VimConnUnexpectedResponse(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 89 | """Get an wrong response from VIM""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 90 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 91 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 92 | VimConnException.__init__(self, message, http_code) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 93 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 94 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 95 | class VimConnAuthException(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 96 | """Invalid credentials or authorization to perform this action over the VIM""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 97 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 98 | def __init__(self, message, http_code=HTTP_Unauthorized): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 99 | VimConnException.__init__(self, message, http_code) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 100 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 101 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 102 | class VimConnNotFoundException(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 103 | """The item is not found at VIM""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 104 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 105 | def __init__(self, message, http_code=HTTP_Not_Found): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 106 | VimConnException.__init__(self, message, http_code) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 107 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 108 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 109 | class VimConnConflictException(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 110 | """There is a conflict, e.g. more item found than one""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 111 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 112 | def __init__(self, message, http_code=HTTP_Conflict): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 113 | VimConnException.__init__(self, message, http_code) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 114 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 115 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 116 | class VimConnNotSupportedException(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 117 | """The request is not supported by connector""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 118 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 119 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 120 | VimConnException.__init__(self, message, http_code) |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 121 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 122 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 123 | class VimConnNotImplemented(VimConnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 124 | """The method is not implemented by the connected""" |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 125 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 126 | def __init__(self, message, http_code=HTTP_Not_Implemented): |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 127 | VimConnException.__init__(self, message, http_code) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 128 | |
| mirabal | 2935631 | 2017-07-27 12:21:22 +0200 | [diff] [blame] | 129 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 130 | class VimConnector: |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 131 | """Abstract base class for all the VIM connector plugins |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 132 | These plugins must implement a VimConnector class derived from this |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 133 | and all these privated methods |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 134 | """ |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 135 | |
| 136 | def __init__( |
| 137 | self, |
| 138 | uuid, |
| 139 | name, |
| 140 | tenant_id, |
| 141 | tenant_name, |
| 142 | url, |
| 143 | url_admin=None, |
| 144 | user=None, |
| 145 | passwd=None, |
| 146 | log_level=None, |
| 147 | config={}, |
| 148 | persistent_info={}, |
| 149 | ): |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 150 | """ |
| 151 | Constructor of VIM. Raise an exception is some needed parameter is missing, but it must not do any connectivity |
| 152 | checking against the VIM |
| 153 | :param uuid: internal id of this VIM |
| 154 | :param name: name assigned to this VIM, can be used for logging |
| 155 | :param tenant_id: 'tenant_id': (only one of them is mandatory) VIM tenant to be used |
| 156 | :param tenant_name: 'tenant_name': (only one of them is mandatory) VIM tenant to be used |
| 157 | :param url: url used for normal operations |
| 158 | :param url_admin: (optional), url used for administrative tasks |
| 159 | :param user: user to access |
| 160 | :param passwd: password |
| 161 | :param log_level: provided if it should use a different log_level than the general one |
| 162 | :param config: dictionary with extra VIM information. This contains a consolidate version of VIM config |
| 163 | at VIM_ACCOUNT (attach) |
| 164 | :param persitent_info: dict where the class can store information that will be available among class |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 165 | destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an |
| 166 | empty dict. Useful to store login/tokens information for speed up communication |
| 167 | |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 168 | """ |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 169 | self.id = uuid |
| 170 | self.name = name |
| 171 | self.url = url |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 172 | self.url_admin = url_admin |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 173 | self.tenant_id = tenant_id |
| 174 | self.tenant_name = tenant_name |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 175 | self.user = user |
| 176 | self.passwd = passwd |
| 177 | self.config = config or {} |
| mirabal | 2935631 | 2017-07-27 12:21:22 +0200 | [diff] [blame] | 178 | self.availability_zone = None |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 179 | self.logger = logging.getLogger("ro.vim") |
| 180 | |
| tierno | fe78990 | 2016-09-29 14:20:44 +0000 | [diff] [blame] | 181 | if log_level: |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 182 | self.logger.setLevel(getattr(logging, log_level)) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 183 | |
| 184 | if not self.url_admin: # try to use normal url |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 185 | self.url_admin = self.url |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 186 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 187 | def __getitem__(self, index): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 188 | if index == "tenant_id": |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 189 | return self.tenant_id |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 190 | |
| 191 | if index == "tenant_name": |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 192 | return self.tenant_name |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 193 | elif index == "id": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 194 | return self.id |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 195 | elif index == "name": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 196 | return self.name |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 197 | elif index == "user": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 198 | return self.user |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 199 | elif index == "passwd": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 200 | return self.passwd |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 201 | elif index == "url": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 202 | return self.url |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 203 | elif index == "url_admin": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 204 | return self.url_admin |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 205 | elif index == "config": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 206 | return self.config |
| 207 | else: |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 208 | raise KeyError("Invalid key '{}'".format(index)) |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 209 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 210 | def __setitem__(self, index, value): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 211 | if index == "tenant_id": |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 212 | self.tenant_id = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 213 | |
| 214 | if index == "tenant_name": |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 215 | self.tenant_name = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 216 | elif index == "id": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 217 | self.id = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 218 | elif index == "name": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 219 | self.name = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 220 | elif index == "user": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 221 | self.user = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 222 | elif index == "passwd": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 223 | self.passwd = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 224 | elif index == "url": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 225 | self.url = value |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 226 | elif index == "url_admin": |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 227 | self.url_admin = value |
| 228 | else: |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 229 | raise KeyError("Invalid key '{}'".format(index)) |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 230 | |
| 231 | @staticmethod |
| 232 | def _create_mimemultipart(content_list): |
| 233 | """Creates a MIMEmultipart text combining the content_list |
| 234 | :param content_list: list of text scripts to be combined |
| 235 | :return: str of the created MIMEmultipart. If the list is empty returns None, if the list contains only one |
| 236 | element MIMEmultipart is not created and this content is returned |
| 237 | """ |
| 238 | if not content_list: |
| 239 | return None |
| 240 | elif len(content_list) == 1: |
| 241 | return content_list[0] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 242 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 243 | combined_message = MIMEMultipart() |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 244 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 245 | for content in content_list: |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 246 | if content.startswith("#include"): |
| 247 | mime_format = "text/x-include-url" |
| 248 | elif content.startswith("#include-once"): |
| 249 | mime_format = "text/x-include-once-url" |
| 250 | elif content.startswith("#!"): |
| 251 | mime_format = "text/x-shellscript" |
| 252 | elif content.startswith("#cloud-config"): |
| 253 | mime_format = "text/cloud-config" |
| 254 | elif content.startswith("#cloud-config-archive"): |
| 255 | mime_format = "text/cloud-config-archive" |
| 256 | elif content.startswith("#upstart-job"): |
| 257 | mime_format = "text/upstart-job" |
| 258 | elif content.startswith("#part-handler"): |
| 259 | mime_format = "text/part-handler" |
| 260 | elif content.startswith("#cloud-boothook"): |
| 261 | mime_format = "text/cloud-boothook" |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 262 | else: # by default |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 263 | mime_format = "text/x-shellscript" |
| 264 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 265 | sub_message = MIMEText(content, mime_format, sys.getdefaultencoding()) |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 266 | combined_message.attach(sub_message) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 267 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 268 | return combined_message.as_string() |
| 269 | |
| 270 | def _create_user_data(self, cloud_config): |
| 271 | """ |
| 272 | Creates a script user database on cloud_config info |
| 273 | :param cloud_config: dictionary with |
| 274 | 'key-pairs': (optional) list of strings with the public key to be inserted to the default user |
| 275 | 'users': (optional) list of users to be inserted, each item is a dict with: |
| 276 | 'name': (mandatory) user name, |
| 277 | 'key-pairs': (optional) list of strings with the public key to be inserted to the user |
| 278 | 'user-data': (optional) can be a string with the text script to be passed directly to cloud-init, |
| 279 | or a list of strings, each one contains a script to be passed, usually with a MIMEmultipart file |
| 280 | 'config-files': (optional). List of files to be transferred. Each item is a dict with: |
| 281 | 'dest': (mandatory) string with the destination absolute path |
| 282 | 'encoding': (optional, by default text). Can be one of: |
| 283 | 'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64' |
| 284 | 'content' (mandatory): string with the content of the file |
| 285 | 'permissions': (optional) string with file permissions, typically octal notation '0644' |
| 286 | 'owner': (optional) file owner, string with the format 'owner:group' |
| 287 | 'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk) |
| 288 | :return: config_drive, userdata. The first is a boolean or None, the second a string or None |
| 289 | """ |
| 290 | config_drive = None |
| 291 | userdata = None |
| 292 | userdata_list = [] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 293 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 294 | if isinstance(cloud_config, dict): |
| 295 | if cloud_config.get("user-data"): |
| 296 | if isinstance(cloud_config["user-data"], str): |
| 297 | userdata_list.append(cloud_config["user-data"]) |
| 298 | else: |
| 299 | for u in cloud_config["user-data"]: |
| 300 | userdata_list.append(u) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 301 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 302 | if cloud_config.get("boot-data-drive") is not None: |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 303 | config_drive = cloud_config["boot-data-drive"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 304 | |
| 305 | if ( |
| 306 | cloud_config.get("config-files") |
| 307 | or cloud_config.get("users") |
| 308 | or cloud_config.get("key-pairs") |
| 309 | ): |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 310 | userdata_dict = {} |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 311 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 312 | # default user |
| 313 | if cloud_config.get("key-pairs"): |
| 314 | userdata_dict["ssh-authorized-keys"] = cloud_config["key-pairs"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 315 | userdata_dict["users"] = [ |
| 316 | { |
| 317 | "default": None, |
| 318 | "ssh-authorized-keys": cloud_config["key-pairs"], |
| 319 | } |
| 320 | ] |
| 321 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 322 | if cloud_config.get("users"): |
| 323 | if "users" not in userdata_dict: |
| 324 | userdata_dict["users"] = ["default"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 325 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 326 | for user in cloud_config["users"]: |
| 327 | user_info = { |
| 328 | "name": user["name"], |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 329 | "sudo": "ALL = (ALL)NOPASSWD:ALL", |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 330 | } |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 331 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 332 | if "user-info" in user: |
| 333 | user_info["gecos"] = user["user-info"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 334 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 335 | if user.get("key-pairs"): |
| 336 | user_info["ssh-authorized-keys"] = user["key-pairs"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 337 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 338 | userdata_dict["users"].append(user_info) |
| 339 | |
| 340 | if cloud_config.get("config-files"): |
| 341 | userdata_dict["write_files"] = [] |
| 342 | for file in cloud_config["config-files"]: |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 343 | file_info = {"path": file["dest"], "content": file["content"]} |
| 344 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 345 | if file.get("encoding"): |
| 346 | file_info["encoding"] = file["encoding"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 347 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 348 | if file.get("permissions"): |
| 349 | file_info["permissions"] = file["permissions"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 350 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 351 | if file.get("owner"): |
| 352 | file_info["owner"] = file["owner"] |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 353 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 354 | userdata_dict["write_files"].append(file_info) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 355 | |
| 356 | userdata_list.append( |
| 357 | "#cloud-config\n" |
| 358 | + yaml.safe_dump(userdata_dict, indent=4, default_flow_style=False) |
| 359 | ) |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 360 | userdata = self._create_mimemultipart(userdata_list) |
| 361 | self.logger.debug("userdata: %s", userdata) |
| 362 | elif isinstance(cloud_config, str): |
| 363 | userdata = cloud_config |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 364 | |
| tierno | 0a1437e | 2017-10-02 00:17:43 +0200 | [diff] [blame] | 365 | return config_drive, userdata |
| 366 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 367 | def check_vim_connectivity(self): |
| 368 | """Checks VIM can be reached and user credentials are ok. |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 369 | Returns None if success or raises VimConnConnectionException, VimConnAuthException, ... |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 370 | """ |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 371 | # by default no checking until each connector implements it |
| 372 | return None |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 373 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 374 | def get_tenant_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 375 | """Obtain tenants of VIM |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 376 | filter_dict dictionary that can contain the following keys: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 377 | name: filter by tenant name |
| 378 | id: filter by tenant uuid/id |
| 379 | <other VIM specific> |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 380 | Returns the tenant list of dictionaries, and empty list if no tenant match all the filers: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 381 | [{'name':'<name>, 'id':'<id>, ...}, ...] |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 382 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 383 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 384 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 385 | def new_network( |
| 386 | self, |
| 387 | net_name, |
| 388 | net_type, |
| 389 | ip_profile=None, |
| 390 | shared=False, |
| 391 | provider_network_profile=None, |
| 392 | ): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 393 | """Adds a tenant network to VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 394 | Params: |
| 395 | 'net_name': name of the network |
| 396 | 'net_type': one of: |
| 397 | 'bridge': overlay isolated network |
| 398 | 'data': underlay E-LAN network for Passthrough and SRIOV interfaces |
| 399 | 'ptp': underlay E-LINE network for Passthrough and SRIOV interfaces. |
| tierno | 41a6981 | 2018-02-16 14:34:33 +0100 | [diff] [blame] | 400 | 'ip_profile': is a dict containing the IP parameters of the network |
| 401 | 'ip_version': can be "IPv4" or "IPv6" (Currently only IPv4 is implemented) |
| 402 | 'subnet_address': ip_prefix_schema, that is X.X.X.X/Y |
| 403 | 'gateway_address': (Optional) ip_schema, that is X.X.X.X |
| 404 | 'dns_address': (Optional) comma separated list of ip_schema, e.g. X.X.X.X[,X,X,X,X] |
| 405 | 'dhcp_enabled': True or False |
| 406 | 'dhcp_start_address': ip_schema, first IP to grant |
| 407 | 'dhcp_count': number of IPs to grant. |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 408 | 'shared': if this network can be seen/use by other tenants/organization |
| kbsub | a85c54d | 2019-10-17 16:30:32 +0000 | [diff] [blame] | 409 | 'provider_network_profile': (optional) contains {segmentation-id: vlan, provider-network: vim_netowrk} |
| garciadeblas | ebd6672 | 2019-01-31 16:01:31 +0000 | [diff] [blame] | 410 | Returns a tuple with the network identifier and created_items, or raises an exception on error |
| 411 | created_items can be None or a dictionary where this method can include key-values that will be passed to |
| 412 | the method delete_network. Can be used to store created segments, created l2gw connections, etc. |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 413 | Format is VimConnector dependent, but do not use nested dictionaries and a value of None should be the same |
| garciadeblas | ebd6672 | 2019-01-31 16:01:31 +0000 | [diff] [blame] | 414 | as not present. |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 415 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 416 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 417 | |
| 418 | def get_network_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 419 | """Obtain tenant networks of VIM |
| 420 | Params: |
| 421 | 'filter_dict' (optional) contains entries to return only networks that matches ALL entries: |
| 422 | name: string => returns only networks with this name |
| 423 | id: string => returns networks with this VIM id, this imply returns one network at most |
| 424 | shared: boolean >= returns only networks that are (or are not) shared |
| 425 | tenant_id: sting => returns only networks that belong to this tenant/project |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 426 | ,#(not used yet) admin_state_up: boolean => returns only networks that are (or are not) in admin state |
| 427 | active |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 428 | #(not used yet) status: 'ACTIVE','ERROR',... => filter networks that are on this status |
| 429 | Returns the network list of dictionaries. each dictionary contains: |
| 430 | 'id': (mandatory) VIM network id |
| 431 | 'name': (mandatory) VIM network name |
| 432 | 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| Pablo Montes Moreno | 3fbff9b | 2017-03-08 11:28:15 +0100 | [diff] [blame] | 433 | 'network_type': (optional) can be 'vxlan', 'vlan' or 'flat' |
| 434 | 'segmentation_id': (optional) in case network_type is vlan or vxlan this field contains the segmentation id |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 435 | 'error_msg': (optional) text that explains the ERROR status |
| 436 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 437 | List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity, |
| 438 | authorization, or some other unspecific error |
| 439 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 440 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 441 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 442 | def get_network(self, net_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 443 | """Obtain network details from the 'net_id' VIM network |
| 444 | Return a dict that contains: |
| 445 | 'id': (mandatory) VIM network id, that is, net_id |
| 446 | 'name': (mandatory) VIM network name |
| 447 | 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 448 | 'error_msg': (optional) text that explains the ERROR status |
| 449 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 450 | Raises an exception upon error or when network is not found |
| 451 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 452 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 453 | |
| garciadeblas | ebd6672 | 2019-01-31 16:01:31 +0000 | [diff] [blame] | 454 | def delete_network(self, net_id, created_items=None): |
| 455 | """ |
| 456 | Removes a tenant network from VIM and its associated elements |
| 457 | :param net_id: VIM identifier of the network, provided by method new_network |
| 458 | :param created_items: dictionary with extra items to be deleted. provided by method new_network |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 459 | Returns the network identifier or raises an exception upon error or when network is not found |
| 460 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 461 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 462 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 463 | def refresh_nets_status(self, net_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 464 | """Get the status of the networks |
| 465 | Params: |
| 466 | 'net_list': a list with the VIM network id to be get the status |
| 467 | Returns a dictionary with: |
| 468 | 'net_id': #VIM id of this network |
| 469 | status: #Mandatory. Text with one of: |
| 470 | # DELETED (not found at vim) |
| 471 | # VIM_ERROR (Cannot connect to VIM, authentication problems, VIM response error, ...) |
| 472 | # OTHER (Vim reported other status not understood) |
| 473 | # ERROR (VIM indicates an ERROR status) |
| 474 | # ACTIVE, INACTIVE, DOWN (admin down), |
| 475 | # BUILD (on building process) |
| 476 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 477 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 478 | 'net_id2': ... |
| 479 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 480 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 481 | |
| 482 | def get_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 483 | """Obtain flavor details from the VIM |
| 484 | Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } |
| 485 | Raises an exception upon error or if not found |
| 486 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 487 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 488 | |
| 489 | def get_flavor_id_from_data(self, flavor_dict): |
| 490 | """Obtain flavor id that match the flavor description |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 491 | Params: |
| 492 | 'flavor_dict': dictionary that contains: |
| 493 | 'disk': main hard disk in GB |
| 494 | 'ram': meomry in MB |
| 495 | 'vcpus': number of virtual cpus |
| 496 | #TODO: complete parameters for EPA |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 497 | Returns the flavor_id or raises a VimConnNotFoundException |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 498 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 499 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 500 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 501 | def new_flavor(self, flavor_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 502 | """Adds a tenant flavor to VIM |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 503 | flavor_data contains a dictionary with information, keys: |
| 504 | name: flavor name |
| 505 | ram: memory (cloud type) in MBytes |
| 506 | vpcus: cpus (cloud type) |
| 507 | extended: EPA parameters |
| 508 | - numas: #items requested in same NUMA |
| 509 | memory: number of 1G huge pages memory |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 510 | paired-threads|cores|threads: number of paired hyperthreads, complete cores OR individual |
| 511 | threads |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 512 | interfaces: # passthrough(PT) or SRIOV interfaces attached to this numa |
| 513 | - name: interface name |
| 514 | dedicated: yes|no|yes:sriov; for PT, SRIOV or only one SRIOV for the physical NIC |
| 515 | bandwidth: X Gbps; requested guarantee bandwidth |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 516 | vpci: requested virtual PCI address |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 517 | disk: disk size |
| 518 | is_public: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 519 | #TODO to concrete |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 520 | Returns the flavor identifier |
| 521 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 522 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 523 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 524 | def delete_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 525 | """Deletes a tenant flavor from VIM identify by its id |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 526 | Returns the used id or raise an exception |
| 527 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 528 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 529 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 530 | def new_image(self, image_dict): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 531 | """Adds a tenant image to VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 532 | Returns the image id or raises an exception if failed |
| 533 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 534 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 535 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 536 | def delete_image(self, image_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 537 | """Deletes a tenant image from VIM |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 538 | Returns the image_id if image is deleted or raises an exception on error |
| 539 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 540 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 541 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 542 | def get_image_id_from_path(self, path): |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 543 | """Get the image id from image path in the VIM database. |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 544 | Returns the image_id or raises a VimConnNotFoundException |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 545 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 546 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 547 | |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 548 | def get_image_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 549 | """Obtain tenant images from VIM |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 550 | Filter_dict can be: |
| 551 | name: image name |
| 552 | id: image uuid |
| 553 | checksum: image checksum |
| 554 | location: image path |
| 555 | Returns the image list of dictionaries: |
| 556 | [{<the fields at Filter_dict plus some VIM specific>}, ...] |
| 557 | List can be empty |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 558 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 559 | raise VimConnNotImplemented("Should have implemented this") |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 560 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 561 | def new_vminstance( |
| 562 | self, |
| 563 | name, |
| 564 | description, |
| 565 | start, |
| 566 | image_id, |
| 567 | flavor_id, |
| 568 | net_list, |
| 569 | cloud_config=None, |
| 570 | disk_list=None, |
| 571 | availability_zone_index=None, |
| 572 | availability_zone_list=None, |
| 573 | ): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 574 | """Adds a VM instance to VIM |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 575 | Params: |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 576 | 'start': (boolean) indicates if VM must start or created in pause mode. |
| 577 | 'image_id','flavor_id': image and flavor VIM id to use for the VM |
| 578 | 'net_list': list of interfaces, each one is a dictionary with: |
| 579 | 'name': (optional) name for the interface. |
| 580 | 'net_id': VIM network id where this interface must be connect to. Mandatory for type==virtual |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 581 | 'vpci': (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 582 | capabilities |
| garciadeblas | c4f4d73 | 2018-10-25 18:17:24 +0200 | [diff] [blame] | 583 | 'model': (optional and only have sense for type==virtual) interface model: virtio, e1000, ... |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 584 | 'mac_address': (optional) mac address to assign to this interface |
| tierno | 41a6981 | 2018-02-16 14:34:33 +0100 | [diff] [blame] | 585 | 'ip_address': (optional) IP address to assign to this interface |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 586 | #TODO: CHECK if an optional 'vlan' parameter is needed for VIMs when type if VF and net_id is not |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 587 | provided, the VLAN tag to be used. In case net_id is provided, the internal network vlan is used |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 588 | for tagging VF |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 589 | 'type': (mandatory) can be one of: |
| 590 | 'virtual', in this case always connected to a network of type 'net_type=bridge' |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 591 | 'PCI-PASSTHROUGH' or 'PF' (passthrough): depending on VIM capabilities it can be connected to a |
| 592 | data/ptp network ot it |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 593 | can created unconnected |
| tierno | 66eba6e | 2017-11-10 17:09:18 +0100 | [diff] [blame] | 594 | 'SR-IOV' or 'VF' (SRIOV with VLAN tag): same as PF for network connectivity. |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 595 | 'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs |
| 596 | are allocated on the same physical NIC |
| 597 | 'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS |
| tierno | b3d3674 | 2017-03-03 23:51:05 +0100 | [diff] [blame] | 598 | 'port_security': (optional) If False it must avoid any traffic filtering at this interface. If missing |
| 599 | or True, it must apply the default VIM behaviour |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 600 | After execution the method will add the key: |
| 601 | 'vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this |
| 602 | interface. 'net_list' is modified |
| 603 | 'cloud_config': (optional) dictionary with: |
| 604 | 'key-pairs': (optional) list of strings with the public key to be inserted to the default user |
| 605 | 'users': (optional) list of users to be inserted, each item is a dict with: |
| 606 | 'name': (mandatory) user name, |
| 607 | 'key-pairs': (optional) list of strings with the public key to be inserted to the user |
| tierno | 40e1bce | 2017-08-09 09:12:04 +0200 | [diff] [blame] | 608 | 'user-data': (optional) can be a string with the text script to be passed directly to cloud-init, |
| 609 | or a list of strings, each one contains a script to be passed, usually with a MIMEmultipart file |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 610 | 'config-files': (optional). List of files to be transferred. Each item is a dict with: |
| 611 | 'dest': (mandatory) string with the destination absolute path |
| 612 | 'encoding': (optional, by default text). Can be one of: |
| 613 | 'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64' |
| 614 | 'content' (mandatory): string with the content of the file |
| 615 | 'permissions': (optional) string with file permissions, typically octal notation '0644' |
| 616 | 'owner': (optional) file owner, string with the format 'owner:group' |
| 617 | 'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk) |
| 618 | 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with: |
| 619 | 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted |
| 620 | 'size': (mandatory) string with the size of the disk in GB |
| tierno | 5a3273c | 2017-08-29 11:43:46 +0200 | [diff] [blame] | 621 | availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required |
| 622 | availability_zone_list: list of availability zones given by user in the VNFD descriptor. Ignore if |
| 623 | availability_zone_index is None |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 624 | Returns a tuple with the instance identifier and created_items or raises an exception on error |
| 625 | created_items can be None or a dictionary where this method can include key-values that will be passed to |
| 626 | the method delete_vminstance and action_vminstance. Can be used to store created ports, volumes, etc. |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 627 | Format is VimConnector dependent, but do not use nested dictionaries and a value of None should be the same |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 628 | as not present. |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 629 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 630 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 631 | |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 632 | def get_vminstance(self, vm_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 633 | """Returns the VM instance information from VIM""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 634 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 635 | |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 636 | def delete_vminstance(self, vm_id, created_items=None): |
| 637 | """ |
| garciadeblas | ebd6672 | 2019-01-31 16:01:31 +0000 | [diff] [blame] | 638 | Removes a VM instance from VIM and its associated elements |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 639 | :param vm_id: VIM identifier of the VM, provided by method new_vminstance |
| 640 | :param created_items: dictionary with extra items to be deleted. provided by method new_vminstance and/or method |
| 641 | action_vminstance |
| 642 | :return: None or the same vm_id. Raises an exception on fail |
| 643 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 644 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 645 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 646 | def refresh_vms_status(self, vm_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 647 | """Get the status of the virtual machines and their interfaces/ports |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 648 | Params: the list of VM identifiers |
| 649 | Returns a dictionary with: |
| 650 | vm_id: #VIM id of this Virtual Machine |
| 651 | status: #Mandatory. Text with one of: |
| 652 | # DELETED (not found at vim) |
| 653 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 654 | # OTHER (Vim reported other status not understood) |
| 655 | # ERROR (VIM indicates an ERROR status) |
| 656 | # ACTIVE, PAUSED, SUSPENDED, INACTIVE (not running), |
| 657 | # BUILD (on building process), ERROR |
| 658 | # ACTIVE:NoMgmtIP (Active but any of its interface has an IP address |
| 659 | # |
| 660 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 661 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 662 | interfaces: list with interface info. Each item a dictionary with: |
| 663 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 664 | mac_address: #Text format XX:XX:XX:XX:XX:XX |
| 665 | vim_net_id: #network id where this interface is connected, if provided at creation |
| 666 | vim_interface_id: #interface/port VIM id |
| 667 | ip_address: #null, or text with IPv4, IPv6 address |
| 668 | compute_node: #identification of compute node where PF,VF interface is allocated |
| 669 | pci: #PCI address of the NIC that hosts the PF,VF |
| 670 | vlan: #physical VLAN used for VF |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 671 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 672 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 673 | |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 674 | def action_vminstance(self, vm_id, action_dict, created_items={}): |
| 675 | """ |
| 676 | Send and action over a VM instance. Returns created_items if the action was successfully sent to the VIM. |
| 677 | created_items is a dictionary with items that |
| 678 | :param vm_id: VIM identifier of the VM, provided by method new_vminstance |
| 679 | :param action_dict: dictionary with the action to perform |
| 680 | :param created_items: provided by method new_vminstance is a dictionary with key-values that will be passed to |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 681 | the method delete_vminstance. Can be used to store created ports, volumes, etc. Format is VimConnector |
| tierno | 98e909c | 2017-10-14 13:27:03 +0200 | [diff] [blame] | 682 | dependent, but do not use nested dictionaries and a value of None should be the same as not present. This |
| 683 | method can modify this value |
| 684 | :return: None, or a console dict |
| 685 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 686 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 687 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 688 | def get_vminstance_console(self, vm_id, console_type="vnc"): |
| 689 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 690 | Get a console for the virtual machine |
| 691 | Params: |
| 692 | vm_id: uuid of the VM |
| 693 | console_type, can be: |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 694 | "novnc" (by default), "xvpvnc" for VNC types, |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 695 | "rdp-html5" for RDP types, "spice-html5" for SPICE types |
| 696 | Returns dict with the console parameters: |
| 697 | protocol: ssh, ftp, http, https, ... |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 698 | server: usually ip address |
| 699 | port: the http, ssh, ... port |
| 700 | suffix: extra text, e.g. the http path and query string |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 701 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 702 | raise VimConnNotImplemented("Should have implemented this") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 703 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 704 | def inject_user_key( |
| 705 | self, ip_addr=None, user=None, key=None, ro_key=None, password=None |
| 706 | ): |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 707 | """ |
| 708 | Inject a ssh public key in a VM |
| 709 | Params: |
| 710 | ip_addr: ip address of the VM |
| 711 | user: username (default-user) to enter in the VM |
| 712 | key: public key to be injected in the VM |
| 713 | ro_key: private key of the RO, used to enter in the VM if the password is not provided |
| 714 | password: password of the user to enter in the VM |
| 715 | The function doesn't return a value: |
| 716 | """ |
| 717 | if not ip_addr or not user: |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 718 | raise VimConnNotSupportedException( |
| 719 | "All parameters should be different from 'None'" |
| 720 | ) |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 721 | elif not ro_key and not password: |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 722 | raise VimConnNotSupportedException( |
| 723 | "All parameters should be different from 'None'" |
| 724 | ) |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 725 | else: |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 726 | commands = { |
| 727 | "mkdir -p ~/.ssh/", |
| 728 | 'echo "{}" >> ~/.ssh/authorized_keys'.format(key), |
| 729 | "chmod 644 ~/.ssh/authorized_keys", |
| 730 | "chmod 700 ~/.ssh/", |
| 731 | } |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 732 | client = paramiko.SSHClient() |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 733 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 734 | try: |
| 735 | if ro_key: |
| tierno | 7d782ef | 2019-10-04 12:56:31 +0000 | [diff] [blame] | 736 | pkey = paramiko.RSAKey.from_private_key(StringIO(ro_key)) |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 737 | else: |
| 738 | pkey = None |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 739 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 740 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 741 | client.connect( |
| 742 | ip_addr, username=user, password=password, pkey=pkey, timeout=10 |
| 743 | ) |
| 744 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 745 | for command in commands: |
| 746 | (i, o, e) = client.exec_command(command, timeout=10) |
| 747 | returncode = o.channel.recv_exit_status() |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 748 | outerror = e.read() |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 749 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 750 | if returncode != 0: |
| 751 | text = "run_command='{}' Error='{}'".format(command, outerror) |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 752 | raise VimConnUnexpectedResponse( |
| 753 | "Cannot inject ssh key in VM: '{}'".format(text) |
| 754 | ) |
| 755 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 756 | return |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 757 | except ( |
| 758 | socket.error, |
| 759 | paramiko.AuthenticationException, |
| 760 | paramiko.SSHException, |
| 761 | ) as message: |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 762 | raise VimConnUnexpectedResponse( |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 763 | "Cannot inject ssh key in VM: '{}' - {}".format( |
| 764 | ip_addr, str(message) |
| 765 | ) |
| 766 | ) |
| 767 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 768 | return |
| 769 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 770 | # Optional methods |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 771 | def new_tenant(self, tenant_name, tenant_description): |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 772 | """Adds a new tenant to VIM with this name and description, this is done using admin_url if provided |
| 773 | "tenant_name": string max lenght 64 |
| 774 | "tenant_description": string max length 256 |
| 775 | returns the tenant identifier or raise exception |
| 776 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 777 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 778 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 779 | def delete_tenant(self, tenant_id): |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 780 | """Delete a tenant from VIM |
| 781 | tenant_id: returned VIM tenant_id on "new_tenant" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 782 | Returns None on success. Raises and exception of failure. If tenant is not found raises VimConnNotFoundException |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 783 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 784 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 785 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 786 | def new_classification(self, name, ctype, definition): |
| 787 | """Creates a traffic classification in the VIM |
| 788 | Params: |
| 789 | 'name': name of this classification |
| 790 | 'ctype': type of this classification |
| 791 | 'definition': definition of this classification (type-dependent free-form text) |
| 792 | Returns the VIM's classification ID on success or raises an exception on failure |
| 793 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 794 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 795 | |
| 796 | def get_classification(self, classification_id): |
| 797 | """Obtain classification details of the VIM's classification with ID='classification_id' |
| 798 | Return a dict that contains: |
| 799 | 'id': VIM's classification ID (same as classification_id) |
| 800 | 'name': VIM's classification name |
| 801 | 'type': type of this classification |
| 802 | 'definition': definition of the classification |
| 803 | 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 804 | 'error_msg': (optional) text that explains the ERROR status |
| 805 | other VIM specific fields: (optional) whenever possible |
| 806 | Raises an exception upon error or when classification is not found |
| 807 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 808 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 809 | |
| 810 | def get_classification_list(self, filter_dict={}): |
| 811 | """Obtain classifications from the VIM |
| 812 | Params: |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 813 | 'filter_dict' (optional): contains the entries to filter the classifications on and only return those that |
| 814 | match ALL: |
| 815 | id: string => returns classifications with this VIM's classification ID, which implies a return of one |
| 816 | classification at most |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 817 | name: string => returns only classifications with this name |
| 818 | type: string => returns classifications of this type |
| 819 | definition: string => returns classifications that have this definition |
| 820 | tenant_id: string => returns only classifications that belong to this tenant/project |
| 821 | Returns a list of classification dictionaries, each dictionary contains: |
| 822 | 'id': (mandatory) VIM's classification ID |
| 823 | 'name': (mandatory) VIM's classification name |
| 824 | 'type': type of this classification |
| 825 | 'definition': definition of the classification |
| 826 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 827 | List can be empty if no classification matches the filter_dict. Raise an exception only upon VIM connectivity, |
| 828 | authorization, or some other unspecific error |
| 829 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 830 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 831 | |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 832 | def refresh_classifications_status(self, classification_list): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 833 | """Get the status of the classifications |
| 834 | Params: the list of classification identifiers |
| 835 | Returns a dictionary with: |
| 836 | vm_id: #VIM id of this classifier |
| 837 | status: #Mandatory. Text with one of: |
| 838 | # DELETED (not found at vim) |
| 839 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 840 | # OTHER (Vim reported other status not understood) |
| 841 | # ERROR (VIM indicates an ERROR status) |
| 842 | # ACTIVE, |
| 843 | # CREATING (on building process) |
| 844 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 845 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 846 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 847 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 848 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 849 | def delete_classification(self, classification_id): |
| 850 | """Deletes a classification from the VIM |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 851 | Returns the classification ID (classification_id) or raises an exception upon error or when classification is |
| 852 | not found |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 853 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 854 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 855 | |
| 856 | def new_sfi(self, name, ingress_ports, egress_ports, sfc_encap=True): |
| 857 | """Creates a service function instance in the VIM |
| 858 | Params: |
| 859 | 'name': name of this service function instance |
| 860 | 'ingress_ports': set of ingress ports (VIM's port IDs) |
| 861 | 'egress_ports': set of egress ports (VIM's port IDs) |
| 862 | 'sfc_encap': boolean stating whether this specific instance supports IETF SFC Encapsulation |
| 863 | Returns the VIM's service function instance ID on success or raises an exception on failure |
| 864 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 865 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 866 | |
| 867 | def get_sfi(self, sfi_id): |
| 868 | """Obtain service function instance details of the VIM's service function instance with ID='sfi_id' |
| 869 | Return a dict that contains: |
| 870 | 'id': VIM's sfi ID (same as sfi_id) |
| 871 | 'name': VIM's sfi name |
| 872 | 'ingress_ports': set of ingress ports (VIM's port IDs) |
| 873 | 'egress_ports': set of egress ports (VIM's port IDs) |
| 874 | 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 875 | 'error_msg': (optional) text that explains the ERROR status |
| 876 | other VIM specific fields: (optional) whenever possible |
| 877 | Raises an exception upon error or when service function instance is not found |
| 878 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 879 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 880 | |
| 881 | def get_sfi_list(self, filter_dict={}): |
| 882 | """Obtain service function instances from the VIM |
| 883 | Params: |
| 884 | 'filter_dict' (optional): contains the entries to filter the sfis on and only return those that match ALL: |
| 885 | id: string => returns sfis with this VIM's sfi ID, which implies a return of one sfi at most |
| 886 | name: string => returns only service function instances with this name |
| 887 | tenant_id: string => returns only service function instances that belong to this tenant/project |
| 888 | Returns a list of service function instance dictionaries, each dictionary contains: |
| 889 | 'id': (mandatory) VIM's sfi ID |
| 890 | 'name': (mandatory) VIM's sfi name |
| 891 | 'ingress_ports': set of ingress ports (VIM's port IDs) |
| 892 | 'egress_ports': set of egress ports (VIM's port IDs) |
| 893 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 894 | List can be empty if no sfi matches the filter_dict. Raise an exception only upon VIM connectivity, |
| 895 | authorization, or some other unspecific error |
| 896 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 897 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 898 | |
| 899 | def delete_sfi(self, sfi_id): |
| 900 | """Deletes a service function instance from the VIM |
| 901 | Returns the service function instance ID (sfi_id) or raises an exception upon error or when sfi is not found |
| 902 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 903 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 904 | |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 905 | def refresh_sfis_status(self, sfi_list): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 906 | """Get the status of the service function instances |
| 907 | Params: the list of sfi identifiers |
| 908 | Returns a dictionary with: |
| 909 | vm_id: #VIM id of this service function instance |
| 910 | status: #Mandatory. Text with one of: |
| 911 | # DELETED (not found at vim) |
| 912 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 913 | # OTHER (Vim reported other status not understood) |
| 914 | # ERROR (VIM indicates an ERROR status) |
| 915 | # ACTIVE, |
| 916 | # CREATING (on building process) |
| 917 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 918 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 919 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 920 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 921 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 922 | def new_sf(self, name, sfis, sfc_encap=True): |
| 923 | """Creates (an abstract) service function in the VIM |
| 924 | Params: |
| 925 | 'name': name of this service function |
| 926 | 'sfis': set of service function instances of this (abstract) service function |
| 927 | 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation |
| 928 | Returns the VIM's service function ID on success or raises an exception on failure |
| 929 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 930 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 931 | |
| 932 | def get_sf(self, sf_id): |
| 933 | """Obtain service function details of the VIM's service function with ID='sf_id' |
| 934 | Return a dict that contains: |
| 935 | 'id': VIM's sf ID (same as sf_id) |
| 936 | 'name': VIM's sf name |
| 937 | 'sfis': VIM's sf's set of VIM's service function instance IDs |
| 938 | 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation |
| 939 | 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 940 | 'error_msg': (optional) text that explains the ERROR status |
| 941 | other VIM specific fields: (optional) whenever possible |
| 942 | Raises an exception upon error or when sf is not found |
| 943 | """ |
| 944 | |
| 945 | def get_sf_list(self, filter_dict={}): |
| 946 | """Obtain service functions from the VIM |
| 947 | Params: |
| 948 | 'filter_dict' (optional): contains the entries to filter the sfs on and only return those that match ALL: |
| 949 | id: string => returns sfs with this VIM's sf ID, which implies a return of one sf at most |
| 950 | name: string => returns only service functions with this name |
| 951 | tenant_id: string => returns only service functions that belong to this tenant/project |
| 952 | Returns a list of service function dictionaries, each dictionary contains: |
| 953 | 'id': (mandatory) VIM's sf ID |
| 954 | 'name': (mandatory) VIM's sf name |
| 955 | 'sfis': VIM's sf's set of VIM's service function instance IDs |
| 956 | 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation |
| 957 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 958 | List can be empty if no sf matches the filter_dict. Raise an exception only upon VIM connectivity, |
| 959 | authorization, or some other unspecific error |
| 960 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 961 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 962 | |
| 963 | def delete_sf(self, sf_id): |
| 964 | """Deletes (an abstract) service function from the VIM |
| 965 | Returns the service function ID (sf_id) or raises an exception upon error or when sf is not found |
| 966 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 967 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 968 | |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 969 | def refresh_sfs_status(self, sf_list): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 970 | """Get the status of the service functions |
| 971 | Params: the list of sf identifiers |
| 972 | Returns a dictionary with: |
| 973 | vm_id: #VIM id of this service function |
| 974 | status: #Mandatory. Text with one of: |
| 975 | # DELETED (not found at vim) |
| 976 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 977 | # OTHER (Vim reported other status not understood) |
| 978 | # ERROR (VIM indicates an ERROR status) |
| 979 | # ACTIVE, |
| 980 | # CREATING (on building process) |
| 981 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 982 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 983 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 984 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 985 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 986 | def new_sfp(self, name, classifications, sfs, sfc_encap=True, spi=None): |
| 987 | """Creates a service function path |
| 988 | Params: |
| 989 | 'name': name of this service function path |
| 990 | 'classifications': set of traffic classifications that should be matched on to get into this sfp |
| 991 | 'sfs': list of every service function that constitutes this path , from first to last |
| 992 | 'sfc_encap': whether this is an SFC-Encapsulated chain (i.e using NSH), True by default |
| 993 | 'spi': (optional) the Service Function Path identifier (SPI: Service Path Identifier) for this path |
| 994 | Returns the VIM's sfp ID on success or raises an exception on failure |
| 995 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 996 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 997 | |
| 998 | def get_sfp(self, sfp_id): |
| 999 | """Obtain service function path details of the VIM's sfp with ID='sfp_id' |
| 1000 | Return a dict that contains: |
| 1001 | 'id': VIM's sfp ID (same as sfp_id) |
| 1002 | 'name': VIM's sfp name |
| 1003 | 'classifications': VIM's sfp's list of VIM's classification IDs |
| 1004 | 'sfs': VIM's sfp's list of VIM's service function IDs |
| 1005 | 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 1006 | 'error_msg': (optional) text that explains the ERROR status |
| 1007 | other VIM specific fields: (optional) whenever possible |
| 1008 | Raises an exception upon error or when sfp is not found |
| 1009 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1010 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 1011 | |
| 1012 | def get_sfp_list(self, filter_dict={}): |
| 1013 | """Obtain service function paths from VIM |
| 1014 | Params: |
| 1015 | 'filter_dict' (optional): contains the entries to filter the sfps on, and only return those that match ALL: |
| 1016 | id: string => returns sfps with this VIM's sfp ID , which implies a return of one sfp at most |
| 1017 | name: string => returns only sfps with this name |
| 1018 | tenant_id: string => returns only sfps that belong to this tenant/project |
| 1019 | Returns a list of service function path dictionaries, each dictionary contains: |
| 1020 | 'id': (mandatory) VIM's sfp ID |
| 1021 | 'name': (mandatory) VIM's sfp name |
| 1022 | 'classifications': VIM's sfp's list of VIM's classification IDs |
| 1023 | 'sfs': VIM's sfp's list of VIM's service function IDs |
| 1024 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 1025 | List can be empty if no sfp matches the filter_dict. Raise an exception only upon VIM connectivity, |
| 1026 | authorization, or some other unspecific error |
| 1027 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1028 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 1029 | |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 1030 | def refresh_sfps_status(self, sfp_list): |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 1031 | """Get the status of the service function path |
| 1032 | Params: the list of sfp identifiers |
| 1033 | Returns a dictionary with: |
| 1034 | vm_id: #VIM id of this service function path |
| 1035 | status: #Mandatory. Text with one of: |
| 1036 | # DELETED (not found at vim) |
| 1037 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 1038 | # OTHER (Vim reported other status not understood) |
| 1039 | # ERROR (VIM indicates an ERROR status) |
| 1040 | # ACTIVE, |
| 1041 | # CREATING (on building process) |
| 1042 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 1043 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump)F |
| 1044 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1045 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 1046 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 1047 | def delete_sfp(self, sfp_id): |
| 1048 | """Deletes a service function path from the VIM |
| 1049 | Returns the sfp ID (sfp_id) or raises an exception upon error or when sf is not found |
| 1050 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1051 | raise VimConnNotImplemented("SFC support not implemented") |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 1052 | |
| sousaedu | 2ad8517 | 2021-02-17 15:05:18 +0100 | [diff] [blame^] | 1053 | # NOT USED METHODS in current version. Deprecated |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1054 | @deprecated |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1055 | def host_vim2gui(self, host, server_dict): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1056 | """Transform host dictionary from VIM format to GUI format, |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1057 | and append to the server_dict |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1058 | """ |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1059 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1060 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1061 | @deprecated |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1062 | def get_hosts_info(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1063 | """Get the information of deployed hosts |
| 1064 | Returns the hosts content""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1065 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1066 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1067 | @deprecated |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1068 | def get_hosts(self, vim_tenant): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1069 | """Get the hosts and deployed instances |
| 1070 | Returns the hosts content""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1071 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1072 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1073 | @deprecated |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 1074 | def get_processor_rankings(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1075 | """Get the processor rankings in the VIM database""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1076 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 1077 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1078 | @deprecated |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1079 | def new_host(self, host_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1080 | """Adds a new host to VIM""" |
| 1081 | """Returns status code of the VIM response""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1082 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 1083 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1084 | @deprecated |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1085 | def new_external_port(self, port_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1086 | """Adds a external port to VIM""" |
| 1087 | """Returns the port identifier""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1088 | raise VimConnNotImplemented("Should have implemented this") |
| borsatti | 8a2dda3 | 2019-12-18 15:08:57 +0000 | [diff] [blame] | 1089 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1090 | @deprecated |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1091 | def new_external_network(self, net_name, net_type): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1092 | """Adds a external network to VIM (shared)""" |
| 1093 | """Returns the network identifier""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1094 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1095 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1096 | @deprecated |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1097 | def connect_port_network(self, port_id, network_id, admin=False): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1098 | """Connects a external port to a network""" |
| 1099 | """Returns status code of the VIM response""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1100 | raise VimConnNotImplemented("Should have implemented this") |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1101 | |
| tierno | 9228f51 | 2019-07-04 16:23:00 +0000 | [diff] [blame] | 1102 | @deprecated |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 1103 | def new_vminstancefromJSON(self, vm_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 1104 | """Adds a VM instance to VIM""" |
| 1105 | """Returns the instance identifier""" |
| tierno | 7277486 | 2020-05-04 11:44:15 +0000 | [diff] [blame] | 1106 | raise VimConnNotImplemented("Should have implemented this") |