open-nomad/ui/app/serializers/resources.js
2023-04-10 15:36:59 +00:00

29 lines
859 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
import classic from 'ember-classic-decorator';
@classic
export default class ResourcesSerializer extends ApplicationSerializer {
arrayNullOverrides = ['Ports', 'Networks'];
normalize(typeHash, hash) {
hash.Cpu = hash.Cpu && hash.Cpu.CpuShares;
hash.Memory = hash.Memory && hash.Memory.MemoryMB;
hash.Disk = hash.Disk && hash.Disk.DiskMB;
// Networks for ReservedResources is different than for Resources.
// This smooths over the differences, but doesn't actually support
// anything in the ReservedResources.Networks object, since we don't
// use any of it in the UI.
if (!(hash.Networks instanceof Array)) {
hash.Networks = [];
}
return super.normalize(...arguments);
}
}