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
9bd6841c
authored
May 13, 2019
by
edems
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OpenstackFloatingIPManager added
parent
63c0becf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
2 deletions
+88
-2
implementation/network/OpenstackFloatingIPManager.py
+67
-0
main.py
+21
-2
No files found.
implementation/network/OpenstackFloatingIPManager.py
0 → 100644
View file @
9bd6841c
from
typing
import
Optional
from
openstack.exceptions
import
ResourceNotFound
from
interface.network.FloatingIP
import
FloatingIP
from
interface.network.FloatingIPManager
import
FloatingIPManager
class
OpenstackFloatingIPManager
(
FloatingIPManager
):
def
__init__
(
self
,
openstack
)
->
None
:
super
()
.
__init__
()
self
.
openstack
=
openstack
@staticmethod
def
os_floating_ip_to_rc_floating_ip
(
os_floating_ip
)
->
FloatingIP
:
return
FloatingIP
(
os_floating_ip
.
id
,
os_floating_ip
.
router_id
,
os_floating_ip
.
floating_network_id
,
os_floating_ip
.
subnet_id
,
os_floating_ip
.
port_id
,
os_floating_ip
.
name
,
os_floating_ip
.
fixed_ip_address
,
os_floating_ip
.
floating_ip_address
,
os_floating_ip
.
status
,
os_floating_ip
.
created_at
,
os_floating_ip
.
updated_at
)
def
create
(
self
,
floating_network_id
)
->
FloatingIP
:
os_floating_ip
=
self
.
openstack
.
network
.
create_ip
(
floating_network_id
=
floating_network_id
)
return
self
.
os_floating_ip_to_rc_floating_ip
(
os_floating_ip
)
def
get
(
self
,
id
)
->
Optional
[
FloatingIP
]:
try
:
os_floating_ip
=
self
.
openstack
.
network
.
get_ip
(
id
)
except
ResourceNotFound
:
return
None
return
self
.
os_floating_ip_to_rc_floating_ip
(
os_floating_ip
)
def
update
(
self
,
id
,
params
)
->
Optional
[
FloatingIP
]:
try
:
os_floating_ip
=
self
.
openstack
.
network
.
update_ip
(
id
,
**
params
)
except
ResourceNotFound
:
return
None
return
self
.
os_floating_ip_to_rc_floating_ip
(
os_floating_ip
)
def
delete
(
self
,
id
)
->
bool
:
try
:
self
.
openstack
.
network
.
delete_ip
(
id
)
except
ResourceNotFound
:
return
False
return
True
def
list
(
self
)
->
[]:
floating_ips
=
[]
for
os_floating_ip
in
self
.
openstack
.
floating_ip
.
ips
():
floating_ips
.
append
(
self
.
os_floating_ip_to_rc_floating_ip
(
os_floating_ip
))
return
floating_ips
main.py
View file @
9bd6841c
...
...
@@ -2,7 +2,9 @@
import
openstack
from
implementation.network.OpenstackFloatingIPManager
import
OpenstackFloatingIPManager
from
implementation.network.OpenstackNetworkManager
import
OpenstackNetworkManager
from
implementation.network.OpenstackPortManager
import
OpenstackPortManager
from
implementation.network.OpenstackRouterManager
import
OpenstackRouterManager
from
implementation.network.OpenstackSubnetManager
import
OpenstackSubnetManager
...
...
@@ -11,6 +13,8 @@ os = openstack.connect(cloud='openstack')
router_manager
=
OpenstackRouterManager
(
os
)
network_manager
=
OpenstackNetworkManager
(
os
)
subnet_manager
=
OpenstackSubnetManager
(
os
)
port_manager
=
OpenstackPortManager
(
os
)
floating_ip_manager
=
OpenstackFloatingIPManager
(
os
)
#router = router_manager.create()
router
=
router_manager
.
get
(
'3ee87bcd-b1b5-4e14-86a1-ce691bd3e5a2'
)
...
...
@@ -34,6 +38,21 @@ print('Subnet:')
print
(
'
\t
Public:
%
s'
%
public_subnet
)
print
(
'
\t
Inner:
%
s'
%
inner_subnet
)
vm_port
=
port_manager
.
get
(
'bd1f0753-613d-4ecf-8605-eacc3ca63373'
)
# inner
print
(
'Port:'
)
print
(
'
\t
VM:
%
s'
%
vm_port
)
#floating_ip = floating_ip_manager.create(public_network.id)
floating_ip
=
floating_ip_manager
.
get
(
'df353eb0-9f0b-4bee-9492-148e29873450'
)
print
(
'Floating IP:'
)
print
(
'
\t
Floating IP:
%
s'
%
floating_ip
)
#print(router_manager.add_interface(router.id, subnet.id))
#print(router_manager.add_interface(router.id, public_subnet.id))
\ No newline at end of file
#print(router_manager.add_gateway(router.id, public_network.id)) # TODO: fix it!
# print(floating_ip_manager.update(floating_ip.id, {
# 'port_id': vm_port.id
# }))
\ No newline at end of file
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