'Walk the parent tree to find the objects datacenter'

def get_parent_datacenter(self, obj):

    if isinstance(obj, vim.Datacenter):
        return obj
    if (obj in self.parent_datacenters):
        return self.parent_datacenters[obj]
    datacenter = None
    while True:
        if (not hasattr(obj, 'parent')):
            break
        obj = obj.parent
        if isinstance(obj, vim.Datacenter):
            datacenter = obj
            break
    self.parent_datacenters[obj] = datacenter
    return datacenter
