1 # -*- coding: utf-8 -*-
4 # Copyright 2018 Telefonica S.A.
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
21 import logging
.handlers
23 from lcm_utils
import LcmException
, LcmBase
24 from osm_common
.dbbase
import DbException
25 from copy
import deepcopy
27 __author__
= "Alfonso Tierno"
30 class VimLcm(LcmBase
):
31 # values that are encrypted at vim config because they are passwords
32 vim_config_encrypted
= ("admin_password", "nsx_password", "vcenter_password")
34 def __init__(self
, db
, msg
, fs
, lcm_tasks
, ro_config
, loop
):
36 Init, Connect to database, filesystem storage, and messaging
37 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
41 self
.logger
= logging
.getLogger('lcm.vim')
43 self
.lcm_tasks
= lcm_tasks
44 self
.ro_config
= ro_config
46 super().__init
__(db
, msg
, fs
, self
.logger
)
48 async def create(self
, vim_content
, order_id
):
49 vim_id
= vim_content
["_id"]
50 logging_text
= "Task vim_create={} ".format(vim_id
)
51 self
.logger
.debug(logging_text
+ "Enter")
57 step
= "Getting vim-id='{}' from db".format(vim_id
)
58 db_vim
= self
.db
.get_one("vim_accounts", {"_id": vim_id
})
59 db_vim_update
["_admin.deployed.RO"] = None
60 if vim_content
.get("config") and vim_content
["config"].get("sdn-controller"):
61 step
= "Getting sdn-controller-id='{}' from db".format(vim_content
["config"]["sdn-controller"])
62 db_sdn
= self
.db
.get_one("sdns", {"_id": vim_content
["config"]["sdn-controller"]})
63 if db_sdn
.get("_admin") and db_sdn
["_admin"].get("deployed") and db_sdn
["_admin"]["deployed"].get("RO"):
64 RO_sdn_id
= db_sdn
["_admin"]["deployed"]["RO"]
66 raise LcmException("sdn-controller={} is not available. Not deployed at RO".format(
67 vim_content
["config"]["sdn-controller"]))
69 step
= "Creating vim at RO"
70 db_vim_update
["_admin.detailed-status"] = step
71 self
.update_db_2("vim_accounts", vim_id
, db_vim_update
)
72 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
73 vim_RO
= deepcopy(vim_content
)
74 vim_RO
.pop("_id", None)
75 vim_RO
.pop("_admin", None)
76 schema_version
= vim_RO
.pop("schema_version", None)
77 vim_RO
.pop("schema_type", None)
78 vim_RO
.pop("vim_tenant_name", None)
79 vim_RO
["type"] = vim_RO
.pop("vim_type")
80 vim_RO
.pop("vim_user", None)
81 vim_RO
.pop("vim_password", None)
83 vim_RO
["config"]["sdn-controller"] = RO_sdn_id
84 desc
= await RO
.create("vim", descriptor
=vim_RO
)
85 RO_vim_id
= desc
["uuid"]
86 db_vim_update
["_admin.deployed.RO"] = RO_vim_id
87 self
.logger
.debug(logging_text
+ "VIM created at RO_vim_id={}".format(RO_vim_id
))
89 step
= "Creating vim_account at RO"
90 db_vim_update
["_admin.detailed-status"] = step
91 self
.update_db_2("vim_accounts", vim_id
, db_vim_update
)
93 if vim_content
.get("vim_password"):
94 vim_content
["vim_password"] = self
.db
.decrypt(vim_content
["vim_password"],
95 schema_version
=schema_version
,
97 vim_account_RO
= {"vim_tenant_name": vim_content
["vim_tenant_name"],
98 "vim_username": vim_content
["vim_user"],
99 "vim_password": vim_content
["vim_password"]
101 if vim_RO
.get("config"):
102 vim_account_RO
["config"] = vim_RO
["config"]
103 if "sdn-controller" in vim_account_RO
["config"]:
104 del vim_account_RO
["config"]["sdn-controller"]
105 if "sdn-port-mapping" in vim_account_RO
["config"]:
106 del vim_account_RO
["config"]["sdn-port-mapping"]
107 for p
in self
.vim_config_encrypted
:
108 if vim_account_RO
["config"].get(p
):
109 vim_account_RO
["config"][p
] = self
.db
.decrypt(vim_account_RO
["config"][p
],
110 schema_version
=schema_version
,
113 desc
= await RO
.attach("vim_account", RO_vim_id
, descriptor
=vim_account_RO
)
114 db_vim_update
["_admin.deployed.RO-account"] = desc
["uuid"]
115 db_vim_update
["_admin.operationalState"] = "ENABLED"
116 db_vim_update
["_admin.detailed-status"] = "Done"
118 # await asyncio.sleep(15) # TODO remove. This is for test
119 self
.logger
.debug(logging_text
+ "Exit Ok VIM account created at RO_vim_account_id={}".format(desc
["uuid"]))
122 except (ROclient
.ROClientException
, DbException
) as e
:
123 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
125 except Exception as e
:
126 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
130 db_vim_update
["_admin.operationalState"] = "ERROR"
131 db_vim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
133 self
.update_db_2("vim_accounts", vim_id
, db_vim_update
)
134 self
.lcm_tasks
.remove("vim_account", vim_id
, order_id
)
136 async def edit(self
, vim_content
, order_id
):
137 vim_id
= vim_content
["_id"]
138 logging_text
= "Task vim_edit={} ".format(vim_id
)
139 self
.logger
.debug(logging_text
+ "Enter")
145 step
= "Getting vim-id='{}' from db".format(vim_id
)
147 db_vim
= self
.db
.get_one("vim_accounts", {"_id": vim_id
})
149 # look if previous tasks in process
150 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("vim_account", vim_id
, order_id
)
152 step
= "Waiting for related tasks to be completed: {}".format(task_name
)
153 self
.logger
.debug(logging_text
+ step
)
154 # TODO write this to database
155 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
157 raise LcmException("Timeout waiting related tasks to be completed")
159 if db_vim
.get("_admin") and db_vim
["_admin"].get("deployed") and db_vim
["_admin"]["deployed"].get("RO"):
160 if vim_content
.get("config") and vim_content
["config"].get("sdn-controller"):
161 step
= "Getting sdn-controller-id='{}' from db".format(vim_content
["config"]["sdn-controller"])
162 db_sdn
= self
.db
.get_one("sdns", {"_id": vim_content
["config"]["sdn-controller"]})
164 # look if previous tasks in process
165 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("sdn", db_sdn
["_id"])
167 step
= "Waiting for related tasks to be completed: {}".format(task_name
)
168 self
.logger
.debug(logging_text
+ step
)
169 # TODO write this to database
170 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
172 raise LcmException("Timeout waiting related tasks to be completed")
174 if db_sdn
.get("_admin") and db_sdn
["_admin"].get("deployed") and db_sdn
["_admin"]["deployed"].get(
176 RO_sdn_id
= db_sdn
["_admin"]["deployed"]["RO"]
178 raise LcmException("sdn-controller={} is not available. Not deployed at RO".format(
179 vim_content
["config"]["sdn-controller"]))
181 RO_vim_id
= db_vim
["_admin"]["deployed"]["RO"]
182 step
= "Editing vim at RO"
183 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
184 vim_RO
= deepcopy(vim_content
)
185 vim_RO
.pop("_id", None)
186 vim_RO
.pop("_admin", None)
187 schema_version
= vim_RO
.pop("schema_version", None)
188 vim_RO
.pop("schema_type", None)
189 vim_RO
.pop("vim_tenant_name", None)
190 if "vim_type" in vim_RO
:
191 vim_RO
["type"] = vim_RO
.pop("vim_type")
192 vim_RO
.pop("vim_user", None)
193 vim_RO
.pop("vim_password", None)
195 vim_RO
["config"]["sdn-controller"] = RO_sdn_id
196 # TODO make a deep update of sdn-port-mapping
198 await RO
.edit("vim", RO_vim_id
, descriptor
=vim_RO
)
200 step
= "Editing vim-account at RO tenant"
202 if "config" in vim_content
:
203 if "sdn-controller" in vim_content
["config"]:
204 del vim_content
["config"]["sdn-controller"]
205 if "sdn-port-mapping" in vim_content
["config"]:
206 del vim_content
["config"]["sdn-port-mapping"]
207 if not vim_content
["config"]:
208 del vim_content
["config"]
209 if "vim_tenant_name" in vim_content
:
210 vim_account_RO
["vim_tenant_name"] = vim_content
["vim_tenant_name"]
211 if "vim_password" in vim_content
:
212 vim_account_RO
["vim_password"] = vim_content
["vim_password"]
213 if vim_content
.get("vim_password"):
214 vim_account_RO
["vim_password"] = self
.db
.decrypt(vim_content
["vim_password"],
215 schema_version
=schema_version
,
217 if "config" in vim_content
:
218 vim_account_RO
["config"] = vim_content
["config"]
219 if vim_content
.get("config"):
220 for p
in self
.vim_config_encrypted
:
221 if vim_content
["config"].get(p
):
222 vim_account_RO
["config"][p
] = self
.db
.decrypt(vim_content
["config"][p
],
223 schema_version
=schema_version
,
226 if "vim_user" in vim_content
:
227 vim_content
["vim_username"] = vim_content
["vim_user"]
228 # vim_account must be edited always even if empty in order to ensure changes are translated to RO
229 # vim_thread. RO will remove and relaunch a new thread for this vim_account
230 await RO
.edit("vim_account", RO_vim_id
, descriptor
=vim_account_RO
)
231 db_vim_update
["_admin.operationalState"] = "ENABLED"
233 self
.logger
.debug(logging_text
+ "Exit Ok RO_vim_id={}".format(RO_vim_id
))
236 except (ROclient
.ROClientException
, DbException
) as e
:
237 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
239 except Exception as e
:
240 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
244 db_vim_update
["_admin.operationalState"] = "ERROR"
245 db_vim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
247 self
.update_db_2("vim_accounts", vim_id
, db_vim_update
)
248 self
.lcm_tasks
.remove("vim_account", vim_id
, order_id
)
250 async def delete(self
, vim_id
, order_id
):
251 logging_text
= "Task vim_delete={} ".format(vim_id
)
252 self
.logger
.debug(logging_text
+ "Enter")
256 step
= "Getting vim from db"
258 db_vim
= self
.db
.get_one("vim_accounts", {"_id": vim_id
})
259 if db_vim
.get("_admin") and db_vim
["_admin"].get("deployed") and db_vim
["_admin"]["deployed"].get("RO"):
260 RO_vim_id
= db_vim
["_admin"]["deployed"]["RO"]
261 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
262 step
= "Detaching vim from RO tenant"
264 await RO
.detach("vim_account", RO_vim_id
)
265 except ROclient
.ROClientException
as e
:
266 if e
.http_code
== 404: # not found
267 self
.logger
.debug(logging_text
+ "RO_vim_id={} already detached".format(RO_vim_id
))
271 step
= "Deleting vim from RO"
273 await RO
.delete("vim", RO_vim_id
)
274 except ROclient
.ROClientException
as e
:
275 if e
.http_code
== 404: # not found
276 self
.logger
.debug(logging_text
+ "RO_vim_id={} already deleted".format(RO_vim_id
))
281 self
.logger
.error(logging_text
+ "Nohing to remove at RO")
282 self
.db
.del_one("vim_accounts", {"_id": vim_id
})
283 self
.logger
.debug(logging_text
+ "Exit Ok")
286 except (ROclient
.ROClientException
, DbException
) as e
:
287 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
289 except Exception as e
:
290 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
293 self
.lcm_tasks
.remove("vim_account", vim_id
, order_id
)
295 db_vim_update
["_admin.operationalState"] = "ERROR"
296 db_vim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
298 self
.update_db_2("vim_accounts", vim_id
, db_vim_update
)
299 self
.lcm_tasks
.remove("vim_account", vim_id
, order_id
)
302 class WimLcm(LcmBase
):
303 # values that are encrypted at wim config because they are passwords
304 wim_config_encrypted
= ()
306 def __init__(self
, db
, msg
, fs
, lcm_tasks
, ro_config
, loop
):
308 Init, Connect to database, filesystem storage, and messaging
309 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
313 self
.logger
= logging
.getLogger('lcm.vim')
315 self
.lcm_tasks
= lcm_tasks
316 self
.ro_config
= ro_config
318 super().__init
__(db
, msg
, fs
, self
.logger
)
320 async def create(self
, wim_content
, order_id
):
321 wim_id
= wim_content
["_id"]
322 logging_text
= "Task wim_create={} ".format(wim_id
)
323 self
.logger
.debug(logging_text
+ "Enter")
328 step
= "Getting wim-id='{}' from db".format(wim_id
)
329 db_wim
= self
.db
.get_one("wim_accounts", {"_id": wim_id
})
330 db_wim_update
["_admin.deployed.RO"] = None
332 step
= "Creating wim at RO"
333 db_wim_update
["_admin.detailed-status"] = step
334 self
.update_db_2("wim_accounts", wim_id
, db_wim_update
)
335 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
336 wim_RO
= deepcopy(wim_content
)
337 wim_RO
.pop("_id", None)
338 wim_RO
.pop("_admin", None)
339 schema_version
= wim_RO
.pop("schema_version", None)
340 wim_RO
.pop("schema_type", None)
341 wim_RO
.pop("wim_tenant_name", None)
342 wim_RO
["type"] = wim_RO
.pop("wim_type")
343 wim_RO
.pop("wim_user", None)
344 wim_RO
.pop("wim_password", None)
345 desc
= await RO
.create("wim", descriptor
=wim_RO
)
346 RO_wim_id
= desc
["uuid"]
347 db_wim_update
["_admin.deployed.RO"] = RO_wim_id
348 self
.logger
.debug(logging_text
+ "WIM created at RO_wim_id={}".format(RO_wim_id
))
350 step
= "Creating wim_account at RO"
351 db_wim_update
["_admin.detailed-status"] = step
352 self
.update_db_2("wim_accounts", wim_id
, db_wim_update
)
354 if wim_content
.get("wim_password"):
355 wim_content
["wim_password"] = self
.db
.decrypt(wim_content
["wim_password"],
356 schema_version
=schema_version
,
358 wim_account_RO
= {"name": wim_content
["name"],
359 "user": wim_content
["user"],
360 "password": wim_content
["password"]
362 if wim_RO
.get("config"):
363 wim_account_RO
["config"] = wim_RO
["config"]
364 if "wim_port_mapping" in wim_account_RO
["config"]:
365 del wim_account_RO
["config"]["wim_port_mapping"]
366 for p
in self
.wim_config_encrypted
:
367 if wim_account_RO
["config"].get(p
):
368 wim_account_RO
["config"][p
] = self
.db
.decrypt(wim_account_RO
["config"][p
],
369 schema_version
=schema_version
,
372 desc
= await RO
.attach("wim_account", RO_wim_id
, descriptor
=wim_account_RO
)
373 db_wim_update
["_admin.deployed.RO-account"] = desc
["uuid"]
374 db_wim_update
["_admin.operationalState"] = "ENABLED"
375 db_wim_update
["_admin.detailed-status"] = "Done"
377 self
.logger
.debug(logging_text
+ "Exit Ok WIM account created at RO_wim_account_id={}".format(desc
["uuid"]))
380 except (ROclient
.ROClientException
, DbException
) as e
:
381 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
383 except Exception as e
:
384 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
388 db_wim_update
["_admin.operationalState"] = "ERROR"
389 db_wim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
391 self
.update_db_2("wim_accounts", wim_id
, db_wim_update
)
392 self
.lcm_tasks
.remove("wim_account", wim_id
, order_id
)
394 async def edit(self
, wim_content
, order_id
):
395 wim_id
= wim_content
["_id"]
396 logging_text
= "Task wim_edit={} ".format(wim_id
)
397 self
.logger
.debug(logging_text
+ "Enter")
402 step
= "Getting wim-id='{}' from db".format(wim_id
)
404 db_wim
= self
.db
.get_one("wim_accounts", {"_id": wim_id
})
406 # look if previous tasks in process
407 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("wim_account", wim_id
, order_id
)
409 step
= "Waiting for related tasks to be completed: {}".format(task_name
)
410 self
.logger
.debug(logging_text
+ step
)
411 # TODO write this to database
412 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
414 raise LcmException("Timeout waiting related tasks to be completed")
416 if db_wim
.get("_admin") and db_wim
["_admin"].get("deployed") and db_wim
["_admin"]["deployed"].get("RO"):
418 RO_wim_id
= db_wim
["_admin"]["deployed"]["RO"]
419 step
= "Editing wim at RO"
420 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
421 wim_RO
= deepcopy(wim_content
)
422 wim_RO
.pop("_id", None)
423 wim_RO
.pop("_admin", None)
424 schema_version
= wim_RO
.pop("schema_version", None)
425 wim_RO
.pop("schema_type", None)
426 wim_RO
.pop("wim_tenant_name", None)
427 if "wim_type" in wim_RO
:
428 wim_RO
["type"] = wim_RO
.pop("wim_type")
429 wim_RO
.pop("wim_user", None)
430 wim_RO
.pop("wim_password", None)
431 # TODO make a deep update of wim_port_mapping
433 await RO
.edit("wim", RO_wim_id
, descriptor
=wim_RO
)
435 step
= "Editing wim-account at RO tenant"
437 if "config" in wim_content
:
438 if "wim_port_mapping" in wim_content
["config"]:
439 del wim_content
["config"]["wim_port_mapping"]
440 if not wim_content
["config"]:
441 del wim_content
["config"]
442 if "wim_tenant_name" in wim_content
:
443 wim_account_RO
["wim_tenant_name"] = wim_content
["wim_tenant_name"]
444 if "wim_password" in wim_content
:
445 wim_account_RO
["wim_password"] = wim_content
["wim_password"]
446 if wim_content
.get("wim_password"):
447 wim_account_RO
["wim_password"] = self
.db
.decrypt(wim_content
["wim_password"],
448 schema_version
=schema_version
,
450 if "config" in wim_content
:
451 wim_account_RO
["config"] = wim_content
["config"]
452 if wim_content
.get("config"):
453 for p
in self
.wim_config_encrypted
:
454 if wim_content
["config"].get(p
):
455 wim_account_RO
["config"][p
] = self
.db
.decrypt(wim_content
["config"][p
],
456 schema_version
=schema_version
,
459 if "wim_user" in wim_content
:
460 wim_content
["wim_username"] = wim_content
["wim_user"]
461 # wim_account must be edited always even if empty in order to ensure changes are translated to RO
462 # wim_thread. RO will remove and relaunch a new thread for this wim_account
463 await RO
.edit("wim_account", RO_wim_id
, descriptor
=wim_account_RO
)
464 db_wim_update
["_admin.operationalState"] = "ENABLED"
466 self
.logger
.debug(logging_text
+ "Exit Ok RO_wim_id={}".format(RO_wim_id
))
469 except (ROclient
.ROClientException
, DbException
) as e
:
470 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
472 except Exception as e
:
473 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
477 db_wim_update
["_admin.operationalState"] = "ERROR"
478 db_wim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
480 self
.update_db_2("wim_accounts", wim_id
, db_wim_update
)
481 self
.lcm_tasks
.remove("wim_account", wim_id
, order_id
)
483 async def delete(self
, wim_id
, order_id
):
484 logging_text
= "Task wim_delete={} ".format(wim_id
)
485 self
.logger
.debug(logging_text
+ "Enter")
489 step
= "Getting wim from db"
491 db_wim
= self
.db
.get_one("wim_accounts", {"_id": wim_id
})
492 if db_wim
.get("_admin") and db_wim
["_admin"].get("deployed") and db_wim
["_admin"]["deployed"].get("RO"):
493 RO_wim_id
= db_wim
["_admin"]["deployed"]["RO"]
494 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
495 step
= "Detaching wim from RO tenant"
497 await RO
.detach("wim_account", RO_wim_id
)
498 except ROclient
.ROClientException
as e
:
499 if e
.http_code
== 404: # not found
500 self
.logger
.debug(logging_text
+ "RO_wim_id={} already detached".format(RO_wim_id
))
504 step
= "Deleting wim from RO"
506 await RO
.delete("wim", RO_wim_id
)
507 except ROclient
.ROClientException
as e
:
508 if e
.http_code
== 404: # not found
509 self
.logger
.debug(logging_text
+ "RO_wim_id={} already deleted".format(RO_wim_id
))
514 self
.logger
.error(logging_text
+ "Nohing to remove at RO")
515 self
.db
.del_one("wim_accounts", {"_id": wim_id
})
516 self
.logger
.debug(logging_text
+ "Exit Ok")
519 except (ROclient
.ROClientException
, DbException
) as e
:
520 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
522 except Exception as e
:
523 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
526 self
.lcm_tasks
.remove("wim_account", wim_id
, order_id
)
528 db_wim_update
["_admin.operationalState"] = "ERROR"
529 db_wim_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
531 self
.update_db_2("wim_accounts", wim_id
, db_wim_update
)
532 self
.lcm_tasks
.remove("wim_account", wim_id
, order_id
)
535 class SdnLcm(LcmBase
):
537 def __init__(self
, db
, msg
, fs
, lcm_tasks
, ro_config
, loop
):
539 Init, Connect to database, filesystem storage, and messaging
540 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
544 self
.logger
= logging
.getLogger('lcm.sdn')
546 self
.lcm_tasks
= lcm_tasks
547 self
.ro_config
= ro_config
549 super().__init
__(db
, msg
, fs
, self
.logger
)
551 async def create(self
, sdn_content
, order_id
):
552 sdn_id
= sdn_content
["_id"]
553 logging_text
= "Task sdn_create={} ".format(sdn_id
)
554 self
.logger
.debug(logging_text
+ "Enter")
560 step
= "Getting sdn from db"
561 db_sdn
= self
.db
.get_one("sdns", {"_id": sdn_id
})
562 db_sdn_update
["_admin.deployed.RO"] = None
564 step
= "Creating sdn at RO"
565 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
566 sdn_RO
= deepcopy(sdn_content
)
567 sdn_RO
.pop("_id", None)
568 sdn_RO
.pop("_admin", None)
569 schema_version
= sdn_RO
.pop("schema_version", None)
570 sdn_RO
.pop("schema_type", None)
571 sdn_RO
.pop("description", None)
572 if sdn_RO
.get("password"):
573 sdn_RO
["password"] = self
.db
.decrypt(sdn_RO
["password"], schema_version
=schema_version
, salt
=sdn_id
)
575 desc
= await RO
.create("sdn", descriptor
=sdn_RO
)
576 RO_sdn_id
= desc
["uuid"]
577 db_sdn_update
["_admin.deployed.RO"] = RO_sdn_id
578 db_sdn_update
["_admin.operationalState"] = "ENABLED"
579 self
.logger
.debug(logging_text
+ "Exit Ok RO_sdn_id={}".format(RO_sdn_id
))
582 except (ROclient
.ROClientException
, DbException
) as e
:
583 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
585 except Exception as e
:
586 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
590 db_sdn_update
["_admin.operationalState"] = "ERROR"
591 db_sdn_update
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
593 self
.update_db_2("sdns", sdn_id
, db_sdn_update
)
594 self
.lcm_tasks
.remove("sdn", sdn_id
, order_id
)
596 async def edit(self
, sdn_content
, order_id
):
597 sdn_id
= sdn_content
["_id"]
598 logging_text
= "Task sdn_edit={} ".format(sdn_id
)
599 self
.logger
.debug(logging_text
+ "Enter")
603 step
= "Getting sdn from db"
605 db_sdn
= self
.db
.get_one("sdns", {"_id": sdn_id
})
607 if db_sdn
.get("_admin") and db_sdn
["_admin"].get("deployed") and db_sdn
["_admin"]["deployed"].get("RO"):
608 RO_sdn_id
= db_sdn
["_admin"]["deployed"]["RO"]
609 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
610 step
= "Editing sdn at RO"
611 sdn_RO
= deepcopy(sdn_content
)
612 sdn_RO
.pop("_id", None)
613 sdn_RO
.pop("_admin", None)
614 schema_version
= sdn_RO
.pop("schema_version", None)
615 sdn_RO
.pop("schema_type", None)
616 sdn_RO
.pop("description", None)
617 if sdn_RO
.get("password"):
618 sdn_RO
["password"] = self
.db
.decrypt(sdn_RO
["password"], schema_version
=schema_version
, salt
=sdn_id
)
620 await RO
.edit("sdn", RO_sdn_id
, descriptor
=sdn_RO
)
621 db_sdn_update
["_admin.operationalState"] = "ENABLED"
623 self
.logger
.debug(logging_text
+ "Exit Ok RO_sdn_id={}".format(RO_sdn_id
))
626 except (ROclient
.ROClientException
, DbException
) as e
:
627 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
629 except Exception as e
:
630 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
634 db_sdn
["_admin.operationalState"] = "ERROR"
635 db_sdn
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
637 self
.update_db_2("sdns", sdn_id
, db_sdn_update
)
638 self
.lcm_tasks
.remove("sdn", sdn_id
, order_id
)
640 async def delete(self
, sdn_id
, order_id
):
641 logging_text
= "Task sdn_delete={} ".format(sdn_id
)
642 self
.logger
.debug(logging_text
+ "Enter")
646 step
= "Getting sdn from db"
648 db_sdn
= self
.db
.get_one("sdns", {"_id": sdn_id
})
649 if db_sdn
.get("_admin") and db_sdn
["_admin"].get("deployed") and db_sdn
["_admin"]["deployed"].get("RO"):
650 RO_sdn_id
= db_sdn
["_admin"]["deployed"]["RO"]
651 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
652 step
= "Deleting sdn from RO"
654 await RO
.delete("sdn", RO_sdn_id
)
655 except ROclient
.ROClientException
as e
:
656 if e
.http_code
== 404: # not found
657 self
.logger
.debug(logging_text
+ "RO_sdn_id={} already deleted".format(RO_sdn_id
))
662 self
.logger
.error(logging_text
+ "Skipping. There is not RO information at database")
663 self
.db
.del_one("sdns", {"_id": sdn_id
})
664 self
.logger
.debug("sdn_delete task sdn_id={} Exit Ok".format(sdn_id
))
667 except (ROclient
.ROClientException
, DbException
) as e
:
668 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
670 except Exception as e
:
671 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
675 db_sdn
["_admin.operationalState"] = "ERROR"
676 db_sdn
["_admin.detailed-status"] = "ERROR {}: {}".format(step
, exc
)
678 self
.update_db_2("sdns", sdn_id
, db_sdn_update
)
679 self
.lcm_tasks
.remove("sdn", sdn_id
, order_id
)