Commit 9bd6841c by edems

OpenstackFloatingIPManager added

parent 63c0becf
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.network.FloatingIP import FloatingIP
from interface.network.FloatingIPManager import FloatingIPManager
class OpenstackFloatingIPManager(FloatingIPManager):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod
def os_floating_ip_to_rc_floating_ip(os_floating_ip) -> FloatingIP:
return FloatingIP(
os_floating_ip.id,
os_floating_ip.router_id,
os_floating_ip.floating_network_id,
os_floating_ip.subnet_id,
os_floating_ip.port_id,
os_floating_ip.name,
os_floating_ip.fixed_ip_address,
os_floating_ip.floating_ip_address,
os_floating_ip.status,
os_floating_ip.created_at,
os_floating_ip.updated_at
)
def create(self, floating_network_id) -> FloatingIP:
os_floating_ip = self.openstack.network.create_ip(floating_network_id=floating_network_id)
return self.os_floating_ip_to_rc_floating_ip(os_floating_ip)
def get(self, id) -> Optional[FloatingIP]:
try:
os_floating_ip = self.openstack.network.get_ip(id)
except ResourceNotFound:
return None
return self.os_floating_ip_to_rc_floating_ip(os_floating_ip)
def update(self, id, params) -> Optional[FloatingIP]:
try:
os_floating_ip = self.openstack.network.update_ip(id, **params)
except ResourceNotFound:
return None
return self.os_floating_ip_to_rc_floating_ip(os_floating_ip)
def delete(self, id) -> bool:
try:
self.openstack.network.delete_ip(id)
except ResourceNotFound:
return False
return True
def list(self) -> []:
floating_ips = []
for os_floating_ip in self.openstack.floating_ip.ips():
floating_ips.append(self.os_floating_ip_to_rc_floating_ip(os_floating_ip))
return floating_ips
......@@ -2,7 +2,9 @@
import openstack
from implementation.network.OpenstackFloatingIPManager import OpenstackFloatingIPManager
from implementation.network.OpenstackNetworkManager import OpenstackNetworkManager
from implementation.network.OpenstackPortManager import OpenstackPortManager
from implementation.network.OpenstackRouterManager import OpenstackRouterManager
from implementation.network.OpenstackSubnetManager import OpenstackSubnetManager
......@@ -11,6 +13,8 @@ os = openstack.connect(cloud='openstack')
router_manager = OpenstackRouterManager(os)
network_manager = OpenstackNetworkManager(os)
subnet_manager = OpenstackSubnetManager(os)
port_manager = OpenstackPortManager(os)
floating_ip_manager = OpenstackFloatingIPManager(os)
#router = router_manager.create()
router = router_manager.get('3ee87bcd-b1b5-4e14-86a1-ce691bd3e5a2')
......@@ -34,6 +38,21 @@ print('Subnet:')
print('\tPublic: %s' % public_subnet)
print('\tInner: %s' % inner_subnet)
vm_port = port_manager.get('bd1f0753-613d-4ecf-8605-eacc3ca63373') # inner
print('Port:')
print('\tVM: %s' % vm_port)
#floating_ip = floating_ip_manager.create(public_network.id)
floating_ip = floating_ip_manager.get('df353eb0-9f0b-4bee-9492-148e29873450')
print('Floating IP:')
print('\tFloating IP: %s' % floating_ip)
#print(router_manager.add_interface(router.id, subnet.id))
#print(router_manager.add_interface(router.id, public_subnet.id))
\ No newline at end of file
#print(router_manager.add_gateway(router.id, public_network.id)) # TODO: fix it!
# print(floating_ip_manager.update(floating_ip.id, {
# 'port_id': vm_port.id
# }))
\ No newline at end of file
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