github.com/thomasobenaus/nomad@v0.11.1/ui/app/serializers/network.js (about)

     1  import ApplicationSerializer from './application';
     2  import isIp from 'is-ip';
     3  
     4  export default ApplicationSerializer.extend({
     5    attrs: {
     6      cidr: 'CIDR',
     7      ip: 'IP',
     8      mbits: 'MBits',
     9    },
    10  
    11    normalize(typeHash, hash) {
    12      const ip = hash.IP;
    13  
    14      if (isIp.v6(ip)) {
    15        hash.IP = `[${ip}]`;
    16      }
    17  
    18      const reservedPorts = (hash.ReservedPorts || []).map(port => ({
    19        name: port.Label,
    20        port: port.Value,
    21        to: port.To,
    22        isDynamic: false,
    23      }));
    24  
    25      const dynamicPorts = (hash.DynamicPorts || []).map(port => ({
    26        name: port.Label,
    27        port: port.Value,
    28        to: port.To,
    29        isDynamic: true,
    30      }));
    31  
    32      hash.Ports = reservedPorts.concat(dynamicPorts).sortBy('name');
    33  
    34      return this._super(...arguments);
    35    },
    36  });