443 Commits

Author SHA1 Message Date
Zuul
8b394e5641 Merge "Switch openstack server add port/network to using sdk." 2021-11-15 16:31:15 +00:00
Diwei Zhu
2183a61147 Switch openstack server add port/network to using sdk.
The old novaclient.v2.server.Server.interface_attach() method is
replaced with proxy.create_server_interface().
In swargs, 'net_id' and 'port_id' are mutual-exclusive, if one of
them is given with value, the other one cannot be None, as the
API would responde with 400 (None is not string).
In unit test, temporary method 'setup_sdk_servers_mock' is added,
because other tests are still using the old 'setup_servers_mock'.
Functional tests are added. Releasenote is generated.

Change-Id: I9899f0509febc5143560a1859ae6344d0a6d1427
2021-11-14 15:23:36 +00:00
Stephen Finucane
163cb01e46 compute: Return details of attached volumes
The API behind the 'server add volume' command returns details of the
created volume attachment, however, we were dropping these results
rather than displaying them to the user. Correct this.

Change-Id: I3f7e121220d29422ccf4e6940de2f28bb8496c83
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-11-03 11:57:31 +00:00
Stephen Finucane
442838ed15 compute: Use correct command class for 'show migration'
We should be inheriting from 'ShowOne'. Failure to do so results in a
tuple being dumped to the screen. Not what we intended.

While we're here, we update the docstring of this command to clarify the
command's intent. Nova does not provide an API to retrieve an individual
migration record for a cold migration or completed live migration. As
such, the 'server migration show' command only works for in-progress
live-migrations.

Change-Id: I2e2fe3da7d642b9e8e3d930603dcde178cd68cde
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: 2009658
Task: 43837
2021-11-03 10:19:52 +00:00
Stephen Finucane
8cb0a28607 compute: Don't warn if disk overcommit params unset
Due to a small logic error, we were emitting a warning about a
deprecated option when the user tried to live migrate an instance using
microversion 2.25 even though the user hadn't actually set that option.
Correct this.

Change-Id: Ib61e817bd4ced9b5533e7c7f9d8f0b45fe81c211
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: 2009657
Task: 43836
2021-11-03 10:17:37 +00:00
Cyril Roelandt
43639e1118 Fix typos
Change-Id: Idd502c8df21da79ff3b9339870f38378f5337879
2021-10-26 15:53:51 +02:00
Stephen Finucane
53debe7fe1 compute: Fix filtering servers by tags
The nova API expects the 'tags' and 'not-tags' filters of the 'GET
/servers' (list servers) API to be a CSV string [1]:

  tags (Optional)
    A list of tags to filter the server list by. Servers that match all
    tags in this list will be returned. Boolean expression in this case
    is 't1 AND t2'. Tags in query must be separated by comma.

    New in version 2.26

  not-tags (Optional)
    A list of tags to filter the server list by. Servers that don’t
    match all tags in this list will be returned. Boolean expression in
    this case is 'NOT (t1 AND t2)'. Tags in query must be separated by
    comma.

    New in version 2.26

We were instead providing a Python list, which was simply being URL
encoded. Correct this.

[1] https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detail#list-servers

Change-Id: Ie0251a0dccdf3385089e5bbaedf646a5e928cc48
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-Bug: #1946816
2021-10-13 10:30:26 +01:00
Zuul
d79ebc5278 Merge "Add --trusted-image-cert option for server create" 2021-10-06 22:14:37 +00:00
Zuul
49d2c21366 Merge "Fix typo error in listing server's column name" 2021-10-06 17:32:24 +00:00
Pavlo Shchelokovskyy
28a376bfb0 Add --trusted-image-cert option for server create
this already exists for server rebuild, but was missing for server
create.

This option is supported from Compute API version >= 2.63, and is only
available for servers booted directly from images (not from volumes,
not from snapshots, and not from images first converted to volumes).

Additionally, this patch removes mentions of
OS_TRUSTED_IMAGE_CERTIFICATE_IDS env var from similar option help string
in server rebuild command as it is not actually implemented yet.

