cmdlib: Extract migration related functionality