'Recursively build a data structure for the given pSphere object (depth
only applies to ManagedObject instances).'

def _get_obj_info(self, obj, depth=99, seen=None):

    seen = (seen or set())
    if isinstance(obj, ManagedObject):
        try:
            obj_unicode = text_type(getattr(obj, 'name'))
        except AttributeError:
            obj_unicode = ()
        if (obj in seen):
            return obj_unicode
        seen.add(obj)
        if (depth <= 0):
            return obj_unicode
        d = {}
        for attr in dir(obj):
            if attr.startswith('_'):
                continue
            try:
                val = getattr(obj, attr)
                obj_info = self._get_obj_info(val, (depth - 1), seen)
                if (obj_info != ()):
                    d[attr] = obj_info
            except Exception as e:
                pass
        return d
    elif isinstance(obj, SudsObject):
        d = {}
        for (key, val) in iter(obj):
            obj_info = self._get_obj_info(val, depth, seen)
            if (obj_info != ()):
                d[key] = obj_info
        return d
    elif isinstance(obj, (list, tuple)):
        l = []
        for val in iter(obj):
            obj_info = self._get_obj_info(val, depth, seen)
            if (obj_info != ()):
                l.append(obj_info)
        return l
    elif isinstance(obj, (((type(None), bool, float) + string_types) + integer_types)):
        return obj
    else:
        return ()
