// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { connect } from 'react-redux'; import { Grid, Typography, Button, Card, CardContent, TableBody, TableCell, TableHead, TableRow, Table, Tooltip, IconButton } from '@material-ui/core'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; import { ArvadosTheme } from '~/common/custom-theme'; import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet'; import { Link } from 'react-router-dom'; import { compose, Dispatch } from 'redux'; import { saveRequestedDate, loadVirtualMachinesData } from '~/store/virtual-machines/virtual-machines-actions'; import { RootState } from '~/store/store'; import { ListResults } from '~/services/common-service/common-service'; import { HelpIcon, MoreOptionsIcon } from '~/components/icon/icon'; import { VirtualMachineLogins, VirtualMachinesResource } from '~/models/virtual-machines'; import { Routes } from '~/routes/routes'; import { openVirtualMachinesContextMenu } from '~/store/context-menu/context-menu-actions'; type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'rightAlign' | 'cardWithoutMachines' | 'icon' | 'moreOptionsButton' | 'moreOptions'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ button: { marginTop: theme.spacing.unit, marginBottom: theme.spacing.unit }, codeSnippet: { borderRadius: theme.spacing.unit * 0.5, border: '1px solid', borderColor: theme.palette.grey["400"], }, link: { textDecoration: 'none', color: theme.palette.primary.main, "&:hover": { color: theme.palette.primary.dark, transition: 'all 0.5s ease' } }, linkIcon: { textDecoration: 'none', color: theme.palette.grey["500"], textAlign: 'right', "&:hover": { color: theme.palette.common.black, transition: 'all 0.5s ease' } }, rightAlign: { textAlign: "right" }, cardWithoutMachines: { display: 'flex' }, icon: { textAlign: "right", marginTop: theme.spacing.unit }, moreOptionsButton: { padding: 0 }, moreOptions: { textAlign: 'right', '&:last-child': { paddingRight: 0 } }, }); const mapStateToProps = ({ virtualMachines, auth }: RootState) => { return { requestedDate: virtualMachines.date, isAdmin: auth.user!.isAdmin, logins: virtualMachines.logins, ...virtualMachines }; }; const mapDispatchToProps = (dispatch: Dispatch): Pick => ({ saveRequestedDate: () => dispatch(saveRequestedDate()), loadVirtualMachinesData: () => dispatch(loadVirtualMachinesData()), onOptionsMenuOpen: (event, virtualMachine) => { dispatch(openVirtualMachinesContextMenu(event, virtualMachine)); }, }); interface VirtualMachinesPanelDataProps { requestedDate: string; virtualMachines: ListResults; logins: VirtualMachineLogins; links: ListResults; isAdmin: boolean; } interface VirtualMachinesPanelActionProps { saveRequestedDate: () => void; loadVirtualMachinesData: () => string; onOptionsMenuOpen: (event: React.MouseEvent, virtualMachine: VirtualMachinesResource) => void; } type VirtualMachineProps = VirtualMachinesPanelActionProps & VirtualMachinesPanelDataProps & WithStyles; export const VirtualMachinePanel = compose( withStyles(styles), connect(mapStateToProps, mapDispatchToProps))( class extends React.Component { componentDidMount() { this.props.loadVirtualMachinesData(); } render() { const { virtualMachines, links, isAdmin } = this.props; return ( {!isAdmin && virtualMachines.itemsAvailable > 0 && } {virtualMachines.itemsAvailable > 0 && links.itemsAvailable > 0 && } {!isAdmin && } ); } } ); const CardContentWithNoVirtualMachines = (props: VirtualMachineProps) => 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. {props.requestedDate && A request for shell access was sent on {props.requestedDate} } ; const CardContentWithVirtualMachines = (props: VirtualMachineProps) => {props.isAdmin ? {adminVirtualMachinesTable(props)} :
{props.requestedDate && A request for shell access was sent on {props.requestedDate} }
{userVirtualMachinesTable(props)}
}
; const userVirtualMachinesTable = (props: VirtualMachineProps) => Host name Login name Command line Web shell {props.virtualMachines.items.map((it, index) => {it.hostname} {getUsername(props.links)} ssh {getUsername(props.links)}@{it.hostname}.arvados Log in as {getUsername(props.links)} )}
; const adminVirtualMachinesTable = (props: VirtualMachineProps) => Uuid Host name Logins {props.logins.items.length > 0 && props.virtualMachines.items.map((it, index) => {it.uuid} {it.hostname} ["{props.logins.items[0].username}"] props.onOptionsMenuOpen(event, it)} className={props.classes.moreOptionsButton}> )}
; const getUsername = (links: ListResults) => { return links.items[0].properties.username; }; const CardSSHSection = (props: VirtualMachineProps) => In order to access virtual machines using SSH, add an SSH key to your account and add a section like this to your SSH configuration file ( ~/.ssh/config): ; const textSSH = `Host *.arvados TCPKeepAlive yes ServerAliveInterval 60 ProxyCommand ssh -p2222 turnout@switchyard.api.ardev.roche.com -x -a $SSH_PROXY_FLAGS %h`;