def stop_and_destroy(self, sync=True):
def _self_destruct():<EOL><INDENT>"""<STR_LIT>"""<EOL>try_it_n_times(operation=self.destroy,<EOL>expected_error_codes=['<STR_LIT>'],<EOL>custom_error='<STR_LIT>')<EOL>for storage in self.storage_devices:<EOL><INDENT>try_it_n_times(operation=storage.destroy,<EOL>expected_error_codes=['<STR_LIT>'],<EOL>custom_error='<STR_LIT>')<EOL><DEDENT><DEDENT>if sync:<EOL><INDENT>self.populate()<EOL><DEDENT>if self.state in ['<STR_LIT>', '<STR_LIT:error>']:<EOL><INDENT>self._wait_for_state_change(['<STR_LIT>', '<STR_LIT>'])<EOL><DEDENT>if self.state == '<STR_LIT>':<EOL><INDENT>try_it_n_times(operation=self.stop,<EOL>expected_error_codes=['<STR_LIT>'],<EOL>custom_error='<STR_LIT>')<EOL>self._wait_for_state_change(['<STR_LIT>'])<EOL><DEDENT>if self.state == '<STR_LIT>':<EOL><INDENT>_self_destruct()<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>' + self.state)<EOL><DEDENT>
Destroy a server and its storages. Stops the server before destroying.

Syncs the server state from the API, use sync=False to disable.