Commit Graph

65 Commits

Author SHA1 Message Date
jakecoll 30eab20112 Add Resource Allocations API support
The Resource Allocation API was added in Stein. This adds support for
querying it with blazarclient. Only the host resource type is supported
for now.

Co-Authored-By: Matt Crees <mattc@stackhpc.com>
Co-Authored-By: Pierre Riteau <pierre@stackhpc.com>
Change-Id: I28f45320164188df73b70d4c9e04c5e53655062e
2023-02-17 09:50:42 +01:00
Matt Crees 6c0ae07ee2 Separate ID parser argument from ShowCommand
Move the ID parser argument from the base ShowCommand class to the
resource classes. This allows us to define arguments in any order,
instead of requiring the ID to be first.

Change-Id: I8929e631562dc1ed5cd78f71e59517aa50429aca
2023-01-23 10:39:36 +00:00
Mark Powers cf2de7cb63 Add commands for resource property API
This adds commands for interacting with the resource property API
that is specified in blueprint resource-properties-discovery-api.

Change-Id: Ibe024dc9b2d02d4061ab7eb68a4607d1356a6318
2022-02-23 22:47:39 +01:00
Sam Morrison cfabd241df Fix up client init
Commit c9114b7eb8 introduced a critical
bug where service_type is not being passed through to the client making
it fail.

Change-Id: I6c19199785109cacef6d8b06e08d926efc6d4890
Closes-Bug: #1942330
2021-09-02 12:44:24 +02:00
Zuul d2eb2f6583 Merge "Default client service type to reservation" 2021-08-26 16:10:24 +00:00
Mark Powers f2277b5f7a Add openstackclient support
This adds support for the recommended CLI using the OpenStackClient,
without modifying the existing Blazar shell CLI.

The existing shell command classes are used, by introducing a check in
the base comand class to use either the client passed by Blazar shell,
or the client using the osc_lib client_manager.

The argument --physical-reservation is also removed for the create lease
command when using the OpenStack client.

Implements: blueprint openstackclient-support
Change-Id: I97a7b91f0d05efc887307ac167e5c368276d4f81
2021-08-05 10:24:28 -05:00
Sam Morrison c9114b7eb8 Default client service type to reservation
Provide a default service type to avoid having to specify one,
this brings it inline with other openstack clients.

Change-Id: Idf423a87402894c131e6a57a86edc78ddcfd3ff6
2021-03-19 14:46:15 +11:00
Pierre Riteau 22cafd21a5 Provide a default affinity value
Change-Id: Ifd55fce5f9a6eb78aa6a909beab0d502b67c1d7a
Closes-Bug: #1917636
2021-03-03 16:28:05 +01:00
Sean McGinnis d2503ab476 Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I692abac2bf1fe118c27af043e71f315c8354c8a0
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2021-02-23 14:20:15 +00:00
Pierre Riteau 1db6cb37c6 Remove use of mock.seal()
The seal function was introduced in unittest.mock in Python 3.7. It is
preventing us from using unittest.mock instead of mock.

We can restore it when the minimum runtime is Python 3.7 or later.

Change-Id: Ieb26af07da0c4084fb8c4ea2c4d461eb5595f583
2021-02-23 15:10:51 +01:00
Martin Kopec e875b75392 Bump hacking max version to 3.0.1 and fix pep8
pep8 job is failing because the version of flake8
(flake8<2.7.0,>=2.6.0) requested by hacking<1.2.0 is not
compatible with pyflakes>=2.1.1. Therefore the patch increases
the max version of hacking.
Also the patch fixes a few pep8 errors.

Change-Id: Ib9f1cb5a77947cfb1ab28a7f26e97edba007466c
2021-01-03 11:52:53 +00:00
wangzihao cff1b05773 Remove six
Replace the following items with Python 3 style code:

- six.text_type
- six.StringIO

Change-Id: I9db56ea304938d66753106357e572f307d226850
2020-11-09 14:34:07 +00:00
Zuul 5473d56736 Merge "Fixup failing tests due to passing date threshold" 2020-09-10 17:12:23 +00:00
Jason Anderson 886a4d3505 Use KSA loading to support more auth methods
Currently Blazar has hard-coded support for only two login methods:
'token' and 'password'. There are many more auth mechanisms supported by
Keystone and the clients. The complexity of parsing arguments and
constructing an auth/session entity is taken care of in the
keystoneauth1.loading module, which this commit takes advantage of.

