Commit 36576056 by Adam Torok

OpenstackRouterManager impl. added

parent d72dcf1d
Pipeline #704 failed with stage
in 36 seconds
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.network.Router import Router
from interface.network.RouterManager import RouterManager
class OpenstackRouterManager(RouterManager):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod
def os_router_to_rc_router(os_router):
return Router(
os_router.id,
os_router.name,
os_router.status,
os_router.created_at
)
def create(self) -> Router:
os_router = self.openstack.network.create_router()
return self.os_router_to_rc_router(os_router)
def get(self, id) -> Optional[Router]:
try:
os_router = self.openstack.network.get_router(id)
except ResourceNotFound:
return None
return self.os_router_to_rc_router(os_router)
def delete(self, id) -> bool:
try:
self.openstack.network.delete_router(id)
except ResourceNotFound:
return False
return True
def list(self) -> []:
routers = []
for os_router in self.openstack.network.routers():
routers.append(self.os_router_to_rc_router(os_router))
return routers
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment