Make Machine.destroy() block
[osm/N2VC.git] / juju / machine.py
index 5eac6c2..44560bf 100644 (file)
@@ -10,6 +10,8 @@ class Machine(model.ModelEntity):
     async def destroy(self, force=False):
         """Remove this machine from the model.
 
+        Blocks until the machine is actually removed.
+
         """
         facade = client.ClientFacade()
         facade.connect(self.connection)
@@ -17,7 +19,9 @@ class Machine(model.ModelEntity):
         log.debug(
             'Destroying machine %s', self.id)
 
-        return await facade.DestroyMachines(force, [self.id])
+        await facade.DestroyMachines(force, [self.id])
+        return await self.model._wait(
+            'machine', self.id, 'remove')
     remove = destroy
 
     def run(self, command, timeout=None):
@@ -39,7 +43,7 @@ class Machine(model.ModelEntity):
         log.debug('Updating annotations on machine %s', self.id)
 
         self.ann_facade = client.AnnotationsFacade()
-        self.ann_facade.connect(model.connection)
+        self.ann_facade.connect(self.connection)
 
         ann = client.EntityAnnotations(
             entity=self.id,