[openstack-dev] [sdk] issues with using OpenStack SDK Python client

gerard.damm at wipro.com gerard.damm at wipro.com
Fri May 4 18:34:36 UTC 2018


Hi everybody,

As a bit of a novice, I'm trying to use OpenStack SDK 0.13 in an OPNFV/ONAP project (Auto).

I'm able to use the compute and network proxies, but have problems with the identity proxy,
so I can't create projects and users.
With network, I can create a network, a router, router interfaces, but can't add a gateway to a router. Also, deleting a router fails.
With compute, I can't create flavors, and not sure if there is a "create_image" method ?

Specific issues are listed below with more details.

Any pointers (configuration, installation, usage, ...) and URLs to examples and documentation would be welcome.
For documentation, I've been looking mostly at:
https://docs.openstack.org/openstacksdk/latest/user/proxies/network.html
https://docs.openstack.org/openstacksdk/latest/user/proxies/compute.html
https://docs.openstack.org/openstacksdk/latest/user/proxies/identity_v3.html

Thanks in advance,
Gerard




For all code, import statement and Connection creation is as follows (constants defined before):
import openstack
conn = openstack.connect(cloud=OPENSTACK_CLOUD_NAME, region_name=OPENSTACK_REGION_NAME)


1) problem adding a gateway (external network) to a router:
not sure how to build a dictionary body (couldn't find examples online)

tried this:
network_dict_body = {'network_id': public_network.id}

and this (from looking at a router printout):
network_dict_body = {
    'external_fixed_ips': [{'subnet_id' : public_subnet.id}],
    'network_id': public_network.id
}

in both cases, tried this command:
conn.network.add_gateway_to_router(onap_router,network_dict_body)

getting the error:
Exception: <class 'TypeError'> add_gateway_to_router() takes 2 positional arguments but 3 were given

printing the router gave this:
openstack.network.v2.router.Router(distributed=False, tenant_id=03aa47d3bcfd48199e0470b1c86a7f5b, created_at=2018-05-01T01:16:08Z, external_gateway_info=None, status=ACTIVE, availability_zone_hints=[], ha=False, tags=[], description=Router created for ONAP, admin_state_up=True, revision=1, flavor_id=None, id=b923fba5-5027-47b6-b679-29c331ac1aba, updated_at=2018-05-01T01:16:08Z, routes=[], name=onap_router, availability_zones=[])


2) problem deleting routers:
onap_router = conn.network.find_router(ONAP_ROUTER_NAME)
conn.network.delete_router(onap_router.id)
(same if conn.network.delete_router(onap_router))

getting the error:
Exception: <class 'AttributeError'> 'NoneType' object has no attribute '_body'

printing the router that had been created gave this:
openstack.network.v2.router.Router(description=Router created for ONAP, status=ACTIVE, routes=[], updated_at=2018-05-01T01:16:11Z, ha=False, id=b923fba5-5027-47b6-b679-29c331ac1aba, external_gateway_info=None, admin_state_up=True, availability_zone_hints=[], tenant_id=03aa47d3bcfd48199e0470b1c86a7f5b, name=onap_router, availability_zones=['nova'], tags=[], revision=3, distributed=False, flavor_id=None, created_at=2018-05-01T01:16:08Z)



3) problem reaching the identity service:
(although I can reach compute and network services, and although there are users and projects in the Openstack instance: "admin" and "service" projects, "ceilometer", "nova", etc. (and "admin") users)

        print("\nList Users:")
        i=1
        for user in conn.identity.users():
            print('User',str(i),'\n',user,'\n')
            i+=1

getting the error:
List Users:
Exception: <class 'openstack.exceptions.NotFoundException'> NotFoundException: 404

        print("\nList Projects:")
        i=1
        for project in conn.identity.projects():
            print('Project',str(i),'\n',project,'\n')
            i+=1

also getting an error, but not the same as users:
List Projects:
Exception: <class 'AttributeError'> 'Proxy' object has no attribute 'projects'


if trying to create a project:

        onap_project = conn.identity.find_project(ONAP_TENANT_NAME)
        if onap_project != None:
            print('ONAP project/tenant already exists')
        else:
            print('Creating ONAP project/tenant...')
            onap_project = conn.identity.create_project(
                name = ONAP_TENANT_NAME,
                description = ONAP_TENANT_DESC,
                is_enabled = True)


getting the error:
Exception: <class 'AttributeError'> 'Proxy' object has no attribute 'find_project'


4) problem creating flavors:

        tiny_flavor = conn.compute.find_flavor("m1.tiny")
        if tiny_flavor != None:
            print('m1.tiny Flavor already exists')
       else:
            print('Creating m1.tiny Flavor...')
            tiny_flavor = conn.compute.create_flavor(
                name = 'm1.tiny',
                vcpus = 1,
                disk = 1,
                ram = 512,
                ephemeral = 0,
                #swap = 0,
                #rxtx_factor = 1.0,
                is_public = True)

(by the way, maybe swap and rxtx are not supposed to be set ?)

getting the error:
Exception: <class 'AttributeError'> 'NoneType' object has no attribute '_body'


5) how to create images ?
there is a compute proxy method: find_image()
but it looks like there is no create_image() ?

say you wanted to add this image: Ubuntu Server 16.04 LTS (Xenial Xerus)
https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
how would you do it ?



openstacksdk version 0.13.0 is installed:

$ pip3 list
Package             Version
------------------- ---------
appdirs             1.4.3
certifi             2018.4.16
chardet             3.0.4
command-not-found   0.3
decorator           4.3.0
deprecation         2.0.2
dogpile.cache       0.6.5
idna                2.6
iso8601             0.1.12
jmespath            0.9.3
jsonpatch           1.23
jsonpointer         2.0
keystoneauth1       3.5.0
language-selector   0.1
munch               2.3.1
netifaces           0.10.6
openstacksdk        0.13.0
os-service-types    1.2.0
packaging           17.1
pbr                 4.0.2
pip                 10.0.1
pycurl              7.43.0
pygobject           3.20.0
pyparsing           2.2.0
python-apt          1.1.0b1
python-debian       0.1.27
python-systemd      231
PyYAML              3.12
requests            2.18.4
requestsexceptions  1.4.0
setuptools          20.7.0
six                 1.10.0
ssh-import-id       5.5
stevedore           1.28.0
ufw                 0.35
unattended-upgrades 0.1
urllib3             1.22
wheel               0.29.0

$ pip3 check
No broken requirements found.



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20180504/fd144045/attachment.html>


More information about the OpenStack-dev mailing list