23 Commits

Author SHA1 Message Date
Stephen Finucane
e0f57ad81f Bump Python version used for linters to 3.10
This looks very large, but the only manual change is in pyproject.toml
and the bump of the ruff pre-commit hook: the rest is entirely ruff
converting our use of e.g. 'typing.Union[X, Y]' to 'X | Y', as added by
PEP-604 [1].

[1] https://peps.python.org/pep-0604/

Change-Id: I3ed176018cf78c417e751834e57412d72884a69b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-05-12 12:04:42 +01:00
Pavlo Shchelokovskyy
f25c47e0ba Fix argparse integration
fix docstrings and pass correct arguments around.

Change-Id: I2b029b6b93853744e1a6d29f2473ae15980462a9
Closes-Bug: #2102667
2025-03-14 17:21:29 +00:00
Stephen Finucane
5c0ca60b7d mypy: Enable disallow_incomplete_defs
Change-Id: I28a4d4c1f2e04c6284cbc1dc4f543df0a0706d59
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-02-19 11:05:52 +00:00
Stephen Finucane
62f64754f1 docs: Add docstring to 'openstack' module
Change-Id: I8e16961c8812ee9c15a8771ea7babf81c9ec534e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-11-21 18:07:54 +00:00
Sean McGinnis
8ca613e43f Raise hacking to 2.x
We have kept hacking capped below 1.2 for quite awhile. Newer versions
of hacking pull in updated linters that have some good checks.

We want to limit the maximum version of hacking installed since the
global upper constraints does not do this for linters. Otherwise when a
new release of hacking is available in the future, stable branches may
suddenly be broken.

Change-Id: I0e0ee8a169ae93f7efb2cda2b1d2458c1d49e46b
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-29 11:07:34 -05:00
Monty Taylor
7fcfeeb08f Start supporting type info
This is super basic, but it's a starting point to us being able to
start adding typing info.

Adding it with python2 syntax for now, since we haven't dropped py2
yet.

Change-Id: I4f9b95b02d43c81acb60d224584d60331f5a7784
2019-10-04 13:08:21 +02:00
Artem Goncharov
75b0f292f8 Add support for vendor hooks
Add possibility to pass a hook in the vendor config, clouds-public.* or 
upon building a connection. This should be a string parameter - function
name to be executed. This gives possibility to register new services of 
the cloud automatically or alter behavior of the present services.
It would have not been necessary, if public clouds followed 
upstream-first aproach.

While we are here fix warnings on not closed files in the test_json

Change-Id: Ifd6c0847102af4f46e361dcb1a665829c77553b9
2019-05-13 20:15:07 +02:00
Monty Taylor
d5fd3e8f1b Clean up floating ip tests
There are timeout issues as well as sometimes something goes wrong in
the shade floating ip tests. Update the tests to try to make them more
stable.

This also fixes a bug in find_available_ip that was causing ips with
port_ids to be returned that was accidentally working in the functional
tests as a race condition.

While working on this, pycodestyle made a release and broke us. Add pep8
changes to allow landing this patch. Fix two of them, ignore two of them.

Change-Id: I128e85048b91f0508798d6c0c2a7e3aacb1c92c1
2018-05-09 11:09:44 -05:00
Monty Taylor
aff2b6ab40 Ensure Connection can be made from keyword arguments
Although driving configuration from clouds.yaml and environment
variables is super handy for many use cases, there are also plenty where
avoiding config files or environment variables is important.

Add a flag, "load_envvars" which defaults to True but can be disabled.

Update the Connection constructor to set load_yaml_config and
load_envvars to False if a named cloud is not given.

Update the docs to make it clear which form should be used for which use
case. Also, move the profile backwards compat documentation to its own
document so that it doesn't present needless complexity to users.

Change-Id: I6e05da5e73aff4143550e1d18fb0f743d51f2b70
2018-01-30 20:13:50 -06:00
Monty Taylor
e636890d59 Move openstack_cloud helper functions
We don't want these where they look like supported interfaces just yet.
Move them below openstack.cloud.

Change-Id: I653e5aaba8084e8c226fd0e787dfff01050e7a6c
2018-01-18 16:54:55 -06:00
Jacky Hu
34f1e046b4 Use version definition from openstack.version
Having openstack/__init__.py referencing pbr is causing some problems
sometimes when invoking sdk apis. This patch propose using the version
definition from version module under openstack/.

