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 } from '~/models/virtual-machines';
18 import { Routes } from '~/routes/routes';
20 type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'icon';
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24 marginTop: theme.spacing.unit,
25 marginBottom: theme.spacing.unit * 2
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'
54 const mapStateToProps = (state: RootState) => {
56 requestedDate: state.virtualMachines.date,
57 virtualMachines: state.virtualMachines.virtualMachines,
58 logins: state.virtualMachines.logins,
59 links: state.virtualMachines.links
63 const mapDispatchToProps = (dispatch: Dispatch) => ({
64 saveRequestedDate: () => dispatch<any>(saveRequestedDate()),
65 loadVirtualMachinesData: () => dispatch<any>(loadVirtualMachinesData())
68 interface VirtualMachinesPanelDataProps {
69 requestedDate: string;
70 virtualMachines: ListResults<any>;
71 logins: VirtualMachinesLoginsResource[];
72 links: ListResults<any>;
75 interface VirtualMachinesPanelActionProps {
76 saveRequestedDate: () => void;
77 loadVirtualMachinesData: () => string;
80 type VirtualMachineProps = VirtualMachinesPanelActionProps & VirtualMachinesPanelDataProps & WithStyles<CssRules>;
82 export const VirtualMachinePanel = compose(
84 connect(mapStateToProps, mapDispatchToProps))(
85 class extends React.Component<VirtualMachineProps> {
87 this.props.loadVirtualMachinesData();
91 const { classes, saveRequestedDate, requestedDate, virtualMachines, logins, links } = this.props;
93 <Grid container spacing={16}>
94 {cardContentWithNoVirtualMachines(requestedDate, saveRequestedDate, classes)}
95 {virtualMachines.itemsAvailable > 0 && links.itemsAvailable > 0 && cardContentWithVirtualMachines(virtualMachines, links, classes)}
96 {cardSSHSection(classes)}
103 const cardContentWithNoVirtualMachines = (requestedDate: string, saveRequestedDate: () => void, classes: any) =>
107 <Typography variant="body2">
108 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.
110 <Button variant="contained" color="primary" className={classes.button} onClick={saveRequestedDate}>
111 SEND REQUEST FOR SHELL ACCESS
114 <Typography variant="body1">
115 A request for shell access was sent on {requestedDate}
121 const login = 'pawelkowalczyk';
123 const cardContentWithVirtualMachines = (virtualMachines: ListResults<any>, links: ListResults<any>, classes: any) =>
127 <div className={classes.icon}>
128 <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" className={classes.linkIcon}>
129 <Tooltip title="Access VM using webshell">
137 <TableCell>Host name</TableCell>
138 <TableCell>Login name</TableCell>
139 <TableCell>Command line</TableCell>
140 <TableCell>Web shell</TableCell>
144 {virtualMachines.items.map((it, index) =>
145 <TableRow key={index}>
146 <TableCell>{it.hostname}</TableCell>
147 <TableCell>{getUsername(links, it)}</TableCell>
148 <TableCell>ssh {getUsername(links, it)}@shell.arvados</TableCell>
150 <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${getUsername(links, it)}`} target="_blank" className={classes.link}>
151 Log in as {getUsername(links, it)}
162 const getUsername = (links: ListResults<any>, virtualMachine: any) => {
163 const link = links.items.find((item: any) => item.headUuid === virtualMachine.uuid);
164 return link.properties.username || undefined;
167 const cardSSHSection = (classes: any) =>
171 <Typography variant="body2">
172 In order to access virtual machines using SSH, <Link to={Routes.SSH_KEYS} className={classes.link}>add an SSH key to your account</Link> and add a section like this to your SSH configuration file ( ~/.ssh/config):
175 className={classes.codeSnippet}
181 const textSSH = `Host *.arvados
183 ServerAliveInterval 60
184 ProxyCommand ssh -p2222 turnout@switchyard.api.ardev.roche.com -x -a $SSH_PROXY_FLAGS %h`;