436 Commits

Author SHA1 Message Date
dae2539490 compute: Migrate to 'compute' client alias
This is no longer assigned to novaclient, meaning we can use it for SDK.

Change-Id: I43d9ede39d36cc29301f94fa462b9b9d9441807c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-04-03 16:39:03 +01:00
dc8596fe74 Prepare for osc-lib changes
Change-Id: I665cd61272f881dce2d387da6035a2f35c866add
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-04-01 13:39:50 +01:00
e28046cc19 typing: Correct type for missing attributes
Change-Id: I55652220ecd663fa024937646dfef92595e1cd0f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-03-31 17:52:16 +01:00
7380fbe300 typing: Add types for empty dicts, tuples
In some cases, simply remove them.

Change-Id: I24a311a24eb533325dda83005777bcb2e0afc320
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-03-31 17:48:36 +01:00
bdd55d989d typing: Indicate tuples to be extended
Change-Id: Ie5907de8d60f2f39e98f6a88227cebb2e2ff565c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2025-03-31 17:48:36 +01:00
6d27b2f2b6 Fix networking quota usage show
Quotas details returned from the Neutron service are in different format
then quota details returned from Nova and Cinder services. This patch
fixes helper function to convert data from Neutron to the same
format as data from Nova and Cinder is given.

Closes-Bug: #2102513
Change-Id: I18649f6c2ee179b64b7e605f4ea07d4b0c7a1635
2025-03-25 09:52:39 +01:00
99cef9354b quota: Catch correct exception type for Compute quotas
There is a flaw (IMO) in the design of Nova's os-quota-sets API: despite
project IDs forming the identifier for an individual resource, we get a
HTTP 400 (Bad Request) error if you pass an ID that does not exist,
rather than the HTTP 404 (Not Found) we would expect.

Correct this, noting why we're doing what we're doing for readers from
the future (hi!). Note that HTTP 400 is unfortunately quite broad and
means we'll also catch things like invalid requests but the exception
may have been translated so we can't rely on a string match.

Change-Id: I720502930d50be8ead5f2033d9dbcab5d99a37a9
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Closes-bug: #2091086
2024-12-09 15:49:40 +00:00
e5ccf1eb1c common: Use correct argument for volume limits
The sooner we have type hints in SDK, the better /o\

Change-Id: Iaf9596aea02f683c280ae68504a14d43dbd6134a
Closes-bug: #2077634
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-11-05 17:07:49 +00:00
7c6b47b451 clientmanager: Check for 'block-storage' service type
This is a fun one driven by two separate changes. We recently started
checking whether the volume service was available before setting quotas
in order to allow us to use quota set for other services [1]. This
merged a number of weeks ago and was included in 7.1.0. More recently,
we modified DevStack to stop publishing a service catalog entry with a
service type of 'volumev3', preferring instead to use the correct
'block-storage' service type. Taken separately, neither of these changes
would have caused issues. Together, they mean our lookups for the volume
service now fail and we can't set volume quotas.

Fix things by checking for the block-storage service type also. A future
change will raise a warning (later an error) if the volume service is
not found and you're attempting to set a quota since this is clearly a
mistake.

Change-Id: Ibbeef52225e18757cd28d0fbfb14c1ca06975b60
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Closes-bug: #2084580
2024-10-15 18:07:26 +01:00
f98006ca9d pre-commit: Migrate pyupgrade to ruff
Change-Id: Ic50d2a5e0bc9dcdfe29f382607135cab510cd396
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-09-12 18:08:23 +01:00
fc6852cd94 pre-commit: Migrate bandit to ruff
The name of the errors change and we need to move things around a
little, but it's otherwise a straight swap.

Change-Id: I0a19765ebeaa14c0534faa1542165b76ed2bf4e2
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-09-12 18:08:23 +01:00
9fca2b51ee Merge "pre-commit: Migrate from flake8 to ruff" 2024-09-11 21:16:44 +00:00
73e9dd1934 Merge "quota: Allow 'quota set' to function without volume service" 2024-09-06 15:46:49 +00:00
2ba90581d5 pre-commit: Migrate from flake8 to ruff
Well, mostly. We still keep our own flake8 hooks and the hacking hooks
enabled. Everything else can be handled by ruff.

Doing this enables a couple of hacking checks that were previously
unaddressed. It also highlights a few cases that flake8 missed. Both are
addressed.

Change-Id: If81c7055e9ef692425da2789bae18a96d04b104f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-08-29 15:55:13 +01:00
50d1e0916b Merge "Add callback on plugin load failure" 2024-08-14 11:12:03 +00:00
6693f555bc quota: Allow 'quota set' to function without volume service
Unlike cinderclient, SDK attempts to connect to a service as soon as you
create a client. A keystoneauth1.exceptions.catalog.EndpointNotFound
exception can be raised if this service does not exist in the service
catalog. Avoid this for the quota and limits commands by first checking
if the service is enabled.

In the process, we rework the 'is_volume_endpoint_enabled' helper we are
using to check for the existence of the service to *not* require a
volume client, since this was causing a chicken and egg issue for us
(and was also pretty much unnecessary).

