ipAutoSort() {
      const ipAutoSort = _.get(this.sort, 'ipAutoSort', false);
      const ipListSortedKeys = _.get(this.infra, 'internet.ipList.sortedKeys', []);
      const publicCloudSortedKeys = _.get(this.infra, 'vrack.publicCloud.sortedKeys', []);

      return (ip) => {
        // only if autoSort is enabled ...
        if (!ipAutoSort) {
          return _.indexOf(ipListSortedKeys, ip.id);
        }
        let order = 0;
        let routeCount = 0;
        _.forEach(ip.routedTo, (route) => {
          const vmPosition = _.indexOf(publicCloudSortedKeys, route);
          if (vmPosition !== -1) {
            order += vmPosition * 5; // arbitrary weight of 5 for a link with a vm
            routeCount += 1;
          }
        });

        if (routeCount > 0) {
          order /= routeCount; // compute our position with average order
          if (ip.type === 'failover') {
            order += 1;
          }
          return order;
        }

        return Number.MAX_VALUE; // goes to the bottom
      };
    }
/**
         * Sort the ip in order to have the least crossing between links
         */
Sort the ip in order to have the least crossing between links
Sort the ip in order to have the least crossing between links
ipAutoSort() {
      const ipAutoSort = _.get(this.sort, 'ipAutoSort', false);
      const ipListSortedKeys = _.get(this.infra, 'internet.ipList.sortedKeys', []);
      const publicCloudSortedKeys = _.get(this.infra, 'vrack.publicCloud.sortedKeys', []);
      return (ip) => {
        if (!ipAutoSort) {
          return _.indexOf(ipListSortedKeys, ip.id);
        }
        let order = 0;
        let routeCount = 0;
        _.forEach(ip.routedTo, (route) => {
          const vmPosition = _.indexOf(publicCloudSortedKeys, route);
          if (vmPosition !== -1) {
            order += vmPosition * 5; 
            routeCount += 1;
          }
        });
        if (routeCount > 0) {
          order /= routeCount; 
          if (ip.type === 'failover') {
            order += 1;
          }
          return order;
        }
        return Number.MAX_VALUE; 
      };
    }
ipAutoSort ( ) { const ipAutoSort = _ . get ( this . sort , 'ipAutoSort' , false ) ; const ipListSortedKeys = _ . get ( this . infra , 'internet.ipList.sortedKeys' , [ ] ) ; const publicCloudSortedKeys = _ . get ( this . infra , 'vrack.publicCloud.sortedKeys' , [ ] ) ; return ( ip ) => { if ( ! ipAutoSort ) { return _ . indexOf ( ipListSortedKeys , ip . id ) ; } let order = 0 ; let routeCount = 0 ; _ . forEach ( ip . routedTo , ( route ) => { const vmPosition = _ . indexOf ( publicCloudSortedKeys , route ) ; if ( vmPosition !== - 1 ) { order += vmPosition * 5 ; routeCount += 1 ; } } ) ; if ( routeCount > 0 ) { order /= routeCount ; if ( ip . type === 'failover' ) { order += 1 ; } return order ; } return Number . MAX_VALUE ; } ; }
Sort the ip in order to have the least crossing between links
Sort the ip in order to have the least crossing between links
// only if autoSort is enabled ... // arbitrary weight of 5 for a link with a vm // compute our position with average order // goes to the bottom