@@ -1388,7 +1388,12 @@ export default {
13881388 })
13891389 },
13901390 normalizeGuestOsName (name ) {
1391- return (name || ' ' ).toLowerCase ().replace (/ [^ a-z0-9 ] + / g , ' ' ).trim ()
1391+ return (name || ' ' )
1392+ .toLowerCase ()
1393+ .replace (/ ^ microsoft\s + / , ' ' )
1394+ .replace (/ [^ a-z0-9 ] + / g , ' ' )
1395+ .replace (/ \s + / g , ' ' )
1396+ .trim ()
13921397 },
13931398 isStrongGuestOsNameMatch (osType , osDisplayName ) {
13941399 const candidate = this .normalizeGuestOsName (osType .description || osType .osdisplayname )
@@ -1425,32 +1430,55 @@ export default {
14251430 return []
14261431 })
14271432 },
1433+ filterGuestOsMappings (mappings , params , osDisplayName ) {
1434+ if (! mappings || mappings .length === 0 ) {
1435+ return []
1436+ }
1437+
1438+ const osNameForHypervisor = (params .osnameforhypervisor || ' ' ).toLowerCase ()
1439+ let filteredMappings = mappings
1440+ if (osNameForHypervisor) {
1441+ filteredMappings = mappings .filter (mapping => (mapping .osnameforhypervisor || ' ' ).toLowerCase () === osNameForHypervisor)
1442+ }
1443+
1444+ if (osDisplayName) {
1445+ const displayNameMatches = filteredMappings .filter (mapping => this .isStrongGuestOsNameMatch (mapping, osDisplayName))
1446+ if (displayNameMatches .length > 0 ) {
1447+ return displayNameMatches
1448+ }
1449+ if (params .osdisplayname ) {
1450+ return []
1451+ }
1452+ }
1453+
1454+ return filteredMappings
1455+ },
14281456 async fetchGuestOsMappings (osIdentifier , osDisplayName , hypervisorVersion ) {
14291457 const lookups = []
1430- if (osDisplayName ) {
1458+ if (osIdentifier ) {
14311459 lookups .push ({
14321460 hypervisor: ' VMware' ,
14331461 hypervisorversion: hypervisorVersion,
1434- osdisplayname : osDisplayName
1462+ osnameforhypervisor : osIdentifier
14351463 })
14361464 }
14371465 if (osIdentifier) {
14381466 lookups .push ({
14391467 hypervisor: ' VMware' ,
1440- hypervisorversion: hypervisorVersion,
14411468 osnameforhypervisor: osIdentifier
14421469 })
14431470 }
14441471 if (osDisplayName) {
14451472 lookups .push ({
14461473 hypervisor: ' VMware' ,
1474+ hypervisorversion: hypervisorVersion,
14471475 osdisplayname: osDisplayName
14481476 })
14491477 }
1450- if (osIdentifier ) {
1478+ if (osDisplayName ) {
14511479 lookups .push ({
14521480 hypervisor: ' VMware' ,
1453- osnameforhypervisor : osIdentifier
1481+ osdisplayname : osDisplayName
14541482 })
14551483 }
14561484
@@ -1459,8 +1487,9 @@ export default {
14591487 delete params .hypervisorversion
14601488 }
14611489 const mappings = await this .fetchGuestOsMappingsByParams (params)
1462- if (mappings .length > 0 ) {
1463- return mappings
1490+ const filteredMappings = this .filterGuestOsMappings (mappings, params, osDisplayName)
1491+ if (filteredMappings .length > 0 ) {
1492+ return filteredMappings
14641493 }
14651494 }
14661495 return await this .fetchGuestOsTypeFallbackMappings (osDisplayName)
0 commit comments