Change-Id: I56e68f00ea221d689eb7f668e9e5ffa7d1a20184
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Closes-bug: #2076229
2024-08-07 11:56:07 +00:00
1d4aabab2e Respect --skip-resource when deleting.
When running project cleanup and using the --skip-resource flag, this
flag is only used during the --dry-run stage. This change ensures it is
also used when deleting the resources which fixes the bug mentioned below.

Closes-Bug: #2074109
Change-Id: I8e50fd14dcde069b932cc8ec4bb4fc809f7d2eb7
2024-07-25 20:20:56 +01:00
aa88db9448 Add callback on plugin load failure
I have seen a few cases where import errors (distutils - I am looking at you)
result in an extension not being available, but there is no indication why this
is the case. We do configure logging, but this happens too late (as part
of the 'cliff.app.App.run' call to execute a command, which calls
osc-lib's 'configure_logging' but which happens long after we've tried
to import our plugins) to be of any use. Instead, make use of a callback
to make it more obvious.

Change-Id: Id68b06161e445b79fe43f463e06cda3c4771ef02
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-24 17:00:07 +01:00
6127b44d0a quota: Migrate 'quota *' to SDK
This is done for both the compute and block storage services. The
network service was already using SDK.

Change-Id: Id7a6943b8b4d7d1330e7d7f13705f027d1b67189
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/923864
2024-07-15 18:19:43 +01:00
b4f30a1583 quota: Split up 'quota list' command
This is really three separate commands rolled into one. Split the logic
up more to simplify it somewhat.

Change-Id: Ief3c3c413f791dda076f90e5ec76a033d3a9e12b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-11 11:34:24 +01:00
da7eda66e9 quota: Default network quotas to not force
The existing default behavior has been deprecated for over a 18 months
(change I25828a3d68e2e900f498e17a0d01fb70be77548e). It's time for a new
default.

Change-Id: Iaf4fa931dcbf16c22933f63629c6a4d443ac5310
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-11 11:34:02 +01:00
7d8baa87bb quota: Add 'quota set --default' option
This should have been added as a counterpart to the 'quota show
--default' option way back when we added that. Better late than never!

Change-Id: I0e3719e585353664fea6f23ec658a330086db3df
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-11 11:21:24 +01:00
ba2d2358e6 quota: Remove deprecated quota options
These are all deprecated for over 18 months (change
I0dd38e5cb252a01d5817ed168be040b21b35e348). It's time to remove them and
simplify this code.

Change-Id: I9ee3bfebbad21eec3eb1b475a813bcbc450edea4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>

Change-Id: Ibdd329a6db8bd176af065d7f5190f0901d3c3f8d
2024-07-11 11:10:11 +01:00
f5f543b8de quota: Move nova-network-related quota
This was incorrectly grouped as a general compute quota, when in fact
it's a nova-network quota. Move it.

Change-Id: If93c95bc181ab766137b61943a09821810345300
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-10 12:16:16 +01:00
9d39437282 common: Migrate 'limits show' to SDK
This is done for both the compute and block storage services even though
the compute service hasn't supported rate limits since API v2.1 was
introduced [1].

[1] https://github.com/openstack/nova/commit/ca4ec762804

Change-Id: Idd9f4a1c23952a6087f08c03ac8b5bebd5a0c86d
Co-authored-by: Stephen Finucane <stephenfin@redhat.com>
Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/918519
2024-07-08 10:30:36 +01:00
c5b772db76 trivial: Prepare for pyupgrade pre-commit hook
This change is entirely automated save for the update of some mocks from
'io.open' to '__builtins__.open').

We are keeping this change separate from addition of the actual hook so
that we can ignore the commit later.

Change-Id: I0a9d8736632084473b57b57b693322447d7be519
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-04-23 12:24:23 +01:00
0646f9b4e4 tox: Remove bandit skips, run via pre-commit
Most of these skips were unnecessary. The few that did generate warnings
could be skipped.

We also set 'skip_install' since there's no reason to build the package
for linting purposes.

Change-Id: I9644e5c19720b9c41c60e0a5882b7cd7f6a71f7b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-04-26 13:17:15 +01:00
f3207bdf3f Fix availability zone list command
there are two problems currently:
- SDK's `availability_zones()` returns a generator that raises errors
  only when actually accessing its items
- the error raised is the sdk exception, not nova one, and thus is not
  being handled correctly

As a result, currently nova AZs can not be listed by non-admins.

Story: 2010989
Task: 49220
Change-Id: Ia299faea85857d3fc3a9b539800f3483f84ccbc0
2023-12-07 16:24:34 +00:00
c7e3529dea Add pagination helpers
Add some pagination helpers to configure pagination parameters for
various commands. Two pagination schemes are supported, based on what we
currently support across OSC commands: marker-based pagination and
offset-based pagination.

