'Adds an ElastiCache cluster to the inventory and index, as long as
it\'s nodes are addressable'

def add_elasticache_cluster(self, cluster, region):

    if ((not self.all_elasticache_clusters) and (cluster['CacheClusterStatus'] != 'available')):
        return
    if (('ConfigurationEndpoint' in cluster) and cluster['ConfigurationEndpoint']):
        dest = cluster['ConfigurationEndpoint']['Address']
        is_redis = False
    else:
        dest = cluster['CacheNodes'][0]['Endpoint']['Address']
        is_redis = True
    if (not dest):
        return
    self.index[dest] = [region, cluster['CacheClusterId']]
    if self.group_by_instance_id:
        self.inventory[cluster['CacheClusterId']] = [dest]
        if self.nested_groups:
            self.push_group(self.inventory, 'instances', cluster['CacheClusterId'])
    if (self.group_by_region and (not is_redis)):
        self.push(self.inventory, region, dest)
        if self.nested_groups:
            self.push_group(self.inventory, 'regions', region)
    if (self.group_by_availability_zone and (not is_redis)):
        self.push(self.inventory, cluster['PreferredAvailabilityZone'], dest)
        if self.nested_groups:
            if self.group_by_region:
                self.push_group(self.inventory, region, cluster['PreferredAvailabilityZone'])
            self.push_group(self.inventory, 'zones', cluster['PreferredAvailabilityZone'])
    if (self.group_by_instance_type and (not is_redis)):
        type_name = self.to_safe(('type_' + cluster['CacheNodeType']))
        self.push(self.inventory, type_name, dest)
        if self.nested_groups:
            self.push_group(self.inventory, 'types', type_name)
    if (self.group_by_security_group and (not is_redis)):
        if (('SecurityGroups' in cluster) and (cluster['SecurityGroups'] is not None)):
            for security_group in cluster['SecurityGroups']:
                key = self.to_safe(('security_group_' + security_group['SecurityGroupId']))
                self.push(self.inventory, key, dest)
                if self.nested_groups:
                    self.push_group(self.inventory, 'security_groups', key)
    if (self.group_by_elasticache_engine and (not is_redis)):
        self.push(self.inventory, self.to_safe(('elasticache_' + cluster['Engine'])), dest)
        if self.nested_groups:
            self.push_group(self.inventory, 'elasticache_engines', self.to_safe(cluster['Engine']))
    if self.group_by_elasticache_parameter_group:
        self.push(self.inventory, self.to_safe(('elasticache_parameter_group_' + cluster['CacheParameterGroup']['CacheParameterGroupName'])), dest)
        if self.nested_groups:
            self.push_group(self.inventory, 'elasticache_parameter_groups', self.to_safe(cluster['CacheParameterGroup']['CacheParameterGroupName']))
    if (self.group_by_elasticache_replication_group and ('ReplicationGroupId' in cluster) and cluster['ReplicationGroupId']):
        self.push(self.inventory, self.to_safe(('elasticache_replication_group_' + cluster['ReplicationGroupId'])), dest)
        if self.nested_groups:
            self.push_group(self.inventory, 'elasticache_replication_groups', self.to_safe(cluster['ReplicationGroupId']))
    self.push(self.inventory, 'elasticache_clusters', cluster['CacheClusterId'])
    host_info = self.get_host_info_dict_from_describe_dict(cluster)
    self.inventory['_meta']['hostvars'][dest] = host_info
    for node in cluster['CacheNodes']:
        self.add_elasticache_node(node, cluster, region)