Change-Id: I7173d1880c8938ac54a0fb3495417f5ce40db4e7
2020-09-08 14:18:28 +02:00
Jason Anderson 1632a19633
Fixup failing tests due to passing date threshold
Some of the tests rely on a hard-coded date being actually in the past
when the test runs. This fixes that by fixing the value of utctime when
the test executes to a date in the past relative to the test input.

Change-Id: Iccb57dca5c1130a0e6ca88e9ca387fc218891369
2020-08-27 16:19:11 -05:00
Pierre Riteau 14846e1928 Fix test_args2body_start_now unit test
The test_args2body_start_now unit test started failing because the end
date was set to August 9, 2020 which is now in the past.

Change-Id: I8cc4f4ec7bf2af5bdfef37253801fd4c970b7977
2020-08-18 12:05:58 +02:00
Hervé Beraud 38073db106 Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: Iccb1384832b5f0892ddc3e5c2adec20e312add6a
2020-06-02 20:46:12 +02:00
Jason Anderson 3f30c49c6b Don't fetch entire list when looking up by ID
Blazar APIs support directly fetching a resource (whether host, floating
ip, or lease) with its ID. However, the default logic for this includes
a block that supports additionally looking up the resource by name (to
allow looking up e.g., a lease by it's name.) This requires fetching the
entire list of all resources and iterating over them until a match is
found, which is very inefficient. Moreover, this branch would be taken
even if the input was already a UUID.

This commit changes that behavior so that if a UUID is provided, it is
used to directly fetch the resource, which seems to be what the original
intent was in the first place.

Change-Id: I5b1ccf4abfe4aa9068bc011764cac4b3507ef697
2020-01-30 16:59:44 +01:00
Pierre Riteau e98421c919 Support floating IP reservation parameters in lease-update
The lease-update command needs to know about all possible keys that can
be passed as reservation parameters. Also treat required_floatingips as
a list, like in commit 9183950833.

Change-Id: Iad95ebf662fb052000f05aa3d76f76308704fd1d
Related-Bug: #1843258
2019-09-11 17:50:43 +02:00
Pierre Riteau 9183950833 Parse required_floatingips parameter as a JSON array
An API request to create a floating IP reservation is expected to pass
the required_floatingips parameter as a list, not as a string. Modify
the CLI to parse required_floatingips as a JSON array so it can be
passed to the API in the right format.

Change-Id: Ia84ceb881f0889266c8f0349a1ffb047597bac2d
Closes-Bug: #1843258
2019-09-10 09:52:21 +00:00
Pierre Riteau 0d733b8017 Clarify how reservation parameters should be defined
Change-Id: I84d9e97e26f7569767deac4144d57590896047fc
2019-08-20 12:14:45 +02:00
Pierre Riteau f9a191a2cf Fix parsing of network_id reservation parameter
The network_id parameter was not defined in CREATE_RESERVATION_KEYS. As
a result, it could not be parsed by the command-line client.

Change-Id: Icad6533ea32967601cf8d3bd4ccee659bb0b5abd
Closes-Bug: #1840759
2019-08-20 12:12:58 +02:00
Pierre Riteau ea96686ffb Add support for floating IP reservation
Change-Id: I7a73a4e7d2026eba2d0a3d6dfe9db42879ff6416
2019-05-30 11:29:04 +01:00
Zuul ac372aab53 Merge "Update hacking version" 2019-01-29 09:40:09 +00:00
ZhijunWei dd62254686 Update hacking version
Change-Id: I90fb45e5065f13e3a5cc803d5caf42f0e9653da1
2019-01-03 20:48:47 +08:00
Pierre Riteau c222b2eac3 Fix typo in exception class name
Change-Id: I3edee36fe577fe60052749858dd994a5fea7fff8
2018-12-17 15:24:01 +01:00
lvxianguo 8983bed2ea Fix link to oslo.i18n usage documentation
Change-Id: Id97e2836e9f55de610e580ccbabe07cf00d32c47
2018-08-15 09:22:10 +00:00
Pierre Riteau 92e26f3417 Fix exception message when there are leases with the same name
The resource variable, originally containing the resource type, i.e.
'lease', was reassigned with a lease object before being used in the
exception message. As a result, the message displayed a dictionary of
lease values, instead of "type 'lease'".

Change-Id: If4cb03cfb4a895c11e3952f0f1b79e0c7d14de8c
Closes-Bug: #1786030
2018-08-08 15:00:48 +02:00
Pierre Riteau 1e31dcaeb5 Fix lease creation when start date is not provided
Change-Id: I5fe0de436dd5e2c21ab9eb08b47c1995b5154a53
Closes-Bug: #1784038
2018-07-27 18:49:26 +01:00
Pierre Riteau f017a924d3 Set start date to 'now' rather than current time
When the Blazar CLI client is run without specifying a start date, it
uses the current time on the client machine. If the lease creation
request is sent to the Blazar service just before the end of a minute,
e.g. at 12:34:59, the Blazar manager might only process it during the
next minute (i.e. after 12:35:00). In this case, the manager will reject
the request with:

    Start date must be later than current date

This can also be an issue if the clocks on the client and server are not
synchronized closely.

This patch uses the special start date value 'now' which is resolved to
the current time on the server rather than on the client. Note that this
can result in leases that are one minute shorter than what the user
might expect, as the end date is still specified by the client.

It also clarifies help messages for start and end dates.

Change-Id: Ib761d8f4f15e44e28452497f282447472f0cf918
Closes-Bug: #1783296
2018-07-24 11:56:15 +01:00
Tetsuro Nakamura 98b2414eec Catch exceptions for session client
Exceptions from the API were not properly caught when it uses
keystone session client path. As a result, error messages in the
response body from blazar REST APIs were not displayed.

This patch fixes it creating the new SessionClient class, which
is basically the same as its parent class, but it can raise
BlazarClientException if requests to the blazar server failed.

Change-Id: I98ba3949742f2a987beb7e16400608b8ebb60065
Closes-Bug: #1777548
2018-07-09 15:23:33 +09:00
Pierre Riteau b51395f392 Respect selected region in multi-region clouds
The region name value provided via an environment variable or a command
line argument was not passed to the client object, meaning that the
wrong endpoint could be selected in a multi-region cloud.

Change-Id: Ia8bbec7e429d5a2385b7f38310512a93fbfb9ce1
2018-06-06 16:25:20 +01:00
Zuul 122ca0844c Merge "Support resource_properties key in instance_reservation" 2018-06-04 04:51:25 +00:00
Masahito Muroi b224d3e730 Support resource_properties key in instance_reservation
Partially Implements: blueprint flavors-extra-specs

Change-Id: I894afd8b358e7834e5e1f94c6dd2b4f4173a96fa
Depends-On: https://review.openstack.org/#/c/527343/
2018-05-11 05:49:40 +00:00
Masahito Muroi 60e658d667 Support hostname in show, update and delete host operations
The Blazar CLI doesn't support show, update and delete host operations
with hostname. It only accepts id because host uses a key called
hypervisor_hostname, rather one called name like for leases.

This patch enables the Blazar CLI to support hostname as well.

Change-Id: I3a7a3307099ed518d89de37039f9366770a21ce2
Closes-Bug: #1702266
2018-04-19 09:55:28 +00:00
Zuul a85eb18e8d Merge "Fix issues with Python3" 2018-01-31 10:56:42 +00:00
Hiroaki Kobayashi 39e1b71b81 Fix issues with Python3
Partially implements: blueprint python-3

Change-Id: I766594fb09047c0f114e20dc718bca2b374f3165
2018-01-25 14:37:10 +09:00
Hiroaki Kobayashi 34c711ea70 Align json indents
This patch aligns indents for showing json data.

Change-Id: I042f50a5bb06a0e84b142f9cd8f32ae26a4eb7a7
2018-01-15 15:40:56 +09:00
Hiroaki Kobayashi 7635be6271 Fix incorrect descriptions of host commands
Change-Id: Ib00f8858dc95a314fd0629673124a4dac60948c9
2017-12-21 11:19:33 +09:00
Masahito Muroi a46724a584 Support update lease API for instance reservation plugin
This patch adds instance reservation update support to the Blazar
command-line client.

Change-Id: I2a5ab7f6d05c0351930f69d894005329ed637dd7
Depends-On: Ibdf7a730ae45ff6d8c17de62b0fc69262df2db79
2017-12-05 09:14:56 +00:00
Zuul d4cf4ddc12 Merge "Replace six.iteritems() with .items()" 2017-11-28 02:58:27 +00:00
rajat29 c477796f42 Replace six.iteritems() with .items()
As mentioned in [1], we should avoid using six.iteritems() to achieve
iterators. We can use dict.items() instead, as it will return iterators
in Python 3 as well, and it is more readable.

In Python 2, the overhead of dict.items() creating a new list should be
negligible for most use cases in OpenStack [2].

[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I620c9cc201c62f033a5467aa52625b56e19933cb
2017-11-27 10:50:40 +00:00
Hiroki Ito 2afa290302 Restore backward compatibility for init client
After merged the patch I08c8b753972c27b4e6bbe07a8aa51e0e72fbc56d,
blazarclient can't be used with blazar_url and auth_token since this
patch only allows sessions for the initiation of client.
For backward compatibility, blazarclient should be initiated with
blazar_url and auth_token as before.

This patch enables using blazarclient with a set of blazar_url and
auth_token or session by reviving BaseClientManager class with adding
a logic to chose an auth method based on given params.

Change-Id: I25a665145b0503cc04e49bc85c39e2f6dca36925
Closes-Bug: #1724757
2017-11-17 07:48:38 +00:00
Zuul 8d897c5220 Merge "Use fixtures instead of deprecated mockpatch module" 2017-10-17 00:57:17 +00:00
Hiroki Ito a3448e5510 Migrate to keystoneauth1
For authentication, the community recommends the use of keystoneauth1
instead of python-keystoneclient. Therefore, Blazar should follow
this trend and migrate to keystoneauth1.

This patch enables blazarclient to use keystoneauth1 for authentications
and REST API requests and also enables use of project_id, project_name,
project_domain_id, project_domain_name, user_domain_id and user_domain_name
for authentication.

Change-Id: I08c8b753972c27b4e6bbe07a8aa51e0e72fbc56d
Closes-Bug: #1661215
2017-10-06 17:20:19 +09:00
chenghuiyu 3a2fbabbcc Stop using oslo_utils.timeutils.strtime()
This patch stops using oslo_utils.timeutils.strtime(), as it was
deprecated in version 1.6 and will be removed in a future version.

Change-Id: I6690420c8ce001ed12f47f78e657b4ad26bec816
2017-09-15 15:40:38 +00:00
rajat29 674dfb000c Use fixtures instead of deprecated mockpatch module
The mockpatch module of oslotest is deprecated since version 1.13
and may be removed in version 2.0. Use fixtures.Mock* classes instead.

Change-Id: I0ea834d41664efe84aa28ef2362467e2ad8b1928
2017-08-24 05:18:21 +00:00
Hiroaki Kobayashi 57e0e5bd5c Add a reservation parameter to the lease_update command
Implements: blueprint update-reserved-capacity
Depends-On: Ia990e126607657c8811fe92f23f6c30cc9889946
Change-Id: I617a335a49c8be35da610a49dc3642efae81dd27
2017-08-23 01:30:37 +00:00
Hiroaki Kobayashi 5cb6ad8c2a Add before_end_date and before_end parameters
This patch adds a before_end_date option to the lease-create command. It
also adds a before_end parameter to the physical_reservation option.

Partially Implements: blueprint on-end-options
Depends-On: I90fb90d9d53814791d863f4ce5dab28388d3688d
Change-Id: I2a6f3477509f5b549edbdc25cb2c6ac457c7c100
2017-08-18 10:58:11 +00:00
Jenkins 9e0b7110f0 Merge "Fix unicode issues with Python 3" 2017-08-15 08:22:41 +00:00