Wait for entity if it doesn't exist yet
[osm/N2VC.git] / juju / unit.py
index 2b7170e..78acaff 100644 (file)
@@ -7,9 +7,6 @@ log = logging.getLogger(__name__)
 
 
 class Unit(model.ModelEntity):
-    def _get_tag(self):
-        return 'unit-{}'.format(self.data['Name'].replace('/', '-'))
-
     def add_storage(self, name, constraints=None):
         """Add unit storage dynamically.
 
@@ -26,11 +23,17 @@ class Unit(model.ModelEntity):
         """
         pass
 
-    def destroy(self):
+    async def destroy(self):
         """Destroy this unit.
 
         """
-        pass
+        app_facade = client.ApplicationFacade()
+        app_facade.connect(self.connection)
+
+        log.debug(
+            'Destroying %s', self.name)
+
+        return await app_facade.DestroyUnits([self.name])
     remove = destroy
 
     def get_resources(self, details=False):
@@ -58,18 +61,17 @@ class Unit(model.ModelEntity):
 
         """
         action = client.ActionFacade()
-        conn = await self.model.connection.clone()
-        action.connect(conn)
+        action.connect(self.connection)
 
         log.debug(
-            'Running `%s` on %s', command, self.Name)
+            'Running `%s` on %s', command, self.name)
 
         return await action.Run(
             [],
             command,
             [],
             timeout,
-            [self.Name],
+            [self.name],
         )
 
     def run_action(self, action_name, **params):