[python-openstacksdk] Create a new Keystone auth session with a profile.

asked 2016-03-30 07:08:49 -0500

Stavros gravatar image

I am trying to execute the following python script:

import sys
import os

from openstack import connection
from openstack import profile
from openstack import session

prof = profile.Profile()
prof.set_region(prof.ALL, "RegionOne")

action = {'reboot': {'type': 'SOFT'}}

auth_args = {
    'auth_url': 'http://cloud.XXXXX.net:5000/v2.0/',
    'project_name': 'xxxxxx',
    'username': 'xxxxxxx',
    'password': 'xxxxxxx',
    'profile': prof}

conn = connection.Connection(**auth_args)

sess = session.Session(profile=prof, user_agent=None)

for server in conn.compute.servers():
    if server.metadata:
        if server.status == "ACTIVE" and server.metadata['ENV'] == os.getenv('ENV'):
            server.action(session=sess, body=action)

and I get the following error message:

Traceback (most recent call last):
  File "E:\Temp\d.py", line 32, in <module>
    server.action(session=sess, body=action)
  File "E:\Python\lib\site-packages\openstack\compute\v2\server.py", line 92, in action
    url, endpoint_filter=self.service, json=body, headers=headers)
  File "E:\Python\lib\site-packages\keystoneauth1\session.py", line 572, in post
    return self.request(url, 'POST', **kwargs)
  File "E:\Python\lib\site-packages\openstack\session.py", line 65, in map_exceptions_wrapper
    raise exceptions.SDKException(message=e.message, cause=e)
openstack.exceptions.SDKException: An authenticated request is required but no plugin available.

I think that the script doesn't create a new session, right?

Could someone give me a tip?

Thank you in advance!

edit retag flag offensive close merge delete