FYI: this function is also used in nova code, will need a followup commit there.