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
5ee369c7
authored
Aug 01, 2020
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add code style and import changes
parent
a011c0fa
Pipeline
#1344
failed with stage
in 31 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
37 deletions
+39
-37
implementation/network/interfaces.py
+12
-13
implementation/network/openstack_floating_ip_manager.py
+2
-2
implementation/network/openstack_network_manager.py
+2
-2
implementation/network/openstack_port_manager.py
+2
-2
implementation/network/openstack_router_manager.py
+8
-6
implementation/network/openstack_subnet_manager.py
+2
-2
implementation/network/port_forwarding.py
+11
-10
No files found.
implementation/network/interfaces.py
View file @
5ee369c7
...
@@ -7,11 +7,9 @@ from implementation.utils.decorators import OpenStackError
...
@@ -7,11 +7,9 @@ from implementation.utils.decorators import OpenStackError
class
OSNetworkInterfacesManager
(
NetworkInterfacesInterface
,
OpenStackConnection
):
class
OSNetworkInterfacesManager
(
NetworkInterfacesInterface
,
OpenStackConnection
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
super
()
.
__init__
(
*
args
,
**
kwargs
)
@OpenStackError
@OpenStackError
def
create_interface
(
self
,
name
):
def
create_interface
(
self
,
name
):
""" Creates a set of OpenStack resources to provide the functionality of
""" Creates a set of OpenStack resources to provide the functionality of
...
@@ -28,7 +26,8 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -28,7 +26,8 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
is_router_external
=
True
)]
.
pop
()
.
id
is_router_external
=
True
)]
.
pop
()
.
id
# create the router
# 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
,
external_gateway_info
=
{
'network_id'
:
public_network_id
,
'enable_snat'
:
True
},
is_admin_state_up
=
True
)
'enable_snat'
:
True
},
is_admin_state_up
=
True
)
...
@@ -37,12 +36,14 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -37,12 +36,14 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
is_admin_state_up
=
True
,
name
=
name
)
is_admin_state_up
=
True
,
name
=
name
)
# create the IPv4 subnet
# 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
,
ip_version
=
4
,
is_dhcp_enabled
=
True
,
use_default_subnet_pool
=
True
,
network_id
=
network
.
id
)
network_id
=
network
.
id
)
# create the IPv6 subnet
# 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
,
ip_version
=
6
,
is_dhcp_enabled
=
True
,
use_default_subnet_pool
=
True
,
network_id
=
network
.
id
)
network_id
=
network
.
id
)
...
@@ -54,7 +55,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -54,7 +55,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
# return the equivalent "interface id"
# return the equivalent "interface id"
return
interface
return
interface
@OpenStackError
@OpenStackError
def
delete_interface
(
self
,
interface
):
def
delete_interface
(
self
,
interface
):
""" Deletes the set of OpenStack resources that represent the specified
""" Deletes the set of OpenStack resources that represent the specified
...
@@ -90,7 +90,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -90,7 +90,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
# delete the network, which should be free of ports (except the network:dhcp)
# delete the network, which should be free of ports (except the network:dhcp)
self
.
openstack
.
network
.
delete_network
(
interface
.
id
)
self
.
openstack
.
network
.
delete_network
(
interface
.
id
)
@OpenStackError
@OpenStackError
def
add_vm_to_interface
(
self
,
device_id
,
interface
):
def
add_vm_to_interface
(
self
,
device_id
,
interface
):
""" Attaches the specified device to a "vlan" identified by the
""" Attaches the specified device to a "vlan" identified by the
...
@@ -105,24 +104,25 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -105,24 +104,25 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
project_id
=
self
.
openstack
.
auth
[
'project_id'
]
project_id
=
self
.
openstack
.
auth
[
'project_id'
]
#for subnet in self.openstack.network.subnets(network_id=interface.id):
# for subnet in self.openstack.network.subnets(network_id=interface.id):
port
=
self
.
openstack
.
network
.
create_port
(
project_id
=
project_id
,
port
=
self
.
openstack
.
network
.
create_port
(
project_id
=
project_id
,
network_id
=
interface
.
id
,
is_admin_state_up
=
True
,
network_id
=
interface
.
id
,
is_admin_state_up
=
True
,
device_id
=
device_id
,
device_owner
=
"compute:nova"
,
device_id
=
device_id
,
device_owner
=
"compute:nova"
,
is_port_security_enabled
=
True
,
binding_vnic_type
=
"normal"
)
is_port_security_enabled
=
True
,
binding_vnic_type
=
"normal"
)
#fixed_ips=[{
# fixed_ips=[{
# 'subnet_id': subnet.id,
# 'subnet_id': subnet.id,
# 'ip_address': '29.29.29.29'}]
# 'ip_address': '29.29.29.29'}]
# adds a fixed IP address from the network (interface.id) to a server
# adds a fixed IP address from the network (interface.id) to a server
# instance (device_id)
# 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
)
interface
.
set_port
(
port
)
return
interface
return
interface
@OpenStackError
@OpenStackError
def
remove_vm_from_interface
(
self
,
interface
):
def
remove_vm_from_interface
(
self
,
interface
):
""" Detaches the specified device from the "vlan".
""" Detaches the specified device from the "vlan".
...
@@ -133,7 +133,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
...
@@ -133,7 +133,6 @@ class OSNetworkInterfacesManager(NetworkInterfacesInterface, OpenStackConnection
self
.
openstack
.
network
.
delete_port
(
interface
.
port
.
id
)
self
.
openstack
.
network
.
delete_port
(
interface
.
port
.
id
)
@OpenStackError
@OpenStackError
def
list_all_vm_interfaces
(
self
,
device_id
):
def
list_all_vm_interfaces
(
self
,
device_id
):
""" Fetches network ports from the vm instance, to find the networks
""" Fetches network ports from the vm instance, to find the networks
...
...
implementation/network/openstack_floating_ip_manager.py
View file @
5ee369c7
...
@@ -2,8 +2,8 @@ from typing import Optional
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.FloatingIP
import
floating_ip
from
interface_openstack.interface.network
import
FloatingIP
from
interface_openstack.interface.network
.FloatingIPManager
import
floating_ip_m
anager
from
interface_openstack.interface.network
import
FloatingIPM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
...
implementation/network/openstack_network_manager.py
View file @
5ee369c7
...
@@ -2,8 +2,8 @@ from typing import Optional
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Network
import
n
etwork
from
interface_openstack.interface.network
import
N
etwork
from
interface_openstack.interface.network
.NetworkManager
import
network_m
anager
from
interface_openstack.interface.network
import
NetworkM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
...
implementation/network/openstack_port_manager.py
View file @
5ee369c7
...
@@ -2,8 +2,8 @@ from typing import Optional
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Port
import
p
ort
from
interface_openstack.interface.network
import
P
ort
from
interface_openstack.interface.network
.PortManager
import
port_m
anager
from
interface_openstack.interface.network
import
PortM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
...
implementation/network/openstack_router_manager.py
View file @
5ee369c7
...
@@ -2,8 +2,8 @@ from typing import Optional
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Router
import
r
outer
from
interface_openstack.interface.network
import
R
outer
from
interface_openstack.interface.network
.RouterManager
import
router_m
anager
from
interface_openstack.interface.network
import
RouterM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
@@ -43,16 +43,18 @@ class OpenstackRouterManager(RouterManager, OpenStackConnection):
...
@@ -43,16 +43,18 @@ class OpenstackRouterManager(RouterManager, OpenStackConnection):
def
add_interface
(
self
,
id
,
subnet_id
):
def
add_interface
(
self
,
id
,
subnet_id
):
try
:
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
:
except
ResourceNotFound
:
return
None
return
None
return
self
.
os_router_to_rc_router
(
os_router
)
return
self
.
os_router_to_rc_router
(
os_router
)
def
add_gateway
(
self
,
id
,
network_id
):
def
add_gateway
(
self
,
id
,
network_id
):
#try:
# try:
os_router
=
self
.
openstack
.
network
.
add_gateway_to_router
(
id
,
external_gateway_info
=
network_id
)
os_router
=
self
.
openstack
.
network
.
add_gateway_to_router
(
#except ResourceNotFound:
id
,
external_gateway_info
=
network_id
)
# except ResourceNotFound:
# return None
# return None
print
(
os_router
)
print
(
os_router
)
...
...
implementation/network/openstack_subnet_manager.py
View file @
5ee369c7
...
@@ -2,8 +2,8 @@ from typing import Optional
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Subnet
import
s
ubnet
from
interface_openstack.interface.network
import
S
ubnet
from
interface_openstack.interface.network
.SubnetManager
import
subnet_m
anager
from
interface_openstack.interface.network
import
SubnetM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
...
implementation/network/port_forwarding.py
View file @
5ee369c7
...
@@ -15,7 +15,6 @@ class OSPortForwardingManager(PortForwardingInterface, 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?
# 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
# el delete el podem fer a partir de la ip i no de la instance_id
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
super
()
.
__init__
(
*
args
,
**
kwargs
)
...
@@ -27,10 +26,9 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -27,10 +26,9 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
floating_ip
.
port_forwardings
=
[
floating_ip
.
port_forwardings
=
[
PortForwarding
(
item
,
floating_ip
.
address
)
for
item
in
items
]
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)]
# PortForwarding(item) for item in self.openstack.network.port_forwardings(self.floating_ips[0].id)]
@OpenStackError
@OpenStackError
def
create_port_forwarding
(
self
,
instance_id
,
internal_port_number
,
protocol
):
def
create_port_forwarding
(
self
,
instance_id
,
internal_port_number
,
protocol
):
"""DUBTE hem de gestionar condicions com ara que no estigui creat ja
"""DUBTE hem de gestionar condicions com ara que no estigui creat ja
...
@@ -39,6 +37,13 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -39,6 +37,13 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
Les floating ips estan separades de la ip on hi ha les apis dels serveis
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
d'openstack? Perquè en devstack no, i no es pot habilitar un port extern
que ja es faci servir (s'ha de restringir)?
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'
]
project_id
=
self
.
openstack
.
auth
[
'project_id'
]
...
@@ -66,13 +71,12 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -66,13 +71,12 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
# more handcrafted alternatives
# more handcrafted alternatives
#res = self.openstack.network.post(
#
res = self.openstack.network.post(
# f"/floatingips/{floating_ip_id}/port_forwardings", json=payload)
# 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)
# f"/{floating_ip_id}/port_forwardings", data = payload)
#r.json()
# r.json()
@OpenStackError
@OpenStackError
def
delete_port_forwarding
(
self
,
instance_id
,
internal_port_number
):
def
delete_port_forwarding
(
self
,
instance_id
,
internal_port_number
):
...
@@ -106,7 +110,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -106,7 +110,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
self
.
openstack
.
network
.
delete_port_forwarding
(
self
.
openstack
.
network
.
delete_port_forwarding
(
port_forwarding_id
,
floating_ip_id
)
port_forwarding_id
,
floating_ip_id
)
@OpenStackError
@OpenStackError
def
list_instance_port_forwardings
(
self
,
instance_id
):
def
list_instance_port_forwardings
(
self
,
instance_id
):
""" Lists all port forwarding rules defined from a vm instance
""" Lists all port forwarding rules defined from a vm instance
...
@@ -126,7 +129,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -126,7 +129,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
return
instance_port_forwardings
return
instance_port_forwardings
def
__get_internal_port_object_from_instance_id
(
self
,
instance_id
):
def
__get_internal_port_object_from_instance_id
(
self
,
instance_id
):
""" Fetches Neutron internal port object from instance_id
""" Fetches Neutron internal port object from instance_id
"""
"""
...
@@ -140,7 +142,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
...
@@ -140,7 +142,6 @@ class OSPortForwardingManager(PortForwardingInterface, OpenStackConnection):
return
internal_port_object
return
internal_port_object
def
__obtain_free_port_by_floating_ip_id
(
self
,
floating_ip_id
):
def
__obtain_free_port_by_floating_ip_id
(
self
,
floating_ip_id
):
""" Pot una vm tenir port forwardings en diferents floating ips?
""" Pot una vm tenir port forwardings en diferents floating ips?
"""
"""
...
...
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