This is a follow up of 2f05a3d066.

Change-Id: I3117becd0e91514447a426f2fec4d133dd11f404
2018-01-18 16:54:52 -06:00
Monty Taylor
da2406bace Rationalize logging helpers and docs
shade and openstacksdk each have a logging doc and a logging setup helper
function. They both basically do the same thing, and we have a TODO item
about collapsing them.

This moves openstack.utils.enable_logging to openstack.enable_logging
(leaving behind a compat piece at openstack.utils.enable_logging) It
adds the shade functionality to it, and also changes the behavior to
match shade's WRT behavior when no parameters are passed (defaults to
logging to stdout)

Update the codebase to call openstack._log.setup_logging instead of
logging.getLogger directly, as setup_logging attaches a NullHandler by
default.

Collapse the docs into a single document.

There were only two places where openstacksdk was already logging to
something other than 'openstack'. Collapse those down to 'openstack'
until we come up with a reason to break them out more logically.

Change-Id: I45fd5ffd18255450d38a1f56c80f5c157ea19ae3
2018-01-16 14:46:44 -06:00
Monty Taylor
18fe7b4e2b Rename CloudConfig to CloudRegion
The name CloudConfig has always sucked. While working on the next patch,
it occurred to me that what a CloudConfig represents is the config for a
given region of a cloud. We even reference "Cloud Region" as a unit of
work when giving conference talks.

Take the opportunity while we're doing this sdk/occ merge to rename it.
Obviously we can provide naming compat shim in OCC itself.

Leave in *some* naming compat shims to get us past the 0.10 release so
that OSC continues to have the happies.

Change-Id: Ia0bbc20eb28a3a36e69adba3a4b45323e4aa284e
2018-01-09 11:56:04 -06:00
Monty Taylor
c4acd23525 Remove self argument from connect helper function
This is a factory function, not a class method.

Change-Id: I2ff9654dec4acdbba5d311ef690935ff5d20cbbd
2017-12-31 12:02:01 -06:00
Monty Taylor
4bad718783 Rework config and rest layers
This is a large and invasive change to the underlying guts. Most casual
use should not notice a difference, but advanced users, especially those
using the Profile or Authenticator interfaces or making use of pluggable
providers will be broken.

The overall intent is to align directly on top of the mechanisms that
came from os-client-config for config and to use keystoneauth1's Adapter
interface to make use of the canonical implementations of such things as
service and version discovery. The end goal is that openstacksdk
provides the REST interaction layer for python-openstackclient, shade,
Ansible and nodepool.

Replace profile with openstack.config

os-client-config is used by shade and python-openstackclient to read
and process configuration. openstacksdk also can use the
os-client-config interface, but translates it internally into the
Profile object. As os-client-config has been injested into
openstack.config, remove Profile and just use the config classes.

Make proxy subclass of adapter

This gives every service a generic passthrough for REST calls, which
means we can map unknown service-type values to a generic proxy.

Strip endpoint_filter

We're passing Adapters around, not sessions. Doing so means that
self.service and endpoint_filter have become unnecessary.

Rename _Request.uri to _Request.url

This is a stepping-stone to replacing _Request with requests.Request and
using requests.Session.prepare_request inside of _prepare_request.

Rename service proxy instances to match their official service-type.

Aliases are kept for the old versions, but make the canonical versions
match the official name.

Rename bare_metal to baremetal
Rename cluster to clustering
Rename block_store to block_storage
Rename telemetry to meter

Create generic proxies for all services in STA

Every service listed in service types authority is an OpenStack service.
Even if we don't know about it in SDK, we should at the very least have
a low-level Adapter for it so that people can use REST calls while
waiting on the SDK to add higher-level constructs.

The pypy jobs are happily green. Run them as voting rather than
non-voting.

Add syntatic sugar alias for making connections

Typing:

  import openstack.connection
  conn = openstack.connection.Connection(cloud='example')

is annoying. This allows:

  import openstack
  conn = openstack.connect(cloud='example')

Use task_manager and Adapter from shade

