'Magic tags (host, device) override metric hostname and device_name attributes'

def _extract_magic_tags(self, tags):

    hostname = None
    device_name = None
    if tags:
        tags_to_remove = []
        for tag in tags:
            if tag.startswith('host:'):
                hostname = tag[5:]
                tags_to_remove.append(tag)
            elif tag.startswith('device:'):
                device_name = tag[7:]
                tags_to_remove.append(tag)
        if tags_to_remove:
            tags = list(tags)
            for tag in tags_to_remove:
                tags.remove(tag)
            tags = (tuple(tags) or None)
    return (hostname, device_name, tags)
