Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1828744: do not support SLIRP NetworkInterface in NIC modal #5244

Merged
merged 1 commit into from May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,7 +64,7 @@ export const Network: React.FC<NetworkProps> = ({
getLoadedData(nads, []),
usedMultusNetworkNames,
allowPodNetwork,
);
).filter((n) => n.getType().isSupported());

return (
<FormRow
Expand Down Expand Up @@ -264,7 +264,7 @@ export const NICModal = withHandlePromise((props: NICModalProps) => {
<FormSelectPlaceholderOption isDisabled placeholder="--- Select Type ---" />
{(resultNetwork.getType()
? resultNetwork.getType().getAllowedInterfaceTypes()
: NetworkInterfaceType.getAll()
: NetworkType.getSupportedAllowedInterfaceTypes()
).map((iType) => (
<FormSelectOption
key={iType.getValue()}
Expand Down
Expand Up @@ -12,9 +12,12 @@ export class NetworkType extends ObjectEnum<string> {
NetworkInterfaceType.BRIDGE,
NetworkInterfaceType.SRIOV,
]);
static readonly GENIE = new NetworkType('genie', NetworkInterfaceType.BRIDGE, [
static readonly GENIE = new NetworkType(
'genie',
NetworkInterfaceType.BRIDGE,
]);
[NetworkInterfaceType.BRIDGE],
false,
); // not possible to select in NIC modal

private static ALL = Object.freeze(
ObjectEnum.getAllClassEnumProperties<NetworkType>(NetworkType),
Expand All @@ -35,20 +38,46 @@ export class NetworkType extends ObjectEnum<string> {
private readonly defaultInterfaceType: NetworkInterfaceType;
private readonly allowedInterfaceTypes: Readonly<NetworkInterfaceType[]>;
private readonly allowedInterfaceTypesSet: Set<NetworkInterfaceType>;
private readonly supported: boolean;

private constructor(
value?: string,
defaultInterfaceType?: NetworkInterfaceType,
allowedInterfaceTypes?: NetworkInterfaceType[],
isSupported = true,
) {
super(value);
this.defaultInterfaceType = defaultInterfaceType;
this.allowedInterfaceTypes = Object.freeze(allowedInterfaceTypes);
this.allowedInterfaceTypesSet = new Set(allowedInterfaceTypes);
this.supported = isSupported;
}

getDefaultInterfaceType = () => this.defaultInterfaceType;
getAllowedInterfaceTypes = () => this.allowedInterfaceTypes;
allowsInterfaceType = (interfaceType: NetworkInterfaceType) =>
this.allowedInterfaceTypesSet.has(interfaceType);

isSupported = () => this.supported;

private static getSupportedAllowedInterfaceTypesInternal = () => {
const allowedSupportedInterfaceTypes = new Set();

NetworkType.ALL.filter((network) => network.isSupported()).forEach((network) =>
network
.getAllowedInterfaceTypes()
.forEach((iType) => allowedSupportedInterfaceTypes.add(iType)),
);

// preserve order
return NetworkInterfaceType.getAll().filter((interfaceType) =>
allowedSupportedInterfaceTypes.has(interfaceType),
);
};

private static ALLOWED_SUPPORTED_INTERFACES = Object.freeze(
NetworkType.getSupportedAllowedInterfaceTypesInternal(),
);

static getSupportedAllowedInterfaceTypes = () => NetworkType.ALLOWED_SUPPORTED_INTERFACES;
}