The 2012 27" iMac should be able to run as a mini-Display Port display in display mode. Look up on apple.com how to activate this mode on your iMac. Your iMac I believe will have to be booted and running for it to work, but not certain of that (the 2013 iMac does, I know).
Not sure about the smaller iMac, however.
You'll also need appropriate cables to plug your new MBP in via mini-Display Port.
As for 100% confirmation of it working, hopefully someone else has tried it.