]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/examples/python/DirStartUp.py
- Move Python variables from Job to Bacula. They are
[bacula/bacula] / bacula / examples / python / DirStartUp.py
index 2a810f4bc7a658205d2a4dfaed3346548ebab6a8..00cedc1b05ea9eed9c3c981cb040b27cb329573a 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Bacula Python interface script
+# Bacula Python interface script for the Director
 #
 
 # You must import both sys and bacula
@@ -24,20 +24,15 @@ class BaculaEvents:
      job.set_events(events)       # register events desired
      sys.stderr = events          # send error output to Bacula
      sys.stdout = events          # send stdout to Bacula
-     jobid = job.get("JobId"); client = job.get("Client"); 
-     numvols = job.get("NumVols") 
-     job.set(JobReport="Python StartJob: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols))
-     return 1
+     jobid = job.JobId; client = job.Client
+     numvols = job.NumVols 
+     job.JobReport="Python Dir JobStart: JobId=%d Client=%s NumVols=%d\n" % (jobid,client,numvols) 
 
   # Bacula Job is going to terminate
   def JobEnd(self, job):    
-     jobid = job.get("JobId")
-     client = job.get("Client") 
-     job.set(JobReport="Python EndJob output: JobId=%d Client=%s.\n" % (jobid, client))
-     if (jobid < 2) :
-        startid = job.run("run kernsave")
-        print "Python started new Job: jobid=", startid
-     return 1
+     jobid = job.JobId
+     client = job.Client 
+     job.JobReport="Python Dir JobEnd output: JobId=%d Status=%s Client=%s.\n" % (jobid, job.JobStatus, client) 
 
   # Called here when the Bacula daemon is going to exit
   def Exit(self, job):
@@ -54,14 +49,27 @@ class JobEvents:
      # normally used
      noop = 1
 
+  def JobInit(self, job):
+     noop = 1
+     if (job.JobId < 2):
+        startid = job.run("run kernsave")
+        job.JobReport = "Python started new Job: jobid=%d\n" % startid
+     print "name=%s version=%s conf=%s working=%s" % (bacula.Name, bacula.Version, bacula.ConfigFile, bacula.WorkingDir)
+
+  def JobRun(self, job):
+     noop = 1
+
   def NewVolume(self, job):
-     jobid = job.get("JobId")
-     client = job.get("Client") 
-     numvol = job.get("NumVols");
-     print "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol)
-     job.set(JobReport="Python before New Volume set for Job.\n") 
-     job.set(VolumeName="TestA-001")
-     job.set(JobReport="Python after New Volume set for Job.\n") 
+     jobid = job.JobId
+     client = job.Client 
+     numvol = job.NumVols;
+     print job.CatalogRes
+     job.JobReport = "JobId=%d Client=%s NumVols=%d" % (jobid, client, numvol)
+     job.JobReport="Python before New Volume set for Job.\n"
+     Vol = "TestA-%d" % numvol
+     job.JobReport = "Exists=%d TestA-%d" % (job.DoesVolumeExist(Vol), numvol)
+     job.VolumeName="TestA-%d" % numvol 
+     job.JobReport="Python after New Volume set for Job.\n"  
      return 1
 
 
@@ -73,9 +81,8 @@ class JobEvents:
   def open(self, file):
      print "Open %s called" % file
      self.fd = open('m.py', 'rb')
-     jobid = self.job.get("JobId")
+     jobid = self.job.JobId
      print "Open: JobId=%d" % jobid
-     print "name=%s" % bacula.name
 
   # Read file data into Bacula memory buffer (mem)
   #  return length read. 0 => EOF, -1 => error