github.com/hernad/nomad@v1.6.112/ui/app/serializers/network.js (about)

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