private void createApplyLoadBalancingRulesCommands(
      List<LoadBalancingRule> rules, DomainRouterVO elbVm, Commands cmds, long guestNetworkId) {

    LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    for (LoadBalancingRule rule : rules) {
      boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
      String protocol = rule.getProtocol();
      String algorithm = rule.getAlgorithm();

      String elbIp = _networkModel.getIp(rule.getSourceIpAddressId()).getAddress().addr();
      int srcPort = rule.getSourcePortStart();
      String uuid = rule.getUuid();
      List<LbDestination> destinations = rule.getDestinations();
      LoadBalancerTO lb =
          new LoadBalancerTO(
              uuid, elbIp, srcPort, protocol, algorithm, revoked, false, false, destinations);
      lbs[i++] = lb;
    }

    LoadBalancerConfigCommand cmd =
        new LoadBalancerConfigCommand(
            lbs,
            elbVm.getPublicIpAddress(),
            _nicDao.getIpAddress(guestNetworkId, elbVm.getId()),
            elbVm.getPrivateIpAddress(),
            null,
            null);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, elbVm.getPrivateIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, elbVm.getInstanceName());
    // FIXME: why are we setting attributes directly? Ick!! There should be accessors and
    // the constructor should set defaults.
    cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
    cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
    cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
    cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());

    cmds.addCommand(cmd);
  }