Change-Id: I4e9faea05c499bd91034d1d284c44fdcc8e18db5
2021-09-30 19:42:26 +03:00
Stephen Finucane
8e833a3ed2 compute: Add support for microversion 2.90
Allow configuring hostname when creating a new server or updating or
rebuilding an existing server.

Change-Id: Ibe603eab78bbbec43605f56de62a20493b6aa93d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Depends-On: https://review.opendev.org/c/openstack/python-novaclient/+/806917
2021-09-01 13:18:25 +01:00
LEE JAE YONG
4aad7dd779 Fix typo error in listing server's column name
openstack server list -c "Created At" command doesn't work
because the wrong variable was used here.

When we receive resp data, Created At data is saved with
the name "created". But in "server.py", we append columns
as created_at. So it seems to print an empty table.

Story: 2009149
Task: 43112
Change-Id: I06de6903d5cc427a8b0fdcd168fec47192f4365b
2021-08-28 07:17:04 +00:00
melanie witt
ed87f7949e Correct REST API response fields for /os-migrations API
The compute APIs are unfortunately inconsistent with regard to the
response parameters for migrations.

* GET /servers/{server_id}/migrations returns server_uuid
* GET /os-migrations returns instance_uuid

Because the 'Server UUID' column is being specified for parsing the
response from GET /os-migrations, it is always showing as an empty
string to users.

There are a few other mismatches between the column names and the REST
API response fields [1]:

* 'Old Flavor' vs 'old_instance_type_id'
* 'New Flavor' vs 'new_instance_type_id'
* 'Type' vs 'migration_type'

This adds a new list containing the REST API response field names to
pass to utils.get_item_properties so that the responses are correctly
parsed and the client output contains the response data instead of
empty strings.

Story: 2009078
Task: 42890

[1] https://docs.openstack.org/api-ref/compute/?expanded=list-migrations-detail#list-migrations

Change-Id: I8aab60619e0225047f6a1c31e44917ca8fcc799e
2021-07-28 15:25:06 +00:00
Zuul
59256becc9 Merge "compute: Note that '--password' is deployment-specific" 2021-07-27 12:13:40 +00:00
Zuul
ab6e905353 Merge "compute: Fix typo" 2021-07-02 18:29:30 +00:00
Stephen Finucane
13de349411 compute: Better help text for 'openstack server set --state'
Manually changing the server state is a potentially dangerous operation
that should only be done under limited circumstances. It's also an
admin-only operation by default. Highlight both points.

Change-Id: Ifd8aec94937764202131ba8caf6b507caa76d7e9
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: 2008549
Task: 41672
2021-06-16 18:09:32 +01:00
Stephen Finucane
280b14abcd compute: Note that '--password' is deployment-specific
Password injection requires either hypervisor-support or an agent
running in the guest that will talk to the metadata service. It can be
disabled for a deployment using the '[api] enable_instance_password'
nova config option. Indicate this, albeit briefly.

Change-Id: Ief94ea07fc7ab6a487af972e8759ca6704d8f085
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-06-16 16:19:36 +01:00
Stephen Finucane
d087952717 compute: Fix typo
Change-Id: I3795142318b63b7c8f836d78a415a2161f61164d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-06-02 12:17:35 +01:00
Stephen Finucane
b1a41904c3 compute: Update 'server resize --revert', '--confirm' help
Update the help strings for these two arguments to indicate their
deprecated nature. This was previously flagged via a deprecation warning
but users would only see that if they were to run the command.

Change-Id: I31a5e27ac8bd2625a6073b54a51bf3e8d6126c8c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-05-20 16:58:57 +01:00
Stephen Finucane
2ccf7727a6 compute: Remove 'file://' prefix from '--block-device'
There are a couple of other (networking-related) options which accept
paths, none of which insist on a URI-style path. Let's just drop this
bit of complexity before we release the feature.

Change-Id: Ia7f781d82f3f4695b49b55a39abbb6e582cd879c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-03-11 15:56:59 +00:00
Stephen Finucane
d3bd0146ae compute: Add support for loading BDMs from files
The syntax of the '--block-device' parameter is complex and easily
screwed up. Allow users to load a block device config from a file. For
example:

  $ openstack server create ... --block-device file:///tmp/bdm.json ...

This should alleviate the pain that is BDMv2 somewhat.

