
import os
import subprocess
import time
from kokki import *

class ArrayProvider(Provider):
    def action_create(self):
        if not os.path.exists(self.resource.name):
            subprocess.check_call(["/sbin/mdadm",
                    "--create", self.resource.name,
                    "-R",
                    "-c", str(self.resource.chunksize),
                    "--level", str(self.resource.level),
                    "--metadata", self.resource.metadata,
                    "--raid-devices", str(len(self.resource.devices)),
                ] + self.resource.devices)
            self.wait_for_array(True)
            self.resource.updated()
    
    def action_stop(self):
        if os.path.exists(self.resource.name):
            subprocess.check_call(["/sbin/mdadm",
                    "--stop", self.resource.name])
            self.wait_for_array(False)
            self.resource.updated()

    def action_assemble(self):
        if not os.path.exists(self.resource.name):
            subprocess.check_call(["/sbin/mdadm",
                    "--assemble", self.resource.name,
                ] + self.resource.devices)
            self.wait_for_array(True)
            self.resource.updated()

    def wait_for_array(self, exists):
        for i in range(10):
            if exists == os.path.exists(self.resource.name):
                break
            time.sleep(0.5)

@@ -126,39 +126,36 @@
      if not 
-os.path
+self
 .exists(
 self.resourc
@@ -142,34 +142,16 @@
 .exists(
-self.resource.name
 ):%0A     
@@ -675,31 +675,28 @@
      if 
-os.path
+self
 .exists(
 self.res
@@ -687,34 +687,16 @@
 .exists(
-self.resource.name
 ):%0A     
@@ -913,31 +913,28 @@
  if not 
-os.path
+self
 .exists(
 self.res
@@ -925,34 +925,16 @@
 .exists(
-self.resource.name
 ):%0A     
@@ -1142,32 +1142,151 @@
 urce.updated()%0A%0A
+    def exists(self):%0A        ret = subprocess.call(%5B%22/sbin/mdadm%22, %22-Q%22, self.resource.name%5D)%0A        return not ret%0A%0A
     def wait_for
@@ -1364,23 +1364,20 @@
  == 
-os.path
+self
 .exists(
 self
@@ -1372,34 +1372,16 @@
 .exists(
-self.resource.name
 ):%0A     

use 'mdadm' to check for existance of an array rather than looking for the device