Commit d0818f18 by Arnau Comas Codina

Network Interfaces

parent 84275444
Pipeline #1099 failed with stage
in 47 seconds
from interface.network.interfaces import NetworkInterfacesInterface
from interface.network.resources import Port
from implementation.utils.connection import OpenStackConnection
from implementation.utils.decorators import OpenStackError
class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@OpenStackError
def create_interface(self):
""" Creates a set of OpenStack resources to provide the functionality of
a "vlan". These resources consists of a router connected to public
network, a network and a subnet, where the instance gets the local ip
"""
project_id = self.openstack.auth['project_id']
# fetch public network
public_network_id = [item for item in self.openstack.network.networks(
is_router_external=True)].pop().id
# create the router
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)
# create the network which will hold the subnets
network = self.openstack.network.create_network(project_id=project_id,
is_admin_state_up=True)
# create the IPv4 subnet
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,
ip_version=6, is_dhcp_enabled=True, use_default_subnet_pool=True,
network_id=network.id)
# attach subnets to router
self.openstack.network.add_interface_to_router(router, subnet_v4.id)
self.openstack.network.add_interface_to_router(router, subnet_v6.id)
# return the equivalent "interface id"
return network.id
@OpenStackError
def delete_interface(self, interface_id):
""" Deletes the set of OpenStack resources that represent the specified
"vlan" identified by the "interface_id" param. These are conformed by a
router, a network and a subnet, if and only if there are no devices
attached.
"""
# DUBTE
# should all ports from the network be clean up, which will cause to
# unattach existing "VMs" from the network interface? if not, removal
# won't be allowed if there're "VMs" attached remaining
# obtain router_id and remove+delete all their interfaces
router_id = None
for port in self.openstack.network.ports(network_id=interface_id):
if port.device_owner == "network:router_interface":
router_id = port.device_id
for fixed_ip in port.fixed_ips:
self.openstack.network.remove_interface_from_router(
router_id, fixed_ip['subnet_id'], port.id)
self.openstack.network.delete_port(port)
# clean subnets
for subnet in self.openstack.network.subnets(network_id=interface_id):
self.openstack.network.delete_subnet(subnet)
# delete the router and its port to the network
self.openstack.network.delete_router(router_id)
# 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, interface_id):
""" Attaches the specified device to a "vlan" identified by the
"interface_id" param. This translates on creating a network port into
the corresponding "vlan" and thus assign an ip to the device.
Note that further actions may be required depending on the "vm" to
activate and configure the new interface.
"""
pass
@OpenStackError
def remove_vm_from_interface(self, interface_id):
""" Detaches the specified device from the "vlan" identified by the
"interface_id" param.
Note that further actions may be required depending on the "vm" to
activate and configure the new interface.
"""
pass
@OpenStackError
def list_all_vm_interfaces(self):
"""
"""
pass
......@@ -4,7 +4,6 @@ from interface.network.resources import Port, FloatingIP, PortForwarding
from implementation.utils.connection import OpenStackConnection
from implementation.utils.decorators import OpenStackError
import logging
import random
# for limiting the ones that can be allocated over floating ips
......
......@@ -10,11 +10,14 @@ class NetworkInterfacesInterface:
def create_interface(self, vlan):
raise NotImplementedError
def remove_interface(self, vlan):
def delete_interface(self, vlan):
raise NotImplementedError
def list_all_vlans(self):
def add_vm_to_interface(self):
raise NotImplementedError
def list_all_interfaces(self):
def remove_vm_from_interface(self):
raise NotImplementedError
def list_all_vm_interfaces(self):
raise NotImplementedError
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