<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 23 February 2016 at 01:02, Monty Taylor <span dir="ltr"><<a href="mailto:mordred@inaugust.com" target="_blank">mordred@inaugust.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 02/21/2016 11:40 PM, Andrey Kurilin wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<br>
`novaclient.client.Client` entry-point supports almost the same<br>
arguments as `novaclient.v2.client.Client`. The difference is only in<br>
api_version, so you can set up region via `novaclient.client.Client` in<br>
the same way as `novaclient.v2.client.Client`.<br>
</blockquote>
<br></span>
The easiest way to get a properly constructed nova Client is with os-client-config:<br>
<br>
import os_client_config<br>
<br>
OS_PROJECT_NAME="d8af8a8f-a573-48e6-898a-af333b970a2d"<br>
OS_USERNAME="0b8c435b-cc4d-4e05-8a47-a2ada0539af1"<br>
OS_PASSWORD="REDACTED"<br>
OS_AUTH_URL="<a href="http://auth.vexxhost.net" rel="noreferrer" target="_blank">http://auth.vexxhost.net</a>"<br>
OS_REGION_NAME="ca-ymq-1"<br>
<br>
client = os_client_config.make_client(<br>
    'compute',<br>
    auth_url=OS_AUTH_URL, username=OS_USERNAME,<br>
    password=OS_PASSWORD, project_name=OS_PROJECT_NAME,<br>
    region_name=OS_REGION_NAME)<br>
<br>
The upside is that the constructor interface is the same for all of the rest of the client libs too (just change the first argument) - and it will also read in OS_ env vars or named clouds from clouds.yaml if you have them set.<br>
<br>
(The 'simplest' way is to put your auth and region information into a clouds.yaml file like this:<br>
<br>
<a href="http://docs.openstack.org/developer/os-client-config/#site-specific-file-locations" rel="noreferrer" target="_blank">http://docs.openstack.org/developer/os-client-config/#site-specific-file-locations</a><br>
<br>
Such as:<br>
<br>
# ~/.config/openstack/clouds.yaml<br>
clouds:<br>
  vexxhost:<br>
     profile: vexxhost<br>
     auth:<br>
       project_name: d8af8a8f-a573-48e6-898a-af333b970a2d<br>
       username: 0b8c435b-cc4d-4e05-8a47-a2ada0539af1<br>
       password: REDACTED<br>
     region_name: ca-ymq-1<br>
<br>
<br>
And do:<br>
<br>
client = os_client_config.make_client('compute', cloud='vexxhost')<br>
<br>
<br>
If you don't want to do that for some reason but you'd like to construct a novaclient Client object by hand:<br>
<br>
<br>
from keystoneauth1 import loading<br>
from keystoneauth1 import session as ksa_session<br>
from novaclient import client as nova_client<br>
<br>
OS_PROJECT_NAME="d8af8a8f-a573-48e6-898a-af333b970a2d"<br>
OS_USERNAME="0b8c435b-cc4d-4e05-8a47-a2ada0539af1"<br>
OS_PASSWORD="REDACTED"<br>
OS_AUTH_URL="<a href="http://auth.vexxhost.net" rel="noreferrer" target="_blank">http://auth.vexxhost.net</a>"<br>
OS_REGION_NAME="ca-ymq-1"<br>
<br>
# Get the auth loader for the password auth plugin<br>
loader = loading.get_plugin_loader('password')<br>
# Construct the auth plugin<br>
auth_plugin = loader.load_from_options(<br>
    auth_url=OS_AUTH_URL, username=OS_USERNAME, password=OS_PASSWORD,<br>
    project_name=OS_PROJECT_NAME)<br></blockquote><div> </div><div>note that loaders here are generally things like load from config file, or load from argparse arguments. If you are doing everything in a script like this you would probably just use the keystoneauth1.identity.Password like <br><br></div><div>from keystoneauth1 import identity <br><br></div><div>auth_plugin = identity.Password(auth_url=....)<br></div><div><br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Construct a keystone session<br>
# Other arguments that are potentially useful here are:<br>
#  verify - bool, whether or not to verify SSL connection validity<br>
#  cert - SSL cert information<br>
#  timout - time in seconds to use for connection level TCP timeouts<br>
session = ksa_session.Session(auth_plugin)<br>
<br>
# Now make the client<br>
# Other arguments you may be interested in:<br>
#  service_name - if you need to specify a service name for finding the<br>
#                 right service in the catalog<br>
#  service_type - if the cloud in question has given a different<br>
#                 service type (should be 'compute' for nova - but<br>
#                 novaclient sets it, so it's safe to omit in most cases<br>
#  endpoint_override - if you want to tell it to use a different URL<br>
#                      than what the keystone catalog returns<br>
#  endpoint_type - if you need to specify admin or internal<br>
#                  endpoints rather than the default 'public'<br>
#                  Note that in glance and barbican, this key is called<br>
#                  'interface'<br>
client = nova_client.Client(<br>
    version='2.0', # or set the specific microversion you want<br>
    session=session, region_name=OS_REGION_NAME)<br>
<br>
It might be clear why I prefer the os_client_config factory function instead - but what I prefer and what you prefer might not be the same thing. :)<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On Mon, Feb 22, 2016 at 6:11 AM, Xav Paice <<a href="mailto:xavpaice@gmail.com" target="_blank">xavpaice@gmail.com</a><br></span><span class="">
<mailto:<a href="mailto:xavpaice@gmail.com" target="_blank">xavpaice@gmail.com</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    In <a href="http://docs.openstack.org/developer/python-novaclient/api.html" rel="noreferrer" target="_blank">http://docs.openstack.org/developer/python-novaclient/api.html</a><br>
    it's got some pretty clear instructions not to<br>
    use novaclient.v2.client.Client but I can't see another way to<br>
    specify the region - there's more than one in my installation, and<br>
    no param for region in novaclient.client.Client<br>
<br>
    Shall I hunt down/write a blueprint for that?<br>
<br>
    __________________________________________________________________________<br>
    OpenStack Development Mailing List (not for usage questions)<br>
    Unsubscribe:<br>
    <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br></span>
    <<a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a>><span class=""><br>
    <a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br>
<br>
<br>
<br>
--<br>
Best regards,<br>
Andrey Kurilin.<br>
<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</div></div></blockquote></div><br></div></div>