Skip to content

Commit b805d87

Browse files
authored
Add tag to know if users are creating hosts from Cisco Intersight (#2763)
1 parent 104bb2b commit b805d87

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

Diff for: libs/ui-lib/lib/common/components/clusterConfiguration/DownloadIso.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type DownloadISOProps = {
2626
onClose: () => void;
2727
onReset?: () => void;
2828
docVersion?: string;
29+
updateTagsForCiscoIntersight?: () => void;
2930
};
3031

3132
const DownloadIso = ({
@@ -36,9 +37,16 @@ const DownloadIso = ({
3637
hasDHCP,
3738
isSNO = false,
3839
docVersion,
40+
updateTagsForCiscoIntersight,
3941
}: DownloadISOProps) => {
4042
const wgetCommand = `wget -O ${fileName} '${downloadUrl || ''}'`;
4143
const { t } = useTranslation();
44+
45+
const openCiscoIntersightHostsLink = (downloadUrl: string) => {
46+
updateTagsForCiscoIntersight ? updateTagsForCiscoIntersight() : '';
47+
window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener');
48+
};
49+
4250
return (
4351
<>
4452
<ModalBoxBody>
@@ -66,7 +74,7 @@ const DownloadIso = ({
6674
icon={<ExternalLinkAltIcon />}
6775
iconPosition="right"
6876
isInline
69-
onClick={() => window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener')}
77+
onClick={() => openCiscoIntersightHostsLink(downloadUrl)}
7078
>
7179
{t('ai:Add hosts from Cisco Intersight')}
7280
</Button>

Diff for: libs/ui-lib/lib/common/config/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,5 @@ export const operatorLabels = (
377377
export const AI_UI_TAG = 'ui_ocm';
378378

379379
export const AI_ASSISTED_MIGRATION_TAG = 'assisted_migration';
380+
381+
export const AI_CISCO_INTERSIGHT_TAG = 'cisco_intersight_ui';

Diff for: libs/ui-lib/lib/ocm/components/clusterConfiguration/DiscoveryImageModal.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import React from 'react';
22
import { Button, ButtonVariant, Modal, ModalVariant } from '@patternfly/react-core';
33
import { pluralize } from 'humanize-plus';
4-
import { CpuArchitecture, DownloadIso, ErrorState, isSNO, ToolbarButton } from '../../../common';
4+
import {
5+
AI_CISCO_INTERSIGHT_TAG,
6+
CpuArchitecture,
7+
DownloadIso,
8+
ErrorState,
9+
isSNO,
10+
ToolbarButton,
11+
} from '../../../common';
512
import DiscoveryImageForm from './DiscoveryImageForm';
613
import { useModalDialogsContext } from '../hosts/ModalDialogsContext';
714
import useInfraEnvImageUrl from '../../hooks/useInfraEnvImageUrl';
815
import useInfraEnvIpxeImageUrl from '../../hooks/useInfraEnvIpxeImageUrl';
916
import DownloadIpxeScript from '../../../common/components/clusterConfiguration/DownloadIpxeScript';
1017
import './DiscoveryImageModal.css';
1118
import { Cluster } from '@openshift-assisted/types/assisted-installer-service';
19+
import { ClustersService } from '../../services';
20+
import { useDispatch } from 'react-redux';
21+
import { updateCluster } from '../../store/slices/current-cluster/slice';
1222

1323
type DiscoveryImageModalButtonProps = {
1424
ButtonComponent?: typeof Button | typeof ToolbarButton;
@@ -49,6 +59,8 @@ export const DiscoveryImageModal = () => {
4959
const { getIsoImageUrl } = useInfraEnvImageUrl();
5060
const { getIpxeImageUrl } = useInfraEnvIpxeImageUrl();
5161

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

88+
const updateTagsForCiscoIntersight = async (cluster: Cluster) => {
89+
try {
90+
const { data: updatedCluster } = await ClustersService.update(cluster.id, cluster.tags, {
91+
tags: AI_CISCO_INTERSIGHT_TAG,
92+
});
93+
94+
dispatch(updateCluster(updatedCluster));
95+
} catch (e) {}
96+
};
97+
7698
if (!cluster) {
7799
return null;
78100
}
@@ -98,6 +120,7 @@ export const DiscoveryImageModal = () => {
98120
isSNO={isSNOCluster}
99121
onReset={onReset}
100122
onClose={close}
123+
updateTagsForCiscoIntersight={() => updateTagsForCiscoIntersight(cluster)}
101124
/>
102125
) : ipxeDownloadUrl ? (
103126
<DownloadIpxeScript

Diff for: libs/ui-lib/lib/ocm/services/ClustersService.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import omit from 'lodash-es/omit.js';
1414
import ClustersAPI from '../../common/api/assisted-service/ClustersAPI';
1515
import HostsService from './HostsService';
1616
import InfraEnvsService from './InfraEnvsService';
17-
import { AI_ASSISTED_MIGRATION_TAG, AI_UI_TAG } from '../../common/config/constants';
17+
import {
18+
AI_ASSISTED_MIGRATION_TAG,
19+
AI_CISCO_INTERSIGHT_TAG,
20+
AI_UI_TAG,
21+
} from '../../common/config/constants';
1822
import { isInOcm } from '../../common/api/axiosClient';
1923

2024
const ClustersService = {
@@ -94,7 +98,12 @@ const ClustersService = {
9498
): V2ClusterUpdateParams {
9599
const tags = clusterTags?.split(',') || <string[]>[];
96100
if (tags.includes(AI_UI_TAG)) {
97-
delete params.tags;
101+
if (params.tags && params.tags.includes(AI_CISCO_INTERSIGHT_TAG)) {
102+
tags?.push(AI_CISCO_INTERSIGHT_TAG);
103+
params.tags = tags?.join(',');
104+
} else {
105+
delete params.tags;
106+
}
98107
} else {
99108
tags?.push(AI_UI_TAG);
100109
params.tags = tags?.join(',');

0 commit comments

Comments
 (0)