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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
43 deletions
+45
-43
implementation/network/interfaces.py
+16
-17
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
+13
-12
No files found.
implementation/network/interfaces.py
View file @
5ee369c7
...
...
@@ -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
...
...
implementation/network/openstack_floating_ip_manager.py
View file @
5ee369c7
...
...
@@ -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_m
anager
from
interface_openstack.interface.network
import
FloatingIP
from
interface_openstack.interface.network
import
FloatingIPM
anager
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
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Network
import
n
etwork
from
interface_openstack.interface.network
.NetworkManager
import
network_m
anager
from
interface_openstack.interface.network
import
N
etwork
from
interface_openstack.interface.network
import
NetworkM
anager
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
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Port
import
p
ort
from
interface_openstack.interface.network
.PortManager
import
port_m
anager
from
interface_openstack.interface.network
import
P
ort
from
interface_openstack.interface.network
import
PortM
anager
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
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Router
import
r
outer
from
interface_openstack.interface.network
.RouterManager
import
router_m
anager
from
interface_openstack.interface.network
import
R
outer
from
interface_openstack.interface.network
import
RouterM
anager
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
)
...
...
implementation/network/openstack_subnet_manager.py
View file @
5ee369c7
...
...
@@ -2,8 +2,8 @@ from typing import Optional
from
openstack.exceptions
import
ResourceNotFound
from
interface_openstack.interface.network
.Subnet
import
s
ubnet
from
interface_openstack.interface.network
.SubnetManager
import
subnet_m
anager
from
interface_openstack.interface.network
import
S
ubnet
from
interface_openstack.interface.network
import
SubnetM
anager
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
...
...
implementation/network/port_forwarding.py
View file @
5ee369c7
...
...
@@ -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?
"""
...
...
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