parameters: (self, IOP)
docstring: Called for io operations.
docstring_summary: Called for io operations.
docstring_tokens: Called for io operations .
function: def plugin_io(self, IOP):
          """
          Called for io operations.
          """
          bareosfd.DebugMessage(100, "plugin_io called with function %s\n" % (IOP.func))
          bareosfd.DebugMessage(100, "FNAME is set to %s\n" % (self.FNAME))
          self.jobType = chr(bareosfd.GetValue(bareosfd.bVarType))
          bareosfd.DebugMessage(
              100,
              "BareosFdPluginOvirt::plugin_io() jobType: %s\n" % (self.jobType),
          )
  
          if IOP.func == bareosfd.IO_OPEN:
  
              self.FNAME = IOP.fname
              bareosfd.DebugMessage(
                  100, "self.FNAME was set to %s from IOP.fname\n" % (self.FNAME)
              )
              bareosfd.DebugMessage(100, "type(self.FNAME): %s\n" % (type(self.FNAME)))
  
              if self.options.get("local") == "yes":
                  try:
                      if IOP.flags & (os.O_CREAT | os.O_WRONLY):
                          bareosfd.DebugMessage(
                              100,
                              "Open file %s for writing with %s\n" % (self.FNAME, IOP),
                          )
  
                          dirname = os.path.dirname(self.FNAME)
                          if not os.path.exists(dirname):
                              bareosfd.DebugMessage(
                                  100,
                                  "Directory %s does not exist, creating it now\n"
                                  % (dirname),
                              )
                              os.makedirs(dirname)
                          self.file = open(self.FNAME, "wb")
                      else:
                          IOP.status = -1
                          bareosfd.JobMessage(
                              bareosfd.M_FATAL,
                              "plugin_io: option local=yes can only be used on restore\n",
                          )
                      return bareosfd.bRC_Error
                  except (OSError, IOError) as io_open_error:
                      IOP.status = -1
                      bareosfd.DebugMessage(
                          100,
                          "plugin_io: failed to open %s: %s\n"
                          % (self.FNAME, io_open_error.strerror),
                      )
                      bareosfd.JobMessage(
                          bareosfd.M_FATAL,
                          "plugin_io: failed to open %s: %s\n"
                          % (self.FNAME, io_open_error.strerror),
                      )
                      return bareosfd.bRC_Error
  
              return bareosfd.bRC_OK
  
          elif IOP.func == bareosfd.IO_CLOSE:
              if self.file is not None:
                  bareosfd.DebugMessage(100, "Closing file " + "\n")
                  self.file.close()
              elif self.jobType == "B":
                  if "file" in self.backup_obj:
                      self.backup_obj["file"]["fh"].close()
                  elif "disk" in self.backup_obj:
                      bareosfd.DebugMessage(100, "plugin_io: calling end_transfer()\n")
                      # Backup Job
                      self.ovirt.end_transfer()
              elif self.jobType == "R":
                  if self.FNAME.endswith(".ovf"):
                      return self.ovirt.prepare_vm_restore()
                  else:
                      self.ovirt.end_transfer()
              return bareosfd.bRC_OK
          elif IOP.func == bareosfd.IO_SEEK:
              return bareosfd.bRC_OK
          elif IOP.func == bareosfd.IO_READ:
              if "file" in self.backup_obj:
                  IOP.buf = bytearray(IOP.count)
                  IOP.status = self.backup_obj["file"]["fh"].readinto(IOP.buf)
                  IOP.io_errno = 0
                  bareosfd.DebugMessage(
                      100,
                      "plugin_io: read from file %s\n"
                      % (self.backup_obj["file"]["filename"]),
                  )
              elif "disk" in self.backup_obj:
                  bareosfd.DebugMessage(
                      100,
                      "plugin_io: read from disk %s\n" % (self.backup_obj["disk"].alias),
                  )
                  try:
                      IOP.buf = bytearray(IOP.count)
                      chunk = self.ovirt.process_download(IOP.count)
                      IOP.buf[:] = chunk
                      IOP.status = len(IOP.buf)
                      IOP.io_errno = 0
                  except Exception as e:
                      bareosfd.JobMessage(
                          bareosfd.M_ERROR,
                          "BareosFdPluginOvirt:plugin_io() Error: %s\n" % str(e),
                      )
                      self.ovirt.end_transfer()
                      return bareosfd.bRC_Error
              else:
                  bareosfd.JobMessage(
                      bareosfd.M_ERROR,
                      "BareosFdPluginOvirt:plugin_io() Unable to read data to backup.",
                  )
                  return bareosfd.bRC_Error
              return bareosfd.bRC_OK
          elif IOP.func == bareosfd.IO_WRITE:
              if self.file is not None:
                  try:
                      bareosfd.DebugMessage(
                          200, "Writing buffer to file %s\n" % (self.FNAME)
                      )
                      self.file.write(IOP.buf)
                      IOP.status = IOP.count
                      IOP.io_errno = 0
                  except IOError as msg:
                      IOP.io_errno = -1
                      bareosfd.DebugMessage(100, "Error writing data: " + msg + "\n")
                      return bareosfd.bRC_Error
              elif self.FNAME.endswith(".ovf"):
                  self.ovirt.process_ovf(IOP.buf)
                  IOP.status = IOP.count
                  IOP.io_errno = 0
              else:
                  self.ovirt.process_upload(IOP.buf)
                  IOP.status = IOP.count
                  IOP.io_errno = 0
              return bareosfd.bRC_OK
