Commit 56cede34 by Adam Torok

OpenstackPortManager impl. added

parent 5f8349eb
Pipeline #705 failed with stage
in 35 seconds
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.network.Port import Port
from interface.network.PortManager import PortManager
class OpenstackPortManager(PortManager):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod
def os_port_to_rc_port(os_port):
return Port(
os_port.id,
os_port.network_id,
os_port.device_id,
os_port.security_group_ids,
os_port.name,
os_port.status,
os_port.created_at
)
def create(self, network_id) -> Port:
os_port = self.openstack.network.create_port(network_id=network_id)
return self.os_port_to_rc_port(os_port)
def get(self, id) -> Optional[Port]:
try:
os_port = self.openstack.network.get_port(id)
except ResourceNotFound:
return None
return self.os_port_to_rc_port(os_port)
def delete(self, id) -> bool:
try:
self.openstack.network.delete_port(id)
except ResourceNotFound:
return False
return True
def list(self) -> []:
ports = []
for os_port in self.openstack.network.ports():
ports.append(self.os_port_to_rc_port(os_port))
return ports
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