function AssociateFloatingIpModalController(
    $uibModalInstance, api, gettext, loadbalancer, floatingIps, floatingIpPools
  ) {
    var ctrl = this;
    var port = loadbalancer.vip_port_id + '_' + loadbalancer.vip_address;

    ctrl.cancel = cancel;
    ctrl.save = save;
    ctrl.saving = false;
    ctrl.options = initOptions();
    ctrl.selected = ctrl.options.length === 1 ? ctrl.options[0] : null;

    function save() {
      ctrl.saving = true;
      if (ctrl.selected.type === 'pool') {
        allocateIpAddress(ctrl.selected.id);
      } else {
        associateIpAddress(ctrl.selected.id);
      }
    }

    function cancel() {
      $uibModalInstance.dismiss('cancel');
    }

    function onSuccess() {
      $uibModalInstance.close();
    }

    function onFailure() {
      ctrl.saving = false;
    }

    function initOptions() {
      var options = [];
      floatingIps.forEach(function addFloatingIp(ip) {
        // Only show floating IPs that are not already associated with a fixed IP
        if (!ip.fixed_ip) {
          options.push({
            id: ip.id,
            name: ip.ip || ip.id,
            type: 'ip',
            group: gettext('Floating IP addresses')
          });
        }
      });
      floatingIpPools.forEach(function addFloatingIpPool(pool) {
        options.push({
          id: pool.id,
          name: pool.name || pool.id,
          type: 'pool',
          group: gettext('Floating IP pools')
        });
      });
      return options;
    }

    function allocateIpAddress(poolId) {
      return api.allocateFloatingIp(poolId).then(getId).then(associateIpAddress);
    }

    function associateIpAddress(addressId) {
      return api.associateFloatingIp(addressId, port).then(onSuccess, onFailure);
    }

    function getId(response) {
      return response.data.id;
    }
  }
/**
   * @ngdoc controller
   * @name AssociateFloatingIpModalController
   * @description
   * Controller used by the modal service for associating a floating IP address to a
   * load balancer.
   *
   * @param $uibModalInstance The angular bootstrap $uibModalInstance service.
   * @param api The horizon network API service.
   * @param gettext The horizon gettext function for translation.
   * @param loadbalancer The load balancer to associate the floating IP with.
   * @param floatingIps List of available floating IP addresses.
   * @param floatingIpPools List of available floating IP pools.
   *
   * @returns The Associate Floating IP modal controller.
   */
@ngdoc controller
@name AssociateFloatingIpModalController
@description
Controller used by the modal service for associating a floating IP address to a
load balancer.

@param $uibModalInstance The angular bootstrap $uibModalInstance service.
@param api The horizon network API service.
@param gettext The horizon gettext function for translation.
@param loadbalancer The load balancer to associate the floating IP with.
@param floatingIps List of available floating IP addresses.
@param floatingIpPools List of available floating IP pools.

@returns The Associate Floating IP modal controller.
@ngdoc controller @name AssociateFloatingIpModalController @description Controller used by the modal service for associating a floating IP address to a load balancer . @param $uibModalInstance The angular bootstrap $uibModalInstance service . @param api The horizon network API service . @param gettext The horizon gettext function for translation . @param loadbalancer The load balancer to associate the floating IP with . @param floatingIps List of available floating IP addresses . @param floatingIpPools List of available floating IP pools . @returns The Associate Floating IP modal controller .
function AssociateFloatingIpModalController(
    $uibModalInstance, api, gettext, loadbalancer, floatingIps, floatingIpPools
  ) {
    var ctrl = this;
    var port = loadbalancer.vip_port_id + '_' + loadbalancer.vip_address;
    ctrl.cancel = cancel;
    ctrl.save = save;
    ctrl.saving = false;
    ctrl.options = initOptions();
    ctrl.selected = ctrl.options.length === 1 ? ctrl.options[0] : null;
    function save() {
      ctrl.saving = true;
      if (ctrl.selected.type === 'pool') {
        allocateIpAddress(ctrl.selected.id);
      } else {
        associateIpAddress(ctrl.selected.id);
      }
    }
    function cancel() {
      $uibModalInstance.dismiss('cancel');
    }
    function onSuccess() {
      $uibModalInstance.close();
    }
    function onFailure() {
      ctrl.saving = false;
    }
    function initOptions() {
      var options = [];
      floatingIps.forEach(function addFloatingIp(ip) {
        if (!ip.fixed_ip) {
          options.push({
            id: ip.id,
            name: ip.ip || ip.id,
            type: 'ip',
            group: gettext('Floating IP addresses')
          });
        }
      });
      floatingIpPools.forEach(function addFloatingIpPool(pool) {
        options.push({
          id: pool.id,
          name: pool.name || pool.id,
          type: 'pool',
          group: gettext('Floating IP pools')
        });
      });
      return options;
    }
    function allocateIpAddress(poolId) {
      return api.allocateFloatingIp(poolId).then(getId).then(associateIpAddress);
    }
    function associateIpAddress(addressId) {
      return api.associateFloatingIp(addressId, port).then(onSuccess, onFailure);
    }
    function getId(response) {
      return response.data.id;
    }
  }
function AssociateFloatingIpModalController ( $uibModalInstance , api , gettext , loadbalancer , floatingIps , floatingIpPools ) { var ctrl = this ; var port = loadbalancer . vip_port_id + '_' + loadbalancer . vip_address ; ctrl . cancel = cancel ; ctrl . save = save ; ctrl . saving = false ; ctrl . options = initOptions ( ) ; ctrl . selected = ctrl . options . length === 1 ? ctrl . options [ 0 ] : null ; function save ( ) { ctrl . saving = true ; if ( ctrl . selected . type === 'pool' ) { allocateIpAddress ( ctrl . selected . id ) ; } else { associateIpAddress ( ctrl . selected . id ) ; } } function cancel ( ) { $uibModalInstance . dismiss ( 'cancel' ) ; } function onSuccess ( ) { $uibModalInstance . close ( ) ; } function onFailure ( ) { ctrl . saving = false ; } function initOptions ( ) { var options = [ ] ; floatingIps . forEach ( function addFloatingIp ( ip ) { if ( ! ip . fixed_ip ) { options . push ( { id : ip . id , name : ip . ip || ip . id , type : 'ip' , group : gettext ( 'Floating IP addresses' ) } ) ; } } ) ; floatingIpPools . forEach ( function addFloatingIpPool ( pool ) { options . push ( { id : pool . id , name : pool . name || pool . id , type : 'pool' , group : gettext ( 'Floating IP pools' ) } ) ; } ) ; return options ; } function allocateIpAddress ( poolId ) { return api . allocateFloatingIp ( poolId ) . then ( getId ) . then ( associateIpAddress ) ; } function associateIpAddress ( addressId ) { return api . associateFloatingIp ( addressId , port ) . then ( onSuccess , onFailure ) ; } function getId ( response ) { return response . data . id ; } }
@ngdoc controller
 @name AssociateFloatingIpModalController
 @description
 Controller used by the modal service for associating a floating IP address to a
 load balancer.
@ngdoc controller @name AssociateFloatingIpModalController @description Controller used by the modal service for associating a floating IP address to a load balancer .
// Only show floating IPs that are not already associated with a fixed IP