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 } 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 } 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["400"],
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 = withStyles(styles)(connect(mapStateToProps, mapDispatchToProps)(
80 class extends React.Component<VirtualMachineProps> {
82 this.props.loadVirtualMachinesData();
86 const { classes, saveRequestedDate, requestedDate, virtualMachines, logins } = this.props;
88 <Grid container spacing={16}>
92 {virtualMachines.itemsAvailable === 0
93 ? cardContentWithNoVirtualMachines(requestedDate, saveRequestedDate, classes)
94 : cardContentWithVirtualMachines(virtualMachines, classes)}
99 {cardSSHSection(classes)}
107 const cardContentWithNoVirtualMachines = (requestedDate: string, saveRequestedDate: () => void, classes: any) =>
109 <Typography variant="body2">
110 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.
112 <Button variant="contained" color="primary" className={classes.button} onClick={saveRequestedDate}>
113 SEND REQUEST FOR SHELL ACCESS
116 <Typography variant="body1">
117 A request for shell access was sent on {requestedDate}
121 const login = 'pawelkowalczyk';
123 const cardContentWithVirtualMachines = (virtualMachines: ListResults<any>, classes: any) =>
125 <div className={classes.icon}>
126 <a href="https://doc.arvados.org/user/getting_started/vm-login-with-webshell.html" target="_blank" className={classes.linkIcon}>
133 <TableCell>Host name</TableCell>
134 <TableCell>Login name</TableCell>
135 <TableCell>Command line</TableCell>
136 <TableCell>Web shell</TableCell>
140 {virtualMachines.items.map((it, index) =>
141 <TableRow key={index}>
142 <TableCell>{it.hostname}</TableCell>
143 <TableCell>{login}</TableCell>
144 <TableCell>ssh {login}@shell.arvados</TableCell>
146 <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${login}`} target="_blank" className={classes.link}>
156 // dodac link do ssh panelu jak juz bedzie
157 const cardSSHSection = (classes: any) =>
160 <Typography variant="body2">
161 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):
164 className={classes.codeSnippet}
169 const textSSH = `Host *.arvados
171 ServerAliveInterval 60
172 ProxyCommand ssh -p2222 turnout@switchyard.api.ardev.roche.com -x -a $SSH_PROXY_FLAGS %h`;