No functional tests are provided since we already have tests for the CSV
style of passing parameters and the unit tests show that the net result
is the same.

Change-Id: I3e3299bbdbbb343863b4c14fb4d9196ff3e1698d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-03-05 13:11:09 +00:00
Stephen Finucane
7c1d6f769c compute: Add functional tests for --block-device
This mostly reuses the existing tests for '--block-device-mapping',
which can hopefully be removed at some point in the future.

This highlights two issues with the implementation of this option.
Firstly, the 'boot_index' parameter is not required so don't mandate it.
Secondly, and more significantly, we were defaulting the destination
type for the 'image' source type to 'local'. Nova only allows you to
attach a single image to local mapping [1], which means this default
would only make sense if you were expecting users to use the
'--block-device' option exclusively and omit the '--image' option. This
is the *less common* case so this is a bad default. Default instead to a
destination type of 'volume' like everything else, and require users
specifying '--block-device' alone to pass 'destination_type=local'
explicitly.

[1] https://github.com/openstack/nova/blob/c8a6f8d2e/nova/block_device.py#L193-L206

Change-Id: I1718be965f57c3bbdb8a14f3cfac967dd4c55b4d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-03-05 12:44:52 +00:00
Stephen Finucane
70480fa862 compute: Remove deprecated 'server migrate --live' option
It's been long enough. Time to remove this.

Change-Id: I37ef09eca0db9286544a4b0bb33f845311baa9b2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-22 13:00:46 +00:00
Stephen Finucane
6f3969a0c8 compute: Deprecate 'server create --file'
The parameter isn't actually deprecated, since we need to support older
API microversion, however, we now emit an error if someone attempts to
boot a server with the wrong microversion. This would happen server-side
anyway since this parameter was removed entirely in API microversion
2.57.

Change-Id: I73864ccbf5bf181fecf505ca168c1a35a8b0af3a
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-22 13:00:46 +00:00
Stephen Finucane
8868c77a20 compute: Stop silently ignore --(no-)disk-overcommit
These options are not supported from Nova API microversion 2.25 and
above. This can be a source of confusion. Start warning, with an eye on
erroring out in the future.

Change-Id: I53f27eb3e3c1a84d0d77a1672c008d0e8bb8536f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-22 13:00:46 +00:00
Stephen Finucane
2bdf34dcc3 compute: Auto-configure shared/block live migration
API microversion 2.25 introduced the 'block_migration=auto' value for
the os-migrateLive server action. This is a sensible default that we
should use, allowing users to avoid stating one of the
'--block-migration' or '--shared-migration' parameters explicitly.

While we're here, we take the opportunity to fix up some formatting in
the function, which is really rather messy.

Change-Id: Ieedc77d6dc3d4a3cd93b29672faa97dd4e8c1185
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-22 13:00:46 +00:00
Stephen Finucane
ace4bfb640 compute: Add 'server create --block-device' option
One of the last big gaps with novaclient. As noted in the release note,
the current '--block-device-mapping' format is based on the old BDM v1
format, even though it actually results in BDM v2-style requests to the
server. It's time to replace that.

Change-Id: If4eba38ccfb208ee186b90a0eec95e5fe6cf8415
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-22 13:00:39 +00:00
Stephen Finucane
f2deabb136 compute: Remove references to optional extensions
This is no longer a thing in nova.

Change-Id: I2413b826385792a4f33ff70e75621b48de65c799
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
4da4b96296 compute: Add missing 'server create' options
Add some volume-related options, namely '--snapshot', '--swap', and
'--ephemeral'. All are shortcuts to avoid having to use
'--block-device-mapping'.

Change-Id: I450e429ade46a7103740150c90e3ba9f2894e1a5
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
074e045c69 compute: Improve 'server create --block-device-mapping' option parsing
Once again, custom actions to the rescue.

Change-Id: I6b4f80882dbbeb6a2a7e877f63becae7211b7f9a
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
a52beacaa6 compute: Rename 'server migrate (confirm|revert)'
We're confirming or reverting a server migration, not a server migrate.
We've a number of 'server migration *' commands now so it makes sense to
move them under here.

