[openstack-dev] [nova] python-novaclient region setting
Monty Taylor
mordred at inaugust.com
Mon Feb 22 14:02:45 UTC 2016
On 02/21/2016 11:40 PM, Andrey Kurilin wrote:
> Hi!
> `novaclient.client.Client` entry-point supports almost the same
> arguments as `novaclient.v2.client.Client`. The difference is only in
> api_version, so you can set up region via `novaclient.client.Client` in
> the same way as `novaclient.v2.client.Client`.
The easiest way to get a properly constructed nova Client is with
os-client-config:
import os_client_config
OS_PROJECT_NAME="d8af8a8f-a573-48e6-898a-af333b970a2d"
OS_USERNAME="0b8c435b-cc4d-4e05-8a47-a2ada0539af1"
OS_PASSWORD="REDACTED"
OS_AUTH_URL="http://auth.vexxhost.net"
OS_REGION_NAME="ca-ymq-1"
client = os_client_config.make_client(
'compute',
auth_url=OS_AUTH_URL, username=OS_USERNAME,
password=OS_PASSWORD, project_name=OS_PROJECT_NAME,
region_name=OS_REGION_NAME)
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.
(The 'simplest' way is to put your auth and region information into a
clouds.yaml file like this:
http://docs.openstack.org/developer/os-client-config/#site-specific-file-locations
Such as:
# ~/.config/openstack/clouds.yaml
clouds:
vexxhost:
profile: vexxhost
auth:
project_name: d8af8a8f-a573-48e6-898a-af333b970a2d
username: 0b8c435b-cc4d-4e05-8a47-a2ada0539af1
password: REDACTED
region_name: ca-ymq-1
And do:
client = os_client_config.make_client('compute', cloud='vexxhost')
If you don't want to do that for some reason but you'd like to construct
a novaclient Client object by hand:
from keystoneauth1 import loading
from keystoneauth1 import session as ksa_session
from novaclient import client as nova_client
OS_PROJECT_NAME="d8af8a8f-a573-48e6-898a-af333b970a2d"
OS_USERNAME="0b8c435b-cc4d-4e05-8a47-a2ada0539af1"
OS_PASSWORD="REDACTED"
OS_AUTH_URL="http://auth.vexxhost.net"
OS_REGION_NAME="ca-ymq-1"
# Get the auth loader for the password auth plugin
loader = loading.get_plugin_loader('password')
# Construct the auth plugin
auth_plugin = loader.load_from_options(
auth_url=OS_AUTH_URL, username=OS_USERNAME, password=OS_PASSWORD,
project_name=OS_PROJECT_NAME)
# Construct a keystone session
# Other arguments that are potentially useful here are:
# verify - bool, whether or not to verify SSL connection validity
# cert - SSL cert information
# timout - time in seconds to use for connection level TCP timeouts
session = ksa_session.Session(auth_plugin)
# Now make the client
# Other arguments you may be interested in:
# service_name - if you need to specify a service name for finding the
# right service in the catalog
# service_type - if the cloud in question has given a different
# service type (should be 'compute' for nova - but
# novaclient sets it, so it's safe to omit in most cases
# endpoint_override - if you want to tell it to use a different URL
# than what the keystone catalog returns
# endpoint_type - if you need to specify admin or internal
# endpoints rather than the default 'public'
# Note that in glance and barbican, this key is called
# 'interface'
client = nova_client.Client(
version='2.0', # or set the specific microversion you want
session=session, region_name=OS_REGION_NAME)
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. :)
> On Mon, Feb 22, 2016 at 6:11 AM, Xav Paice <xavpaice at gmail.com
> <mailto:xavpaice at gmail.com>> wrote:
>
> Hi,
>
> In http://docs.openstack.org/developer/python-novaclient/api.html
> it's got some pretty clear instructions not to
> use novaclient.v2.client.Client but I can't see another way to
> specify the region - there's more than one in my installation, and
> no param for region in novaclient.client.Client
>
> Shall I hunt down/write a blueprint for that?
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe:
> OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> <http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe>
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
>
>
> --
> Best regards,
> Andrey Kurilin.
>
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
More information about the OpenStack-dev
mailing list