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
0b5dc350
authored
Dec 02, 2020
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix novclient connection
parent
cc7bd247
Pipeline
#1380
failed with stage
in 11 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
18 deletions
+26
-18
implementation/utils/connection.py
+14
-7
implementation/vm/instance.py
+12
-11
No files found.
implementation/utils/connection.py
View file @
0b5dc350
import
openstack
from
keystoneauth1.identity
import
v3
from
keystoneauth1
import
session
from
keystoneauth1
import
loading
from
novaclient
import
client
class
OpenStackConnection
(
object
):
...
...
@@ -16,10 +17,16 @@ class OpenStackConnection(object):
project_name
=
auth
[
"project_name"
],
region_name
=
auth
[
"region_name"
]
)
client_auth
=
v3
.
Password
(
auth_url
=
auth
[
"auth_url"
],
username
=
auth
[
"username"
],
password
=
auth
[
"password"
],
user_domain_id
=
auth
[
"user_domain_id"
],
project_id
=
auth
[
"project_id"
],)
self
.
client_session
=
session
.
Session
(
auth
=
client_auth
)
loader
=
loading
.
get_plugin_loader
(
'password'
)
auth
=
loader
.
load_from_options
(
auth_url
=
auth
[
"auth_url"
],
username
=
auth
[
"username"
],
user_domain_name
=
"default"
,
password
=
auth
[
"password"
],
project_id
=
auth
[
"project_id"
],
project_name
=
auth
[
"project_name"
])
client_session
=
session
.
Session
(
auth
=
auth
)
self
.
nova_client
=
client
.
Client
(
"2"
,
session
=
client_session
)
implementation/vm/instance.py
View file @
0b5dc350
from
openstack.exceptions
import
SDKException
from
novaclient
import
client
import
logging
from
interface_openstack.implementation.utils.connection
import
OpenStackConnection
import
secrets
...
...
@@ -8,6 +7,7 @@ from interface_openstack.interface.vm.instance import InstanceInterface
from
interface_openstack.interface.vm.resources
import
Instance
,
Flavor
from
interface_openstack.interface.image.image
import
Image
def
openstackError
(
func
):
def
wrap_OpenStackError
(
*
args
,
**
kw
):
""" Decorator to wrap openstack error in simple Exception.
...
...
@@ -17,10 +17,10 @@ def openstackError(func):
try
:
return
func
(
*
args
,
**
kw
)
except
SDKException
as
e
:
logging
.
error
(
e
)
new_e
=
Exception
(
e
)
new_e
.
OpenStackError
=
True
raise
new_e
logging
.
error
(
e
)
new_e
=
Exception
(
e
)
new_e
.
OpenStackError
=
True
raise
new_e
return
wrap_OpenStackError
...
...
@@ -171,13 +171,12 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
image_name
,
metadata
)
image
=
self
.
openstack
.
compute
.
find_image
(
image_name
)
return
self
.
os_image_to_rc_image
(
image
)
return
self
.
os_image_to_rc_image
(
image
)
@openstackError
def
get_vnc_console
(
self
,
server_id
):
with
client
.
Client
(
"2"
,
session
=
self
.
client_session
)
as
nova
:
if
server_id
:
instance
=
nova
.
servers
.
get
(
server_id
)
return
instance
.
get_vnc_console
(
"novnc"
)
instance
=
self
.
nova_client
.
servers
.
get
(
server_id
)
return
instance
.
get_vnc_console
(
"novnc"
)
@openstackError
def
attach_volume
(
self
,
server_id
,
volume_id
,
device
=
None
):
...
...
@@ -209,5 +208,7 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
def
os_image_to_rc_image
(
self
,
os_image
):
return
Image
(
os_image
.
id
,
os_image
.
name
os_image
.
name
,
"unknown"
,
os_image
.
size
)
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