Add EC2 instance(s) to an Elastic Load Balancer. Removing an instance from
    the ``instances`` list does not remove it from the ELB.

    name
        The name of the Elastic Load Balancer to add EC2 instances to.

    instances
        A list of EC2 instance IDs that this Elastic Load Balancer should
        distribute traffic to. This state will only ever append new instances
        to the ELB. EC2 instances already associated with this ELB will not be
        removed if they are not in the ``instances`` list.

    .. versionadded:: 2015.8.0

    .. code-block:: yaml

        add-instances:
          boto_elb.register_instances:
            - name: myloadbalancer
            - instances:
              - instance-id1
              - instance-id2

def register_instances(name, instances, region=None, key=None, keyid=None,
                       profile=None):
    '''
    Add EC2 instance(s) to an Elastic Load Balancer. Removing an instance from
    the ``instances`` list does not remove it from the ELB.

    name
        The name of the Elastic Load Balancer to add EC2 instances to.

    instances
        A list of EC2 instance IDs that this Elastic Load Balancer should
        distribute traffic to. This state will only ever append new instances
        to the ELB. EC2 instances already associated with this ELB will not be
        removed if they are not in the ``instances`` list.

    .. versionadded:: 2015.8.0

    .. code-block:: yaml

        add-instances:
          boto_elb.register_instances:
            - name: myloadbalancer
            - instances:
              - instance-id1
              - instance-id2
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    lb = __salt__['boto_elb.exists'](name, region, key, keyid, profile)
    if not lb:
        msg = 'Could not find lb {0}'.format(name)
        log.error(msg)
        ret.update({'comment': msg, 'result': False})
        return ret

    health = __salt__['boto_elb.get_instance_health'](
            name, region, key, keyid, profile)
    nodes = [value['instance_id'] for value in health
             if value['description'] != 'Instance deregistration currently in progress.']
    new = [value for value in instances if value not in nodes]
    if not new:
        msg = 'Instance/s {0} already exist.'.format(six.text_type(instances).strip('[]'))
        log.debug(msg)
        ret.update({'comment': msg})
        return ret

    if __opts__['test']:
        ret['comment'] = 'ELB {0} is set to register : {1}.'.format(name, new)
        ret['result'] = None
        return ret

    state = __salt__['boto_elb.register_instances'](
            name, instances, region, key, keyid, profile)
    if state:
        msg = 'Load Balancer {0} has been changed'.format(name)
        log.info(msg)
        new = set().union(nodes, instances)
        ret.update({'comment': msg, 'changes': {'old': '\n'.join(nodes),
                                                'new': '\n'.join(list(new))}})
    else:
        msg = 'Load balancer {0} failed to add instances'.format(name)
        log.error(msg)
        ret.update({'comment': msg, 'result': False})
    return ret