Skip to content

Commit

Permalink
GUI Instance family parsing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rodichenko committed Oct 4, 2023
1 parent 3e66c1b commit fa7b08d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions client/src/utils/instance-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ function getAWSInstanceFamily (instanceType) {
}

function getGCPInstanceFamily (instanceType) {
const e = /^(?!custom)(\w+-(?!custom)\w+)-?.*/.exec(instanceType);
if (e && e[1]) {
return e[1];
}
return undefined;
const extractFromPattern = (pattern, extractor, ...group) => {
const e = pattern.exec(instanceType);
if (e && !group.some((g) => e[g] === undefined)) {
return extractor(e);
}
return undefined;
};
return extractFromPattern(/^(\w*-?custom)-\w+-\w+$/, (e) => e[1], 1) ||
extractFromPattern(/^(gpu-\w*-?custom)-\w+-\w+(-\w+)-\w+$/, (e) => e[1].concat(e[2]), 1, 2) ||
extractFromPattern(/^(\w+-\w+)-?\w*(-?\w*)/, (e) => e[1].concat(e[2]), 1, 2);
}

function getAzureInstanceFamily (instanceType) {
const e = /^([a-zA-Z]+)\d+(.*)/.exec(instanceType);
const instanceTypeCorrected = /_/.test(instanceType)
? (instanceType || '').split('_').slice(1).join('')
: instanceType;
const e = /^([a-zA-Z]+)\d+(.*)/.exec(instanceTypeCorrected);
if (e && e[1] && e[2]) {
return e[1].concat(e[2]);
}
Expand Down

0 comments on commit fa7b08d

Please sign in to comment.