diff --git a/frontend/public/kubevirt/components/_vmconsoles.scss b/frontend/public/kubevirt/components/_vmconsoles.scss index 9e2e2ff26d9..238d3593f62 100644 --- a/frontend/public/kubevirt/components/_vmconsoles.scss +++ b/frontend/public/kubevirt/components/_vmconsoles.scss @@ -12,3 +12,7 @@ padding: 0; } } + +.console-terminal-pf { + padding-top: 15px; // fix OKD core vs pf-react styling difference +} diff --git a/frontend/public/kubevirt/components/utils/resources.js b/frontend/public/kubevirt/components/utils/resources.js index b9f5947418f..ec4dddfc424 100644 --- a/frontend/public/kubevirt/components/utils/resources.js +++ b/frontend/public/kubevirt/components/utils/resources.js @@ -43,22 +43,39 @@ export const getFlattenForKind = (kind) => { return resources => _.get(resources, kind, {}).data; }; +// TODO: move following to web-ui-components export const isVmiRunning = (vmi) => _.get(vmi, 'status.phase') === 'Running'; export const isVmStarting = (vm, vmi) => _.get(vm, 'spec.running') && !isVmiRunning(vmi); +export const getVmStatus = vm => _.get(vm, 'spec.running', false) ? 'Running' : 'Stopped'; -export const getVncConnectionDetails = vmi => { - // Example: ws://localhost:9000/api/kubernetes/apis/subresources.kubevirt.io/v1alpha2/namespaces/kube-system/virtualmachineinstances/vm-cirros1/vnc +const getApiConsoleApiBase = () => { let base = k8sBasePath; - base = base[0] === '/' ? base.substring(1) : base; // avpid the extra slash when compose the URL by VncConsole - const context = `${base}/apis/subresources.${VirtualMachineInstanceModel.apiGroup}`; - const apiPath = `${VirtualMachineInstanceModel.apiVersion}/namespaces/${vmi.metadata.namespace}/${VirtualMachineInstanceModel.path}/${vmi.metadata.name}`; - const query = `?x-csrf-token=${encodeURIComponent(getCSRFToken())}`; - const encrypt = window.location.protocol === 'https:'; + base = base[0] === '/' ? base.substring(1) : base; // avoid the extra slash when compose the URL by VncConsole + return base; +}; + +const getConsoleApiContext = () => `${getApiConsoleApiBase()}/apis/subresources.${VirtualMachineInstanceModel.apiGroup}`; +const getConsoleApiPath = vmi => `${VirtualMachineInstanceModel.apiVersion}/namespaces/${vmi.metadata.namespace}/${VirtualMachineInstanceModel.path}/${vmi.metadata.name}`; +const getConsoleApiQuery = () => `?x-csrf-token=${encodeURIComponent(getCSRFToken())}`; +const isEncrypted = () => window.location.protocol === 'https:'; + +export const getVncConnectionDetails = vmi => { // the novnc library requires protocol to be specified so the URL must be absolute - including host:port return { encrypt: isEncrypted(), // whether ws or wss to be used host: window.location.hostname, - port: window.location.port || (encrypt ? '443' : '80'), - path: `${context}/${apiPath}/vnc${query}`, + port: window.location.port || (isEncrypted() ? '443' : '80'), + + // Example: ws://localhost:9000/api/kubernetes/apis/subresources.kubevirt.io/v1alpha2/namespaces/kube-system/virtualmachineinstances/vm-cirros1/vnc + path: `${getConsoleApiContext()}/${getConsoleApiPath(vmi)}/vnc${getConsoleApiQuery()}`, + }; +}; + +export const getSerialConsoleConnectionDetails = vmi => { + const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; + return { + vmi, + host: `${protocol}://${window.location.hostname}:${window.location.port || (isEncrypted() ? '443' : '80')}`, + path: `/${getConsoleApiContext()}/${getConsoleApiPath(vmi)}/console`, // CSRF Token will be added in WSFactory }; }; diff --git a/frontend/public/kubevirt/components/vmconsoles.jsx b/frontend/public/kubevirt/components/vmconsoles.jsx index 6020828c2b9..cd55a22063c 100644 --- a/frontend/public/kubevirt/components/vmconsoles.jsx +++ b/frontend/public/kubevirt/components/vmconsoles.jsx @@ -1,68 +1,15 @@ import React from 'react'; -import { VncConsole } from '@patternfly/react-console'; -import { Button } from 'patternfly-react'; -import { getLabelMatcher, getResourceKind, getVncConnectionDetails, getFlattenForKind, findVMI, isVmiRunning, isVmStarting } from './utils/resources'; +import { getLabelMatcher, getResourceKind, getVncConnectionDetails, getSerialConsoleConnectionDetails, getFlattenForKind, findVMI } from './utils/resources'; + import { Firehose } from './utils/okdutils'; import { LoadingInline } from './okdcomponents'; +import { WSFactory } from '../module/okdk8s'; import { VirtualMachineInstanceModel, VirtualMachineModel } from '../models'; import { startStopVmModal } from './modals/start-stop-vm-modal'; -const VmIsDown = ({ vm }) => { - const action = ( - ); - - return ( -