As a stepping-stone towards shade and sdk codepaths being rationalized,
we need to get SDK using the Adapter from shade that submits requests
into the TaskManager. For normal operation this is a passthrough/no-op
sort of thing, but it's essential for high-volume consumers such as
nodepool.

This exposes a bunch of places in tests where we're mocking a bit too
deeply. We should go back through and fix all of those via
requests_mock, but that's WAY too much for today.

This was a 'for later' task, but it turns out that the move to Adapter
was causing exceptions to be thrown that were not the exceptions that
were intended to be caught in the SDK layer, which was causing
functional tests of things like GET operations to fail. So it became a
today task.

Change-Id: I7b46e263a76d84573bdfbbece57b1048764ed939
2017-11-15 11:46:50 -06:00
Monty Taylor
535f2f48ff Merge shade and os-client-config into the tree
This sucks in the git history for both projects, then moves their files
in place. It should not introduce any behavior changes to any of the
existing openstacksdk code, nor to openstack.config and openstack.cloud
- other than the name change.

TODO(shade) comments have been left indicating places where further
integration work should be done.

It should not be assumed that these are the final places for either to
live. This is just about getting them in-tree so we can work with them.

The enforcer code for reasons surpassing understanding does not work
with python setup.py build_sphinx but it does work with sphinx-build
(what?) For now turn it off. We can turn it back on once the build
sphinx job is migrated to the new PTI.

Change-Id: I9523e4e281285360c61e9e0456a8e07b7ac1243c
2017-11-15 09:03:23 -06:00
Brian Curtin
feaa7cc7d5 Shift some compute attributes within request body
The scheduler_hints attribute exists as a top-level key rather than
under the "server" key like most other things, so if we have it set,
shift it out of the resource_key body and into its own top-level key.

The availability_zone attribute exists with two different names,
depending on whether it's in a request or a response. When we're
preparing a request, include it in the request body as
availability_zone, otherwise expect OS-EXT-AZ:availability_zone in the
response body such as for a GET. The same goes for the user_data
attribute, which exists as OS-EXT-SRV-ATTR:user_data in responses.

Change-Id: Ifc261f982f8a13f8ab467350615e08f268a22049
Closes-Bug: 1671073
Closes-Bug: 1671886
2017-03-17 02:04:22 -04:00
Brian Curtin
f51162070c Make end-user modules accessible from top level
There are several modules that end-users are expected to be
using--connection, profile, exceptions, and utils--which could be made
slightly more accessible by having them available in the top level
`openstack` namespace. This change proposes importing `from openstack
import <x>` in openstack.__init__.py so that end-users can do `import
openstack` and then work from there.

Nothing more than the typical end-user entry points are to be exposed
from there, so if you need to get the server resource you still need
to do `from openstack.compute.v2 import server`. Additionally, we should
continue documenting and using in tests everything in the `from
openstack import <x>` format ourselves as this is merely a convenience.

Change-Id: I24a7ce3636b18287fcb2246fbdfa9f8b6767f323
2016-07-22 13:21:06 -04:00
tengqm
2f05a3d066 Move version definition
Having openstack/__init__.py referencing pbr is causing some problems
sometimes when invoking sdk apis. This patch propose moving the version
definition into a module under openstack/.

Close-Bug: 1588823
Change-Id: I587de91ea7f523bb923ed9ac665a0b46d40d722c
2016-06-03 09:32:26 -04:00
TerryHowe
4fd04e3411 Clean up a few more python-openstacksdk references
Change-Id: I4328b898a04344fab94d8c6c39f7e8cdc3c53456
2015-06-17 13:34:02 -06:00
Ian Cordasco
5ad869909e Use project name to retrieve version info
Change-Id: Iaef93bde5183263f900166b8ec90eefb7bfdc99b
2014-11-12 14:16:53 -06:00
Alex Gaynor
fe57620045 Made tox -e pep8 passed. Also made git review work
Two elements to this: make the existing code pass, and skip the
api_strawman/ directory.

Change-Id: Ic85067bdd63337e135f054c9a28e46683c46656c
2014-01-28 09:20:44 -08:00
Jesse Noller
e0418241a3 setting up the initial layout; move the api proposals to api_strawman
Change-Id: I7c933d5e023c2a98a64aa90ed209f1e25d07f0d9
2014-01-24 22:58:25 -06:00