Skip to content

Commit

Permalink
Add tag to know if users are creating hosts from Cisco Intersight (#2763
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ammont82 authored Jan 10, 2025
1 parent 104bb2b commit b805d87
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type DownloadISOProps = {
onClose: () => void;
onReset?: () => void;
docVersion?: string;
updateTagsForCiscoIntersight?: () => void;
};

const DownloadIso = ({
Expand All @@ -36,9 +37,16 @@ const DownloadIso = ({
hasDHCP,
isSNO = false,
docVersion,
updateTagsForCiscoIntersight,
}: DownloadISOProps) => {
const wgetCommand = `wget -O ${fileName} '${downloadUrl || ''}'`;
const { t } = useTranslation();

const openCiscoIntersightHostsLink = (downloadUrl: string) => {
updateTagsForCiscoIntersight ? updateTagsForCiscoIntersight() : '';
window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener');
};

return (
<>
<ModalBoxBody>
Expand Down Expand Up @@ -66,7 +74,7 @@ const DownloadIso = ({
icon={<ExternalLinkAltIcon />}
iconPosition="right"
isInline
onClick={() => window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener')}
onClick={() => openCiscoIntersightHostsLink(downloadUrl)}
>
{t('ai:Add hosts from Cisco Intersight')}
</Button>
Expand Down
2 changes: 2 additions & 0 deletions libs/ui-lib/lib/common/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,5 @@ export const operatorLabels = (
export const AI_UI_TAG = 'ui_ocm';

export const AI_ASSISTED_MIGRATION_TAG = 'assisted_migration';

export const AI_CISCO_INTERSIGHT_TAG = 'cisco_intersight_ui';
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import React from 'react';
import { Button, ButtonVariant, Modal, ModalVariant } from '@patternfly/react-core';
import { pluralize } from 'humanize-plus';
import { CpuArchitecture, DownloadIso, ErrorState, isSNO, ToolbarButton } from '../../../common';
import {
AI_CISCO_INTERSIGHT_TAG,
CpuArchitecture,
DownloadIso,
ErrorState,
isSNO,
ToolbarButton,
} from '../../../common';
import DiscoveryImageForm from './DiscoveryImageForm';
import { useModalDialogsContext } from '../hosts/ModalDialogsContext';
import useInfraEnvImageUrl from '../../hooks/useInfraEnvImageUrl';
import useInfraEnvIpxeImageUrl from '../../hooks/useInfraEnvIpxeImageUrl';
import DownloadIpxeScript from '../../../common/components/clusterConfiguration/DownloadIpxeScript';
import './DiscoveryImageModal.css';
import { Cluster } from '@openshift-assisted/types/assisted-installer-service';
import { ClustersService } from '../../services';
import { useDispatch } from 'react-redux';
import { updateCluster } from '../../store/slices/current-cluster/slice';

type DiscoveryImageModalButtonProps = {
ButtonComponent?: typeof Button | typeof ToolbarButton;
Expand Down Expand Up @@ -49,6 +59,8 @@ export const DiscoveryImageModal = () => {
const { getIsoImageUrl } = useInfraEnvImageUrl();
const { getIpxeImageUrl } = useInfraEnvIpxeImageUrl();

const dispatch = useDispatch();

const onImageReady = React.useCallback(async () => {
// We need to retrieve the Iso for the only infraEnv on Day1, hence we don't specify the architecture
const { url, error } = await getIsoImageUrl(cluster.id, CpuArchitecture.USE_DAY1_ARCHITECTURE);
Expand All @@ -73,6 +85,16 @@ export const DiscoveryImageModal = () => {
setIpxeSelected(true);
}, []);

const updateTagsForCiscoIntersight = async (cluster: Cluster) => {
try {
const { data: updatedCluster } = await ClustersService.update(cluster.id, cluster.tags, {
tags: AI_CISCO_INTERSIGHT_TAG,
});

dispatch(updateCluster(updatedCluster));
} catch (e) {}
};

if (!cluster) {
return null;
}
Expand All @@ -98,6 +120,7 @@ export const DiscoveryImageModal = () => {
isSNO={isSNOCluster}
onReset={onReset}
onClose={close}
updateTagsForCiscoIntersight={() => updateTagsForCiscoIntersight(cluster)}
/>
) : ipxeDownloadUrl ? (
<DownloadIpxeScript
Expand Down
13 changes: 11 additions & 2 deletions libs/ui-lib/lib/ocm/services/ClustersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import omit from 'lodash-es/omit.js';
import ClustersAPI from '../../common/api/assisted-service/ClustersAPI';
import HostsService from './HostsService';
import InfraEnvsService from './InfraEnvsService';
import { AI_ASSISTED_MIGRATION_TAG, AI_UI_TAG } from '../../common/config/constants';
import {
AI_ASSISTED_MIGRATION_TAG,
AI_CISCO_INTERSIGHT_TAG,
AI_UI_TAG,
} from '../../common/config/constants';
import { isInOcm } from '../../common/api/axiosClient';

const ClustersService = {
Expand Down Expand Up @@ -94,7 +98,12 @@ const ClustersService = {
): V2ClusterUpdateParams {
const tags = clusterTags?.split(',') || <string[]>[];
if (tags.includes(AI_UI_TAG)) {
delete params.tags;
if (params.tags && params.tags.includes(AI_CISCO_INTERSIGHT_TAG)) {
tags?.push(AI_CISCO_INTERSIGHT_TAG);
params.tags = tags?.join(',');
} else {
delete params.tags;
}
} else {
tags?.push(AI_UI_TAG);
params.tags = tags?.join(',');
Expand Down

0 comments on commit b805d87

Please sign in to comment.