open-nomad/ui/app/serializers/network.js

37 lines
787 B
JavaScript
Raw Normal View History

2017-09-19 14:47:10 +00:00
import ApplicationSerializer from './application';
import isIp from 'is-ip';
2017-09-19 14:47:10 +00:00
export default class NetworkSerializer extends ApplicationSerializer {
attrs = {
2017-09-19 14:47:10 +00:00
cidr: 'CIDR',
ip: 'IP',
mbits: 'MBits',
};
normalize(typeHash, hash) {
const ip = hash.IP;
if (isIp.v6(ip)) {
hash.IP = `[${ip}]`;
}
2021-12-28 14:45:20 +00:00
const reservedPorts = (hash.ReservedPorts || []).map((port) => ({
name: port.Label,
port: port.Value,
to: port.To,
isDynamic: false,
}));
2021-12-28 14:45:20 +00:00
const dynamicPorts = (hash.DynamicPorts || []).map((port) => ({
name: port.Label,
port: port.Value,
to: port.To,
isDynamic: true,
}));
hash.Ports = reservedPorts.concat(dynamicPorts).sortBy('name');
return super.normalize(...arguments);
}
}