According to Glenn Beck the President must have known about the affair for a long time and chose now to "out" Petraeus to that he wouldn't spill the beans to congress and tell what he knows about the 9/11 attacks in Libya.
In the Glenn Beck universe Barack Obama = Professor Moriarty