Python neutronclient session failed request

asked 2019-03-06 12:43:25 -0500

frenchtoasters gravatar image

updated 2019-03-06 15:56:43 -0500

I am trying to use the python-neutronclient and creating my connection via a keystone session variable however no matter what call i do for neutron I have a hard fail because self.endpoint_url is not defined, thus i am unable to run the _check_uri_length function when making a call. Looking at the call to SessionClienthere https://github.com/openstack/python-neutronclient/blob/master/neutronclient/client.py#L407 (https://github.com/openstack/python-n...) endpoint_url is defined here however it is never passed to the SessionClient class. Yet the class still calls the self.endpoint_url which returns None. I have tried passing this variable a couple different places and I see that it is being passed to construct_http_client however it does not get passed to the SessionClient class.

import argparse
import sys
import os

from keystoneauth1 import loading as ks_loading
from keystoneclient.v3 import client as ks_client
from neutronclient.v2_0 import client as neutron_client    

class OpenStack(object):
    def __repr__(self):
        return "<Server: %s>" % self.data

    def __init__(self, args):
        # get a connection based on those args/vars
        self.auth = ks_loading.load_auth_from_argparse_arguments(args)
        self.sess = ks_loading.load_session_from_argparse_arguments(args, auth=self.auth)
        self._os = ks_client.Client(session=self.sess)
        self._neutron = neutron_client.Client(endpoint_url="https://openstack.future.lab:9696/", 
version=os.getenv('OS_NETWORK_API_VERSION', '2.1'), session=self.sess)
        self._data = dict(
            projects = [],
        )

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        return 0


def main(argv=None):
    # support OS_* environment variables and/or --os-* arguments
    parser = argparse.ArgumentParser()
    ks_loading.register_auth_argparse_arguments(parser, sys.argv[1:], default='v3password')
    ks_loading.register_session_argparse_arguments(parser)
    args = parser.parse_args()

    with OpenStack(args) as OS:
       projects = OS._os.projects.list()
       for project in projects:
           temp = {}
           temp['name'] = project.name
           temp['_id'] = project.id
           neutron_quota = OS._neutron.show_quota(project_id=project.id)
           print(neutron_quota)

if __name__ == '__main__':
    main()

The error that im getting is:

Traceback (most recent call last):
  File "qutoaparser.py", line 70, in <module>
    main()
  File "qutoaparser.py", line 63, in main
    neutron_quota = power_vc._neutron.show_quota(project_id=project.id)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/debtcollector/renames.py", line 43, in decorator
    return wrapped(*args, **kwargs)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/v2_0/client.py", line 753, in 
show_quota
    return self.get(self.quota_path % (project_id), params=_params)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/v2_0/client.py", line 353, in get
    headers=headers, params=params)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/v2_0/client.py", line 330, in 
retry_request
    headers=headers, params=params)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/v2_0/client.py", line 281, in 
do_request
    headers=headers)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/client.py", line 348, in do_request
    self._check_uri_length(url)
  File "/home/ubuntu/powervc/venv/lib/python3.7/site-packages/neutronclient/client.py", line 335, in _ 
 check_uri_length
    uri_len = len(self.endpoint_url) + len(url)
TypeError: object of type 'NoneType' has no len()
edit retag flag offensive close merge delete