1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
|
.. _openstack-config:
======================================
Configuring OpenStack SDK Applications
======================================
.. _config-environment-variables:
Environment Variables
---------------------
`openstacksdk` honors all of the normal `OS_*` variables. It does not
provide backwards compatibility to service-specific variables such as
`NOVA_USERNAME`.
If you have OpenStack environment variables set, `openstacksdk` will
produce a cloud config object named `envvars` containing your values from the
environment. If you don't like the name `envvars`, that's ok, you can override
it by setting `OS_CLOUD_NAME`.
Service specific settings, like the nova service type, are set with the
default service type as a prefix. For instance, to set a special service_type
for trove set
.. code-block:: bash
export OS_DATABASE_SERVICE_TYPE=rax:database
.. _config-clouds-yaml:
Config Files
------------
`openstacksdk` will look for a file called `clouds.yaml` in the following
locations:
* ``.`` (the current directory)
* ``$HOME/.config/openstack``
* ``/etc/openstack``
The first file found wins.
You can also set the environment variable `OS_CLIENT_CONFIG_FILE` to an
absolute path of a file to look for and that location will be inserted at the
front of the file search list.
The keys are all of the keys you'd expect from `OS_*` - except lower case
and without the OS prefix. So, region name is set with `region_name`.
Service specific settings, like the nova service type, are set with the
default service type as a prefix. For instance, to set a special service_type
for trove (because you're using Rackspace) set:
.. code-block:: yaml
database_service_type: 'rax:database'
Site Specific File Locations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In addition to `~/.config/openstack` and `/etc/openstack` - some platforms
have other locations they like to put things. `openstacksdk` will also
look in an OS specific config dir
* `USER_CONFIG_DIR`
* `SITE_CONFIG_DIR`
`USER_CONFIG_DIR` is different on Linux, OSX and Windows.
* Linux: `~/.config/openstack`
* OSX: `~/Library/Application Support/openstack`
* Windows: `C:\\Users\\USERNAME\\AppData\\Local\\OpenStack\\openstack`
`SITE_CONFIG_DIR` is different on Linux, OSX and Windows.
* Linux: `/etc/openstack`
* OSX: `/Library/Application Support/openstack`
* Windows: `C:\\ProgramData\\OpenStack\\openstack`
An example config file is probably helpful:
.. code-block:: yaml
clouds:
mtvexx:
profile: https://vexxhost.com
auth:
username: mordred@inaugust.com
password: XXXXXXXXX
project_name: mordred@inaugust.com
region_name: ca-ymq-1
dns_api_version: 1
mordred:
region_name: RegionOne
auth:
username: 'mordred'
password: XXXXXXX
project_name: 'shade'
auth_url: 'https://montytaylor-sjc.openstack.blueboxgrid.com:5001/v2.0'
infra:
profile: rackspace
auth:
username: openstackci
password: XXXXXXXX
project_id: 610275
regions:
- DFW
- ORD
- IAD
You may note a few things. First, since `auth_url` settings are silly
and embarrassingly ugly, known cloud vendor profile information is included and
may be referenced by name or by base URL to the cloud in question if the
cloud serves a vendor profile. One of the benefits of that is that `auth_url`
isn't the only thing the vendor defaults contain. For instance, since
Rackspace lists `rax:database` as the service type for trove, `openstacksdk`
knows that so that you don't have to. In case the cloud vendor profile is not
available, you can provide one called `clouds-public.yaml`, following the same
location rules previously mentioned for the config files.
`regions` can be a list of regions. When you call `get_all_clouds`,
you'll get a cloud config object for each cloud/region combo.
As seen with `dns_service_type`, any setting that makes sense to be
per-service, like `service_type` or `endpoint` or `api_version` can be set
by prefixing the setting with the default service type. That might strike you
funny when setting `service_type` and it does me too - but that's just the
world we live in.
Auth Settings
-------------
Keystone has auth plugins - which means it's not possible to know ahead of time
which auth settings are needed. `openstacksdk` sets the default plugin type
to `password`, which is what things all were before plugins came about. In
order to facilitate validation of values, all of the parameters that exist
as a result of a chosen plugin need to go into the auth dict. For password
auth, this includes `auth_url`, `username` and `password` as well as anything
related to domains, projects and trusts.
API Settings
------------
The following settings are passed to keystoneauth and are common to
all services.
``api_timeout``
A timeout for API requests. This should be a numerical value
indicating some amount (or fraction) of seconds or 0 for no
timeout. (optional, defaults to 0)
``collect_timing``
Whether or not to collect per-method timing information for each
API call. (optional, defaults to False)
Splitting Secrets
-----------------
In some scenarios, such as configuration management controlled environments,
it might be easier to have secrets in one file and non-secrets in another.
This is fully supported via an optional file `secure.yaml` which follows all
the same location rules as `clouds.yaml`. It can contain anything you put
in `clouds.yaml` and will take precedence over anything in the `clouds.yaml`
file.
.. code-block:: yaml
# clouds.yaml
clouds:
internap:
profile: internap
auth:
username: api-55f9a00fb2619
project_name: inap-17037
regions:
- ams01
- nyj01
# secure.yaml
clouds:
internap:
auth:
password: XXXXXXXXXXXXXXXXX
SSL Settings
------------
When the access to a cloud is done via a secure connection, `openstacksdk`
will always verify the SSL cert by default. This can be disabled by setting
`verify` to `False`. In case the cert is signed by an unknown CA, a specific
cacert can be provided via `cacert`. **WARNING:** `verify` will always have
precedence over `cacert`, so when setting a CA cert but disabling `verify`, the
cloud cert will never be validated.
Client certs are also configurable. `cert` will be the client cert file
location. In case the cert key is not included within the client cert file,
its file location needs to be set via `key`.
.. code-block:: yaml
# clouds.yaml
clouds:
regular-secure-cloud:
auth:
auth_url: https://signed.cert.domain:5000
...
unknown-ca-with-client-cert-secure-cloud:
auth:
auth_url: https://unknown.ca.but.secure.domain:5000
...
key: /home/myhome/client-cert.key
cert: /home/myhome/client-cert.crt
cacert: /home/myhome/ca.crt
self-signed-insecure-cloud:
auth:
auth_url: https://self.signed.cert.domain:5000
...
verify: False
Note for parity with ``openstack`` command-line options the `insecure`
boolean is also recognised (with the opposite semantics to `verify`;
i.e. `True` ignores certificate failures). This should be considered
deprecated for `verify`.
Cache Settings
--------------
.. versionchanged:: 1.0.0
Previously, caching was managed exclusively in the cloud layer. Starting in
openstacksdk 1.0.0, caching is moved to the proxy layer. As the cloud layer
depends on the proxy layer in 1.0.0, this means both layers can benefit from
the cache.
Authenticating and accessing resources on a cloud is often expensive. It is
therefore quite common that applications will wish to do some client-side
caching of both credentials and cloud resources. To facilitate this,
*openstacksdk* supports caching credentials and resources using the system
keyring and *dogpile.cache*, respectively.
.. tip::
It is important to emphasise that *openstacksdk* does not actually cache
anything itself. Rather, it collects and presents the cache information
so that your various applications that are connecting to OpenStack can share
a cache should you desire. It is important that your cache backend is
correctly configured according to the needs of your application.
Caching in enabled or disabled globally, rather than on a cloud-by-cloud basis.
This is done by setting configuring the``cache`` top-level key. Caching of
authentication tokens can be configured using the following settings:
``cache.auth``
A boolean indicating whether tokens should be cached in the keyring.
When enabled, this allows the consequent connections to the same cloud to
skip fetching new token. When the token expires or is invalidated,
`openstacksdk` will automatically establish a new connection.
Defaults to ``false``.
For example, to configure caching of authentication tokens.
.. code-block:: yaml
cache:
auth: true
Caching of resources can be configured using the following settings:
``cache.expiration_time``
The expiration time in seconds for a cache entry.
This should be an integer.
Defaults to ``0``.
``cache.class``
The cache backend to use, which can include any backend supported by
*dogpile.cache* natively as well as backend provided by third-part packages.
This should be a string.
Defaults to ``dogpile.cache.memory``.
``cache.arguments``
A mapping of arbitrary arguments to pass into the cache backend. These are
backend specific. Keys should correspond to a configuration option for the
configured cache backend.
Defaults to ``{}``.
``cache.expirations``
A mapping of resource types to expiration times. The keys should be specified
in the same way as the metrics are emitted, by joining meaningful resource
URL segments with ``.``. For example, both ``/servers`` and ``/servers/ID``
should be specified as ``servers``, while ``/servers/ID/metadata/KEY`` should
be specified as `server.metadata`. Values should be an expiration time in
seconds. A value of ``-1`` indicates that the cache should never expire,
while a value of ``0`` disables caching for the resource.
Defaults to ``{}``
For example, to configure caching with the ``dogpile.cache.memory`` backend
with a 1 hour expiration.
.. code-block:: yaml
cache:
expiration_time: 3600
To configure caching with the ``dogpile.cache.memory`` backend with a 1 hour
expiration but only for requests to the OpenStack Compute service's
``/servers`` API:
.. code-block:: yaml
cache:
expirations:
servers: 3600
To configure caching with the ``dogpile.cache.pylibmc`` backend with a 1 hour
expiration time and a memcached server running on your localhost.
.. code-block:: yaml
cache:
expiration_time: 3600
arguments:
url:
- 127.0.0.1
To configure caching with the ``dogpile.cache.pylibmc`` backend with a 1 hour
expiration time, a memcached server running on your localhost, and multiple
per-resource cache expiration times.
.. code-block:: yaml
cache:
class: dogpile.cache.pylibmc
expiration_time: 3600
arguments:
url:
- 127.0.0.1
expiration:
server: 5
flavor: -1
compute.servers: 5
compute.flavors: -1
image.images: 5
Finally, if the ``cache`` key is undefined, a null cache is enabled meaning
caching is effectively disabled.
.. note::
Non ``GET`` requests cause cache invalidation based on the caching key
prefix. This means that, for example, a ``PUT`` request to ``/images/ID``
will invalidate all images cache (list and all individual entries). Moreover
it is possible to explicitly pass the ``skip_cache`` parameter to the
``proxy._get`` function to bypass cache and invalidate what is already
there. This is happening automatically in the ``wait_for_status`` methods
where it is expected that resource will change some of the attributes over
the time. Forcing complete cache invalidation can be achieved calling
``conn._cache.invalidate``
MFA Support
-----------
MFA support requires a specially prepared configuration file. In this case a
combination of two different authorization plugins is used with their
individual requirements to the specified parameters.
.. code-block:: yaml
clouds:
mfa:
auth_type: "v3multifactor"
auth_methods:
- v3password
- v3totp
auth:
auth_url: https://identity.cloud.com
username: user
user_id: uid
password: XXXXXXXXX
project_name: project
user_domain_name: udn
project_domain_name: pdn
IPv6
----
IPv6 is the future, and you should always use it if your cloud
supports it and if your local network supports it. Both of those are
easily detectable and all friendly software should do the right thing.
However, sometimes a cloud API may return IPv6 information that is not
useful to a production deployment. For example, the API may provide
an IPv6 address for a server, but not provide that to the host
instance via metadata (configdrive) or standard IPv6 autoconfiguration
methods (i.e. the host either needs to make a bespoke API call, or
otherwise statically configure itself).
For such situations, you can set the ``force_ipv4``, or ``OS_FORCE_IPV4``
boolean environment variable. For example:
.. code-block:: yaml
clouds:
mtvexx:
profile: vexxhost
auth:
username: mordred@inaugust.com
password: XXXXXXXXX
project_name: mordred@inaugust.com
region_name: ca-ymq-1
dns_api_version: 1
monty:
profile: fooprovider
force_ipv4: true
auth:
username: mordred@inaugust.com
password: XXXXXXXXX
project_name: mordred@inaugust.com
region_name: RegionFoo
The above snippet will tell client programs to prefer the IPv4 address
and leave the ``public_v6`` field of the `Server` object blank for the
``fooprovider`` cloud . You can also set this with a client flag for
all clouds:
.. code-block:: yaml
client:
force_ipv4: true
Per-region settings
-------------------
Sometimes you have a cloud provider that has config that is common to the
cloud, but also with some things you might want to express on a per-region
basis. For instance, Internap provides a public and private network specific
to the user in each region, and putting the values of those networks into
config can make consuming programs more efficient.
To support this, the region list can actually be a list of dicts, and any
setting that can be set at the cloud level can be overridden for that
region.
.. code-block:: yaml
clouds:
internap:
profile: internap
auth:
password: XXXXXXXXXXXXXXXXX
username: api-55f9a00fb2619
project_name: inap-17037
regions:
- name: ams01
values:
networks:
- name: inap-17037-WAN1654
routes_externally: true
- name: inap-17037-LAN6745
- name: nyj01
values:
networks:
- name: inap-17037-WAN1654
routes_externally: true
- name: inap-17037-LAN6745
Setting Precedence
------------------
Some settings are redundant, e.g. ``project-name`` and ``project-id`` both
specify the project. In a conflict between redundant settings, the
``_name`` ``clouds.yaml`` option (or equivalent ``-name`` CLI option and ``_NAME`` environment variable) will be used.
Some environment variables or commandline flags can override the settings from
clouds.yaml. These are:
- ``--domain-id`` (``OS_DOMAIN_ID``)
- ``--domain-name`` (``OS_DOMAIN_NAME``)
- ``--user-domain-id`` (``OS_USER_DOMAIN_ID``)
- ``--user-domain-name`` (``OS_USER_DOMAIN_NAME``)
- ``--project-domain-id`` (``OS_PROJECT_DOMAIN_ID``)
- ``--project-domain-name`` (``OS_PROJECT_DOMAIN_NAME``)
- ``--auth-token`` (``OS_AUTH_TOKEN``)
- ``--project-id`` (``OS_PROJECT_ID``)
- ``--project-name`` (``OS_PROJECT_NAME``)
- ``--tenant-id`` (``OS_TENANT_ID``) (deprecated for ``--project-id``)
- ``--tenant-name`` (``OS_TENANT_NAME``) (deprecated for ``--project-name``)
Similarly, if one of the above settings is specified in ``clouds.yaml`` as
part of the ``auth`` section as well as the main section, the ``auth`` settings
will be overridden. For example in this config section, note that project is
specified multiple times:
.. code-block:: yaml
clouds:
mtvexx:
profile: https://vexxhost.com
auth:
username: mordred@inaugust.com
password: XXXXXXXXX
project_name: mylessfavoriteproject
project_id: 0bedab75-898c-4521-a038-0b4b71c41bed
region_name: ca-ymq-1
project_name: myfavoriteproject
project_id: 2acf9403-25e8-479e-a3c6-d67540c424a4
In the above example, the ``project_id`` configuration values will be ignored
in favor of the ``project_name`` configuration values, and the higher-level
project will be chosen over the auth-specified project. So the actual project
used will be ```myfavoriteproject```.
Examples
--------
``auth``
~~~~~~~~
.. rubric:: Password-based authentication (project-scoped)
.. code-block:: yaml
example:
auth:
auth_url: http://example.com/identity
password: password
project_domain_id: default
project_name: admin
user_domain_id: default
username: admin
region_name: RegionOne
.. rubric:: Password-based authentication (domain-scoped)
.. code-block:: yaml
example:
auth:
auth_url: http://example.com/identity
domain_id: default
password: password
username: admin
region_name: RegionOne
.. rubric:: Password-based authentication (trust-scoped)
.. code-block:: yaml
example-trust:
auth:
auth_url: http://example.com/identity
password: password
username: admin
trust_id: 95946f9eef864fdc993079d8fe3e5747
region_name: RegionOne
.. rubric:: Password-based authentication (system-scoped)
.. code-block:: yaml
example-system:
auth:
auth_url: http://example.com/identity
password: password
system_scope: all
username: admin
region_name: RegionOne
.. rubric:: Application credential-based authentication
.. code-block:: yaml
example-appcred:
auth:
auth_url: http://example.com/identity
application_credential_id: 9da0a8da3d394d09bf49dfc27014d254
application_credential_secret: pKfDSvUOFwO2t2_XxCajAFhzCKAVHI7yfqPb6xjshVDnMUHF7ifju8gMdhHTI4Eo56UP_hEc8ssmgA1NNtKMpA
auth_type: v3applicationcredential
region_name: RegionOne
.. rubric:: Token-based authentication
.. code-block:: yaml
example-token:
auth:
auth_url: http://example.com/identity
token: gAAAAABl32ptw2PN6L9JyBeO16PwQU1SrdMUvUz8Eon7LC2PFItdGRWFpOkK0qwH3JkukTuEM5qbYK9ucowRXET1RBMjZlfVpUa8Nz3qjQdzXw7pBKH4w1e4tekvDCOKfn15ZoujBOvdGqgtpW-febVGaW9oJzf6R3WTMDxWz3YRJjmiOBpwcN8
project_id: 1fd93a4455c74d2ea94b929fc5f0e488
auth_type: v3token
region_name: RegionOne
.. note::
This is a toy example: by their very definition tokens are short-lived.
You are unlikely to store them in a ``clouds.yaml`` file.
Instead, you would likely pass the TOTP token via the command line
(``--os-token``) or as an environment variable (``OS_TOKEN``).
.. rubric:: TOTP-based authentication
.. code-block:: yaml
example-totp:
auth:
auth_url: http://example.com/identity
passcode: password
project_domain_id: default
project_name: admin
user_domain_id: default
username: admin
auth_type: v3totp
region_name: RegionOne
.. note::
This is a toy example: by their very definition TOTP tokens are
short-lived. You are unlikely to store them in a ``clouds.yaml`` file.
Instead, you would likely pass the TOTP token via the command line
(``--os-passcode``) or as an environment variable (``OS_PASSCODE``).
.. rubric:: OAuth1-based authentication
.. code-block:: yaml
example-oauth:
auth:
auth_url: http://example.com/identity
consumer_key: foo
consumer_secret: secret
access_key: bar
access_secret: secret
auth_type: v3oauth1
region_name: RegionOne
|