Commit 5ebbd560 by Adam Torok

Openstack subnetmanager impl. added

parent cd55b09d
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.network.Subnet import Subnet
from interface.network.SubnetManager import SubnetManager
class OpenstackSubnetManager(SubnetManager):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod
def os_subnet_to_rc_subnet(os_subnet):
return Subnet(
os_subnet.id,
os_subnet.network_id,
os_subnet.name,
os_subnet.cidr,
os_subnet.ip_version,
os_subnet.gateway_ip,
os_subnet.is_dhcp_enabled,
os_subnet.created_at
)
def create(self, network_id, ip_version, cidr) -> Subnet:
os_subnet = self.openstack.network.create_subnet(
network_id=network_id,
ip_version=ip_version,
cidr=cidr
)
return self.os_subnet_to_rc_subnet(os_subnet)
def get(self, id) -> Optional[Subnet]:
try:
os_subnet = self.openstack.network.get_subnet(id)
except ResourceNotFound:
return None
return self.os_subnet_to_rc_subnet(os_subnet)
def delete(self, id) -> bool:
try:
self.openstack.network.delete_subnet(id=id)
except ResourceNotFound:
return False
return True
def list(self) -> []:
subnets = []
for os_subnet in self.openstack.network.subnets():
subnets.append(self.os_subnet_to_rc_subnet(os_subnet))
return subnets
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