Skip to content

Commit 5d730f3

Browse files
committed
Add support for spice-direct console types.
This patch adds support for Nova microversion 2.99 which exposes the new spice-direct console type and the pre-existing /os-console-auth-token/ API. +----------+----------------------------------------------------------+ | Field | Value | +----------+----------------------------------------------------------+ | protocol | spice | | type | spice-direct | | url | http://127.0.0.1:13002/nova?token=f78009fb-41ad-... | +----------+----------------------------------------------------------+ +----------------------+--------------------------------------+ | Field | Value | +----------------------+--------------------------------------+ | host | 127.0.0.1 | | instance_uuid | f2477018-aa93-... | | internal_access_path | None | | port | 5900 | | tls_port | 5901 | +----------------------+--------------------------------------+ Change-Id: I2d33646d6ac9b25076d69be76dcef8f5c465cd1b Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/940479
1 parent a49a290 commit 5d730f3

8 files changed

Lines changed: 164 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
==================
2+
console connection
3+
==================
4+
5+
Server console connection information
6+
7+
Compute v2
8+
9+
.. autoprogram-cliff:: openstack.compute.v2
10+
:command: console connection show

openstackclient/compute/v2/console.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ def get_parser(self, prog_name):
106106
const='spice-html5',
107107
help=_("Show SPICE console URL"),
108108
)
109+
type_group.add_argument(
110+
'--spice-direct',
111+
dest='url_type',
112+
action='store_const',
113+
const='spice-direct',
114+
help=_("Show SPICE direct protocol native console URL"),
115+
)
109116
type_group.add_argument(
110117
'--rdp',
111118
dest='url_type',
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
"""Compute v2 Console auth token implementations."""
15+
16+
from osc_lib.command import command
17+
from osc_lib import utils
18+
19+
from openstackclient.i18n import _
20+
21+
22+
def _get_console_connection_columns(item):
23+
column_map: dict[str, str] = {}
24+
hidden_columns = ['id', 'location', 'name']
25+
return utils.get_osc_show_columns_for_sdk_resource(
26+
item, column_map, hidden_columns
27+
)
28+
29+
30+
class ShowConsoleConnectionInformation(command.ShowOne):
31+
_description = _("Show server's remote console connection information")
32+
33+
def get_parser(self, prog_name):
34+
parser = super().get_parser(prog_name)
35+
parser.add_argument(
36+
'token',
37+
metavar='<token>',
38+
help=_("Nova console token to lookup"),
39+
)
40+
return parser
41+
42+
def take_action(self, parsed_args):
43+
compute_client = self.app.client_manager.compute
44+
data = compute_client.validate_console_auth_token(parsed_args.token)
45+
display_columns, columns = _get_console_connection_columns(data)
46+
data = utils.get_dict_properties(data, columns)
47+
48+
return (display_columns, data)

openstackclient/tests/unit/compute/v2/test_console.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_console_url_show_with_xvpvnc(self):
157157
self.assertEqual(self.columns, columns)
158158
self.assertEqual(self.data, data)
159159

160-
def test_console_url_show_with_spice(self):
160+
def test_console_url_show_with_spice_html5(self):
161161
arglist = [
162162
'--spice',
163163
'foo_vm',
@@ -174,6 +174,23 @@ def test_console_url_show_with_spice(self):
174174
self.assertEqual(self.columns, columns)
175175
self.assertEqual(self.data, data)
176176

177+
def test_console_url_show_with_spice_direct(self):
178+
arglist = [
179+
'--spice-direct',
180+
'foo_vm',
181+
]
182+
verifylist = [
183+
('url_type', 'spice-direct'),
184+
('server', 'foo_vm'),
185+
]
186+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
187+
columns, data = self.cmd.take_action(parsed_args)
188+
self.compute_client.create_console.assert_called_once_with(
189+
self._server.id, console_type='spice-direct'
190+
)
191+
self.assertEqual(self.columns, columns)
192+
self.assertEqual(self.data, data)
193+
177194
def test_console_url_show_with_rdp(self):
178195
arglist = [
179196
'--rdp',
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import uuid
14+
15+
from openstack.compute.v2 import console_auth_token as _console_auth_token
16+
from openstack.test import fakes as sdk_fakes
17+
18+
from openstackclient.compute.v2 import console_connection
19+
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
20+
21+
22+
class TestConsoleTokens(compute_fakes.TestComputev2):
23+
def setUp(self):
24+
super().setUp()
25+
26+
self._console_auth_token = sdk_fakes.generate_fake_resource(
27+
_console_auth_token.ConsoleAuthToken,
28+
host='127.0.0.1',
29+
instance_uuid=uuid.uuid4().hex,
30+
internal_access_path=None,
31+
port=5900,
32+
tls_port=5901,
33+
)
34+
self.compute_client.validate_console_auth_token.return_value = (
35+
self._console_auth_token
36+
)
37+
38+
self.columns = (
39+
'host',
40+
'instance_uuid',
41+
'internal_access_path',
42+
'port',
43+
'tls_port',
44+
)
45+
self.data = (
46+
self._console_auth_token.host,
47+
self._console_auth_token.instance_uuid,
48+
self._console_auth_token.internal_access_path,
49+
self._console_auth_token.port,
50+
self._console_auth_token.tls_port,
51+
)
52+
53+
self.cmd = console_connection.ShowConsoleConnectionInformation(
54+
self.app, None
55+
)
56+
57+
def test_console_connection_show(self):
58+
arglist = [
59+
'token',
60+
]
61+
verifylist = [
62+
('token', 'token'),
63+
]
64+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
65+
66+
columns, data = self.cmd.take_action(parsed_args)
67+
68+
self.compute_client.validate_console_auth_token.assert_called_once_with(
69+
'token'
70+
)
71+
self.assertEqual(self.columns, columns)
72+
self.assertEqual(self.data, data)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add support for the new ``spice-direct`` console type, as well as the
5+
exposing the ability for admins to lookup console connection information
6+
via the new ``console connection show`` command.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
77
cryptography>=2.7 # BSD/Apache-2.0
88
cliff>=3.5.0 # Apache-2.0
99
iso8601>=0.1.11 # MIT
10-
openstacksdk>=4.4.0 # Apache-2.0
10+
openstacksdk>=4.5.0 # Apache-2.0
1111
osc-lib>=2.3.0 # Apache-2.0
1212
oslo.i18n>=3.15.3 # Apache-2.0
1313
python-keystoneclient>=3.22.0 # Apache-2.0

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ openstack.compute.v2 =
7777
console_log_show = openstackclient.compute.v2.console:ShowConsoleLog
7878
console_url_show = openstackclient.compute.v2.console:ShowConsoleURL
7979

80+
console_connection_show = openstackclient.compute.v2.console_connection:ShowConsoleConnectionInformation
81+
8082
flavor_create = openstackclient.compute.v2.flavor:CreateFlavor
8183
flavor_delete = openstackclient.compute.v2.flavor:DeleteFlavor
8284
flavor_list = openstackclient.compute.v2.flavor:ListFlavor

0 commit comments

Comments
 (0)