Cleaning up examples folder
[nepi.git] / src / nepi / resources / linux / ccn / ccnd.py
index 71eb12a..1fc8979 100644 (file)
@@ -50,56 +50,56 @@ class LinuxCCND(LinuxApplication):
             "  -1 - max logging \n"
             "  Or apply bitwise OR to these values to get combinations of them",
             type = Types.Integer,
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         port = Attribute("port", "Sets the CCN_LOCAL_PORT environmental variable. "
             "Defaults to 9695 ", 
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
  
         sockname = Attribute("sockname",
             "Sets the CCN_LOCAL_SCOKNAME environmental variable. "
             "Defaults to /tmp/.ccnd.sock", 
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         capacity = Attribute("capacity",
             "Sets the CCND_CAP environmental variable. "
             "Capacity limit in terms of ContentObjects",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         mtu = Attribute("mtu", "Sets the CCND_MTU environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
   
         data_pause = Attribute("dataPauseMicrosec",
             "Sets the CCND_DATA_PAUSE_MICROSEC environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         default_stale = Attribute("defaultTimeToStale",
              "Sets the CCND_DEFAULT_TIME_TO_STALE environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         max_stale = Attribute("maxTimeToStale",
             "Sets the CCND_MAX_TIME_TO_STALE environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         max_rte = Attribute("maxRteMicrosec",
             "Sets the CCND_MAX_RTE_MICROSEC environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         keystore = Attribute("keyStoreDirectory",
             "Sets the CCND_KEYSTORE_DIRECTORY environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         listen_on = Attribute("listenOn",
             "Sets the CCND_LISTEN_ON environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         autoreg = Attribute("autoreg",
             "Sets the CCND_AUTOREG environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         prefix = Attribute("prefix",
             "Sets the CCND_PREFIX environmental variable. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         cls._register_attribute(debug)
         cls._register_attribute(port)
@@ -136,51 +136,46 @@ class LinuxCCND(LinuxApplication):
     def path(self):
         return "PATH=$PATH:${BIN}/%s/" % self.version 
 
-    def deploy(self):
+    def do_deploy(self):
         if not self.node or self.node.state < ResourceState.READY:
             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
             
             # ccnd needs to wait until node is deployed and running
             self.ec.schedule(reschedule_delay, self.deploy)
         else:
-            try:
-                if not self.get("command"):
-                    self.set("command", self._start_command)
-                
-                if not self.get("depends"):
-                    self.set("depends", self._dependencies)
+            if not self.get("command"):
+                self.set("command", self._start_command)
+            
+            if not self.get("depends"):
+                self.set("depends", self._dependencies)
 
-                if not self.get("sources"):
-                    self.set("sources", self._sources)
+            if not self.get("sources"):
+                self.set("sources", self._sources)
 
-                sources = self.get("sources")
-                source = sources.split(" ")[0]
-                basename = os.path.basename(source)
-                self._version = ( basename.strip().replace(".tar.gz", "")
-                        .replace(".tar","")
-                        .replace(".gz","")
-                        .replace(".zip","") )
+            sources = self.get("sources")
+            source = sources.split(" ")[0]
+            basename = os.path.basename(source)
+            self._version = ( basename.strip().replace(".tar.gz", "")
+                    .replace(".tar","")
+                    .replace(".gz","")
+                    .replace(".zip","") )
 
-                if not self.get("build"):
-                    self.set("build", self._build)
+            if not self.get("build"):
+                self.set("build", self._build)
 
-                if not self.get("install"):
-                    self.set("install", self._install)
+            if not self.get("install"):
+                self.set("install", self._install)
 
-                if not self.get("env"):
-                    self.set("env", self._environment)
+            if not self.get("env"):
+                self.set("env", self._environment)
 
-                command = self.get("command")
+            command = self.get("command")
 
-                self.info("Deploying command '%s' " % command)
+            self.info("Deploying command '%s' " % command)
 
-                self.discover()
-                self.provision()
-            except:
-                self.fail()
-                return
+            self.do_discover()
+            self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def upload_start_command(self):
@@ -199,10 +194,9 @@ class LinuxCCND(LinuxApplication):
         self.node.run_and_wait(command, self.run_home,
                 shfile = shfile,
                 overwrite = False,
-                env = env,
-                raise_on_error = True)
+                env = env)
 
-    def start(self):
+    def do_start(self):
         if self.state == ResourceState.READY:
             command = self.get("command")
             self.info("Starting command '%s'" % command)
@@ -211,9 +205,9 @@ class LinuxCCND(LinuxApplication):
         else:
             msg = " Failed to execute command '%s'" % command
             self.error(msg, out, err)
-            self.fail()
+            raise RuntimeError, msg
 
-    def stop(self):
+    def do_stop(self):
         command = self.get('command') or ''
         
         if self.state == ResourceState.STARTED:
@@ -245,13 +239,13 @@ class LinuxCCND(LinuxApplication):
         state_check_delay = 0.5
         if self._state == ResourceState.STARTED and \
                 tdiffsec(tnow(), self._last_state_check) > state_check_delay:
-            (out, err), proc = self._ccndstatus
+            (out, err), proc = self._ccndstatus()
 
             retcode = proc.poll()
 
             if retcode == 1 and err.find("No such file or directory") > -1:
                 # ccnd is not running (socket not found)
-                self.set_finished()
+                self.set_stopped()
             elif retcode:
                 # other errors ...
                 msg = " Failed to execute command '%s'" % self.get("command")
@@ -262,7 +256,6 @@ class LinuxCCND(LinuxApplication):
 
         return self._state
 
-    @property
     def _ccndstatus(self):
         env = self.get('env') or ""
         environ = self.node.format_environment(env, inline = True)
@@ -289,7 +282,7 @@ class LinuxCCND(LinuxApplication):
 
     @property
     def _sources(self):
-        return "http://www.ccnx.org/releases/ccnx-0.7.2.tar.gz"
+        return "http://www.ccnx.org/releases/ccnx-0.8.2.tar.gz"
 
     @property
     def _build(self):