Created
March 1, 2016 11:10
-
-
Save djoreilly/888abbfc3425e54fa290 to your computer and use it in GitHub Desktop.
Howto use the python-novaclient and python-neutronclient with Keystone V3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.openstack.org/developer/keystoneauth/index.html | |
# http://www.jamielennox.net/blog/2014/09/15/how-to-use-keystoneclient-sessions/ | |
# In iPython: execfile('path/to/this/file') | |
import os | |
import logging | |
from keystoneauth1.identity import v3 | |
from keystoneauth1 import session | |
import requests | |
# suppress warning | |
requests.packages.urllib3.disable_warnings() | |
# logging.basicConfig(level=logging.DEBUG) | |
logging.basicConfig(level=logging.INFO) | |
LOG = logging.getLogger(__name__) | |
if os.environ.get('http_proxy') or os.environ.get('https_proxy'): | |
LOG.WARN("Proxy env vars set") | |
# TODO howto pass internalURL | |
auth = v3.Password(auth_url=os.environ['OS_AUTH_URL'], | |
username=os.environ['OS_USERNAME'], | |
password=os.environ['OS_PASSWORD'], | |
project_name=os.environ['OS_PROJECT_NAME'], | |
user_domain_id=os.environ['OS_USER_DOMAIN_NAME'], | |
project_domain_name=os.environ['OS_PROJECT_DOMAIN_NAME']) | |
# sess = session.Session(auth=auth, verify='/path/to/ca.cert') | |
sess = session.Session(auth=auth, verify=False) | |
import novaclient.client | |
novac = novaclient.client.Client(2, session=sess) | |
novac.servers.list() | |
import neutronclient.neutron.client | |
neutc = neutronclient.neutron.client.Client('2.0', session=sess) | |
neutc.list_networks() |
@heidricha instead of importing v3 do:
from keystoneauth1.identity import identity
auth = identity.Password(auth_url=os.environ["OS_AUTH_URL"],
username=os.environ["OS_USERNAME"],
password=os.environ["OS_PASSWORD"],
project_name=os.environ["OS_TENANT_NAME"])
ensure your OS_AUTH_URL ends in v2.0 it should work, I have done it myself.
For reference
Thanks! This works great :) and was what I was looking for! 👯♀️
Thanks!
works like a charm. Thanks for sharing.
It's showing "The request you have made requires authentication.(HTTP 401)" when executing novac.servers.list()
Any help or guidance will be appreciated.
Also I commented out the logging and warning section of the code. (from line 12 to line 22)
For me, changing user_domain_id
at Line#29 to user_domain_name
did the trick.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice and clean!
unfortunately doesn't work for me:
We are using "mitaka", and there's no OS_PROJECT_DOMAIN_NAME environment var at all. Providing default (same as OS_USER_DOMAIN_NAME) drops error on novaclient calls:
Unauthorized: The request you have made requires authentication. (HTTP 401) (Request-ID: req-b7647c0a...)