1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import { Grid, Typography, Button, Card, CardContent, TableBody, TableCell, TableHead, TableRow, Table, Tooltip } from '@material-ui/core';
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { ArvadosTheme } from '~/common/custom-theme';
10 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
11 import { Link } from 'react-router-dom';
12 import { Dispatch, compose } from 'redux';
13 import { saveRequestedDate, loadVirtualMachinesData } from '~/store/virtual-machines/virtual-machines-actions';
14 import { RootState } from '~/store/store';
15 import { ListResults } from '~/services/common-service/common-resource-service';
16 import { HelpIcon } from '~/components/icon/icon';
17 import { VirtualMachinesLoginsResource, VirtualMachinesResource } from '~/models/virtual-machines';
18 import { Routes } from '~/routes/routes';
20 type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'rightAlign' | 'cardWithoutMachines' | 'icon';
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24 marginTop: theme.spacing.unit,
25 marginBottom: theme.spacing.unit
28 borderRadius: theme.spacing.unit * 0.5,
30 borderColor: theme.palette.grey["400"],
33 textDecoration: 'none',
34 color: theme.palette.primary.main,
36 color: theme.palette.primary.dark,
37 transition: 'all 0.5s ease'
41 textDecoration: 'none',
42 color: theme.palette.grey["500"],
45 color: theme.palette.common.black,
46 transition: 'all 0.5s ease'
52 cardWithoutMachines: {
57 marginTop: theme.spacing.unit
61 const mapStateToProps = ({ virtualMachines }: RootState) => {
63 requestedDate: virtualMachines.date,
68 const mapDispatchToProps = {
70 loadVirtualMachinesData
73 interface VirtualMachinesPanelDataProps {
74 requestedDate: string;
75 virtualMachines: ListResults<any>;
76 logins: VirtualMachinesLoginsResource[];
77 links: ListResults<any>;
80 interface VirtualMachinesPanelActionProps {
81 saveRequestedDate: () => void;
82 loadVirtualMachinesData: () => string;
85 type VirtualMachineProps = VirtualMachinesPanelActionProps & VirtualMachinesPanelDataProps & WithStyles<CssRules>;
87 export const VirtualMachinePanel = compose(
89 connect(mapStateToProps, mapDispatchToProps))(
90 class extends React.Component<VirtualMachineProps> {
92 this.props.loadVirtualMachinesData();
96 const { virtualMachines, links } = this.props;
98 <Grid container spacing={16}>
99 {virtualMachines.itemsAvailable === 0 && <CardContentWithNoVirtualMachines {...this.props} />}
100 {virtualMachines.itemsAvailable > 0 && links.itemsAvailable > 0 && <CardContentWithVirtualMachines {...this.props} />}
101 {<CardSSHSection {...this.props} />}
108 const CardContentWithNoVirtualMachines = (props: VirtualMachineProps) =>
111 <CardContent className={props.classes.cardWithoutMachines}>
113 <Typography variant="body2">
114 You do not have access to any virtual machines. Some Arvados features require using the command line. You may request access to a hosted virtual machine with the command line shell.
117 <Grid item xs={6} className={props.classes.rightAlign}>
118 <Button variant="contained" color="primary" className={props.classes.button} onClick={props.saveRequestedDate}>
119 SEND REQUEST FOR SHELL ACCESS
121 {props.requestedDate &&
122 <Typography variant="body1">
123 A request for shell access was sent on {props.requestedDate}
130 const CardContentWithVirtualMachines = (props: VirtualMachineProps) =>
134 <div className={props.classes.rightAlign}>
135 <Button variant="contained" color="primary" className={props.classes.button} onClick={props.saveRequestedDate}>
136 SEND REQUEST FOR SHELL ACCESS
138 {props.requestedDate &&
139 <Typography variant="body1">
140 A request for shell access was sent on {props.requestedDate}
143 <div className={props.classes.icon}>
144 <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" className={props.classes.linkIcon}>
145 <Tooltip title="Access VM using webshell">
153 <TableCell>Host name</TableCell>
154 <TableCell>Login name</TableCell>
155 <TableCell>Command line</TableCell>
156 <TableCell>Web shell</TableCell>
160 {props.virtualMachines.items.map((it, index) =>
161 <TableRow key={index}>
162 <TableCell>{it.hostname}</TableCell>
163 <TableCell>{getUsername(props.links, it)}</TableCell>
164 <TableCell>ssh {getUsername(props.links, it)}@shell.arvados</TableCell>
166 <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${getUsername(props.links, it)}`} target="_blank" className={props.classes.link}>
167 Log in as {getUsername(props.links, it)}
178 const getUsername = (links: ListResults<any>, virtualMachine: VirtualMachinesResource) => {
179 const link = links.items.find((item: any) => item.headUuid === virtualMachine.uuid);
180 return link.properties.username || undefined;
183 const CardSSHSection = (props: VirtualMachineProps) =>
187 <Typography variant="body2">
188 In order to access virtual machines using SSH, <Link to={Routes.SSH_KEYS} className={props.classes.link}>add an SSH key to your account</Link> and add a section like this to your SSH configuration file ( ~/.ssh/config):
191 className={props.classes.codeSnippet}
197 const textSSH = `Host *.arvados
199 ServerAliveInterval 60
200 ProxyCommand ssh -p2222 turnout@switchyard.api.ardev.roche.com -x -a $SSH_PROXY_FLAGS %h`;