Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show helper to set up SSH tunnel for Desktop Viewer #1084

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/vm/consoles/desktopConsole.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
import React from "react";
import { CodeBlock, CodeBlockCode } from "@patternfly/react-core/dist/esm/components/CodeBlock";
import { DesktopViewer } from '@patternfly/react-console';

import { getServerAddress, needsTunnel } from "./utils.js";
import cockpit from "cockpit";
import store from './../../../store.js';

const _ = cockpit.gettext;

Expand All @@ -37,6 +40,11 @@ function fmt_to_fragments(fmt) {
}

const DesktopConsoleDownload = ({ vnc, spice, onDesktopConsole }) => {
// DesktopViewer prefers spice over vnc
const address = (spice && spice.address) || (vnc && vnc.address);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spice?.address || vnc?.address

const serverAddress = getServerAddress();
const loggedUser = store.getState().systemInfo.loggedUser;

return (
<DesktopViewer spice={spice}
vnc={vnc}
Expand All @@ -57,6 +65,12 @@ const DesktopConsoleDownload = ({ vnc, spice, onDesktopConsole }) => {
<p>
{fmt_to_fragments(_("Clicking \"Launch remote viewer\" will download a .vv file and launch $0."), <i>Remote Viewer</i>)}
</p>
{needsTunnel(address, serverAddress) && <p>
{_("SSH tunnel needs to be set up on client:")}
<CodeBlock>
<CodeBlockCode>{`ssh -L 5900:localhost:5900 -N ${loggedUser.name}@${serverAddress}`}</CodeBlockCode>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually really nice! Even if the serverAddress is slightly incorrect (due to reverse proxy and such), it will at least give admins an idea what needs to happen. Same for the local port -- it might be busy, and this doesn't work if you run this for more than one VM (you need to pick a different local port then), but this is meant as a guideline.

However, is it always 5900 on the remote side? Are VNC and spice using the same port? Can we ask libvirt about the port?

</CodeBlock>
</p>}
<p>
{fmt_to_fragments(_("$0 is available for most operating systems. To install it, search for it in GNOME Software or run the following:"), <i>Remote Viewer</i>)}
</p>
Expand Down
2 changes: 2 additions & 0 deletions test/check-machines-consoles
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class TestMachinesConsoles(VirtualMachinesCase):
b.wait_in_text('.pf-c-expandable-section__content',
'Clicking "Launch remote viewer" will download')

b.wait_not_in_text('.pf-c-expandable-section__content', 'SSH tunnel needs to be set up on client')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a positive test case, too. You already asked about this, just opening a thread to track it.


b.assert_pixels("#vm-subVmTest1-consoles-page", "vm-details-console-external", skip_layouts=["rtl"])

def testInlineConsole(self, urlroot=""):
Expand Down