github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/serializers/network.js (about)

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