Change-Id: Ib95bb36511dad1aafe75f0c88d10ded382e4fa5c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
f80fe2d8cf compute: Add 'server migration show' command
This replaces the 'server-migration-show' command provided by
novaclient.

Change-Id: I413310b481cc13b70853eb579417f6e6fad10d98
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
9ed34aac0a compute: Add support for 'server boot --nic ...,tag=<tag>'
This has been around for a long time but was not exposed via OSC. Close
this gap.

Change-Id: I71aabf10f791f68ee7405ffb5e8317cc96cb3b38
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
c7d582379a compute: Improve 'server create --nic' option parsing
Simplify the parsing of this option by making use of a custom action.

Change-Id: I670ff5109522d533ef4e62a79116e49a35c4e8fa
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
d6c9b7f198 compute: Shuffle options for 'server create'
argparse doesn't sort options by name, meaning we can use the
opportunity to group closely related options together. Do that.

Change-Id: I6714c8db1a549bd4206d2282d2876a406af65aa2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 11:01:15 +00:00
Stephen Finucane
1a6df700be compute: Add 'server * --all-projects' option
Add an '--all-projects' option to a number of commands:

- server delete
- server start
- server stop

This is in addition to 'server list', which already supports this
option.

This option allows users to request the corresponding action on one or
more servers using the server names when that server exists in another
project. This is admin-only by default.

As part of this work, we also introduce a 'boolenv' helper function that
allows us to parse the environment variable as a boolean using
'bool_from_string' helper provided by oslo.utils. This could probably be
clever and it has the unfortunate side effect of modifying the help
text in environments where this is configured, but it's good enough for
now.  It also appears to add a new dependency, in the form of
oslo.utils, but that dependency was already required by osc-lib and
probably more.

Change-Id: I4811f8f66dcb14ed99cc1cfb80b00e2d77afe45f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-21 10:54:27 +00:00
Zuul
6905e97565 Merge "compute: Improve 'server migration list' options" 2021-01-15 21:34:35 +00:00
Zuul
66e33b6edb Merge "compute: Add '--force' option to 'server delete'" 2021-01-15 21:34:25 +00:00
Zuul
3864ceea26 Merge "compute: Add 'server volume update' command" 2021-01-15 04:09:58 +00:00
Stephen Finucane
dfa869ed1d compute: Improve 'server migration list' options
Improve both the '--user' and '--project' options to allow names as well
as UUIDs. There's no release note included since this entire command was
added in change I15b4a5aca8d0dee59dd293e7b1c7272cdfbeea20, which hasn't
been included in a release yet.

Change-Id: I7654f3ffc54d38d5cfb03d8d1b2f4dc4fb06fb3d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-12 17:08:54 +00:00
Stephen Finucane
8a164bb09c compute: Add '--force' option to 'server delete'
This is an admin-only operation by default but can be useful.

Change-Id: I25a4da697e27c0fba4d28b504377667eb18f15fe
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-12 17:07:32 +00:00
Stephen Finucane
ca7f23d0d1 compute: Add 'server volume update' command
We're not going to expose the ability to swap volumes since that's a
things humans should not generally use. From the API docs [1]:

  When updating volumeId, this API is typically meant to only be used
  as part of a larger orchestrated volume migration operation initiated
  in the block storage service via the os-retype or os-migrate_volume
  volume actions. Direct usage of this API to update volumeId is not
  recommended and may result in needing to hard reboot the server to
  update details within the guest such as block storage serial IDs.
  Furthermore, updating volumeId via this API is only implemented by
  certain compute drivers.

We *do* want users to have the ability to change the delete on
termination behavior though, so that's what we expose.

[1] https://docs.openstack.org/api-ref/compute/?expanded=update-a-volume-attachment-detail#update-a-volume-attachment

Change-Id: I50938e1237b4d298521b26a5f9cb90c018dfebaf
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-12 16:29:07 +00:00
Stephen Finucane
2b073c2034 Add 'server unshelve --wait' option
This was recently added to the 'server shelve' command. Add it now for
the 'unshelve' command.

Change-Id: I633dd85b60cf70b4f8610f414d82669dd6a53111
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-08 18:01:29 +00:00
Stephen Finucane
64c2a1a453 Add 'server shelve --offload', 'server shelve --wait' options
The '--offload' option allows us to explicitly request that the server
be offloaded once shelved or if already shelved.

