| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| tierno | d125caf | 2018-11-22 16:05:54 +0000 | [diff] [blame] | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 | # implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 17 | import cherrypy |
| 18 | import time |
| 19 | import json |
| 20 | import yaml |
| tierno | 9c63011 | 2019-08-29 14:21:41 +0000 | [diff] [blame] | 21 | import osm_nbi.html_out as html |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 22 | import logging |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 23 | import logging.handlers |
| 24 | import getopt |
| 25 | import sys |
| Eduardo Sousa | 2f98821 | 2018-07-26 01:04:11 +0100 | [diff] [blame] | 26 | |
| tierno | 9c63011 | 2019-08-29 14:21:41 +0000 | [diff] [blame] | 27 | from osm_nbi.authconn import AuthException, AuthconnException |
| 28 | from osm_nbi.auth import Authenticator |
| 29 | from osm_nbi.engine import Engine, EngineException |
| 30 | from osm_nbi.subscriptions import SubscriptionThread |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 31 | from osm_nbi.utils import cef_event, cef_event_builder |
| tierno | 9c63011 | 2019-08-29 14:21:41 +0000 | [diff] [blame] | 32 | from osm_nbi.validation import ValidationError |
| tierno | a8d6363 | 2018-05-10 13:12:32 +0200 | [diff] [blame] | 33 | from osm_common.dbbase import DbException |
| 34 | from osm_common.fsbase import FsException |
| 35 | from osm_common.msgbase import MsgException |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 36 | from http import HTTPStatus |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 37 | from codecs import getreader |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 38 | from os import environ, path |
| tierno | b2e48bd | 2020-02-04 15:47:18 +0000 | [diff] [blame] | 39 | from osm_nbi import version as nbi_version, version_date as nbi_version_date |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 40 | |
| 41 | __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>" |
| tierno | dfe0957 | 2018-04-24 10:41:10 +0200 | [diff] [blame] | 42 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 43 | __version__ = "0.1.3" # file version, not NBI version |
| tierno | 9c63011 | 2019-08-29 14:21:41 +0000 | [diff] [blame] | 44 | version_date = "Aug 2019" |
| 45 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 46 | database_version = "1.2" |
| 47 | auth_database_version = "1.0" |
| 48 | nbi_server = None # instance of Server class |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 49 | subscription_thread = None # instance of SubscriptionThread class |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 50 | cef_logger = None |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 51 | logger = logging.getLogger("nbi.nbi") |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 52 | |
| 53 | """ |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 54 | North Bound Interface (O: OSM specific; 5,X: SOL005 not implemented yet; O5: SOL005 implemented) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 55 | URL: /osm GET POST PUT DELETE PATCH |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 56 | /nsd/v1 |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 57 | /ns_descriptors_content O O |
| 58 | /<nsdInfoId> O O O O |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 59 | /ns_descriptors O5 O5 |
| 60 | /<nsdInfoId> O5 O5 5 |
| 61 | /nsd_content O5 O5 |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 62 | /nsd O |
| 63 | /artifacts[/<artifactPath>] O |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 64 | /ns_config_template O O |
| 65 | /<nsConfigTemplateId> O O |
| 66 | /template_content O O |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 67 | /pnf_descriptors 5 5 |
| 68 | /<pnfdInfoId> 5 5 5 |
| 69 | /pnfd_content 5 5 |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 70 | /subscriptions 5 5 |
| 71 | /<subscriptionId> 5 X |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 72 | |
| 73 | /vnfpkgm/v1 |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 74 | /vnf_packages_content O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 75 | /<vnfPkgId> O O |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 76 | /vnf_packages O5 O5 |
| 77 | /<vnfPkgId> O5 O5 5 |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 78 | /package_content O5 O5 |
| 79 | /upload_from_uri X |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 80 | /vnfd O5 |
| 81 | /artifacts[/<artifactPath>] O5 |
| 82 | /subscriptions X X |
| 83 | /<subscriptionId> X X |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 84 | |
| 85 | /nslcm/v1 |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 86 | /ns_instances_content O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 87 | /<nsInstanceId> O O |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 88 | /ns_instances 5 5 |
| tierno | 9569244 | 2018-05-24 18:05:28 +0200 | [diff] [blame] | 89 | /<nsInstanceId> O5 O5 |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 90 | instantiate O5 |
| 91 | terminate O5 |
| 92 | action O |
| 93 | scale O5 |
| elumalai | 8e3806c | 2022-04-28 17:26:24 +0530 | [diff] [blame] | 94 | migrate O |
| aticig | 544a2ae | 2022-04-05 09:00:17 +0300 | [diff] [blame] | 95 | update 05 |
| garciadeblas | 0964edf | 2022-02-11 00:43:44 +0100 | [diff] [blame] | 96 | heal O5 |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 97 | /ns_lcm_op_occs 5 5 |
| 98 | /<nsLcmOpOccId> 5 5 5 |
| Gabriel Cuba | 84a60df | 2023-10-30 14:01:54 -0500 | [diff] [blame] | 99 | cancel 05 |
| tierno | f759d82 | 2018-06-11 18:54:54 +0200 | [diff] [blame] | 100 | /vnf_instances (also vnfrs for compatibility) O |
| 101 | /<vnfInstanceId> O |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 102 | /subscriptions 5 5 |
| 103 | /<subscriptionId> 5 X |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 104 | |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 105 | /pdu/v1 |
| tierno | 032916c | 2019-03-22 13:27:12 +0000 | [diff] [blame] | 106 | /pdu_descriptors O O |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 107 | /<id> O O O O |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 108 | |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 109 | /admin/v1 |
| 110 | /tokens O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 111 | /<id> O O |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 112 | /users O O |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 113 | /<id> O O O O |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 114 | /projects O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 115 | /<id> O O |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 116 | /vim_accounts (also vims for compatibility) O O |
| 117 | /<id> O O O |
| 118 | /wim_accounts O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 119 | /<id> O O O |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 120 | /sdns O O |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 121 | /<id> O O O |
| delacruzramo | fe598fe | 2019-10-23 18:25:11 +0200 | [diff] [blame] | 122 | /k8sclusters O O |
| 123 | /<id> O O O |
| 124 | /k8srepos O O |
| 125 | /<id> O O |
| Felipe Vicens | b66b041 | 2020-05-06 10:11:00 +0200 | [diff] [blame] | 126 | /osmrepos O O |
| 127 | /<id> O O |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 128 | |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 129 | /nst/v1 O O |
| 130 | /netslice_templates_content O O |
| 131 | /<nstInfoId> O O O O |
| 132 | /netslice_templates O O |
| 133 | /<nstInfoId> O O O |
| 134 | /nst_content O O |
| 135 | /nst O |
| 136 | /artifacts[/<artifactPath>] O |
| 137 | /subscriptions X X |
| 138 | /<subscriptionId> X X |
| 139 | |
| 140 | /nsilcm/v1 |
| 141 | /netslice_instances_content O O |
| 142 | /<SliceInstanceId> O O |
| 143 | /netslice_instances O O |
| 144 | /<SliceInstanceId> O O |
| 145 | instantiate O |
| 146 | terminate O |
| 147 | action O |
| 148 | /nsi_lcm_op_occs O O |
| 149 | /<nsiLcmOpOccId> O O O |
| 150 | /subscriptions X X |
| 151 | /<subscriptionId> X X |
| 152 | |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 153 | /k8scluster/v1 |
| 154 | /clusters O O |
| 155 | /<clustersId> O O |
| 156 | app_profiles O O |
| 157 | infra_controller_profiles O O |
| 158 | infra_config_profiles O O |
| 159 | resource_profiles O O |
| 160 | deregister O |
| 161 | /register O |
| 162 | /app_profiles O O |
| 163 | /<app_profilesId> O O O |
| 164 | /infra_controller_profiles O O |
| 165 | /<infra_controller_profilesId> O O O |
| 166 | /infra_config_profiles O O |
| 167 | /<infra_config_profilesId> O O O |
| 168 | /resource_profiles O O |
| 169 | /<resource_profilesID> O O O |
| 170 | |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 171 | query string: |
| 172 | Follows SOL005 section 4.3.2 It contains extra METHOD to override http method, FORCE to force. |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 173 | simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]* |
| 174 | filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]* |
| 175 | op := "eq" | "neq" (or "ne") | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont" |
| 176 | attrName := string |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 177 | For filtering inside array, it must select the element of the array, or add ANYINDEX to apply the filtering over any |
| 178 | item of the array, that is, pass if any item of the array pass the filter. |
| 179 | It allows both ne and neq for not equal |
| 180 | TODO: 4.3.3 Attribute selectors |
| 181 | all_fields, fields=x,y,.., exclude_default, exclude_fields=x,y,... |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 182 | (none) … same as “exclude_default” |
| 183 | all_fields … all attributes. |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 184 | fields=<list> … all attributes except all complex attributes with minimum cardinality of zero that are not |
| 185 | conditionally mandatory, and that are not provided in <list>. |
| 186 | exclude_fields=<list> … all attributes except those complex attributes with a minimum cardinality of zero that |
| 187 | are not conditionally mandatory, and that are provided in <list>. |
| 188 | exclude_default … all attributes except those complex attributes with a minimum cardinality of zero that are not |
| 189 | conditionally mandatory, and that are part of the "default exclude set" defined in the present specification for |
| 190 | the particular resource |
| 191 | exclude_default and include=<list> … all attributes except those complex attributes with a minimum cardinality |
| 192 | of zero that are not conditionally mandatory and that are part of the "default exclude set" defined in the |
| 193 | present specification for the particular resource, but that are not part of <list> |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 194 | Additionally it admits some administrator values: |
| 195 | FORCE: To force operations skipping dependency checkings |
| 196 | ADMIN: To act as an administrator or a different project |
| 197 | PUBLIC: To get public descriptors or set a descriptor as public |
| 198 | SET_PROJECT: To make a descriptor available for other project |
| beierlm | bc5a524 | 2022-05-17 21:25:29 -0400 | [diff] [blame] | 199 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 200 | Header field name Reference Example Descriptions |
| 201 | Accept IETF RFC 7231 [19] application/json Content-Types that are acceptable for the response. |
| 202 | This header field shall be present if the response is expected to have a non-empty message body. |
| 203 | Content-Type IETF RFC 7231 [19] application/json The MIME type of the body of the request. |
| 204 | This header field shall be present if the request has a non-empty message body. |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 205 | Authorization IETF RFC 7235 [22] Bearer mF_9.B5f-4.1JqM The authorization token for the request. |
| 206 | Details are specified in clause 4.5.3. |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 207 | Range IETF RFC 7233 [21] 1000-2000 Requested range of bytes from a file |
| 208 | Header field name Reference Example Descriptions |
| 209 | Content-Type IETF RFC 7231 [19] application/json The MIME type of the body of the response. |
| 210 | This header field shall be present if the response has a non-empty message body. |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 211 | Location IETF RFC 7231 [19] http://www.example.com/vnflcm/v1/vnf_instances/123 Used in redirection, or when a |
| 212 | new resource has been created. |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 213 | This header field shall be present if the response status code is 201 or 3xx. |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 214 | In the present document this header field is also used if the response status code is 202 and a new resource was |
| 215 | created. |
| 216 | WWW-Authenticate IETF RFC 7235 [22] Bearer realm="example" Challenge if the corresponding HTTP request has not |
| 217 | provided authorization, or error details if the corresponding HTTP request has provided an invalid authorization |
| 218 | token. |
| 219 | Accept-Ranges IETF RFC 7233 [21] bytes Used by the Server to signal whether or not it supports ranges for |
| 220 | certain resources. |
| 221 | Content-Range IETF RFC 7233 [21] bytes 21010-47021/ 47022 Signals the byte range that is contained in the |
| 222 | response, and the total length of the file. |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 223 | Retry-After IETF RFC 7231 [19] Fri, 31 Dec 1999 23:59:59 GMT |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 224 | """ |
| 225 | |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 226 | valid_query_string = ("ADMIN", "SET_PROJECT", "FORCE", "PUBLIC") |
| 227 | # ^ Contains possible administrative query string words: |
| 228 | # ADMIN=True(by default)|Project|Project-list: See all elements, or elements of a project |
| 229 | # (not owned by my session project). |
| 230 | # PUBLIC=True(by default)|False: See/hide public elements. Set/Unset a topic to be public |
| 231 | # FORCE=True(by default)|False: Force edition/deletion operations |
| 232 | # SET_PROJECT=Project|Project-list: Add/Delete the topic to the projects portfolio |
| 233 | |
| 234 | valid_url_methods = { |
| 235 | # contains allowed URL and methods, and the role_permission name |
| 236 | "admin": { |
| 237 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 238 | "tokens": { |
| 239 | "METHODS": ("GET", "POST", "DELETE"), |
| 240 | "ROLE_PERMISSION": "tokens:", |
| 241 | "<ID>": {"METHODS": ("GET", "DELETE"), "ROLE_PERMISSION": "tokens:id:"}, |
| 242 | }, |
| 243 | "users": { |
| 244 | "METHODS": ("GET", "POST"), |
| 245 | "ROLE_PERMISSION": "users:", |
| 246 | "<ID>": { |
| 247 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 248 | "ROLE_PERMISSION": "users:id:", |
| 249 | }, |
| 250 | }, |
| 251 | "projects": { |
| 252 | "METHODS": ("GET", "POST"), |
| 253 | "ROLE_PERMISSION": "projects:", |
| 254 | "<ID>": { |
| 255 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 256 | "ROLE_PERMISSION": "projects:id:", |
| 257 | }, |
| 258 | }, |
| 259 | "roles": { |
| 260 | "METHODS": ("GET", "POST"), |
| 261 | "ROLE_PERMISSION": "roles:", |
| 262 | "<ID>": { |
| 263 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 264 | "ROLE_PERMISSION": "roles:id:", |
| 265 | }, |
| 266 | }, |
| 267 | "vims": { |
| 268 | "METHODS": ("GET", "POST"), |
| 269 | "ROLE_PERMISSION": "vims:", |
| 270 | "<ID>": { |
| 271 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 272 | "ROLE_PERMISSION": "vims:id:", |
| 273 | }, |
| 274 | }, |
| 275 | "vim_accounts": { |
| 276 | "METHODS": ("GET", "POST"), |
| 277 | "ROLE_PERMISSION": "vim_accounts:", |
| 278 | "<ID>": { |
| 279 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 280 | "ROLE_PERMISSION": "vim_accounts:id:", |
| 281 | }, |
| 282 | }, |
| 283 | "wim_accounts": { |
| 284 | "METHODS": ("GET", "POST"), |
| 285 | "ROLE_PERMISSION": "wim_accounts:", |
| 286 | "<ID>": { |
| 287 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 288 | "ROLE_PERMISSION": "wim_accounts:id:", |
| 289 | }, |
| 290 | }, |
| 291 | "sdns": { |
| 292 | "METHODS": ("GET", "POST"), |
| 293 | "ROLE_PERMISSION": "sdn_controllers:", |
| 294 | "<ID>": { |
| 295 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 296 | "ROLE_PERMISSION": "sdn_controllers:id:", |
| 297 | }, |
| 298 | }, |
| 299 | "k8sclusters": { |
| 300 | "METHODS": ("GET", "POST"), |
| 301 | "ROLE_PERMISSION": "k8sclusters:", |
| 302 | "<ID>": { |
| 303 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 304 | "ROLE_PERMISSION": "k8sclusters:id:", |
| 305 | }, |
| 306 | }, |
| 307 | "vca": { |
| 308 | "METHODS": ("GET", "POST"), |
| 309 | "ROLE_PERMISSION": "vca:", |
| 310 | "<ID>": { |
| 311 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 312 | "ROLE_PERMISSION": "vca:id:", |
| 313 | }, |
| 314 | }, |
| 315 | "k8srepos": { |
| 316 | "METHODS": ("GET", "POST"), |
| 317 | "ROLE_PERMISSION": "k8srepos:", |
| 318 | "<ID>": { |
| 319 | "METHODS": ("GET", "DELETE"), |
| 320 | "ROLE_PERMISSION": "k8srepos:id:", |
| 321 | }, |
| 322 | }, |
| 323 | "osmrepos": { |
| 324 | "METHODS": ("GET", "POST"), |
| 325 | "ROLE_PERMISSION": "osmrepos:", |
| 326 | "<ID>": { |
| 327 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 328 | "ROLE_PERMISSION": "osmrepos:id:", |
| 329 | }, |
| 330 | }, |
| 331 | "domains": { |
| 332 | "METHODS": ("GET",), |
| 333 | "ROLE_PERMISSION": "domains:", |
| 334 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 335 | } |
| 336 | }, |
| 337 | "pdu": { |
| 338 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 339 | "pdu_descriptors": { |
| 340 | "METHODS": ("GET", "POST"), |
| 341 | "ROLE_PERMISSION": "pduds:", |
| 342 | "<ID>": { |
| 343 | "METHODS": ("GET", "POST", "DELETE", "PATCH", "PUT"), |
| 344 | "ROLE_PERMISSION": "pduds:id:", |
| 345 | }, |
| 346 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 347 | } |
| 348 | }, |
| 349 | "nsd": { |
| 350 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 351 | "ns_descriptors_content": { |
| 352 | "METHODS": ("GET", "POST"), |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 353 | "ROLE_PERMISSION": "nsds:content:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 354 | "<ID>": { |
| 355 | "METHODS": ("GET", "PUT", "DELETE"), |
| 356 | "ROLE_PERMISSION": "nsds:id:", |
| 357 | }, |
| 358 | }, |
| 359 | "ns_descriptors": { |
| 360 | "METHODS": ("GET", "POST"), |
| 361 | "ROLE_PERMISSION": "nsds:", |
| 362 | "<ID>": { |
| 363 | "METHODS": ("GET", "DELETE", "PATCH"), |
| 364 | "ROLE_PERMISSION": "nsds:id:", |
| 365 | "nsd_content": { |
| 366 | "METHODS": ("GET", "PUT"), |
| 367 | "ROLE_PERMISSION": "nsds:id:content:", |
| 368 | }, |
| 369 | "nsd": { |
| 370 | "METHODS": ("GET",), # descriptor inside package |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 371 | "ROLE_PERMISSION": "nsds:id:nsd:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 372 | }, |
| 373 | "artifacts": { |
| 374 | "METHODS": ("GET",), |
| 375 | "ROLE_PERMISSION": "nsds:id:nsd_artifact:", |
| 376 | "*": None, |
| 377 | }, |
| 378 | }, |
| 379 | }, |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 380 | "ns_config_template": { |
| 381 | "METHODS": ("GET", "POST"), |
| 382 | "ROLE_PERMISSION": "ns_config_template:content:", |
| 383 | "<ID>": { |
| 384 | "METHODS": ("GET", "DELETE"), |
| 385 | "ROLE_PERMISSION": "ns_config_template:id:", |
| 386 | "template_content": { |
| 387 | "METHODS": ("GET", "PUT"), |
| 388 | "ROLE_PERMISSION": "ns_config_template:id:content:", |
| 389 | }, |
| 390 | }, |
| 391 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 392 | "pnf_descriptors": { |
| 393 | "TODO": ("GET", "POST"), |
| 394 | "<ID>": { |
| 395 | "TODO": ("GET", "DELETE", "PATCH"), |
| 396 | "pnfd_content": {"TODO": ("GET", "PUT")}, |
| 397 | }, |
| 398 | }, |
| 399 | "subscriptions": { |
| 400 | "TODO": ("GET", "POST"), |
| 401 | "<ID>": {"TODO": ("GET", "DELETE")}, |
| 402 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 403 | } |
| 404 | }, |
| 405 | "vnfpkgm": { |
| 406 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 407 | "vnf_packages_content": { |
| 408 | "METHODS": ("GET", "POST"), |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 409 | "ROLE_PERMISSION": "vnfds:content:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 410 | "<ID>": { |
| 411 | "METHODS": ("GET", "PUT", "DELETE"), |
| 412 | "ROLE_PERMISSION": "vnfds:id:", |
| 413 | }, |
| 414 | }, |
| 415 | "vnf_packages": { |
| 416 | "METHODS": ("GET", "POST"), |
| 417 | "ROLE_PERMISSION": "vnfds:", |
| 418 | "<ID>": { |
| 419 | "METHODS": ("GET", "DELETE", "PATCH"), # GET: vnfPkgInfo |
| 420 | "ROLE_PERMISSION": "vnfds:id:", |
| 421 | "package_content": { |
| 422 | "METHODS": ("GET", "PUT"), # package |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 423 | "ROLE_PERMISSION": "vnfds:id:content:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 424 | "upload_from_uri": { |
| 425 | "METHODS": (), |
| 426 | "TODO": ("POST",), |
| 427 | "ROLE_PERMISSION": "vnfds:id:upload:", |
| 428 | }, |
| 429 | }, |
| 430 | "vnfd": { |
| 431 | "METHODS": ("GET",), # descriptor inside package |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 432 | "ROLE_PERMISSION": "vnfds:id:vnfd:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 433 | }, |
| 434 | "artifacts": { |
| 435 | "METHODS": ("GET",), |
| 436 | "ROLE_PERMISSION": "vnfds:id:vnfd_artifact:", |
| 437 | "*": None, |
| 438 | }, |
| 439 | "action": { |
| 440 | "METHODS": ("POST",), |
| 441 | "ROLE_PERMISSION": "vnfds:id:action:", |
| 442 | }, |
| 443 | }, |
| 444 | }, |
| 445 | "subscriptions": { |
| 446 | "TODO": ("GET", "POST"), |
| 447 | "<ID>": {"TODO": ("GET", "DELETE")}, |
| 448 | }, |
| 449 | "vnfpkg_op_occs": { |
| 450 | "METHODS": ("GET",), |
| 451 | "ROLE_PERMISSION": "vnfds:vnfpkgops:", |
| 452 | "<ID>": {"METHODS": ("GET",), "ROLE_PERMISSION": "vnfds:vnfpkgops:id:"}, |
| 453 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 454 | } |
| 455 | }, |
| 456 | "nslcm": { |
| 457 | "v1": { |
| adurti | 3af5095 | 2024-05-31 11:36:57 +0530 | [diff] [blame] | 458 | "ns_instances_terminate": { |
| 459 | "METHODS": ("POST"), |
| 460 | "ROLE_PERMISSION": "ns_instances:", |
| 461 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 462 | "ns_instances_content": { |
| 463 | "METHODS": ("GET", "POST"), |
| Adurti | db4540c | 2024-03-21 08:42:52 +0000 | [diff] [blame] | 464 | "ROLE_PERMISSION": "ns_instances:content:", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 465 | "<ID>": { |
| 466 | "METHODS": ("GET", "DELETE"), |
| 467 | "ROLE_PERMISSION": "ns_instances:id:", |
| 468 | }, |
| 469 | }, |
| 470 | "ns_instances": { |
| 471 | "METHODS": ("GET", "POST"), |
| 472 | "ROLE_PERMISSION": "ns_instances:", |
| 473 | "<ID>": { |
| 474 | "METHODS": ("GET", "DELETE"), |
| 475 | "ROLE_PERMISSION": "ns_instances:id:", |
| garciadeblas | 0964edf | 2022-02-11 00:43:44 +0100 | [diff] [blame] | 476 | "heal": { |
| 477 | "METHODS": ("POST",), |
| 478 | "ROLE_PERMISSION": "ns_instances:id:heal:", |
| 479 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 480 | "scale": { |
| 481 | "METHODS": ("POST",), |
| 482 | "ROLE_PERMISSION": "ns_instances:id:scale:", |
| 483 | }, |
| 484 | "terminate": { |
| 485 | "METHODS": ("POST",), |
| 486 | "ROLE_PERMISSION": "ns_instances:id:terminate:", |
| 487 | }, |
| 488 | "instantiate": { |
| 489 | "METHODS": ("POST",), |
| 490 | "ROLE_PERMISSION": "ns_instances:id:instantiate:", |
| 491 | }, |
| elumalai | 8e3806c | 2022-04-28 17:26:24 +0530 | [diff] [blame] | 492 | "migrate": { |
| 493 | "METHODS": ("POST",), |
| 494 | "ROLE_PERMISSION": "ns_instances:id:migrate:", |
| 495 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 496 | "action": { |
| 497 | "METHODS": ("POST",), |
| 498 | "ROLE_PERMISSION": "ns_instances:id:action:", |
| 499 | }, |
| aticig | 544a2ae | 2022-04-05 09:00:17 +0300 | [diff] [blame] | 500 | "update": { |
| 501 | "METHODS": ("POST",), |
| 502 | "ROLE_PERMISSION": "ns_instances:id:update:", |
| 503 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 504 | }, |
| 505 | }, |
| 506 | "ns_lcm_op_occs": { |
| 507 | "METHODS": ("GET",), |
| 508 | "ROLE_PERMISSION": "ns_instances:opps:", |
| 509 | "<ID>": { |
| 510 | "METHODS": ("GET",), |
| 511 | "ROLE_PERMISSION": "ns_instances:opps:id:", |
| Gabriel Cuba | 84a60df | 2023-10-30 14:01:54 -0500 | [diff] [blame] | 512 | "cancel": { |
| 513 | "METHODS": ("POST",), |
| 514 | "ROLE_PERMISSION": "ns_instances:opps:cancel:", |
| 515 | }, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 516 | }, |
| 517 | }, |
| 518 | "vnfrs": { |
| 519 | "METHODS": ("GET",), |
| 520 | "ROLE_PERMISSION": "vnf_instances:", |
| 521 | "<ID>": {"METHODS": ("GET",), "ROLE_PERMISSION": "vnf_instances:id:"}, |
| 522 | }, |
| 523 | "vnf_instances": { |
| 524 | "METHODS": ("GET",), |
| 525 | "ROLE_PERMISSION": "vnf_instances:", |
| 526 | "<ID>": {"METHODS": ("GET",), "ROLE_PERMISSION": "vnf_instances:id:"}, |
| 527 | }, |
| 528 | "subscriptions": { |
| 529 | "METHODS": ("GET", "POST"), |
| 530 | "ROLE_PERMISSION": "ns_subscriptions:", |
| 531 | "<ID>": { |
| 532 | "METHODS": ("GET", "DELETE"), |
| 533 | "ROLE_PERMISSION": "ns_subscriptions:id:", |
| 534 | }, |
| 535 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 536 | } |
| 537 | }, |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 538 | "vnflcm": { |
| 539 | "v1": { |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 540 | "vnf_instances": { |
| 541 | "METHODS": ("GET", "POST"), |
| 542 | "ROLE_PERMISSION": "vnflcm_instances:", |
| 543 | "<ID>": { |
| 544 | "METHODS": ("GET", "DELETE"), |
| 545 | "ROLE_PERMISSION": "vnflcm_instances:id:", |
| 546 | "scale": { |
| 547 | "METHODS": ("POST",), |
| 548 | "ROLE_PERMISSION": "vnflcm_instances:id:scale:", |
| 549 | }, |
| 550 | "terminate": { |
| 551 | "METHODS": ("POST",), |
| 552 | "ROLE_PERMISSION": "vnflcm_instances:id:terminate:", |
| 553 | }, |
| 554 | "instantiate": { |
| 555 | "METHODS": ("POST",), |
| 556 | "ROLE_PERMISSION": "vnflcm_instances:id:instantiate:", |
| 557 | }, |
| 558 | }, |
| 559 | }, |
| 560 | "vnf_lcm_op_occs": { |
| 561 | "METHODS": ("GET",), |
| 562 | "ROLE_PERMISSION": "vnf_instances:opps:", |
| 563 | "<ID>": { |
| 564 | "METHODS": ("GET",), |
| 565 | "ROLE_PERMISSION": "vnf_instances:opps:id:", |
| 566 | }, |
| 567 | }, |
| 568 | "subscriptions": { |
| 569 | "METHODS": ("GET", "POST"), |
| 570 | "ROLE_PERMISSION": "vnflcm_subscriptions:", |
| 571 | "<ID>": { |
| 572 | "METHODS": ("GET", "DELETE"), |
| 573 | "ROLE_PERMISSION": "vnflcm_subscriptions:id:", |
| 574 | }, |
| 575 | }, |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 576 | } |
| 577 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 578 | "nst": { |
| 579 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 580 | "netslice_templates_content": { |
| 581 | "METHODS": ("GET", "POST"), |
| 582 | "ROLE_PERMISSION": "slice_templates:", |
| 583 | "<ID>": { |
| 584 | "METHODS": ("GET", "PUT", "DELETE"), |
| 585 | "ROLE_PERMISSION": "slice_templates:id:", |
| 586 | }, |
| 587 | }, |
| 588 | "netslice_templates": { |
| 589 | "METHODS": ("GET", "POST"), |
| 590 | "ROLE_PERMISSION": "slice_templates:", |
| 591 | "<ID>": { |
| 592 | "METHODS": ("GET", "DELETE"), |
| 593 | "TODO": ("PATCH",), |
| 594 | "ROLE_PERMISSION": "slice_templates:id:", |
| 595 | "nst_content": { |
| 596 | "METHODS": ("GET", "PUT"), |
| 597 | "ROLE_PERMISSION": "slice_templates:id:content:", |
| 598 | }, |
| 599 | "nst": { |
| 600 | "METHODS": ("GET",), # descriptor inside package |
| 601 | "ROLE_PERMISSION": "slice_templates:id:content:", |
| 602 | }, |
| 603 | "artifacts": { |
| 604 | "METHODS": ("GET",), |
| 605 | "ROLE_PERMISSION": "slice_templates:id:content:", |
| 606 | "*": None, |
| 607 | }, |
| 608 | }, |
| 609 | }, |
| 610 | "subscriptions": { |
| 611 | "TODO": ("GET", "POST"), |
| 612 | "<ID>": {"TODO": ("GET", "DELETE")}, |
| 613 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 614 | } |
| 615 | }, |
| 616 | "nsilcm": { |
| 617 | "v1": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 618 | "netslice_instances_content": { |
| 619 | "METHODS": ("GET", "POST"), |
| 620 | "ROLE_PERMISSION": "slice_instances:", |
| 621 | "<ID>": { |
| 622 | "METHODS": ("GET", "DELETE"), |
| 623 | "ROLE_PERMISSION": "slice_instances:id:", |
| 624 | }, |
| 625 | }, |
| 626 | "netslice_instances": { |
| 627 | "METHODS": ("GET", "POST"), |
| 628 | "ROLE_PERMISSION": "slice_instances:", |
| 629 | "<ID>": { |
| 630 | "METHODS": ("GET", "DELETE"), |
| 631 | "ROLE_PERMISSION": "slice_instances:id:", |
| 632 | "terminate": { |
| 633 | "METHODS": ("POST",), |
| 634 | "ROLE_PERMISSION": "slice_instances:id:terminate:", |
| 635 | }, |
| 636 | "instantiate": { |
| 637 | "METHODS": ("POST",), |
| 638 | "ROLE_PERMISSION": "slice_instances:id:instantiate:", |
| 639 | }, |
| 640 | "action": { |
| 641 | "METHODS": ("POST",), |
| 642 | "ROLE_PERMISSION": "slice_instances:id:action:", |
| 643 | }, |
| 644 | }, |
| 645 | }, |
| 646 | "nsi_lcm_op_occs": { |
| 647 | "METHODS": ("GET",), |
| 648 | "ROLE_PERMISSION": "slice_instances:opps:", |
| 649 | "<ID>": { |
| 650 | "METHODS": ("GET",), |
| 651 | "ROLE_PERMISSION": "slice_instances:opps:id:", |
| 652 | }, |
| 653 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 654 | } |
| 655 | }, |
| 656 | "nspm": { |
| 657 | "v1": { |
| 658 | "pm_jobs": { |
| 659 | "<ID>": { |
| 660 | "reports": { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 661 | "<ID>": { |
| 662 | "METHODS": ("GET",), |
| 663 | "ROLE_PERMISSION": "reports:id:", |
| 664 | } |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 665 | } |
| 666 | }, |
| 667 | }, |
| 668 | }, |
| 669 | }, |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 670 | "nsfm": { |
| 671 | "v1": { |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 672 | "alarms": { |
| 673 | "METHODS": ("GET", "PATCH"), |
| 674 | "ROLE_PERMISSION": "alarms:", |
| 675 | "<ID>": { |
| 676 | "METHODS": ("GET", "PATCH"), |
| 677 | "ROLE_PERMISSION": "alarms:id:", |
| 678 | }, |
| 679 | } |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 680 | }, |
| 681 | }, |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 682 | "k8scluster": { |
| 683 | "v1": { |
| 684 | "clusters": { |
| 685 | "METHODS": ("GET", "POST"), |
| 686 | "ROLE_PERMISSION": "k8scluster:", |
| 687 | "<ID>": { |
| yshah | 99122b8 | 2024-11-18 07:05:29 +0000 | [diff] [blame] | 688 | "METHODS": ("GET", "PATCH", "DELETE"), |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 689 | "ROLE_PERMISSION": "k8scluster:id:", |
| 690 | "app_profiles": { |
| 691 | "METHODS": ("PATCH", "GET"), |
| 692 | "ROLE_PERMISSION": "k8scluster:id:app_profiles:", |
| 693 | }, |
| 694 | "infra_controller_profiles": { |
| 695 | "METHODS": ("PATCH", "GET"), |
| 696 | "ROLE_PERMISSION": "k8scluster:id:infra_profiles:", |
| 697 | }, |
| 698 | "infra_config_profiles": { |
| 699 | "METHODS": ("PATCH", "GET"), |
| 700 | "ROLE_PERMISSION": "k8scluster:id:infra_profiles:", |
| 701 | }, |
| 702 | "resource_profiles": { |
| 703 | "METHODS": ("PATCH", "GET"), |
| 704 | "ROLE_PERMISSION": "k8scluster:id:infra_profiles:", |
| 705 | }, |
| 706 | "deregister": { |
| 707 | "METHODS": ("DELETE",), |
| 708 | "ROLE_PERMISSION": "k8scluster:id:deregister:", |
| 709 | }, |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 710 | "get_creds": { |
| 711 | "METHODS": ("GET",), |
| 712 | "ROLE_PERMISSION": "k8scluster:id:get_creds:", |
| 713 | }, |
| shahithya | b9eb414 | 2024-10-17 05:51:39 +0000 | [diff] [blame] | 714 | "get_creds_file": { |
| 715 | "METHODS": ("GET",), |
| 716 | "ROLE_PERMISSION": "k8scluster:id:get_creds_file:", |
| 717 | "<ID>": { |
| 718 | "METHODS": ("GET",), |
| 719 | "ROLE_PERMISSION": "k8scluster:id:get_creds_file:id", |
| 720 | }, |
| 721 | }, |
| yshah | 99122b8 | 2024-11-18 07:05:29 +0000 | [diff] [blame] | 722 | "update": { |
| 723 | "METHODS": ("POST",), |
| 724 | "ROLE_PERMISSION": "k8scluster:id:update:", |
| 725 | }, |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 726 | "scale": { |
| 727 | "METHODS": ("POST",), |
| 728 | "ROLE_PERMISSION": "k8scluster:id:scale:", |
| 729 | }, |
| 730 | "upgrade": { |
| 731 | "METHODS": ("POST",), |
| 732 | "ROLE_PERMISSION": "k8scluster:id:upgrade:", |
| 733 | }, |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 734 | "nodegroup": { |
| 735 | "METHODS": ("POST", "GET"), |
| 736 | "ROLE_PERMISSION": "k8scluster:id:nodegroup:", |
| 737 | "<ID>": { |
| 738 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 739 | "ROLE_PERMISSION": "k8scluster:id:nodegroup:id", |
| 740 | "scale": { |
| 741 | "METHODS": ("POST",), |
| 742 | "ROLE_PERMISSION": "k8scluster:id:nodegroup:id:scale:", |
| 743 | }, |
| 744 | }, |
| 745 | }, |
| 746 | "ksus": { |
| 747 | "METHODS": ("GET",), |
| 748 | "ROLE_PERMISSION": "k8scluster:id:ksus:", |
| 749 | }, |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 750 | }, |
| 751 | "register": { |
| 752 | "METHODS": ("POST",), |
| 753 | "ROLE_PERMISSION": "k8scluster:register:", |
| 754 | }, |
| 755 | }, |
| 756 | "app_profiles": { |
| 757 | "METHODS": ("POST", "GET"), |
| 758 | "ROLE_PERMISSION": "k8scluster:app_profiles:", |
| 759 | "<ID>": { |
| 760 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 761 | "ROLE_PERMISSION": "k8scluster:app_profiles:id:", |
| 762 | }, |
| 763 | }, |
| 764 | "infra_controller_profiles": { |
| 765 | "METHODS": ("POST", "GET"), |
| 766 | "ROLE_PERMISSION": "k8scluster:infra_controller_profiles:", |
| 767 | "<ID>": { |
| 768 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 769 | "ROLE_PERMISSION": "k8scluster:infra_controller_profiles:id:", |
| 770 | }, |
| 771 | }, |
| 772 | "infra_config_profiles": { |
| 773 | "METHODS": ("POST", "GET"), |
| 774 | "ROLE_PERMISSION": "k8scluster:infra_config_profiles:", |
| 775 | "<ID>": { |
| 776 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 777 | "ROLE_PERMISSION": "k8scluster:infra_config_profiles:id:", |
| 778 | }, |
| 779 | }, |
| 780 | "resource_profiles": { |
| 781 | "METHODS": ("POST", "GET"), |
| 782 | "ROLE_PERMISSION": "k8scluster:resource_profiles:", |
| 783 | "<ID>": { |
| 784 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 785 | "ROLE_PERMISSION": "k8scluster:resource_profiles:id:", |
| 786 | }, |
| 787 | }, |
| 788 | } |
| 789 | }, |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 790 | "ksu": { |
| 791 | "v1": { |
| 792 | "ksus": { |
| 793 | "METHODS": ("GET", "POST"), |
| 794 | "ROLE_PERMISSION": "ksu:", |
| 795 | "<ID>": { |
| 796 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 797 | "ROLE_PERMISSION": "ksu:id:", |
| 798 | "clone": { |
| 799 | "METHODS": ("POST",), |
| 800 | "ROLE_PERMISSION": "ksu:id:clone:", |
| 801 | }, |
| 802 | "move": { |
| 803 | "METHODS": ("POST",), |
| 804 | "ROLE_PERMISSION": "ksu:id:move:", |
| 805 | }, |
| 806 | }, |
| 807 | "update": { |
| 808 | "METHODS": ("POST",), |
| 809 | "ROLE_PERMISSION": "ksu:", |
| 810 | }, |
| 811 | "delete": { |
| 812 | "METHODS": ("POST",), |
| 813 | "ROLE_PERMISSION": "ksu:", |
| 814 | }, |
| 815 | }, |
| 816 | } |
| 817 | }, |
| garciadeblas | b798f45 | 2025-08-05 18:21:26 +0200 | [diff] [blame] | 818 | "appinstance": { |
| 819 | "v1": { |
| 820 | "appinstances": { |
| 821 | "METHODS": ("GET", "POST"), |
| 822 | "ROLE_PERMISSION": "appinstance:", |
| 823 | "<ID>": { |
| 824 | "METHODS": ("GET", "PATCH", "DELETE"), |
| 825 | "ROLE_PERMISSION": "appinstance:id:", |
| 826 | }, |
| 827 | "update": { |
| 828 | "METHODS": ("POST",), |
| 829 | "ROLE_PERMISSION": "appinstance:", |
| 830 | }, |
| 831 | }, |
| 832 | } |
| 833 | }, |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 834 | "oka": { |
| 835 | "v1": { |
| 836 | "oka_packages": { |
| 837 | "METHODS": ("GET", "POST"), |
| 838 | "ROLE_PERMISSION": "oka_pkg:", |
| 839 | "<ID>": { |
| 840 | "METHODS": ("GET", "PATCH", "DELETE", "PUT"), |
| 841 | "ROLE_PERMISSION": "oka_pkg:id:", |
| 842 | }, |
| 843 | } |
| 844 | } |
| 845 | }, |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 848 | |
| 849 | class NbiException(Exception): |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 850 | def __init__(self, message, http_code=HTTPStatus.METHOD_NOT_ALLOWED): |
| 851 | Exception.__init__(self, message) |
| 852 | self.http_code = http_code |
| 853 | |
| 854 | |
| 855 | class Server(object): |
| 856 | instance = 0 |
| 857 | # to decode bytes to str |
| 858 | reader = getreader("utf-8") |
| 859 | |
| 860 | def __init__(self): |
| 861 | self.instance += 1 |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 862 | self.authenticator = Authenticator(valid_url_methods, valid_query_string) |
| delacruzramo | ad682a5 | 2019-12-10 16:26:34 +0100 | [diff] [blame] | 863 | self.engine = Engine(self.authenticator) |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 864 | self.logger = logging.getLogger("nbi.server") |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 865 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 866 | def _format_in(self, kwargs): |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 867 | error_text = "" # error_text must be initialized outside try |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 868 | try: |
| 869 | indata = None |
| 870 | if cherrypy.request.body.length: |
| 871 | error_text = "Invalid input format " |
| 872 | |
| 873 | if "Content-Type" in cherrypy.request.headers: |
| 874 | if "application/json" in cherrypy.request.headers["Content-Type"]: |
| 875 | error_text = "Invalid json format " |
| 876 | indata = json.load(self.reader(cherrypy.request.body)) |
| gcalvino | de4adfe | 2018-10-30 11:46:09 +0100 | [diff] [blame] | 877 | cherrypy.request.headers.pop("Content-File-MD5", None) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 878 | elif "application/yaml" in cherrypy.request.headers["Content-Type"]: |
| 879 | error_text = "Invalid yaml format " |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 880 | indata = yaml.safe_load(cherrypy.request.body) |
| gcalvino | de4adfe | 2018-10-30 11:46:09 +0100 | [diff] [blame] | 881 | cherrypy.request.headers.pop("Content-File-MD5", None) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 882 | elif ( |
| 883 | "application/binary" in cherrypy.request.headers["Content-Type"] |
| 884 | or "application/gzip" |
| 885 | in cherrypy.request.headers["Content-Type"] |
| 886 | or "application/zip" in cherrypy.request.headers["Content-Type"] |
| 887 | or "text/plain" in cherrypy.request.headers["Content-Type"] |
| 888 | ): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 889 | indata = cherrypy.request.body # .read() |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 890 | elif ( |
| 891 | "multipart/form-data" |
| 892 | in cherrypy.request.headers["Content-Type"] |
| 893 | ): |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 894 | if ( |
| 895 | "descriptor_file" in kwargs |
| 896 | or "package" in kwargs |
| 897 | and "name" in kwargs |
| 898 | ): |
| 899 | filecontent = "" |
| 900 | if "descriptor_file" in kwargs: |
| 901 | filecontent = kwargs.pop("descriptor_file") |
| 902 | if "package" in kwargs: |
| 903 | filecontent = kwargs.pop("package") |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 904 | if not filecontent.file: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 905 | raise NbiException( |
| 906 | "empty file or content", HTTPStatus.BAD_REQUEST |
| 907 | ) |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 908 | indata = filecontent |
| 909 | if filecontent.content_type.value: |
| 910 | cherrypy.request.headers[ |
| 911 | "Content-Type" |
| 912 | ] = filecontent.content_type.value |
| 913 | elif "package" in kwargs: |
| 914 | filecontent = kwargs.pop("package") |
| 915 | if not filecontent.file: |
| 916 | raise NbiException( |
| 917 | "empty file or content", HTTPStatus.BAD_REQUEST |
| 918 | ) |
| 919 | indata = filecontent |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 920 | if filecontent.content_type.value: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 921 | cherrypy.request.headers[ |
| 922 | "Content-Type" |
| 923 | ] = filecontent.content_type.value |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 924 | else: |
| 925 | # raise cherrypy.HTTPError(HTTPStatus.Not_Acceptable, |
| 926 | # "Only 'Content-Type' of type 'application/json' or |
| 927 | # 'application/yaml' for input format are available") |
| 928 | error_text = "Invalid yaml format " |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 929 | indata = yaml.safe_load(cherrypy.request.body) |
| gcalvino | de4adfe | 2018-10-30 11:46:09 +0100 | [diff] [blame] | 930 | cherrypy.request.headers.pop("Content-File-MD5", None) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 931 | else: |
| 932 | error_text = "Invalid yaml format " |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 933 | indata = yaml.safe_load(cherrypy.request.body) |
| gcalvino | de4adfe | 2018-10-30 11:46:09 +0100 | [diff] [blame] | 934 | cherrypy.request.headers.pop("Content-File-MD5", None) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 935 | if not indata: |
| 936 | indata = {} |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 937 | format_yaml = False |
| 938 | if cherrypy.request.headers.get("Query-String-Format") == "yaml": |
| 939 | format_yaml = True |
| 940 | |
| 941 | for k, v in kwargs.items(): |
| 942 | if isinstance(v, str): |
| 943 | if v == "": |
| 944 | kwargs[k] = None |
| 945 | elif format_yaml: |
| 946 | try: |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 947 | kwargs[k] = yaml.safe_load(v) |
| tierno | e128118 | 2018-05-22 12:24:36 +0200 | [diff] [blame] | 948 | except Exception: |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 949 | pass |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 950 | elif ( |
| 951 | k.endswith(".gt") |
| 952 | or k.endswith(".lt") |
| 953 | or k.endswith(".gte") |
| 954 | or k.endswith(".lte") |
| 955 | ): |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 956 | try: |
| 957 | kwargs[k] = int(v) |
| tierno | e128118 | 2018-05-22 12:24:36 +0200 | [diff] [blame] | 958 | except Exception: |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 959 | try: |
| 960 | kwargs[k] = float(v) |
| tierno | e128118 | 2018-05-22 12:24:36 +0200 | [diff] [blame] | 961 | except Exception: |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 962 | pass |
| 963 | elif v.find(",") > 0: |
| 964 | kwargs[k] = v.split(",") |
| 965 | elif isinstance(v, (list, tuple)): |
| 966 | for index in range(0, len(v)): |
| 967 | if v[index] == "": |
| 968 | v[index] = None |
| 969 | elif format_yaml: |
| 970 | try: |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 971 | v[index] = yaml.safe_load(v[index]) |
| tierno | e128118 | 2018-05-22 12:24:36 +0200 | [diff] [blame] | 972 | except Exception: |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 973 | pass |
| 974 | |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 975 | return indata |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 976 | except (ValueError, yaml.YAMLError) as exc: |
| 977 | raise NbiException(error_text + str(exc), HTTPStatus.BAD_REQUEST) |
| 978 | except KeyError as exc: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 979 | raise NbiException( |
| 980 | "Query string error: " + str(exc), HTTPStatus.BAD_REQUEST |
| 981 | ) |
| tierno | b92094f | 2018-05-11 13:44:22 +0200 | [diff] [blame] | 982 | except Exception as exc: |
| 983 | raise NbiException(error_text + str(exc), HTTPStatus.BAD_REQUEST) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 984 | |
| 985 | @staticmethod |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 986 | def _format_out(data, token_info=None, _format=None): |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 987 | """ |
| 988 | return string of dictionary data according to requested json, yaml, xml. By default json |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 989 | :param data: response to be sent. Can be a dict, text or file |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 990 | :param token_info: Contains among other username and project |
| tierno | 5792d7d | 2019-08-30 15:37:12 +0000 | [diff] [blame] | 991 | :param _format: The format to be set as Content-Type if data is a file |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 992 | :return: None |
| 993 | """ |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 994 | accept = cherrypy.request.headers.get("Accept") |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 995 | if data is None: |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 996 | if accept and "text/html" in accept: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 997 | return html.format( |
| 998 | data, cherrypy.request, cherrypy.response, token_info |
| 999 | ) |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 1000 | # cherrypy.response.status = HTTPStatus.NO_CONTENT.value |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1001 | return |
| 1002 | elif hasattr(data, "read"): # file object |
| 1003 | if _format: |
| 1004 | cherrypy.response.headers["Content-Type"] = _format |
| 1005 | elif "b" in data.mode: # binariy asssumig zip |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1006 | cherrypy.response.headers["Content-Type"] = "application/zip" |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1007 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1008 | cherrypy.response.headers["Content-Type"] = "text/plain" |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1009 | # TODO check that cherrypy close file. If not implement pending things to close per thread next |
| 1010 | return data |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 1011 | if accept: |
| Frank Bryden | 02e700c | 2020-06-03 13:34:16 +0000 | [diff] [blame] | 1012 | if "text/html" in accept: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1013 | return html.format( |
| 1014 | data, cherrypy.request, cherrypy.response, token_info |
| 1015 | ) |
| Frank Bryden | b5422da | 2020-08-10 11:44:11 +0000 | [diff] [blame] | 1016 | elif "application/yaml" in accept or "*/*" in accept: |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1017 | pass |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1018 | elif "application/json" in accept or ( |
| 1019 | cherrypy.response.status and cherrypy.response.status >= 300 |
| 1020 | ): |
| 1021 | cherrypy.response.headers[ |
| 1022 | "Content-Type" |
| 1023 | ] = "application/json; charset=utf-8" |
| Frank Bryden | 02e700c | 2020-06-03 13:34:16 +0000 | [diff] [blame] | 1024 | a = json.dumps(data, indent=4) + "\n" |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1025 | return a.encode("utf8") |
| 1026 | cherrypy.response.headers["Content-Type"] = "application/yaml" |
| 1027 | return yaml.safe_dump( |
| 1028 | data, |
| 1029 | explicit_start=True, |
| 1030 | indent=4, |
| 1031 | default_flow_style=False, |
| 1032 | tags=False, |
| 1033 | encoding="utf-8", |
| 1034 | allow_unicode=True, |
| 1035 | ) # , canonical=True, default_style='"' |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1036 | |
| 1037 | @cherrypy.expose |
| 1038 | def index(self, *args, **kwargs): |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1039 | token_info = None |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1040 | try: |
| 1041 | if cherrypy.request.method == "GET": |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1042 | token_info = self.authenticator.authorize() |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1043 | outdata = token_info # Home page |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1044 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1045 | raise cherrypy.HTTPError( |
| 1046 | HTTPStatus.METHOD_NOT_ALLOWED.value, |
| 1047 | "Method {} not allowed for tokens".format(cherrypy.request.method), |
| 1048 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1049 | |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1050 | return self._format_out(outdata, token_info) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1051 | |
| Eduardo Sousa | 819d34c | 2018-07-31 01:20:02 +0100 | [diff] [blame] | 1052 | except (EngineException, AuthException) as e: |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1053 | # cherrypy.log("index Exception {}".format(e)) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1054 | cherrypy.response.status = e.http_code.value |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1055 | return self._format_out("Welcome to OSM!", token_info) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1056 | |
| 1057 | @cherrypy.expose |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1058 | def version(self, *args, **kwargs): |
| tierno | dfe0957 | 2018-04-24 10:41:10 +0200 | [diff] [blame] | 1059 | # TODO consider to remove and provide version using the static version file |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1060 | try: |
| 1061 | if cherrypy.request.method != "GET": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1062 | raise NbiException( |
| 1063 | "Only method GET is allowed", HTTPStatus.METHOD_NOT_ALLOWED |
| 1064 | ) |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1065 | elif args or kwargs: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1066 | raise NbiException( |
| 1067 | "Invalid URL or query string for version", |
| 1068 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1069 | ) |
| tierno | 9c63011 | 2019-08-29 14:21:41 +0000 | [diff] [blame] | 1070 | # TODO include version of other modules, pick up from some kafka admin message |
| tierno | 5792d7d | 2019-08-30 15:37:12 +0000 | [diff] [blame] | 1071 | osm_nbi_version = {"version": nbi_version, "date": nbi_version_date} |
| 1072 | return self._format_out(osm_nbi_version) |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1073 | except NbiException as e: |
| 1074 | cherrypy.response.status = e.http_code.value |
| 1075 | problem_details = { |
| 1076 | "code": e.http_code.name, |
| 1077 | "status": e.http_code.value, |
| 1078 | "detail": str(e), |
| 1079 | } |
| 1080 | return self._format_out(problem_details, None) |
| 1081 | |
| tierno | 12eac3c | 2020-03-19 23:22:08 +0000 | [diff] [blame] | 1082 | def domain(self): |
| 1083 | try: |
| 1084 | domains = { |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1085 | "user_domain_name": cherrypy.tree.apps["/osm"] |
| 1086 | .config["authentication"] |
| 1087 | .get("user_domain_name"), |
| 1088 | "project_domain_name": cherrypy.tree.apps["/osm"] |
| 1089 | .config["authentication"] |
| 1090 | .get("project_domain_name"), |
| 1091 | } |
| tierno | 12eac3c | 2020-03-19 23:22:08 +0000 | [diff] [blame] | 1092 | return self._format_out(domains) |
| 1093 | except NbiException as e: |
| 1094 | cherrypy.response.status = e.http_code.value |
| 1095 | problem_details = { |
| 1096 | "code": e.http_code.name, |
| 1097 | "status": e.http_code.value, |
| 1098 | "detail": str(e), |
| 1099 | } |
| 1100 | return self._format_out(problem_details, None) |
| 1101 | |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1102 | @staticmethod |
| 1103 | def _format_login(token_info): |
| 1104 | """ |
| 1105 | Changes cherrypy.request.login to include username/project_name;session so that cherrypy access log will |
| 1106 | log this information |
| 1107 | :param token_info: Dictionary with token content |
| 1108 | :return: None |
| 1109 | """ |
| 1110 | cherrypy.request.login = token_info.get("username", "-") |
| 1111 | if token_info.get("project_name"): |
| 1112 | cherrypy.request.login += "/" + token_info["project_name"] |
| 1113 | if token_info.get("id"): |
| 1114 | cherrypy.request.login += ";session=" + token_info["id"][0:12] |
| 1115 | |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1116 | # NS Fault Management |
| 1117 | @cherrypy.expose |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1118 | def nsfm( |
| 1119 | self, |
| 1120 | version=None, |
| 1121 | topic=None, |
| 1122 | uuid=None, |
| 1123 | project_name=None, |
| 1124 | ns_id=None, |
| 1125 | *args, |
| garciadeblas | 57dddce | 2025-07-04 09:24:53 +0200 | [diff] [blame] | 1126 | **kwargs, |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1127 | ): |
| 1128 | if topic == "alarms": |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1129 | try: |
| 1130 | method = cherrypy.request.method |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1131 | role_permission = self._check_valid_url_method( |
| 1132 | method, "nsfm", version, topic, None, None, *args |
| 1133 | ) |
| 1134 | query_string_operations = self._extract_query_string_operations( |
| 1135 | kwargs, method |
| 1136 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1137 | |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1138 | self.authenticator.authorize( |
| 1139 | role_permission, query_string_operations, None |
| 1140 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1141 | |
| 1142 | # to handle get request |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1143 | if cherrypy.request.method == "GET": |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1144 | # if request is on basis of uuid |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1145 | if uuid and uuid != "None": |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1146 | try: |
| 1147 | alarm = self.engine.db.get_one("alarms", {"uuid": uuid}) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1148 | alarm_action = self.engine.db.get_one( |
| 1149 | "alarms_action", {"uuid": uuid} |
| 1150 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1151 | alarm.update(alarm_action) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1152 | vnf = self.engine.db.get_one( |
| 1153 | "vnfrs", {"nsr-id-ref": alarm["tags"]["ns_id"]} |
| 1154 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1155 | alarm["vnf-id"] = vnf["_id"] |
| 1156 | return self._format_out(str(alarm)) |
| 1157 | except Exception: |
| 1158 | return self._format_out("Please provide valid alarm uuid") |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1159 | elif ns_id and ns_id != "None": |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1160 | # if request is on basis of ns_id |
| 1161 | try: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1162 | alarms = self.engine.db.get_list( |
| 1163 | "alarms", {"tags.ns_id": ns_id} |
| 1164 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1165 | for alarm in alarms: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1166 | alarm_action = self.engine.db.get_one( |
| 1167 | "alarms_action", {"uuid": alarm["uuid"]} |
| 1168 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1169 | alarm.update(alarm_action) |
| 1170 | return self._format_out(str(alarms)) |
| 1171 | except Exception: |
| 1172 | return self._format_out("Please provide valid ns id") |
| 1173 | else: |
| 1174 | # to return only alarm which are related to given project |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1175 | project = self.engine.db.get_one( |
| 1176 | "projects", {"name": project_name} |
| 1177 | ) |
| 1178 | project_id = project.get("_id") |
| 1179 | ns_list = self.engine.db.get_list( |
| 1180 | "nsrs", {"_admin.projects_read": project_id} |
| 1181 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1182 | ns_ids = [] |
| 1183 | for ns in ns_list: |
| 1184 | ns_ids.append(ns.get("_id")) |
| 1185 | alarms = self.engine.db.get_list("alarms") |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1186 | alarm_list = [ |
| 1187 | alarm |
| 1188 | for alarm in alarms |
| 1189 | if alarm["tags"]["ns_id"] in ns_ids |
| 1190 | ] |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1191 | for alrm in alarm_list: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1192 | action = self.engine.db.get_one( |
| 1193 | "alarms_action", {"uuid": alrm.get("uuid")} |
| 1194 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1195 | alrm.update(action) |
| 1196 | return self._format_out(str(alarm_list)) |
| 1197 | # to handle patch request for alarm update |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1198 | elif cherrypy.request.method == "PATCH": |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 1199 | data = yaml.safe_load(cherrypy.request.body) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1200 | try: |
| 1201 | # check if uuid is valid |
| 1202 | self.engine.db.get_one("alarms", {"uuid": data.get("uuid")}) |
| 1203 | except Exception: |
| 1204 | return self._format_out("Please provide valid alarm uuid.") |
| 1205 | if data.get("is_enable") is not None: |
| 1206 | if data.get("is_enable"): |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1207 | alarm_status = "ok" |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1208 | else: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1209 | alarm_status = "disabled" |
| 1210 | self.engine.db.set_one( |
| 1211 | "alarms", |
| 1212 | {"uuid": data.get("uuid")}, |
| 1213 | {"alarm_status": alarm_status}, |
| 1214 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1215 | else: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1216 | self.engine.db.set_one( |
| 1217 | "alarms", |
| 1218 | {"uuid": data.get("uuid")}, |
| 1219 | {"threshold": data.get("threshold")}, |
| 1220 | ) |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1221 | return self._format_out("Alarm updated") |
| 1222 | except Exception as e: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1223 | if isinstance( |
| 1224 | e, |
| 1225 | ( |
| 1226 | NbiException, |
| 1227 | EngineException, |
| 1228 | DbException, |
| 1229 | FsException, |
| 1230 | MsgException, |
| 1231 | AuthException, |
| 1232 | ValidationError, |
| 1233 | AuthconnException, |
| 1234 | ), |
| 1235 | ): |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1236 | http_code_value = cherrypy.response.status = e.http_code.value |
| 1237 | http_code_name = e.http_code.name |
| 1238 | cherrypy.log("Exception {}".format(e)) |
| 1239 | else: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1240 | http_code_value = ( |
| 1241 | cherrypy.response.status |
| 1242 | ) = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR |
| Atul Agarwal | b6480fc | 2021-03-18 08:19:32 +0000 | [diff] [blame] | 1243 | cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) |
| 1244 | http_code_name = HTTPStatus.BAD_REQUEST.name |
| 1245 | problem_details = { |
| 1246 | "code": http_code_name, |
| 1247 | "status": http_code_value, |
| 1248 | "detail": str(e), |
| 1249 | } |
| 1250 | return self._format_out(problem_details) |
| 1251 | |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1252 | @cherrypy.expose |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1253 | def token(self, method, token_id=None, kwargs=None): |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1254 | token_info = None |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1255 | # self.engine.load_dbase(cherrypy.request.app.config) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1256 | indata = self._format_in(kwargs) |
| 1257 | if not isinstance(indata, dict): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1258 | raise NbiException( |
| 1259 | "Expected application/yaml or application/json Content-Type", |
| 1260 | HTTPStatus.BAD_REQUEST, |
| 1261 | ) |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1262 | |
| 1263 | if method == "GET": |
| 1264 | token_info = self.authenticator.authorize() |
| 1265 | # for logging |
| 1266 | self._format_login(token_info) |
| 1267 | if token_id: |
| 1268 | outdata = self.authenticator.get_token(token_info, token_id) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1269 | else: |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1270 | outdata = self.authenticator.get_token_list(token_info) |
| 1271 | elif method == "POST": |
| 1272 | try: |
| 1273 | token_info = self.authenticator.authorize() |
| 1274 | except Exception: |
| 1275 | token_info = None |
| 1276 | if kwargs: |
| 1277 | indata.update(kwargs) |
| 1278 | # This is needed to log the user when authentication fails |
| 1279 | cherrypy.request.login = "{}".format(indata.get("username", "-")) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1280 | outdata = token_info = self.authenticator.new_token( |
| 1281 | token_info, indata, cherrypy.request.remote |
| 1282 | ) |
| jegan | be1a3df | 2024-06-04 12:05:19 +0000 | [diff] [blame] | 1283 | if outdata.get("email") or outdata.get("otp") == "invalid": |
| 1284 | return self._format_out(outdata, token_info) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1285 | cherrypy.session["Authorization"] = outdata["_id"] # pylint: disable=E1101 |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1286 | self._set_location_header("admin", "v1", "tokens", outdata["_id"]) |
| 1287 | # for logging |
| 1288 | self._format_login(token_info) |
| jegan | be1a3df | 2024-06-04 12:05:19 +0000 | [diff] [blame] | 1289 | if outdata.get("otp") == "valid": |
| 1290 | outdata = { |
| 1291 | "id": outdata["id"], |
| 1292 | "message": "valid_otp", |
| 1293 | "user_id": outdata["user_id"], |
| 1294 | } |
| selvi.j | a9a1fc8 | 2022-04-04 06:54:30 +0000 | [diff] [blame] | 1295 | # password expiry check |
| jegan | be1a3df | 2024-06-04 12:05:19 +0000 | [diff] [blame] | 1296 | elif self.authenticator.check_password_expiry(outdata): |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1297 | outdata = { |
| 1298 | "id": outdata["id"], |
| 1299 | "message": "change_password", |
| 1300 | "user_id": outdata["user_id"], |
| 1301 | } |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1302 | # cherrypy.response.cookie["Authorization"] = outdata["id"] |
| 1303 | # cherrypy.response.cookie["Authorization"]['expires'] = 3600 |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 1304 | cef_event( |
| 1305 | cef_logger, |
| 1306 | { |
| 1307 | "name": "User Login", |
| 1308 | "sourceUserName": token_info.get("username"), |
| 1309 | "message": "User Logged In, Project={} Outcome=Success".format( |
| 1310 | token_info.get("project_name") |
| 1311 | ), |
| 1312 | }, |
| 1313 | ) |
| 1314 | cherrypy.log("{}".format(cef_logger)) |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1315 | elif method == "DELETE": |
| 1316 | if not token_id and "id" in kwargs: |
| 1317 | token_id = kwargs["id"] |
| 1318 | elif not token_id: |
| 1319 | token_info = self.authenticator.authorize() |
| 1320 | # for logging |
| 1321 | self._format_login(token_info) |
| 1322 | token_id = token_info["_id"] |
| Rahul | c72bc8e | 2023-12-05 11:54:38 +0000 | [diff] [blame] | 1323 | if current_backend != "keystone": |
| 1324 | token_details = self.engine.db.get_one("tokens", {"_id": token_id}) |
| 1325 | current_user = token_details.get("username") |
| 1326 | current_project = token_details.get("project_name") |
| 1327 | else: |
| 1328 | current_user = "keystone backend" |
| 1329 | current_project = "keystone backend" |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1330 | outdata = self.authenticator.del_token(token_id) |
| 1331 | token_info = None |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1332 | cherrypy.session["Authorization"] = "logout" # pylint: disable=E1101 |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 1333 | cef_event( |
| 1334 | cef_logger, |
| 1335 | { |
| 1336 | "name": "User Logout", |
| 1337 | "sourceUserName": current_user, |
| 1338 | "message": "User Logged Out, Project={} Outcome=Success".format( |
| 1339 | current_project |
| 1340 | ), |
| 1341 | }, |
| 1342 | ) |
| 1343 | cherrypy.log("{}".format(cef_logger)) |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1344 | # cherrypy.response.cookie["Authorization"] = token_id |
| 1345 | # cherrypy.response.cookie["Authorization"]['expires'] = 0 |
| 1346 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1347 | raise NbiException( |
| 1348 | "Method {} not allowed for token".format(method), |
| 1349 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1350 | ) |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 1351 | return self._format_out(outdata, token_info) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1352 | |
| 1353 | @cherrypy.expose |
| 1354 | def test(self, *args, **kwargs): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1355 | if not cherrypy.config.get("server.enable_test") or ( |
| 1356 | isinstance(cherrypy.config["server.enable_test"], str) |
| 1357 | and cherrypy.config["server.enable_test"].lower() == "false" |
| 1358 | ): |
| tierno | 4836bac | 2020-01-15 14:41:48 +0000 | [diff] [blame] | 1359 | cherrypy.response.status = HTTPStatus.METHOD_NOT_ALLOWED.value |
| 1360 | return "test URL is disabled" |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1361 | thread_info = None |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1362 | if args and args[0] == "help": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1363 | return ( |
| 1364 | "<html><pre>\ninit\nfile/<name> download file\ndb-clear/table\nfs-clear[/folder]\nlogin\nlogin2\n" |
| 1365 | "sleep/<time>\nmessage/topic\n</pre></html>" |
| 1366 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1367 | |
| 1368 | elif args and args[0] == "init": |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1369 | try: |
| 1370 | # self.engine.load_dbase(cherrypy.request.app.config) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1371 | pid = self.authenticator.create_admin_project() |
| 1372 | self.authenticator.create_admin_user(pid) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1373 | return "Done. User 'admin', password 'admin' created" |
| 1374 | except Exception: |
| 1375 | cherrypy.response.status = HTTPStatus.FORBIDDEN.value |
| 1376 | return self._format_out("Database already initialized") |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1377 | elif args and args[0] == "file": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1378 | return cherrypy.lib.static.serve_file( |
| 1379 | cherrypy.tree.apps["/osm"].config["storage"]["path"] + "/" + args[1], |
| 1380 | "text/plain", |
| 1381 | "attachment", |
| 1382 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1383 | elif args and args[0] == "file2": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1384 | f_path = ( |
| 1385 | cherrypy.tree.apps["/osm"].config["storage"]["path"] + "/" + args[1] |
| 1386 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1387 | f = open(f_path, "r") |
| 1388 | cherrypy.response.headers["Content-type"] = "text/plain" |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1389 | return f |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1390 | |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1391 | elif len(args) == 2 and args[0] == "db-clear": |
| tierno | f717cbe | 2018-12-03 16:35:42 +0000 | [diff] [blame] | 1392 | deleted_info = self.engine.db.del_list(args[1], kwargs) |
| 1393 | return "{} {} deleted\n".format(deleted_info["deleted"], args[1]) |
| 1394 | elif len(args) and args[0] == "fs-clear": |
| 1395 | if len(args) >= 2: |
| 1396 | folders = (args[1],) |
| 1397 | else: |
| 1398 | folders = self.engine.fs.dir_ls(".") |
| 1399 | for folder in folders: |
| 1400 | self.engine.fs.file_delete(folder) |
| 1401 | return ",".join(folders) + " folders deleted\n" |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1402 | elif args and args[0] == "login": |
| 1403 | if not cherrypy.request.headers.get("Authorization"): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1404 | cherrypy.response.headers[ |
| 1405 | "WWW-Authenticate" |
| 1406 | ] = 'Basic realm="Access to OSM site", charset="UTF-8"' |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1407 | cherrypy.response.status = HTTPStatus.UNAUTHORIZED.value |
| 1408 | elif args and args[0] == "login2": |
| 1409 | if not cherrypy.request.headers.get("Authorization"): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1410 | cherrypy.response.headers[ |
| 1411 | "WWW-Authenticate" |
| 1412 | ] = 'Bearer realm="Access to OSM site"' |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1413 | cherrypy.response.status = HTTPStatus.UNAUTHORIZED.value |
| 1414 | elif args and args[0] == "sleep": |
| 1415 | sleep_time = 5 |
| 1416 | try: |
| 1417 | sleep_time = int(args[1]) |
| 1418 | except Exception: |
| 1419 | cherrypy.response.status = HTTPStatus.FORBIDDEN.value |
| 1420 | return self._format_out("Database already initialized") |
| 1421 | thread_info = cherrypy.thread_data |
| 1422 | print(thread_info) |
| 1423 | time.sleep(sleep_time) |
| 1424 | # thread_info |
| 1425 | elif len(args) >= 2 and args[0] == "message": |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1426 | main_topic = args[1] |
| 1427 | return_text = "<html><pre>{} ->\n".format(main_topic) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1428 | try: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1429 | if cherrypy.request.method == "POST": |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 1430 | to_send = yaml.safe_load(cherrypy.request.body) |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1431 | for k, v in to_send.items(): |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1432 | self.engine.msg.write(main_topic, k, v) |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1433 | return_text += " {}: {}\n".format(k, v) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1434 | elif cherrypy.request.method == "GET": |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1435 | for k, v in kwargs.items(): |
| garciadeblas | 4cd875d | 2023-02-14 19:05:34 +0100 | [diff] [blame] | 1436 | v_dict = yaml.safe_load(v) |
| tierno | f1509b2 | 2020-05-12 14:32:37 +0000 | [diff] [blame] | 1437 | self.engine.msg.write(main_topic, k, v_dict) |
| 1438 | return_text += " {}: {}\n".format(k, v_dict) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1439 | except Exception as e: |
| tierno | 55945e7 | 2018-04-06 16:40:27 +0200 | [diff] [blame] | 1440 | return_text += "Error: " + str(e) |
| 1441 | return_text += "</pre></html>\n" |
| 1442 | return return_text |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1443 | |
| 1444 | return_text = ( |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1445 | "<html><pre>\nheaders:\n args: {}\n".format(args) |
| 1446 | + " kwargs: {}\n".format(kwargs) |
| 1447 | + " headers: {}\n".format(cherrypy.request.headers) |
| 1448 | + " path_info: {}\n".format(cherrypy.request.path_info) |
| 1449 | + " query_string: {}\n".format(cherrypy.request.query_string) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1450 | + " session: {}\n".format(cherrypy.session) # pylint: disable=E1101 |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1451 | + " cookie: {}\n".format(cherrypy.request.cookie) |
| 1452 | + " method: {}\n".format(cherrypy.request.method) |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1453 | + " session: {}\n".format( |
| 1454 | cherrypy.session.get("fieldname") # pylint: disable=E1101 |
| 1455 | ) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1456 | + " body:\n" |
| 1457 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1458 | return_text += " length: {}\n".format(cherrypy.request.body.length) |
| 1459 | if cherrypy.request.body.length: |
| 1460 | return_text += " content: {}\n".format( |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1461 | str( |
| 1462 | cherrypy.request.body.read( |
| 1463 | int(cherrypy.request.headers.get("Content-Length", 0)) |
| 1464 | ) |
| 1465 | ) |
| 1466 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1467 | if thread_info: |
| 1468 | return_text += "thread: {}\n".format(thread_info) |
| 1469 | return_text += "</pre></html>" |
| 1470 | return return_text |
| 1471 | |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1472 | @staticmethod |
| 1473 | def _check_valid_url_method(method, *args): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1474 | if len(args) < 3: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1475 | raise NbiException( |
| 1476 | "URL must contain at least 'main_topic/version/topic'", |
| 1477 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1478 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1479 | |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1480 | reference = valid_url_methods |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1481 | for arg in args: |
| 1482 | if arg is None: |
| 1483 | break |
| 1484 | if not isinstance(reference, dict): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1485 | raise NbiException( |
| 1486 | "URL contains unexpected extra items '{}'".format(arg), |
| 1487 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1488 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1489 | |
| 1490 | if arg in reference: |
| 1491 | reference = reference[arg] |
| 1492 | elif "<ID>" in reference: |
| 1493 | reference = reference["<ID>"] |
| 1494 | elif "*" in reference: |
| tierno | 74b5358 | 2020-06-18 10:52:37 +0000 | [diff] [blame] | 1495 | # if there is content |
| 1496 | if reference["*"]: |
| 1497 | reference = reference["*"] |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1498 | break |
| 1499 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1500 | raise NbiException( |
| 1501 | "Unexpected URL item {}".format(arg), HTTPStatus.METHOD_NOT_ALLOWED |
| 1502 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1503 | if "TODO" in reference and method in reference["TODO"]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1504 | raise NbiException( |
| 1505 | "Method {} not supported yet for this URL".format(method), |
| 1506 | HTTPStatus.NOT_IMPLEMENTED, |
| 1507 | ) |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 1508 | elif "METHODS" in reference and method not in reference["METHODS"]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1509 | raise NbiException( |
| 1510 | "Method {} not supported for this URL".format(method), |
| 1511 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1512 | ) |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1513 | return reference["ROLE_PERMISSION"] + method.lower() |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1514 | |
| 1515 | @staticmethod |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1516 | def _set_location_header(main_topic, version, topic, id): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1517 | """ |
| 1518 | Insert response header Location with the URL of created item base on URL params |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1519 | :param main_topic: |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1520 | :param version: |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1521 | :param topic: |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1522 | :param id: |
| 1523 | :return: None |
| 1524 | """ |
| 1525 | # Use cherrypy.request.base for absoluted path and make use of request.header HOST just in case behind aNAT |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1526 | cherrypy.response.headers["Location"] = "/osm/{}/{}/{}/{}".format( |
| 1527 | main_topic, version, topic, id |
| 1528 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1529 | return |
| 1530 | |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1531 | @staticmethod |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1532 | def _extract_query_string_operations(kwargs, method): |
| 1533 | """ |
| 1534 | |
| 1535 | :param kwargs: |
| 1536 | :return: |
| 1537 | """ |
| 1538 | query_string_operations = [] |
| 1539 | if kwargs: |
| 1540 | for qs in ("FORCE", "PUBLIC", "ADMIN", "SET_PROJECT"): |
| 1541 | if qs in kwargs and kwargs[qs].lower() != "false": |
| 1542 | query_string_operations.append(qs.lower() + ":" + method.lower()) |
| 1543 | return query_string_operations |
| 1544 | |
| 1545 | @staticmethod |
| 1546 | def _manage_admin_query(token_info, kwargs, method, _id): |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1547 | """ |
| 1548 | Processes the administrator query inputs (if any) of FORCE, ADMIN, PUBLIC, SET_PROJECT |
| 1549 | Check that users has rights to use them and returs the admin_query |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1550 | :param token_info: token_info rights obtained by token |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1551 | :param kwargs: query string input. |
| 1552 | :param method: http method: GET, POSST, PUT, ... |
| 1553 | :param _id: |
| 1554 | :return: admin_query dictionary with keys: |
| 1555 | public: True, False or None |
| 1556 | force: True or False |
| 1557 | project_id: tuple with projects used for accessing an element |
| 1558 | set_project: tuple with projects that a created element will belong to |
| 1559 | method: show, list, delete, write |
| 1560 | """ |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1561 | admin_query = { |
| 1562 | "force": False, |
| 1563 | "project_id": (token_info["project_id"],), |
| 1564 | "username": token_info["username"], |
| Adurti | 76d4b76 | 2024-05-07 06:04:37 +0000 | [diff] [blame] | 1565 | "user_id": token_info["user_id"], |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1566 | "admin": token_info["admin"], |
| 37177 | 091c032 | 2024-11-01 08:55:59 +0000 | [diff] [blame] | 1567 | "admin_show": token_info["admin_show"], |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1568 | "public": None, |
| 1569 | "allow_show_user_project_role": token_info["allow_show_user_project_role"], |
| 1570 | } |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1571 | if kwargs: |
| 1572 | # FORCE |
| 1573 | if "FORCE" in kwargs: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1574 | if ( |
| 1575 | kwargs["FORCE"].lower() != "false" |
| 1576 | ): # if None or True set force to True |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1577 | admin_query["force"] = True |
| 1578 | del kwargs["FORCE"] |
| 1579 | # PUBLIC |
| 1580 | if "PUBLIC" in kwargs: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1581 | if ( |
| 1582 | kwargs["PUBLIC"].lower() != "false" |
| 1583 | ): # if None or True set public to True |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1584 | admin_query["public"] = True |
| 1585 | else: |
| 1586 | admin_query["public"] = False |
| 1587 | del kwargs["PUBLIC"] |
| 1588 | # ADMIN |
| 1589 | if "ADMIN" in kwargs: |
| 1590 | behave_as = kwargs.pop("ADMIN") |
| 1591 | if behave_as.lower() != "false": |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1592 | if not token_info["admin"]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1593 | raise NbiException( |
| 1594 | "Only admin projects can use 'ADMIN' query string", |
| 1595 | HTTPStatus.UNAUTHORIZED, |
| 1596 | ) |
| 1597 | if ( |
| 1598 | not behave_as or behave_as.lower() == "true" |
| 1599 | ): # convert True, None to empty list |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1600 | admin_query["project_id"] = () |
| 1601 | elif isinstance(behave_as, (list, tuple)): |
| 1602 | admin_query["project_id"] = behave_as |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1603 | else: # isinstance(behave_as, str) |
| 1604 | admin_query["project_id"] = (behave_as,) |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1605 | if "SET_PROJECT" in kwargs: |
| 1606 | set_project = kwargs.pop("SET_PROJECT") |
| 1607 | if not set_project: |
| 1608 | admin_query["set_project"] = list(admin_query["project_id"]) |
| 1609 | else: |
| 1610 | if isinstance(set_project, str): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1611 | set_project = (set_project,) |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1612 | if admin_query["project_id"]: |
| 1613 | for p in set_project: |
| 1614 | if p not in admin_query["project_id"]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1615 | raise NbiException( |
| 1616 | "Unauthorized for 'SET_PROJECT={p}'. Try with 'ADMIN=True' or " |
| 1617 | "'ADMIN='{p}'".format(p=p), |
| 1618 | HTTPStatus.UNAUTHORIZED, |
| 1619 | ) |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1620 | admin_query["set_project"] = set_project |
| 1621 | |
| 1622 | # PROJECT_READ |
| 1623 | # if "PROJECT_READ" in kwargs: |
| 1624 | # admin_query["project"] = kwargs.pop("project") |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1625 | # if admin_query["project"] == token_info["project_id"]: |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1626 | if method == "GET": |
| 1627 | if _id: |
| 1628 | admin_query["method"] = "show" |
| 1629 | else: |
| 1630 | admin_query["method"] = "list" |
| 1631 | elif method == "DELETE": |
| 1632 | admin_query["method"] = "delete" |
| 1633 | else: |
| 1634 | admin_query["method"] = "write" |
| 1635 | return admin_query |
| 1636 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1637 | @cherrypy.expose |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1638 | def default( |
| 1639 | self, |
| 1640 | main_topic=None, |
| 1641 | version=None, |
| 1642 | topic=None, |
| 1643 | _id=None, |
| 1644 | item=None, |
| 1645 | *args, |
| garciadeblas | 57dddce | 2025-07-04 09:24:53 +0200 | [diff] [blame] | 1646 | **kwargs, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1647 | ): |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1648 | token_info = None |
| selvi.j | 9919bbc | 2023-04-26 12:22:13 +0000 | [diff] [blame] | 1649 | outdata = {} |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1650 | _format = None |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 1651 | method = "DONE" |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1652 | engine_topic = None |
| tierno | db9dc58 | 2018-06-20 17:27:29 +0200 | [diff] [blame] | 1653 | rollback = [] |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1654 | engine_session = None |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 1655 | url_id = "" |
| 1656 | log_mapping = { |
| 1657 | "POST": "Creating", |
| 1658 | "GET": "Fetching", |
| 1659 | "DELETE": "Deleting", |
| 1660 | "PUT": "Updating", |
| 1661 | "PATCH": "Updating", |
| 1662 | } |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1663 | try: |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1664 | if not main_topic or not version or not topic: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1665 | raise NbiException( |
| 1666 | "URL must contain at least 'main_topic/version/topic'", |
| 1667 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1668 | ) |
| 1669 | if main_topic not in ( |
| 1670 | "admin", |
| 1671 | "vnfpkgm", |
| 1672 | "nsd", |
| 1673 | "nslcm", |
| 1674 | "pdu", |
| 1675 | "nst", |
| 1676 | "nsilcm", |
| 1677 | "nspm", |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 1678 | "vnflcm", |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 1679 | "k8scluster", |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 1680 | "ksu", |
| garciadeblas | b798f45 | 2025-08-05 18:21:26 +0200 | [diff] [blame] | 1681 | "appinstance", |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 1682 | "oka", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1683 | ): |
| 1684 | raise NbiException( |
| 1685 | "URL main_topic '{}' not supported".format(main_topic), |
| 1686 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1687 | ) |
| 1688 | if version != "v1": |
| 1689 | raise NbiException( |
| 1690 | "URL version '{}' not supported".format(version), |
| 1691 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 1692 | ) |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 1693 | if _id is not None: |
| 1694 | url_id = _id |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1695 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1696 | if ( |
| 1697 | kwargs |
| 1698 | and "METHOD" in kwargs |
| 1699 | and kwargs["METHOD"] in ("PUT", "POST", "DELETE", "GET", "PATCH") |
| 1700 | ): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1701 | method = kwargs.pop("METHOD") |
| 1702 | else: |
| 1703 | method = cherrypy.request.method |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 1704 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1705 | role_permission = self._check_valid_url_method( |
| 1706 | method, main_topic, version, topic, _id, item, *args |
| 1707 | ) |
| 1708 | query_string_operations = self._extract_query_string_operations( |
| 1709 | kwargs, method |
| 1710 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1711 | if main_topic == "admin" and topic == "tokens": |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1712 | return self.token(method, _id, kwargs) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1713 | token_info = self.authenticator.authorize( |
| 1714 | role_permission, query_string_operations, _id |
| 1715 | ) |
| tierno | 12eac3c | 2020-03-19 23:22:08 +0000 | [diff] [blame] | 1716 | if main_topic == "admin" and topic == "domains": |
| 1717 | return self.domain() |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 1718 | engine_session = self._manage_admin_query(token_info, kwargs, method, _id) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1719 | indata = self._format_in(kwargs) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1720 | engine_topic = topic |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 1721 | |
| vijay.r | 35ef2f7 | 2019-04-30 17:55:49 +0530 | [diff] [blame] | 1722 | if item and topic != "pm_jobs": |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1723 | engine_topic = item |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1724 | |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1725 | if main_topic == "nsd": |
| 1726 | engine_topic = "nsds" |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 1727 | if topic == "ns_config_template": |
| 1728 | engine_topic = "nsconfigtemps" |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1729 | elif main_topic == "vnfpkgm": |
| 1730 | engine_topic = "vnfds" |
| delacruzramo | 271d200 | 2019-12-02 21:00:37 +0100 | [diff] [blame] | 1731 | if topic == "vnfpkg_op_occs": |
| 1732 | engine_topic = "vnfpkgops" |
| 1733 | if topic == "vnf_packages" and item == "action": |
| 1734 | engine_topic = "vnfpkgops" |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1735 | elif main_topic == "nslcm": |
| 1736 | engine_topic = "nsrs" |
| 1737 | if topic == "ns_lcm_op_occs": |
| 1738 | engine_topic = "nslcmops" |
| 1739 | if topic == "vnfrs" or topic == "vnf_instances": |
| 1740 | engine_topic = "vnfrs" |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 1741 | elif main_topic == "vnflcm": |
| 1742 | if topic == "vnf_lcm_op_occs": |
| 1743 | engine_topic = "vnflcmops" |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 1744 | elif main_topic == "nst": |
| 1745 | engine_topic = "nsts" |
| 1746 | elif main_topic == "nsilcm": |
| 1747 | engine_topic = "nsis" |
| 1748 | if topic == "nsi_lcm_op_occs": |
| delacruzramo | c061f56 | 2019-04-05 11:00:02 +0200 | [diff] [blame] | 1749 | engine_topic = "nsilcmops" |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1750 | elif main_topic == "pdu": |
| 1751 | engine_topic = "pdus" |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 1752 | elif main_topic == "k8scluster": |
| shrinithi | 28d887f | 2025-01-08 05:27:19 +0000 | [diff] [blame] | 1753 | engine_topic = "cluster" |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 1754 | if topic == "clusters" and _id == "register" or item == "deregister": |
| shrinithi | 28d887f | 2025-01-08 05:27:19 +0000 | [diff] [blame] | 1755 | engine_topic = "clusterops" |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 1756 | elif topic == "infra_controller_profiles": |
| 1757 | engine_topic = "infras_cont" |
| 1758 | elif topic == "infra_config_profiles": |
| 1759 | engine_topic = "infras_conf" |
| 1760 | elif topic == "resource_profiles": |
| 1761 | engine_topic = "resources" |
| 1762 | elif topic == "app_profiles": |
| 1763 | engine_topic = "apps" |
| garciadeblas | 1fbe71a | 2025-08-05 09:36:10 +0200 | [diff] [blame] | 1764 | elif topic == "clusters" and item == "nodegroup": |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 1765 | engine_topic = "node_groups" |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 1766 | elif main_topic == "ksu" and engine_topic in ("ksus", "clone", "move"): |
| 1767 | engine_topic = "ksus" |
| garciadeblas | b798f45 | 2025-08-05 18:21:26 +0200 | [diff] [blame] | 1768 | elif main_topic == "appinstance": |
| 1769 | engine_topic = "appinstances" |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1770 | if ( |
| 1771 | engine_topic == "vims" |
| 1772 | ): # TODO this is for backward compatibility, it will be removed in the future |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1773 | engine_topic = "vim_accounts" |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1774 | |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 1775 | if topic == "subscriptions": |
| 1776 | engine_topic = main_topic + "_" + topic |
| 1777 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1778 | if method == "GET": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1779 | if item in ( |
| 1780 | "nsd_content", |
| 1781 | "package_content", |
| 1782 | "artifacts", |
| 1783 | "vnfd", |
| 1784 | "nsd", |
| 1785 | "nst", |
| 1786 | "nst_content", |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 1787 | "ns_config_template", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1788 | ): |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 1789 | if item in ("vnfd", "nsd", "nst"): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1790 | path = "$DESCRIPTOR" |
| 1791 | elif args: |
| 1792 | path = args |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1793 | elif item == "artifacts": |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1794 | path = () |
| 1795 | else: |
| 1796 | path = None |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1797 | file, _format = self.engine.get_file( |
| 1798 | engine_session, |
| 1799 | engine_topic, |
| 1800 | _id, |
| 1801 | path, |
| 1802 | cherrypy.request.headers.get("Accept"), |
| 1803 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1804 | outdata = file |
| shrinithi | 28d887f | 2025-01-08 05:27:19 +0000 | [diff] [blame] | 1805 | # elif not _id and topic != "clusters": |
| 1806 | # outdata = self.engine.get_item_list( |
| 1807 | # engine_session, engine_topic, kwargs, api_req=True |
| 1808 | # ) |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 1809 | elif topic == "clusters" and item in ( |
| 1810 | "infra_controller_profiles", |
| 1811 | "infra_config_profiles", |
| 1812 | "app_profiles", |
| 1813 | "resource_profiles", |
| 1814 | ): |
| 1815 | profile = item |
| 1816 | filter_q = None |
| 1817 | outdata = self.engine.get_one_item( |
| 1818 | engine_session, |
| 1819 | engine_topic, |
| 1820 | _id, |
| 1821 | profile, |
| 1822 | filter_q, |
| 1823 | api_req=True, |
| 1824 | ) |
| shahithya | b9eb414 | 2024-10-17 05:51:39 +0000 | [diff] [blame] | 1825 | elif ( |
| 1826 | topic == "clusters" |
| 1827 | and item == "get_creds_file" |
| 1828 | or item == "get_creds" |
| 1829 | ): |
| 1830 | if item == "get_creds_file": |
| 1831 | op_id = args[0] |
| 1832 | file, _format = self.engine.get_cluster_creds_file( |
| 1833 | engine_session, engine_topic, _id, item, op_id |
| 1834 | ) |
| 1835 | outdata = file |
| 1836 | if item == "get_creds": |
| 1837 | op_id = self.engine.get_cluster_creds( |
| 1838 | engine_session, engine_topic, _id, item |
| 1839 | ) |
| 1840 | outdata = {"op_id": op_id} |
| shrinithi | 28d887f | 2025-01-08 05:27:19 +0000 | [diff] [blame] | 1841 | elif topic == "clusters" and not _id: |
| 1842 | outdata = self.engine.get_item_list_cluster( |
| 1843 | engine_session, engine_topic, kwargs, api_req=True |
| 1844 | ) |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 1845 | elif topic == "clusters" and item == "nodegroup" and args: |
| 1846 | _id = args[0] |
| 1847 | outdata = outdata = self.engine.get_item( |
| 1848 | engine_session, engine_topic, _id, kwargs, True |
| 1849 | ) |
| 1850 | elif topic == "clusters" and item == "nodegroup": |
| 1851 | kwargs["cluster_id"] = _id |
| 1852 | outdata = self.engine.get_item_list( |
| 1853 | engine_session, engine_topic, kwargs, api_req=True |
| 1854 | ) |
| 1855 | elif topic == "clusters" and item == "ksus": |
| 1856 | engine_topic = "ksus" |
| 1857 | kwargs["cluster_id"] = _id |
| 1858 | outdata = self.engine.get_cluster_list_ksu( |
| 1859 | engine_session, engine_topic, kwargs, api_req=True |
| 1860 | ) |
| shrinithi | 28d887f | 2025-01-08 05:27:19 +0000 | [diff] [blame] | 1861 | elif not _id: |
| 1862 | outdata = self.engine.get_item_list( |
| 1863 | engine_session, engine_topic, kwargs, api_req=True |
| 1864 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 1865 | else: |
| vijay.r | 35ef2f7 | 2019-04-30 17:55:49 +0530 | [diff] [blame] | 1866 | if item == "reports": |
| 1867 | # TODO check that project_id (_id in this context) has permissions |
| 1868 | _id = args[0] |
| K Sai Kiran | 5758955 | 2021-01-27 21:38:34 +0530 | [diff] [blame] | 1869 | filter_q = None |
| 1870 | if "vcaStatusRefresh" in kwargs: |
| 1871 | filter_q = {"vcaStatusRefresh": kwargs["vcaStatusRefresh"]} |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 1872 | outdata = self.engine.get_item( |
| 1873 | engine_session, engine_topic, _id, filter_q, True |
| 1874 | ) |
| delacruzramo | 271d200 | 2019-12-02 21:00:37 +0100 | [diff] [blame] | 1875 | |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1876 | elif method == "POST": |
| tierno | bdebce9 | 2019-07-01 15:36:49 +0000 | [diff] [blame] | 1877 | cherrypy.response.status = HTTPStatus.CREATED.value |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1878 | if topic in ( |
| 1879 | "ns_descriptors_content", |
| 1880 | "vnf_packages_content", |
| 1881 | "netslice_templates_content", |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 1882 | "ns_config_template", |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1883 | ): |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1884 | _id = cherrypy.request.headers.get("Transaction-Id") |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 1885 | |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1886 | if not _id: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1887 | _id, _ = self.engine.new_item( |
| 1888 | rollback, |
| 1889 | engine_session, |
| 1890 | engine_topic, |
| 1891 | {}, |
| 1892 | None, |
| 1893 | cherrypy.request.headers, |
| 1894 | ) |
| 1895 | completed = self.engine.upload_content( |
| 1896 | engine_session, |
| 1897 | engine_topic, |
| 1898 | _id, |
| 1899 | indata, |
| 1900 | kwargs, |
| 1901 | cherrypy.request.headers, |
| 1902 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1903 | if completed: |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1904 | self._set_location_header(main_topic, version, topic, _id) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 1905 | else: |
| 1906 | cherrypy.response.headers["Transaction-Id"] = _id |
| 1907 | outdata = {"id": _id} |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 1908 | elif topic == "oka_packages": |
| 1909 | _id = cherrypy.request.headers.get("Transaction-Id") |
| 1910 | |
| 1911 | if not _id: |
| 1912 | _id, _ = self.engine.new_item( |
| 1913 | rollback, |
| 1914 | engine_session, |
| 1915 | engine_topic, |
| 1916 | {}, |
| 1917 | kwargs, |
| 1918 | cherrypy.request.headers, |
| 1919 | ) |
| 1920 | cherrypy.request.headers["method"] = cherrypy.request.method |
| 1921 | if indata: |
| 1922 | completed = self.engine.upload_content( |
| 1923 | engine_session, |
| 1924 | engine_topic, |
| 1925 | _id, |
| 1926 | indata, |
| 1927 | None, |
| 1928 | cherrypy.request.headers, |
| 1929 | ) |
| 1930 | if completed: |
| 1931 | self._set_location_header(main_topic, version, topic, _id) |
| 1932 | else: |
| 1933 | cherrypy.response.headers["Transaction-Id"] = _id |
| yshah | e08aff1 | 2024-11-07 09:32:22 +0000 | [diff] [blame] | 1934 | outdata = {"_id": _id, "id": _id} |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1935 | elif topic == "ns_instances_content": |
| 1936 | # creates NSR |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1937 | _id, _ = self.engine.new_item( |
| 1938 | rollback, engine_session, engine_topic, indata, kwargs |
| 1939 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1940 | # creates nslcmop |
| 1941 | indata["lcmOperationType"] = "instantiate" |
| 1942 | indata["nsInstanceId"] = _id |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 1943 | nslcmop_id, nsName, _ = self.engine.new_item( |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1944 | rollback, engine_session, "nslcmops", indata, None |
| 1945 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1946 | self._set_location_header(main_topic, version, topic, _id) |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 1947 | outdata = {"id": _id, "nslcmop_id": nslcmop_id, "nsName": nsName} |
| adurti | 3af5095 | 2024-05-31 11:36:57 +0530 | [diff] [blame] | 1948 | elif topic == "ns_instances_terminate": |
| 1949 | if indata.get("ns_ids"): |
| 1950 | for ns_id in indata.get("ns_ids"): |
| 1951 | nslcmop_desc = { |
| 1952 | "lcmOperationType": "terminate", |
| 1953 | "nsInstanceId": ns_id, |
| shahithya | b9eb414 | 2024-10-17 05:51:39 +0000 | [diff] [blame] | 1954 | "autoremove": ( |
| 1955 | indata.get("autoremove") |
| 1956 | if "autoremove" in indata |
| 1957 | else True |
| 1958 | ), |
| adurti | 3af5095 | 2024-05-31 11:36:57 +0530 | [diff] [blame] | 1959 | } |
| 1960 | op_id, _, _ = self.engine.new_item( |
| 1961 | rollback, |
| 1962 | engine_session, |
| 1963 | "nslcmops", |
| 1964 | nslcmop_desc, |
| 1965 | kwargs, |
| 1966 | ) |
| 1967 | if not op_id: |
| 1968 | _ = self.engine.del_item( |
| 1969 | engine_session, engine_topic, ns_id |
| 1970 | ) |
| 1971 | outdata = {"ns_ids": indata.get("ns_ids")} |
| 1972 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 1973 | elif topic == "ns_instances" and item: |
| 1974 | indata["lcmOperationType"] = item |
| 1975 | indata["nsInstanceId"] = _id |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 1976 | _id, nsName, _ = self.engine.new_item( |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1977 | rollback, engine_session, "nslcmops", indata, kwargs |
| 1978 | ) |
| 1979 | self._set_location_header( |
| 1980 | main_topic, version, "ns_lcm_op_occs", _id |
| 1981 | ) |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 1982 | outdata = {"id": _id, "nsName": nsName} |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 1983 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 1984 | elif topic == "netslice_instances_content": |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 1985 | # creates NetSlice_Instance_record (NSIR) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1986 | _id, _ = self.engine.new_item( |
| 1987 | rollback, engine_session, engine_topic, indata, kwargs |
| 1988 | ) |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 1989 | self._set_location_header(main_topic, version, topic, _id) |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 1990 | indata["lcmOperationType"] = "instantiate" |
| Felipe Vicens | 126af57 | 2019-06-05 19:13:04 +0200 | [diff] [blame] | 1991 | indata["netsliceInstanceId"] = _id |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1992 | nsilcmop_id, _ = self.engine.new_item( |
| 1993 | rollback, engine_session, "nsilcmops", indata, kwargs |
| 1994 | ) |
| kuuse | 078f55e | 2019-05-16 19:24:21 +0200 | [diff] [blame] | 1995 | outdata = {"id": _id, "nsilcmop_id": nsilcmop_id} |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 1996 | elif topic == "netslice_instances" and item: |
| 1997 | indata["lcmOperationType"] = item |
| Felipe Vicens | 126af57 | 2019-06-05 19:13:04 +0200 | [diff] [blame] | 1998 | indata["netsliceInstanceId"] = _id |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 1999 | _id, _ = self.engine.new_item( |
| 2000 | rollback, engine_session, "nsilcmops", indata, kwargs |
| 2001 | ) |
| 2002 | self._set_location_header( |
| 2003 | main_topic, version, "nsi_lcm_op_occs", _id |
| 2004 | ) |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 2005 | outdata = {"id": _id} |
| 2006 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| delacruzramo | 271d200 | 2019-12-02 21:00:37 +0100 | [diff] [blame] | 2007 | elif topic == "vnf_packages" and item == "action": |
| 2008 | indata["lcmOperationType"] = item |
| 2009 | indata["vnfPkgId"] = _id |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2010 | _id, _ = self.engine.new_item( |
| 2011 | rollback, engine_session, "vnfpkgops", indata, kwargs |
| 2012 | ) |
| 2013 | self._set_location_header( |
| 2014 | main_topic, version, "vnfpkg_op_occs", _id |
| 2015 | ) |
| delacruzramo | 271d200 | 2019-12-02 21:00:37 +0100 | [diff] [blame] | 2016 | outdata = {"id": _id} |
| 2017 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 2018 | elif topic == "subscriptions": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2019 | _id, _ = self.engine.new_item( |
| 2020 | rollback, engine_session, engine_topic, indata, kwargs |
| 2021 | ) |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 2022 | self._set_location_header(main_topic, version, topic, _id) |
| 2023 | link = {} |
| 2024 | link["self"] = cherrypy.response.headers["Location"] |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2025 | outdata = { |
| 2026 | "id": _id, |
| 2027 | "filter": indata["filter"], |
| 2028 | "callbackUri": indata["CallbackUri"], |
| 2029 | "_links": link, |
| 2030 | } |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 2031 | cherrypy.response.status = HTTPStatus.CREATED.value |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 2032 | elif topic == "vnf_instances" and item: |
| 2033 | indata["lcmOperationType"] = item |
| 2034 | indata["vnfInstanceId"] = _id |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2035 | _id, nsName, _ = self.engine.new_item( |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 2036 | rollback, engine_session, "vnflcmops", indata, kwargs |
| 2037 | ) |
| 2038 | self._set_location_header( |
| 2039 | main_topic, version, "vnf_lcm_op_occs", _id |
| 2040 | ) |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2041 | outdata = {"id": _id, "nsName": nsName} |
| almagia | e47b913 | 2022-05-17 14:12:22 +0200 | [diff] [blame] | 2042 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| Gabriel Cuba | 84a60df | 2023-10-30 14:01:54 -0500 | [diff] [blame] | 2043 | elif topic == "ns_lcm_op_occs" and item == "cancel": |
| 2044 | indata["nsLcmOpOccId"] = _id |
| 2045 | self.engine.cancel_item( |
| 2046 | rollback, engine_session, "nslcmops", indata, None |
| 2047 | ) |
| 2048 | self._set_location_header(main_topic, version, topic, _id) |
| 2049 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2050 | elif topic == "clusters" and _id == "register": |
| 2051 | # To register a cluster |
| 2052 | _id, _ = self.engine.add_item( |
| 2053 | rollback, engine_session, engine_topic, indata, kwargs |
| 2054 | ) |
| 2055 | self._set_location_header(main_topic, version, topic, _id) |
| yshah | e08aff1 | 2024-11-07 09:32:22 +0000 | [diff] [blame] | 2056 | outdata = {"_id": _id, "id": _id} |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2057 | elif ( |
| 2058 | topic |
| 2059 | in ( |
| 2060 | "clusters", |
| 2061 | "infra_controller_profiles", |
| 2062 | "infra_config_profiles", |
| 2063 | "app_profiles", |
| 2064 | "resource_profiles", |
| 2065 | ) |
| 2066 | and item is None |
| 2067 | ): |
| 2068 | # creates cluster, infra_controller_profiles, app_profiles, infra_config_profiles, and resource_profiles |
| 2069 | _id, _ = self.engine.new_item( |
| 2070 | rollback, engine_session, engine_topic, indata, kwargs |
| 2071 | ) |
| 2072 | self._set_location_header(main_topic, version, topic, _id) |
| yshah | e08aff1 | 2024-11-07 09:32:22 +0000 | [diff] [blame] | 2073 | outdata = {"_id": _id, "id": _id} |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2074 | elif topic == "ksus" and item: |
| 2075 | if item == "clone": |
| 2076 | _id = self.engine.clone( |
| 2077 | rollback, |
| 2078 | engine_session, |
| 2079 | engine_topic, |
| 2080 | _id, |
| 2081 | indata, |
| 2082 | kwargs, |
| 2083 | cherrypy.request.headers, |
| 2084 | ) |
| 2085 | self._set_location_header(main_topic, version, topic, _id) |
| yshah | e08aff1 | 2024-11-07 09:32:22 +0000 | [diff] [blame] | 2086 | outdata = {"_id": _id, "id": _id} |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2087 | if item == "move": |
| 2088 | op_id = self.engine.move_ksu( |
| 2089 | engine_session, engine_topic, _id, indata, kwargs |
| 2090 | ) |
| 2091 | outdata = {"op_id": op_id} |
| 2092 | elif topic == "ksus" and _id == "delete": |
| 2093 | op_id = self.engine.delete_ksu( |
| 2094 | engine_session, engine_topic, _id, indata |
| 2095 | ) |
| 2096 | outdata = {"op_id": op_id} |
| 2097 | elif topic == "ksus" and _id == "update": |
| 2098 | op_id = self.engine.edit_item( |
| 2099 | engine_session, engine_topic, _id, indata, kwargs |
| 2100 | ) |
| 2101 | outdata = {"op_id": op_id} |
| garciadeblas | b798f45 | 2025-08-05 18:21:26 +0200 | [diff] [blame] | 2102 | elif topic == "appinstances" and item == "update": |
| 2103 | op_id = self.engine.update_appinstance( |
| 2104 | engine_session, engine_topic, _id, indata, kwargs |
| 2105 | ) |
| 2106 | outdata = {"op_id": op_id} |
| garciadeblas | ffce2a4 | 2025-03-21 11:39:39 +0100 | [diff] [blame] | 2107 | elif topic == "clusters" and item in ("upgrade", "scale"): |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 2108 | op_id = self.engine.update_item( |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2109 | engine_session, engine_topic, _id, item, indata |
| 2110 | ) |
| 2111 | outdata = {"op_id": op_id} |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 2112 | elif topic == "clusters" and item == "nodegroup": |
| 2113 | indata["cluster_id"] = _id |
| 2114 | if args: |
| 2115 | _id = args[0] |
| 2116 | op_id = self.engine.update_item( |
| 2117 | engine_session, engine_topic, _id, item, indata |
| 2118 | ) |
| 2119 | outdata = {"op_id": op_id} |
| 2120 | else: |
| 2121 | _id, _ = self.engine.new_item( |
| 2122 | rollback, engine_session, engine_topic, indata, kwargs |
| 2123 | ) |
| 2124 | self._set_location_header(main_topic, version, topic, _id) |
| 2125 | outdata = {"_id": _id, "id": _id} |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 2126 | else: |
| garciadeblas | be6498e | 2025-11-05 11:55:37 +0100 | [diff] [blame^] | 2127 | self.logger.debug( |
| 2128 | "Creating new item in topic {}".format(engine_topic) |
| 2129 | ) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2130 | _id, op_id = self.engine.new_item( |
| 2131 | rollback, |
| 2132 | engine_session, |
| 2133 | engine_topic, |
| 2134 | indata, |
| 2135 | kwargs, |
| 2136 | cherrypy.request.headers, |
| 2137 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2138 | self._set_location_header(main_topic, version, topic, _id) |
| yshah | e08aff1 | 2024-11-07 09:32:22 +0000 | [diff] [blame] | 2139 | outdata = {"_id": _id, "id": _id} |
| tierno | bdebce9 | 2019-07-01 15:36:49 +0000 | [diff] [blame] | 2140 | if op_id: |
| 2141 | outdata["op_id"] = op_id |
| 2142 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2143 | # TODO form NsdInfo when topic in ("ns_descriptors", "vnf_packages") |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 2144 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2145 | elif method == "DELETE": |
| 2146 | if not _id: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2147 | outdata = self.engine.del_item_list( |
| 2148 | engine_session, engine_topic, kwargs |
| 2149 | ) |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 2150 | cherrypy.response.status = HTTPStatus.OK.value |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2151 | else: # len(args) > 1 |
| tierno | 2257743 | 2020-04-08 15:16:57 +0000 | [diff] [blame] | 2152 | # for NS NSI generate an operation |
| 2153 | op_id = None |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 2154 | if topic == "ns_instances_content" and not engine_session["force"]: |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2155 | nslcmop_desc = { |
| 2156 | "lcmOperationType": "terminate", |
| 2157 | "nsInstanceId": _id, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2158 | "autoremove": True, |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2159 | } |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2160 | op_id, nsName, _ = self.engine.new_item( |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2161 | rollback, engine_session, "nslcmops", nslcmop_desc, kwargs |
| 2162 | ) |
| tierno | 2257743 | 2020-04-08 15:16:57 +0000 | [diff] [blame] | 2163 | if op_id: |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2164 | outdata = {"_id": op_id, "nsName": nsName} |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2165 | elif ( |
| 2166 | topic == "netslice_instances_content" |
| 2167 | and not engine_session["force"] |
| 2168 | ): |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 2169 | nsilcmop_desc = { |
| 2170 | "lcmOperationType": "terminate", |
| Felipe Vicens | 126af57 | 2019-06-05 19:13:04 +0200 | [diff] [blame] | 2171 | "netsliceInstanceId": _id, |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2172 | "autoremove": True, |
| garciadeblas | 9750c5a | 2018-10-15 16:20:35 +0200 | [diff] [blame] | 2173 | } |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2174 | op_id, _ = self.engine.new_item( |
| 2175 | rollback, engine_session, "nsilcmops", nsilcmop_desc, None |
| 2176 | ) |
| tierno | 2257743 | 2020-04-08 15:16:57 +0000 | [diff] [blame] | 2177 | if op_id: |
| 2178 | outdata = {"_id": op_id} |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2179 | elif topic == "clusters" and item == "deregister": |
| 2180 | if not op_id: |
| 2181 | op_id = self.engine.remove( |
| 2182 | engine_session, engine_topic, _id |
| 2183 | ) |
| 2184 | if op_id: |
| 2185 | outdata = {"_id": op_id} |
| 2186 | cherrypy.response.status = ( |
| 2187 | HTTPStatus.ACCEPTED.value |
| 2188 | if op_id |
| 2189 | else HTTPStatus.NO_CONTENT.value |
| 2190 | ) |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 2191 | elif topic == "clusters" and item == "nodegroup" and args: |
| 2192 | _id = args[0] |
| 2193 | op_id = self.engine.del_item(engine_session, engine_topic, _id) |
| 2194 | if op_id: |
| 2195 | outdata = {"_id": op_id} |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2196 | elif topic == "ksus": |
| 2197 | op_id = self.engine.delete_ksu( |
| 2198 | engine_session, engine_topic, _id, indata |
| 2199 | ) |
| 2200 | outdata = {"op_id": op_id} |
| tierno | 2257743 | 2020-04-08 15:16:57 +0000 | [diff] [blame] | 2201 | # if there is not any deletion in process, delete |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2202 | elif not op_id: |
| tierno | 2257743 | 2020-04-08 15:16:57 +0000 | [diff] [blame] | 2203 | op_id = self.engine.del_item(engine_session, engine_topic, _id) |
| 2204 | if op_id: |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2205 | outdata = {"_id": op_id} |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2206 | cherrypy.response.status = ( |
| 2207 | HTTPStatus.ACCEPTED.value |
| 2208 | if op_id |
| 2209 | else HTTPStatus.NO_CONTENT.value |
| 2210 | ) |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 2211 | |
| tierno | 7ae1011 | 2018-05-18 14:36:02 +0200 | [diff] [blame] | 2212 | elif method in ("PUT", "PATCH"): |
| tierno | bdebce9 | 2019-07-01 15:36:49 +0000 | [diff] [blame] | 2213 | op_id = None |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 2214 | if not indata and not kwargs and not engine_session.get("set_project"): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2215 | raise NbiException( |
| 2216 | "Nothing to update. Provide payload and/or query string", |
| 2217 | HTTPStatus.BAD_REQUEST, |
| 2218 | ) |
| 2219 | if ( |
| kayal2001 | f71c2e8 | 2024-06-25 15:26:24 +0530 | [diff] [blame] | 2220 | item |
| 2221 | in ( |
| 2222 | "nsd_content", |
| 2223 | "package_content", |
| 2224 | "nst_content", |
| 2225 | "template_content", |
| 2226 | ) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2227 | and method == "PUT" |
| 2228 | ): |
| 2229 | completed = self.engine.upload_content( |
| 2230 | engine_session, |
| 2231 | engine_topic, |
| 2232 | _id, |
| 2233 | indata, |
| 2234 | kwargs, |
| 2235 | cherrypy.request.headers, |
| 2236 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 2237 | if not completed: |
| 2238 | cherrypy.response.headers["Transaction-Id"] = id |
| rshri | 2d386cb | 2024-07-05 14:35:51 +0000 | [diff] [blame] | 2239 | elif item in ( |
| 2240 | "app_profiles", |
| 2241 | "resource_profiles", |
| 2242 | "infra_controller_profiles", |
| 2243 | "infra_config_profiles", |
| 2244 | ): |
| 2245 | op_id = self.engine.edit( |
| 2246 | engine_session, engine_topic, _id, item, indata, kwargs |
| 2247 | ) |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2248 | elif topic == "oka_packages" and method == "PATCH": |
| 2249 | if kwargs: |
| 2250 | op_id = self.engine.edit_item( |
| 2251 | engine_session, engine_topic, _id, None, kwargs |
| 2252 | ) |
| 2253 | if indata: |
| yshah | ffcac5f | 2024-08-19 12:49:07 +0000 | [diff] [blame] | 2254 | if isinstance(indata, dict): |
| yshah | 53cc9eb | 2024-07-05 13:06:31 +0000 | [diff] [blame] | 2255 | op_id = self.engine.edit_item( |
| 2256 | engine_session, engine_topic, _id, indata, kwargs |
| 2257 | ) |
| 2258 | else: |
| 2259 | cherrypy.request.headers["method"] = cherrypy.request.method |
| 2260 | completed = self.engine.upload_content( |
| 2261 | engine_session, |
| 2262 | engine_topic, |
| 2263 | _id, |
| 2264 | indata, |
| 2265 | {}, |
| 2266 | cherrypy.request.headers, |
| 2267 | ) |
| 2268 | if not completed: |
| 2269 | cherrypy.response.headers["Transaction-Id"] = id |
| 2270 | elif topic == "oka_packages" and method == "PUT": |
| 2271 | if indata: |
| 2272 | cherrypy.request.headers["method"] = cherrypy.request.method |
| 2273 | completed = self.engine.upload_content( |
| 2274 | engine_session, |
| 2275 | engine_topic, |
| 2276 | _id, |
| 2277 | indata, |
| 2278 | {}, |
| 2279 | cherrypy.request.headers, |
| 2280 | ) |
| 2281 | if not completed: |
| 2282 | cherrypy.response.headers["Transaction-Id"] = id |
| yshah | d23c6a5 | 2025-06-13 05:49:31 +0000 | [diff] [blame] | 2283 | elif topic == "clusters" and item == "nodegroup" and args: |
| 2284 | _id = args[0] |
| 2285 | op_id = self.engine.edit_item( |
| 2286 | engine_session, engine_topic, _id, indata, kwargs |
| 2287 | ) |
| tierno | f27c79b | 2018-03-12 17:08:42 +0100 | [diff] [blame] | 2288 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2289 | op_id = self.engine.edit_item( |
| 2290 | engine_session, engine_topic, _id, indata, kwargs |
| 2291 | ) |
| tierno | bdebce9 | 2019-07-01 15:36:49 +0000 | [diff] [blame] | 2292 | |
| 2293 | if op_id: |
| 2294 | cherrypy.response.status = HTTPStatus.ACCEPTED.value |
| 2295 | outdata = {"op_id": op_id} |
| 2296 | else: |
| 2297 | cherrypy.response.status = HTTPStatus.NO_CONTENT.value |
| 2298 | outdata = None |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2299 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2300 | raise NbiException( |
| 2301 | "Method {} not allowed".format(method), |
| 2302 | HTTPStatus.METHOD_NOT_ALLOWED, |
| 2303 | ) |
| tierno | a6bb45d | 2019-06-14 09:45:39 +0000 | [diff] [blame] | 2304 | |
| 2305 | # if Role information changes, it is needed to reload the information of roles |
| 2306 | if topic == "roles" and method != "GET": |
| 2307 | self.authenticator.load_operation_to_allowed_roles() |
| delacruzramo | ad682a5 | 2019-12-10 16:26:34 +0100 | [diff] [blame] | 2308 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2309 | if ( |
| 2310 | topic == "projects" |
| 2311 | and method == "DELETE" |
| 2312 | or topic in ["users", "roles"] |
| 2313 | and method in ["PUT", "PATCH", "DELETE"] |
| 2314 | ): |
| delacruzramo | ad682a5 | 2019-12-10 16:26:34 +0100 | [diff] [blame] | 2315 | self.authenticator.remove_token_from_cache() |
| 2316 | |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2317 | cef_event( |
| 2318 | cef_logger, |
| 2319 | { |
| 2320 | "name": "User Operation", |
| 2321 | "sourceUserName": token_info.get("username"), |
| 2322 | }, |
| 2323 | ) |
| 2324 | if topic == "ns_instances_content" and url_id: |
| 2325 | nsName = ( |
| 2326 | outdata.get("name") if method == "GET" else outdata.get("nsName") |
| 2327 | ) |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2328 | cef_event( |
| 2329 | cef_logger, |
| 2330 | { |
| garciadeblas | f53612b | 2024-07-12 14:44:37 +0200 | [diff] [blame] | 2331 | "message": "{} {}, nsName={}, nsdId={}, Project={} Outcome=Success".format( |
| 2332 | log_mapping[method], |
| 2333 | topic, |
| 2334 | nsName, |
| 2335 | outdata.get("id"), |
| 2336 | token_info.get("project_name"), |
| 2337 | ), |
| 2338 | }, |
| 2339 | ) |
| 2340 | cherrypy.log("{}".format(cef_logger)) |
| 2341 | elif topic == "ns_instances_content" and method == "POST": |
| 2342 | cef_event( |
| 2343 | cef_logger, |
| 2344 | { |
| 2345 | "message": "{} {}, nsName={}, nsdId={}, Project={} Outcome=Success".format( |
| 2346 | log_mapping[method], |
| 2347 | topic, |
| 2348 | outdata.get("nsName"), |
| 2349 | outdata.get("id"), |
| 2350 | token_info.get("project_name"), |
| 2351 | ), |
| 2352 | }, |
| 2353 | ) |
| 2354 | cherrypy.log("{}".format(cef_logger)) |
| 2355 | elif topic in ("ns_instances", "vnf_instances") and item: |
| 2356 | cef_event( |
| 2357 | cef_logger, |
| 2358 | { |
| 2359 | "message": "{} {}, nsName={}, nsdId={}, Project={} Outcome=Success".format( |
| 2360 | log_mapping[method], |
| 2361 | topic, |
| 2362 | outdata.get("nsName"), |
| 2363 | url_id, |
| 2364 | token_info.get("project_name"), |
| 2365 | ), |
| 2366 | }, |
| 2367 | ) |
| 2368 | cherrypy.log("{}".format(cef_logger)) |
| 2369 | elif item is not None: |
| 2370 | cef_event( |
| 2371 | cef_logger, |
| 2372 | { |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2373 | "message": "Performing {} operation on {} {}, Project={} Outcome=Success".format( |
| 2374 | item, |
| 2375 | topic, |
| 2376 | url_id, |
| 2377 | token_info.get("project_name"), |
| 2378 | ), |
| 2379 | }, |
| 2380 | ) |
| 2381 | cherrypy.log("{}".format(cef_logger)) |
| 2382 | else: |
| 2383 | cef_event( |
| 2384 | cef_logger, |
| 2385 | { |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2386 | "message": "{} {} {}, Project={} Outcome=Success".format( |
| 2387 | log_mapping[method], |
| 2388 | topic, |
| 2389 | url_id, |
| 2390 | token_info.get("project_name"), |
| 2391 | ), |
| 2392 | }, |
| 2393 | ) |
| 2394 | cherrypy.log("{}".format(cef_logger)) |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 2395 | return self._format_out(outdata, token_info, _format) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2396 | except Exception as e: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2397 | if isinstance( |
| 2398 | e, |
| 2399 | ( |
| 2400 | NbiException, |
| 2401 | EngineException, |
| 2402 | DbException, |
| 2403 | FsException, |
| 2404 | MsgException, |
| 2405 | AuthException, |
| 2406 | ValidationError, |
| 2407 | AuthconnException, |
| 2408 | ), |
| 2409 | ): |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2410 | http_code_value = cherrypy.response.status = e.http_code.value |
| 2411 | http_code_name = e.http_code.name |
| 2412 | cherrypy.log("Exception {}".format(e)) |
| 2413 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2414 | http_code_value = ( |
| 2415 | cherrypy.response.status |
| 2416 | ) = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR |
| Felipe Vicens | e36ab85 | 2018-11-23 14:12:09 +0100 | [diff] [blame] | 2417 | cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2418 | http_code_name = HTTPStatus.BAD_REQUEST.name |
| tierno | 3ace63c | 2018-05-03 17:51:43 +0200 | [diff] [blame] | 2419 | if hasattr(outdata, "close"): # is an open file |
| 2420 | outdata.close() |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2421 | error_text = str(e) |
| 2422 | rollback.reverse() |
| tierno | db9dc58 | 2018-06-20 17:27:29 +0200 | [diff] [blame] | 2423 | for rollback_item in rollback: |
| tierno | 3ace63c | 2018-05-03 17:51:43 +0200 | [diff] [blame] | 2424 | try: |
| tierno | cc10343 | 2018-10-19 14:10:35 +0200 | [diff] [blame] | 2425 | if rollback_item.get("operation") == "set": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2426 | self.engine.db.set_one( |
| 2427 | rollback_item["topic"], |
| 2428 | {"_id": rollback_item["_id"]}, |
| 2429 | rollback_item["content"], |
| 2430 | fail_on_empty=False, |
| 2431 | ) |
| preethika.p | 329b818 | 2020-04-22 12:25:39 +0530 | [diff] [blame] | 2432 | elif rollback_item.get("operation") == "del_list": |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2433 | self.engine.db.del_list( |
| 2434 | rollback_item["topic"], |
| 2435 | rollback_item["filter"], |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2436 | ) |
| tierno | cc10343 | 2018-10-19 14:10:35 +0200 | [diff] [blame] | 2437 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2438 | self.engine.db.del_one( |
| 2439 | rollback_item["topic"], |
| 2440 | {"_id": rollback_item["_id"]}, |
| 2441 | fail_on_empty=False, |
| 2442 | ) |
| tierno | 3ace63c | 2018-05-03 17:51:43 +0200 | [diff] [blame] | 2443 | except Exception as e2: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2444 | rollback_error_text = "Rollback Exception {}: {}".format( |
| 2445 | rollback_item, e2 |
| 2446 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2447 | cherrypy.log(rollback_error_text) |
| 2448 | error_text += ". " + rollback_error_text |
| 2449 | # if isinstance(e, MsgException): |
| 2450 | # error_text = "{} has been '{}' but other modules cannot be informed because an error on bus".format( |
| 2451 | # engine_topic[:-1], method, error_text) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2452 | problem_details = { |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2453 | "code": http_code_name, |
| 2454 | "status": http_code_value, |
| 2455 | "detail": error_text, |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2456 | } |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2457 | if item is not None and token_info is not None: |
| 2458 | cef_event( |
| 2459 | cef_logger, |
| 2460 | { |
| 2461 | "name": "User Operation", |
| 2462 | "sourceUserName": token_info.get("username", None), |
| 2463 | "message": "Performing {} operation on {} {}, Project={} Outcome=Failure".format( |
| 2464 | item, |
| 2465 | topic, |
| 2466 | url_id, |
| 2467 | token_info.get("project_name", None), |
| 2468 | ), |
| 2469 | "severity": "2", |
| 2470 | }, |
| 2471 | ) |
| 2472 | cherrypy.log("{}".format(cef_logger)) |
| 2473 | elif token_info is not None: |
| 2474 | cef_event( |
| 2475 | cef_logger, |
| 2476 | { |
| 2477 | "name": "User Operation", |
| 2478 | "sourceUserName": token_info.get("username", None), |
| 2479 | "message": "{} {} {}, Project={} Outcome=Failure".format( |
| 2480 | item, |
| 2481 | topic, |
| 2482 | url_id, |
| 2483 | token_info.get("project_name", None), |
| 2484 | ), |
| 2485 | "severity": "2", |
| 2486 | }, |
| 2487 | ) |
| 2488 | cherrypy.log("{}".format(cef_logger)) |
| tierno | 701018c | 2019-06-25 11:13:14 +0000 | [diff] [blame] | 2489 | return self._format_out(problem_details, token_info) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2490 | # raise cherrypy.HTTPError(e.http_code.value, str(e)) |
| tierno | a503570 | 2019-07-29 08:54:42 +0000 | [diff] [blame] | 2491 | finally: |
| 2492 | if token_info: |
| 2493 | self._format_login(token_info) |
| 2494 | if method in ("PUT", "PATCH", "POST") and isinstance(outdata, dict): |
| 2495 | for logging_id in ("id", "op_id", "nsilcmop_id", "nslcmop_id"): |
| 2496 | if outdata.get(logging_id): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2497 | cherrypy.request.login += ";{}={}".format( |
| 2498 | logging_id, outdata[logging_id][:36] |
| 2499 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2500 | |
| 2501 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2502 | def _start_service(): |
| 2503 | """ |
| 2504 | Callback function called when cherrypy.engine starts |
| 2505 | Override configuration with env variables |
| 2506 | Set database, storage, message configuration |
| 2507 | Init database with admin/admin user password |
| 2508 | """ |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2509 | global subscription_thread |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2510 | global cef_logger |
| Rahul | c72bc8e | 2023-12-05 11:54:38 +0000 | [diff] [blame] | 2511 | global current_backend |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2512 | cherrypy.log.error("Starting osm_nbi") |
| 2513 | # update general cherrypy configuration |
| 2514 | update_dict = {} |
| 2515 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2516 | engine_config = cherrypy.tree.apps["/osm"].config |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2517 | for k, v in environ.items(): |
| garciadeblas | 6d83f8f | 2023-06-19 22:34:49 +0200 | [diff] [blame] | 2518 | if k == "OSMNBI_USER_MANAGEMENT": |
| garciadeblas | 7a0dace | 2024-09-17 18:00:50 +0200 | [diff] [blame] | 2519 | feature_state = v.lower() == "true" |
| garciadeblas | 6d83f8f | 2023-06-19 22:34:49 +0200 | [diff] [blame] | 2520 | engine_config["authentication"]["user_management"] = feature_state |
| Adurti | d68526d | 2023-11-14 11:14:53 +0000 | [diff] [blame] | 2521 | elif k == "OSMNBI_PWD_EXPIRE_DAYS": |
| 2522 | pwd_expire_days = int(v) |
| 2523 | engine_config["authentication"]["pwd_expire_days"] = pwd_expire_days |
| 2524 | elif k == "OSMNBI_MAX_PWD_ATTEMPT": |
| 2525 | max_pwd_attempt = int(v) |
| 2526 | engine_config["authentication"]["max_pwd_attempt"] = max_pwd_attempt |
| 2527 | elif k == "OSMNBI_ACCOUNT_EXPIRE_DAYS": |
| 2528 | account_expire_days = int(v) |
| 2529 | engine_config["authentication"]["account_expire_days"] = account_expire_days |
| jegan | be1a3df | 2024-06-04 12:05:19 +0000 | [diff] [blame] | 2530 | elif k == "OSMNBI_SMTP_SERVER": |
| 2531 | engine_config["authentication"]["smtp_server"] = v |
| 2532 | engine_config["authentication"]["all"] = environ |
| 2533 | elif k == "OSMNBI_SMTP_PORT": |
| 2534 | port = int(v) |
| 2535 | engine_config["authentication"]["smtp_port"] = port |
| 2536 | elif k == "OSMNBI_SENDER_EMAIL": |
| 2537 | engine_config["authentication"]["sender_email"] = v |
| 2538 | elif k == "OSMNBI_EMAIL_PASSWORD": |
| 2539 | engine_config["authentication"]["sender_password"] = v |
| 2540 | elif k == "OSMNBI_OTP_RETRY_COUNT": |
| 2541 | otp_retry_count = int(v) |
| 2542 | engine_config["authentication"]["retry_count"] = otp_retry_count |
| 2543 | elif k == "OSMNBI_OTP_EXPIRY_TIME": |
| 2544 | otp_expiry_time = int(v) |
| 2545 | engine_config["authentication"]["otp_expiry_time"] = otp_expiry_time |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2546 | if not k.startswith("OSMNBI_"): |
| 2547 | continue |
| tierno | e128118 | 2018-05-22 12:24:36 +0200 | [diff] [blame] | 2548 | k1, _, k2 = k[7:].lower().partition("_") |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2549 | if not k2: |
| 2550 | continue |
| 2551 | try: |
| 2552 | # update static configuration |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2553 | if k == "OSMNBI_STATIC_DIR": |
| 2554 | engine_config["/static"]["tools.staticdir.dir"] = v |
| 2555 | engine_config["/static"]["tools.staticdir.on"] = True |
| 2556 | elif k == "OSMNBI_SOCKET_PORT" or k == "OSMNBI_SERVER_PORT": |
| 2557 | update_dict["server.socket_port"] = int(v) |
| 2558 | elif k == "OSMNBI_SOCKET_HOST" or k == "OSMNBI_SERVER_HOST": |
| 2559 | update_dict["server.socket_host"] = v |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2560 | elif k1 in ("server", "test", "auth", "log"): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2561 | update_dict[k1 + "." + k2] = v |
| Eduardo Sousa | 819d34c | 2018-07-31 01:20:02 +0100 | [diff] [blame] | 2562 | elif k1 in ("message", "database", "storage", "authentication"): |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2563 | # k2 = k2.replace('_', '.') |
| Eduardo Sousa | 819d34c | 2018-07-31 01:20:02 +0100 | [diff] [blame] | 2564 | if k2 in ("port", "db_port"): |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2565 | engine_config[k1][k2] = int(v) |
| 2566 | else: |
| 2567 | engine_config[k1][k2] = v |
| Eduardo Sousa | 819d34c | 2018-07-31 01:20:02 +0100 | [diff] [blame] | 2568 | |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2569 | except ValueError as e: |
| 2570 | cherrypy.log.error("Ignoring environ '{}': " + str(e)) |
| 2571 | except Exception as e: |
| garciadeblas | f2af4a1 | 2023-01-24 16:56:54 +0100 | [diff] [blame] | 2572 | cherrypy.log( |
| 2573 | "WARNING: skipping environ '{}' on exception '{}'".format(k, e) |
| 2574 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2575 | |
| 2576 | if update_dict: |
| 2577 | cherrypy.config.update(update_dict) |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2578 | engine_config["global"].update(update_dict) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2579 | |
| 2580 | # logging cherrypy |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2581 | log_format_simple = ( |
| 2582 | "%(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s %(message)s" |
| 2583 | ) |
| 2584 | log_formatter_simple = logging.Formatter( |
| 2585 | log_format_simple, datefmt="%Y-%m-%dT%H:%M:%S" |
| 2586 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2587 | logger_server = logging.getLogger("cherrypy.error") |
| 2588 | logger_access = logging.getLogger("cherrypy.access") |
| 2589 | logger_cherry = logging.getLogger("cherrypy") |
| 2590 | logger_nbi = logging.getLogger("nbi") |
| 2591 | |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2592 | if "log.file" in engine_config["global"]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2593 | file_handler = logging.handlers.RotatingFileHandler( |
| 2594 | engine_config["global"]["log.file"], maxBytes=100e6, backupCount=9, delay=0 |
| 2595 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2596 | file_handler.setFormatter(log_formatter_simple) |
| 2597 | logger_cherry.addHandler(file_handler) |
| 2598 | logger_nbi.addHandler(file_handler) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2599 | # log always to standard output |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2600 | for format_, logger in { |
| 2601 | "nbi.server %(filename)s:%(lineno)s": logger_server, |
| 2602 | "nbi.access %(filename)s:%(lineno)s": logger_access, |
| 2603 | "%(name)s %(filename)s:%(lineno)s": logger_nbi, |
| 2604 | }.items(): |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2605 | log_format_cherry = "%(asctime)s %(levelname)s {} %(message)s".format(format_) |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2606 | log_formatter_cherry = logging.Formatter( |
| 2607 | log_format_cherry, datefmt="%Y-%m-%dT%H:%M:%S" |
| 2608 | ) |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 2609 | str_handler = logging.StreamHandler() |
| 2610 | str_handler.setFormatter(log_formatter_cherry) |
| 2611 | logger.addHandler(str_handler) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2612 | |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2613 | if engine_config["global"].get("log.level"): |
| 2614 | logger_cherry.setLevel(engine_config["global"]["log.level"]) |
| 2615 | logger_nbi.setLevel(engine_config["global"]["log.level"]) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2616 | |
| 2617 | # logging other modules |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2618 | for k1, logname in { |
| 2619 | "message": "nbi.msg", |
| 2620 | "database": "nbi.db", |
| 2621 | "storage": "nbi.fs", |
| 2622 | }.items(): |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2623 | engine_config[k1]["logger_name"] = logname |
| 2624 | logger_module = logging.getLogger(logname) |
| 2625 | if "logfile" in engine_config[k1]: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2626 | file_handler = logging.handlers.RotatingFileHandler( |
| 2627 | engine_config[k1]["logfile"], maxBytes=100e6, backupCount=9, delay=0 |
| 2628 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2629 | file_handler.setFormatter(log_formatter_simple) |
| 2630 | logger_module.addHandler(file_handler) |
| 2631 | if "loglevel" in engine_config[k1]: |
| 2632 | logger_module.setLevel(engine_config[k1]["loglevel"]) |
| 2633 | # TODO add more entries, e.g.: storage |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2634 | cherrypy.tree.apps["/osm"].root.engine.start(engine_config) |
| 2635 | cherrypy.tree.apps["/osm"].root.authenticator.start(engine_config) |
| 2636 | cherrypy.tree.apps["/osm"].root.engine.init_db(target_version=database_version) |
| 2637 | cherrypy.tree.apps["/osm"].root.authenticator.init_db( |
| 2638 | target_version=auth_database_version |
| 2639 | ) |
| tierno | bee508e | 2019-01-21 11:21:49 +0000 | [diff] [blame] | 2640 | |
| elumalai | 7802ff8 | 2023-04-24 20:38:32 +0530 | [diff] [blame] | 2641 | cef_logger = cef_event_builder(engine_config["authentication"]) |
| 2642 | |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2643 | # start subscriptions thread: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2644 | subscription_thread = SubscriptionThread( |
| 2645 | config=engine_config, engine=nbi_server.engine |
| 2646 | ) |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2647 | subscription_thread.start() |
| 2648 | # Do not capture except SubscriptionException |
| 2649 | |
| tierno | b2e48bd | 2020-02-04 15:47:18 +0000 | [diff] [blame] | 2650 | backend = engine_config["authentication"]["backend"] |
| Rahul | c72bc8e | 2023-12-05 11:54:38 +0000 | [diff] [blame] | 2651 | current_backend = backend |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2652 | cherrypy.log.error( |
| 2653 | "Starting OSM NBI Version '{} {}' with '{}' authentication backend".format( |
| 2654 | nbi_version, nbi_version_date, backend |
| 2655 | ) |
| 2656 | ) |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2657 | |
| 2658 | |
| 2659 | def _stop_service(): |
| 2660 | """ |
| 2661 | Callback function called when cherrypy.engine stops |
| 2662 | TODO: Ending database connections. |
| 2663 | """ |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2664 | global subscription_thread |
| tierno | 65ca36d | 2019-02-12 19:27:52 +0100 | [diff] [blame] | 2665 | if subscription_thread: |
| 2666 | subscription_thread.terminate() |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2667 | subscription_thread = None |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2668 | cherrypy.tree.apps["/osm"].root.engine.stop() |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2669 | cherrypy.log.error("Stopping osm_nbi") |
| 2670 | |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 2671 | |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2672 | def nbi(config_file): |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2673 | global nbi_server |
| tierno | 932499c | 2019-01-28 17:28:10 +0000 | [diff] [blame] | 2674 | nbi_server = Server() |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2675 | cherrypy.engine.subscribe("start", _start_service) |
| 2676 | cherrypy.engine.subscribe("stop", _stop_service) |
| 2677 | cherrypy.quickstart(nbi_server, "/osm", config_file) |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2678 | |
| 2679 | |
| 2680 | def usage(): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2681 | print( |
| 2682 | """Usage: {} [options] |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2683 | -c|--config [configuration_file]: loads the configuration file (default: ./nbi.cfg) |
| 2684 | -h|--help: shows this help |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2685 | """.format( |
| 2686 | sys.argv[0] |
| 2687 | ) |
| 2688 | ) |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 2689 | # --log-socket-host HOST: send logs to this host") |
| 2690 | # --log-socket-port PORT: send logs using this port (default: 9022)") |
| tierno | c94c3df | 2018-02-09 15:38:54 +0100 | [diff] [blame] | 2691 | |
| 2692 | |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2693 | if __name__ == "__main__": |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2694 | try: |
| 2695 | # load parameters and configuration |
| 2696 | opts, args = getopt.getopt(sys.argv[1:], "hvc:", ["config=", "help"]) |
| 2697 | # TODO add "log-socket-host=", "log-socket-port=", "log-file=" |
| 2698 | config_file = None |
| 2699 | for o, a in opts: |
| 2700 | if o in ("-h", "--help"): |
| 2701 | usage() |
| 2702 | sys.exit() |
| 2703 | elif o in ("-c", "--config"): |
| 2704 | config_file = a |
| 2705 | # elif o == "--log-socket-port": |
| 2706 | # log_socket_port = a |
| 2707 | # elif o == "--log-socket-host": |
| 2708 | # log_socket_host = a |
| 2709 | # elif o == "--log-file": |
| 2710 | # log_file = a |
| 2711 | else: |
| garciadeblas | cffd278 | 2025-07-03 17:52:04 +0200 | [diff] [blame] | 2712 | raise getopt.GetoptError(f"Unhandled option: {o}") |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2713 | if config_file: |
| 2714 | if not path.isfile(config_file): |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2715 | print( |
| 2716 | "configuration file '{}' that not exist".format(config_file), |
| 2717 | file=sys.stderr, |
| 2718 | ) |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2719 | exit(1) |
| 2720 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2721 | for config_file in ( |
| 2722 | __file__[: __file__.rfind(".")] + ".cfg", |
| 2723 | "./nbi.cfg", |
| 2724 | "/etc/osm/nbi.cfg", |
| 2725 | ): |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2726 | if path.isfile(config_file): |
| 2727 | break |
| 2728 | else: |
| garciadeblas | 4568a37 | 2021-03-24 09:19:48 +0100 | [diff] [blame] | 2729 | print( |
| 2730 | "No configuration file 'nbi.cfg' found neither at local folder nor at /etc/osm/", |
| 2731 | file=sys.stderr, |
| 2732 | ) |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 2733 | exit(1) |
| 2734 | nbi(config_file) |
| 2735 | except getopt.GetoptError as e: |
| 2736 | print(str(e), file=sys.stderr) |
| 2737 | # usage() |
| 2738 | exit(1) |