The above code actually picks the first datacenter returned by the vSphere APIs (per the rbvmomi spec), rather than assume there is only one. That said, this behavior is not a sane default in a multiple datacenter environment as it who knows how random that selection might be.

I assume you were seeing behavior where you didn't know which datacenter was chosen, or did you see an actual error? If it was an actual error, then that gives me concerns that even when the datacenter is selected, things may still fail for some other reason.