Don't execute build teardown multiple times

This fixes a bug where, even after a slave disconnected from the
master, the master could send a teardown command to the slave. Since
the slave already runs build_teardown when it's shutting down, it was
possible for build_teardown to get run twice.

This change fixes the master so that it doesn't send a teardown command
when a slave has already disconnected. It also makes the slave raise an
exception if build_teardown gets executed more than once.
I added the api version here and stopped importing it from the master so that we could get rid of circular imports.