Commit 5ee369c7 by Belákovics Ádám

Add code style and import changes

parent a011c0fa
Pipeline #1344 failed with stage
in 31 seconds
......@@ -7,11 +7,9 @@ from implementation.utils.decorators import OpenStackError
class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@OpenStackError
def create_interface(self, name):
""" Creates a set of OpenStack resources to provide the functionality of
......@@ -28,21 +26,24 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
is_router_external=True)].pop().id
# create the router
router = self.openstack.network.create_router(project_id=project_id,
router = self.openstack.network.create_router(
project_id=project_id,
external_gateway_info={'network_id': public_network_id,
'enable_snat': True}, is_admin_state_up=True)
'enable_snat': True}, is_admin_state_up=True)
# create the network which will hold the subnets
network = self.openstack.network.create_network(project_id=project_id,
is_admin_state_up=True, name=name)
is_admin_state_up=True, name=name)
# create the IPv4 subnet
subnet_v4 = self.openstack.network.create_subnet(project_id=project_id,
subnet_v4 = self.openstack.network.create_subnet(
project_id=project_id,
ip_version=4, is_dhcp_enabled=True, use_default_subnet_pool=True,
network_id=network.id)
# create the IPv6 subnet
subnet_v6 = self.openstack.network.create_subnet(project_id=project_id,
subnet_v6 = self.openstack.network.create_subnet(
project_id=project_id,
ip_version=6, is_dhcp_enabled=True, use_default_subnet_pool=True,
network_id=network.id)
......@@ -54,7 +55,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
# return the equivalent "interface id"
return interface
@OpenStackError
def delete_interface(self, interface):
""" Deletes the set of OpenStack resources that represent the specified
......@@ -90,7 +90,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
# delete the network, which should be free of ports (except the network:dhcp)
self.openstack.network.delete_network(interface.id)
@OpenStackError
def add_vm_to_interface(self, device_id, interface):
""" Attaches the specified device to a "vlan" identified by the
......@@ -105,24 +104,25 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
project_id = self.openstack.auth['project_id']
#for subnet in self.openstack.network.subnets(network_id=interface.id):
port = self.openstack.network.create_port(project_id=project_id,
# for subnet in self.openstack.network.subnets(network_id=interface.id):
port = self.openstack.network.create_port(
project_id=project_id,
network_id=interface.id, is_admin_state_up=True,
device_id=device_id, device_owner="compute:nova",
is_port_security_enabled=True, binding_vnic_type="normal")
#fixed_ips=[{
# 'subnet_id': subnet.id,
# 'ip_address': '29.29.29.29'}]
# fixed_ips=[{
# 'subnet_id': subnet.id,
# 'ip_address': '29.29.29.29'}]
# adds a fixed IP address from the network (interface.id) to a server
# instance (device_id)
#self.openstack.compute.add_fixed_ip_to_server(device_id, interface.id)
# self.openstack.compute.add_fixed_ip_to_server(device_id, interface.id)
interface.set_port(port)
return interface
@OpenStackError
def remove_vm_from_interface(self, interface):
""" Detaches the specified device from the "vlan".
......@@ -133,7 +133,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
self.openstack.network.delete_port(interface.port.id)
@OpenStackError
def list_all_vm_interfaces(self, device_id):
""" Fetches network ports from the vm instance, to find the networks
......
......@@ -2,8 +2,8 @@ from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.FloatingIP import floating_ip
from interface_openstack.interface.network.FloatingIPManager import floating_ip_manager
from interface_openstack.interface.network import FloatingIP
from interface_openstack.interface.network import FloatingIPManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
......
......@@ -2,8 +2,8 @@ from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Network import network
from interface_openstack.interface.network.NetworkManager import network_manager
from interface_openstack.interface.network import Network
from interface_openstack.interface.network import NetworkManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
......
......@@ -2,8 +2,8 @@ from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Port import port
from interface_openstack.interface.network.PortManager import port_manager
from interface_openstack.interface.network import Port
from interface_openstack.interface.network import PortManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
......
......@@ -2,8 +2,8 @@ from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Router import router
from interface_openstack.interface.network.RouterManager import router_manager
from interface_openstack.interface.network import Router
from interface_openstack.interface.network import RouterManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
......@@ -43,16 +43,18 @@ class OpenstackRouterManager(RouterManager, OpenStackConnection):
def add_interface(self, id, subnet_id):
try:
os_router = self.openstack.network.add_interface_to_router(id, subnet_id) # TODO: can't get the id of the router from dict
os_router = self.openstack.network.add_interface_to_router(
id, subnet_id) # TODO: can't get the id of the router from dict
except ResourceNotFound:
return None
return self.os_router_to_rc_router(os_router)
def add_gateway(self, id, network_id):
#try:
os_router = self.openstack.network.add_gateway_to_router(id, external_gateway_info=network_id)
#except ResourceNotFound:
# try:
os_router = self.openstack.network.add_gateway_to_router(
id, external_gateway_info=network_id)
# except ResourceNotFound:
# return None
print(os_router)
......
......@@ -2,8 +2,8 @@ from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Subnet import subnet
from interface_openstack.interface.network.SubnetManager import subnet_manager
from interface_openstack.interface.network import Subnet
from interface_openstack.interface.network import SubnetManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
......
......@@ -15,7 +15,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
# TODO: gestionar els rangs de ports lliures/ocupats i floating ips? aquí o al django o on?
# el delete el podem fer a partir de la ip i no de la instance_id
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......@@ -27,10 +26,9 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
floating_ip.port_forwardings = [
PortForwarding(item, floating_ip.address) for item in items]
#self.port_forwardings = [
# self.port_forwardings = [
# PortForwarding(item) for item in self.openstack.network.port_forwardings(self.floating_ips[0].id)]
@OpenStackError
def create_port_forwarding(self, instance_id, internal_port_number, protocol):
"""DUBTE hem de gestionar condicions com ara que no estigui creat ja
......@@ -39,6 +37,13 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
Les floating ips estan separades de la ip on hi ha les apis dels serveis
d'openstack? Perquè en devstack no, i no es pot habilitar un port extern
que ja es faci servir (s'ha de restringir)?
via Google Translate
DO WE HAVE to deal with conditions such as that an equal forwarding port is no longer created,
that the floating_ip is not active, that it is not associated with a router, etc.?
Are floating ips separate from the ip where are the openstack services apis?
Why not in devstack, and can't enable an external port that is already in use (must be restricted)?
"""
project_id = self.openstack.auth['project_id']
......@@ -66,13 +71,12 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
# more handcrafted alternatives
#res = self.openstack.network.post(
# res = self.openstack.network.post(
# f"/floatingips/{floating_ip_id}/port_forwardings", json=payload)
#r = requests.post("http://vm.niif.cloud.bme.hu:18686/v2.0/floatingips" \
# r = requests.post("http://vm.niif.cloud.bme.hu:18686/v2.0/floatingips" \
# f"/{floating_ip_id}/port_forwardings", data = payload)
#r.json()
# r.json()
@OpenStackError
def delete_port_forwarding(self, instance_id, internal_port_number):
......@@ -89,7 +93,7 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
for floating_ip in self.openstack.list_floating_ips():
for port_forwarding in floating_ip.port_forwardings:
if ((port_forwarding.internal_ip_address == internal_ip_address)
and (port_forwarding.internal_port == internal_port_number)):
and (port_forwarding.internal_port == internal_port_number)):
# found
floating_ip_id = floating_ip.id
break
......@@ -100,13 +104,12 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
port_forwarding_id = None
for port_forwarding in self.openstack.network.floating_ip_port_forwardings(floating_ip_id):
if ((port_forwarding.internal_ip_address == internal_ip_address)
and (port_forwarding.internal_port == internal_port_number)):
and (port_forwarding.internal_port == internal_port_number)):
port_forwarding_id = port_forwarding.id
self.openstack.network.delete_port_forwarding(
port_forwarding_id, floating_ip_id)
@OpenStackError
def list_instance_port_forwardings(self, instance_id):
""" Lists all port forwarding rules defined from a vm instance
......@@ -126,7 +129,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
return instance_port_forwardings
def __get_internal_port_object_from_instance_id(self, instance_id):
""" Fetches Neutron internal port object from instance_id
"""
......@@ -140,7 +142,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
return internal_port_object
def __obtain_free_port_by_floating_ip_id(self, floating_ip_id):
""" Pot una vm tenir port forwardings en diferents floating ips?
"""
......
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