Ahmadinejad seems to be baiting the US and Israel to execute a limited military strike so that he can rally the flag, but is trying to avoid a complete annihilation of the country as well. A limited strike would strengthen his hand while weakening Khamenei's and any new green movement. In some ways, developing nuclear power is a similar tightrope for Ahmadinejad. Building some reactors gives leverage whereas with a full nuclear test, he'd be risking annihilation by the US or Israel.
The Obama administration is betting that economic sanctions and political shunning might tighten the screws enough to keep the heat on both Ahmadinejad and Khamenei in hopes that a new green movement might spring up and slow the nuclear development. Republic saber rattling is a bad tactic, but not surprising.