Change-Id: I551bb4c3ff0568c6df5244a1d0f0669497bee58f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-11-03 23:16:18 +00:00
601d9717c2 Remove project purge image commands
This was still using glanceclient-style calls despite us having switched
all image command to SDK way back in 5.2.0 (Ussuri). It therefore hasn't
worked since then, so we remove without deprecation.

Change-Id: Ibea79ea10bb272cba194debfe4bcbaeebf3875b7
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-08-28 13:52:23 +01:00
b87b57551b Migrate 'extension list' to SDK
Migrate the block storage aspects of this command to SDK. This means the
'extension list' command, like the 'availability zone list' command
previously, is now using SDK entirely.

While we're here, we also make some fixes to the unit tests for the
network and compute aspects of the command. While we migrated the
network and compute extension commands from neutronclient and novaclient
respectively some time back, we never fully updated the tests. Do this
now.

Change-Id: I631a6a09dfd9d614b1dd7b322dcee8490a52cc43
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/885132
2023-08-28 13:51:34 +01:00
44cf963d8e Migrate 'availability zone list' to SDK
This is a bit of an odd one. Because this is a "common" command, there
are three clients in play here: a compute client, a block storage
client, and a networking client. The networking aspects of this command
are already using SDK though the tests were mistakenly using a fake
version of the legacy neutron client (albeit one with the correct SDK
properties). We were still using legacy clients for the other two.
Correct the networking tests and migrate the compute and block storage
aspects of the command.

Change-Id: I292e1a712bca97e1270e8a97606e02a8a44c2954
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-08-28 13:51:33 +01:00
f29e3ccc37 Add --skip-resource option to project cleanup
Story: 2010370
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/878646
Change-Id: I9eb10cfd8612fa9faf2a734a517078b12a9ca3c3
Signed-off-by: Jan Hartkopf <jhartkopf@inovex.de>
2023-08-21 11:47:24 +02:00
7d80f9e962 Blacken openstack.common
Black used with the '-l 79 -S' flags.

A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.

Change-Id: Ifcb3c798666d74d596b8ecb3d6d507f782de7ba5
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-05-10 10:51:30 +01:00
65b667af20 Merge "Add auto-approve option to project cleanup" 2023-03-20 12:07:44 +00:00
43f04c874f Merge "Drop default from ask_user_yesno question" 2023-02-22 12:32:22 +00:00
7506eb8e0c Add auto-approve option to project cleanup
Sometimes it is useful to be able to use the project cleanup function in
scripts and having to add "echo y | openstack" isn't really nice.

Signed-off-by: Dr. Jens Harbott <harbott@osism.tech>
Change-Id: I3ded9982769b4568b6dcfc49bc31ba67a6227839
2023-02-15 09:42:45 +01:00
69182a04b2 Drop default from ask_user_yesno question
There is no default for ask_user_yesno() since an empty answer instead
just repeats the question. Drop the unnecessary parameter.

Change-Id: I207bccbcbd31f831765e74a20c503b695790c0f5
2022-12-27 13:03:14 +01:00
5afe48040c Fix really long help strings
Each command should have a summary line followed by a longer
description, if needed. Some commands were not following this. Fix them.

Change-Id: If1ce7654037d192626460f34c069ea0979919b9b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-12-12 18:04:01 +00:00
837cbfbcdb Merge "quota: Deprecate "force" behavior for network quotas" 2022-11-05 09:24:51 +00:00
b0b47472d8 Merge "quota: Fix issues with delete quota command" 2022-11-05 09:24:49 +00:00
c458ad4692 Merge "quota: Trivial style fixups" 2022-11-05 09:09:21 +00:00
6898bc0ae3 Merge "quota: Deprecate 'quota show --class', 'quota set --class' arguments" 2022-11-05 09:09:19 +00:00
1e37c12b16 Merge "quota: Allow showing project-specific quotas" 2022-11-05 09:09:16 +00:00
ccd9356550 Merge "quota: Add 'quota show --usage' option" 2022-10-12 11:22:09 +00:00
351b2b1074 Merge "quota: Simplify logic used to list, show quotas" 2022-10-12 11:14:20 +00:00
09ff9a0f4c quota: Deprecate "force" behavior for network quotas
In change Idc1b99492d609eb699d0a6bef6cd760458a774f6, we added a
'--check-limit' option to enable "no force" behavior for network quotas.
This was already the default for compute quotas. Provide a path for
harmonizing the behavior of the two options by instead using a
'--no-force' option which will become the eventual default for the
network quotas also.

Change-Id: I25828a3d68e2e900f498e17a0d01fb70be77548e
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-10-11 16:52:08 +01:00
2da4aa99aa quota: Fix issues with delete quota command
We were passing a project object rather than just the ID. Also correct a
typo in the call to delete network quotas.

Change-Id: I2292db7932ec01026f0e54014e3d02218792617a
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-10-11 16:41:28 +01:00
8be0c641e1 Merge "quota: Add support for detailed volume quotas" 2022-10-07 17:05:55 +00:00
eac38feef0 Merge "quota: Add 'quota delete' command" 2022-10-07 16:37:20 +00:00