function_tokens: def plugin_io ( self , IOP ) : bareosfd . DebugMessage ( 100 , "plugin_io called with function %s\n" % ( IOP . func ) ) bareosfd . DebugMessage ( 100 , "FNAME is set to %s\n" % ( self . FNAME ) ) self . jobType = chr ( bareosfd . GetValue ( bareosfd . bVarType ) ) bareosfd . DebugMessage ( 100 , "BareosFdPluginOvirt::plugin_io() jobType: %s\n" % ( self . jobType ) , ) if IOP . func == bareosfd . IO_OPEN : self . FNAME = IOP . fname bareosfd . DebugMessage ( 100 , "self.FNAME was set to %s from IOP.fname\n" % ( self . FNAME ) ) bareosfd . DebugMessage ( 100 , "type(self.FNAME): %s\n" % ( type ( self . FNAME ) ) ) if self . options . get ( "local" ) == "yes" : try : if IOP . flags & ( os . O_CREAT | os . O_WRONLY ) : bareosfd . DebugMessage ( 100 , "Open file %s for writing with %s\n" % ( self . FNAME , IOP ) , ) dirname = os . path . dirname ( self . FNAME ) if not os . path . exists ( dirname ) : bareosfd . DebugMessage ( 100 , "Directory %s does not exist, creating it now\n" % ( dirname ) , ) os . makedirs ( dirname ) self . file = open ( self . FNAME , "wb" ) else : IOP . status = - 1 bareosfd . JobMessage ( bareosfd . M_FATAL , "plugin_io: option local=yes can only be used on restore\n" , ) return bareosfd . bRC_Error except ( OSError , IOError ) as io_open_error : IOP . status = - 1 bareosfd . DebugMessage ( 100 , "plugin_io: failed to open %s: %s\n" % ( self . FNAME , io_open_error . strerror ) , ) bareosfd . JobMessage ( bareosfd . M_FATAL , "plugin_io: failed to open %s: %s\n" % ( self . FNAME , io_open_error . strerror ) , ) return bareosfd . bRC_Error return bareosfd . bRC_OK elif IOP . func == bareosfd . IO_CLOSE : if self . file is not None : bareosfd . DebugMessage ( 100 , "Closing file " + "\n" ) self . file . close ( ) elif self . jobType == "B" : if "file" in self . backup_obj : self . backup_obj [ "file" ] [ "fh" ] . close ( ) elif "disk" in self . backup_obj : bareosfd . DebugMessage ( 100 , "plugin_io: calling end_transfer()\n" ) # Backup Job self . ovirt . end_transfer ( ) elif self . jobType == "R" : if self . FNAME . endswith ( ".ovf" ) : return self . ovirt . prepare_vm_restore ( ) else : self . ovirt . end_transfer ( ) return bareosfd . bRC_OK elif IOP . func == bareosfd . IO_SEEK : return bareosfd . bRC_OK elif IOP . func == bareosfd . IO_READ : if "file" in self . backup_obj : IOP . buf = bytearray ( IOP . count ) IOP . status = self . backup_obj [ "file" ] [ "fh" ] . readinto ( IOP . buf ) IOP . io_errno = 0 bareosfd . DebugMessage ( 100 , "plugin_io: read from file %s\n" % ( self . backup_obj [ "file" ] [ "filename" ] ) , ) elif "disk" in self . backup_obj : bareosfd . DebugMessage ( 100 , "plugin_io: read from disk %s\n" % ( self . backup_obj [ "disk" ] . alias ) , ) try : IOP . buf = bytearray ( IOP . count ) chunk = self . ovirt . process_download ( IOP . count ) IOP . buf [ : ] = chunk IOP . status = len ( IOP . buf ) IOP . io_errno = 0 except Exception as e : bareosfd . JobMessage ( bareosfd . M_ERROR , "BareosFdPluginOvirt:plugin_io() Error: %s\n" % str ( e ) , ) self . ovirt . end_transfer ( ) return bareosfd . bRC_Error else : bareosfd . JobMessage ( bareosfd . M_ERROR , "BareosFdPluginOvirt:plugin_io() Unable to read data to backup." , ) return bareosfd . bRC_Error return bareosfd . bRC_OK elif IOP . func == bareosfd . IO_WRITE : if self . file is not None : try : bareosfd . DebugMessage ( 200 , "Writing buffer to file %s\n" % ( self . FNAME ) ) self . file . write ( IOP . buf ) IOP . status = IOP . count IOP . io_errno = 0 except IOError as msg : IOP . io_errno = - 1 bareosfd . DebugMessage ( 100 , "Error writing data: " + msg + "\n" ) return bareosfd . bRC_Error elif self . FNAME . endswith ( ".ovf" ) : self . ovirt . process_ovf ( IOP . buf ) IOP . status = IOP . count IOP . io_errno = 0 else : self . ovirt . process_upload ( IOP . buf ) IOP . status = IOP . count IOP . io_errno = 0 return bareosfd . bRC_OK