1
votes

I try to create a small python app to create/delete instances on a fresh DevStack install. Following the documentation, I have this code:

#!/usr/bin/env python

import os
import openstack
import sys

from openstack import utils

utils.enable_logging(True, stream=sys.stdout)

def create_connection():
    return openstack.connect(
            auth_url='http://127.0.0.1:5000/v2.0',
            project_name='demo',
            username='demo',
            password='secret',
            region_name='RegionOne',
            app_name='nfvm',
            app_version='1.0',
    )

con = create_connection()

Which produce the following error:

Traceback (most recent call last):
  File "nfvm.py", line 22, in <module>
    con = create_connection()
  File "nfvm.py", line 12, in create_connection
    return openstack.connect(
AttributeError: 'module' object has no attribute 'connect'  

What am I doing wrong ? Thank you in advance.

2
If you do pip freeze | grep openstacksdk what does it say? - eandersson
@eandersson 'openstacksdk==0.13.0' - Nakrule

2 Answers

2
votes

You most likely have another file in the same directory called openstack.py, or a folder with the name openstack.

Delete or re-name that file and you should be good to go.

1
votes

Solved, I dont know why, but you have to import some Openstack module explicitly:

from openstack import connection

Then use the following:

return connection.Connection(
...
)