Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
interface-openstack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0818f18
authored
May 07, 2020
by
Arnau Comas Codina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Network Interfaces
parent
84275444
Pipeline
#1099
failed with stage
in 47 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
4 deletions
+124
-4
implementation/network/interfaces.py
+118
-0
implementation/network/port_forwarding.py
+0
-1
interface/network/interfaces.py
+6
-3
No files found.
implementation/network/interfaces.py
0 → 100644
View file @
d0818f18
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
implementation/network/port_forwarding.py
View file @
d0818f18
...
...
@@ -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
...
...
interface/network/interfaces.py
View file @
d0818f18
...
...
@@ -10,11 +10,14 @@ class NetworkInterfacesInterface:
def
create_interface
(
self
,
vlan
):
raise
NotImplementedError
def
remov
e_interface
(
self
,
vlan
):
def
delet
e_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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment