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';
19 type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'icon';
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23 marginTop: theme.spacing.unit,
24 marginBottom: theme.spacing.unit * 2
27 borderRadius: theme.spacing.unit * 0.5,
29 borderColor: theme.palette.grey["400"],
32 textDecoration: 'none',
33 color: theme.palette.primary.main,
35 color: theme.palette.primary.dark,
36 transition: 'all 0.5s ease'
40 textDecoration: 'none',
41 color: theme.palette.grey["500"],
44 color: theme.palette.common.black,
45 transition: 'all 0.5s ease'
53 const mapStateToProps = (state: RootState) => {
55 requestedDate: state.virtualMachines.date,
56 virtualMachines: state.virtualMachines.virtualMachines,
57 logins: state.virtualMachines.logins
61 const mapDispatchToProps = (dispatch: Dispatch) => ({
62 saveRequestedDate: () => dispatch<any>(saveRequestedDate()),
63 loadVirtualMachinesData: () => dispatch<any>(loadVirtualMachinesData())
66 interface VirtualMachinesPanelDataProps {
67 requestedDate: string;
68 virtualMachines: ListResults<any>;
69 logins: VirtualMachinesLoginsResource[];
72 interface VirtualMachinesPanelActionProps {
73 saveRequestedDate: () => void;
74 loadVirtualMachinesData: () => string;
77 type VirtualMachineProps = VirtualMachinesPanelActionProps & VirtualMachinesPanelDataProps & WithStyles<CssRules>;
79 export const VirtualMachinePanel = compose(
81 connect(mapStateToProps, mapDispatchToProps))(
82 class extends React.Component<VirtualMachineProps> {
84 this.props.loadVirtualMachinesData();
88 const { classes, saveRequestedDate, requestedDate, virtualMachines, logins } = this.props;
90 <Grid container spacing={16}>
91 {cardContentWithNoVirtualMachines(requestedDate, saveRequestedDate, classes)}
92 {virtualMachines.itemsAvailable > 0 && cardContentWithVirtualMachines(virtualMachines, classes)}
93 {cardSSHSection(classes)}
100 const cardContentWithNoVirtualMachines = (requestedDate: string, saveRequestedDate: () => void, classes: any) =>
104 <Typography variant="body2">
105 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.
107 <Button variant="contained" color="primary" className={classes.button} onClick={saveRequestedDate}>
108 SEND REQUEST FOR SHELL ACCESS
111 <Typography variant="body1">
112 A request for shell access was sent on {requestedDate}
118 const login = 'pawelkowalczyk';
120 const cardContentWithVirtualMachines = (virtualMachines: ListResults<any>, classes: any) =>
124 <div className={classes.icon}>
125 <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" className={classes.linkIcon}>
126 <Tooltip title="Access VM using webshell">
134 <TableCell>Host name</TableCell>
135 <TableCell>Login name</TableCell>
136 <TableCell>Command line</TableCell>
137 <TableCell>Web shell</TableCell>
141 {virtualMachines.items.map((it, index) =>
142 <TableRow key={index}>
143 <TableCell>{it.hostname}</TableCell>
144 <TableCell>{login}</TableCell>
145 <TableCell>ssh {login}@shell.arvados</TableCell>
147 <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${login}`} target="_blank" className={classes.link}>
159 // dodac link do ssh panelu jak juz bedzie
160 const cardSSHSection = (classes: any) =>
164 <Typography variant="body2">
165 In order to access virtual machines using SSH, <Link to='' className={classes.link}>add an SSH key to your account</Link> and add a section like this to your SSH configuration file ( ~/.ssh/config):
168 className={classes.codeSnippet}
174 const textSSH = `Host *.arvados
176 ServerAliveInterval 60
177 ProxyCommand ssh -p2222 turnout@switchyard.api.ardev.roche.com -x -a $SSH_PROXY_FLAGS %h`;