The '--wait' option allows us to wait for the shelve and/or offload
operations to complete before returning. It is implied when attempting
to offload a server than is not yet shelved.

Change-Id: Id226831e3c09bc95c34b222151b27391a844b073
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-08 18:01:25 +00:00
Stephen Finucane
8a0f3fc6a8 compute: Add missing options for 'server set'
Add a new '--no-password' option to unset the password on an existing
server. In addition, add a new '--password' option that replaces the
interactive '--root-password' option. This makes sense given no other
commands uses interactive password options.

Checks that rely on specific API microversions now run before we execute
any action, to avoid situations where an update is only partially
applied.

Change-Id: Ibf8717efdd418a2d95215b4d9ab2acf0d57c4a70
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-08 12:14:41 +00:00
Zuul
9a976ada8e Merge "compute: Add missing options for 'server list'" 2021-01-08 02:26:08 +00:00
Stephen Finucane
d0112a801a compute: Add missing options for 'server list'
This accepts a large number of options that we weren't exposing. Add the
following options: '--availability-zone', '--key-name',
'--config-drive' and '--no-config-drive', '--progress', '--vm-state',
'--task-state' and '--power-state'.

In addition, refine the 'openstack server list --status' parameter to
restrict users to the actual choices supported by the server.

Change-Id: Ieeb1f22df7092e66a411b6a36eafb3e16efc2fc2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-07 14:10:54 +00:00
Stephen Finucane
bbf7de83ff trivial: Use plural for appended parameters
Multiple compute commands take a '--property' parameter or variant
thereof. These should be stored in a 'properties' (plural) dest for
sanity's sake. Correct this.

Change-Id: If393836925fa736404527d9abd212b8ac9931027
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-06 12:02:57 +00:00
Yongli He
f200799848 compute: Add 'server show --topology' option
Add support for compute microversion 2.78 by adding a '--topology'
option to 'openstack server show' command that retrieves server NUMA
information.

Change-Id: Ie22979df2ea9082ca64a4d43b571bd4025684825
2021-01-06 12:02:25 +00:00
Stephen Finucane
03776d82e5 compute: Fix 'server * -f yaml' output
Make use of 'FormattableColumn'-derived formatters, which provide better
output than what we were using before, particularly for the YAML output
format. For example, compare before for the 'server show' command:

  $ openstack --os-compute-api-version 2.79 server show test-server -f yaml
  ...
  addresses: private=fdff:77e3:9bb4:0:f816:3eff:fe6d:a944, 10.0.0.44
  flavor: disk='1', ephemeral='0', extra_specs.hw_rng:allowed='True', original_name='m1.tiny',
    ram='512', swap='0', vcpus='1'
  ...

To after:

  $ openstack --os-compute-api-version 2.79 server show test-server -f yaml
  ...
  addresses:
    private:
    - fdff:77e3:9bb4:0:f816:3eff:fe6d:a944
    - 10.0.0.44
  flavor:
    disk: 1
    ephemeral: 0
    extra_specs:
      hw_rng:allowed: 'True'
    original_name: m1.tiny
    ram: 512
    swap: 0
    vcpus: 1
  ...

Similarly, compare before for 'server list':

  $ openstack --os-compute-api-version 2.79 server list -f yaml
  - ...
    Networks: private=fdff:77e3:9bb4:0:f816:3eff:fe6d:a944, 10.0.0.44
    Power State: Running
    Properties: ''
    ...

To after:

  $ openstack --os-compute-api-version 2.79 server list -f yaml
  - ...
    Networks:
      private:
      - fdff:77e3:9bb4:0:f816:3eff:fe6d:a944
      - 10.0.0.44
    Power State: 1
    Properties: {}
    ...

We also fix the human-readable output for the 'tags' field.

Before:

  $ openstack --os-compute-api-version 2.79 server list
  ...
  | tags   | ['bar', 'foo']  |

After:

  $ openstack --os-compute-api-version 2.79 server list
  ...
  | tags   | bar, foo  |

Change-Id: I7a8349106e211c57c4577b75326b39b88bd9ac1e
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-06 12:02:24 +00:00