Exemplo n.º 1
0
 def migrate(self, dryRun=False):
     self._verify()
     if not self.is_legacy():
         return
     name = self.name()
     src = self.location()
     cleanup = True
     if (name == self._DEFAULT) or (name == "README"):
         logger.notice(lit("INFO_MIGRATE_OMIT__S") % name)
     elif name == self._LOCAL:
         if not dryRun:
             self._rearrange_conf_files(self._LOCAL)
         comm.mergeDirs(src, get_system_bundle_path(), dryRun, self._merger)
     else:
         if not dryRun:
             self._rearrange_conf_files(self._DEFAULT)
         collision = get_bundle(name)
         if collision is None:
             comm.moveItem(src, make_bundle_install_path(name), dryRun)
             cleanup = False
         else:
             logger.notice(
                 lit("INFO_MIGRATE_COLLISION__S_S") %
                 (collision.name(), collision.location()))
             logger.notice(lit("INFO_MIGRATE_OMIT__S") % name)
     if cleanup and not dryRun:
         logger.info(lit("INFO_MIGRATE_CLEANUP__S") % src)
         self.delete()
Exemplo n.º 2
0
    def install(self, cleanup=True):
        self._verify()
        if self.is_installed():
            return
        src = self.location()
        collision = get_bundle(self.name())

        if collision is None:
            dst = make_bundle_install_path(self._rawname)
            if cleanup:
                comm.moveItem(src, dst)
            else:
                comm.mkdirItem(dst)
                comm.mergeDirs(src, dst)
        else:
            default_path = os.path.join(collision.location(), self._DEFAULT)
            if os.path.exists(default_path):
                default_path_bkup = "%s.old.%s" % (
                    default_path,
                    time.strftime("%Y%m%d-%H%M%S", time.localtime()))
                comm.moveItem(default_path, default_path_bkup)
                comm.mkdirItem(default_path)
            self._rearrange_conf_files(self._DEFAULT)
            comm.mergeDirs(src, collision.location())

            if cleanup:
                self.delete()
Exemplo n.º 3
0
def mergeApp(appName):
    appPath = _getAppPath(appName, True)
    if not appPath:
        return None
    tmpPath = os.path.join(PACKAGE_PATH, 'DELETEME_' + appName)

    # this should copy app dir to tmp dir
    bundle_paths.maybe_makedirs(tmpPath)
    comm.mergeDirs(appPath, tmpPath)

    localPath = os.path.join(tmpPath, 'local')
    defaultPath = os.path.join(tmpPath, 'default')

    # check if the app is allowed to be merged

    if os.path.exists(localPath) and os.path.exists(defaultPath):
        # merge local and default dirs in tmp, result in local
        b = bundle_paths.Bundle('dummy', 'bundle')
        comm.mergeDirs(defaultPath, localPath, False, b._merger)

        # remove default
        bundle_paths.safe_remove(defaultPath)

        # move local to default
        comm.moveItem(localPath, defaultPath)

    return tmpPath
def mergeApp(appName):
    appPath = _getAppPath(appName, True)
    if not appPath:
        return None
    tmpPath = os.path.join(PACKAGE_PATH, 'DELETEME_' + appName)
    
    # this should copy app dir to tmp dir
    bundle_paths.maybe_makedirs(tmpPath)
    comm.mergeDirs(appPath, tmpPath)

    localPath = os.path.join(tmpPath, 'local')
    defaultPath = os.path.join(tmpPath, 'default')
    
    # check if the app is allowed to be merged

    if os.path.exists(localPath) and os.path.exists(defaultPath):
        # merge local and default dirs in tmp, result in local
        b = bundle_paths.Bundle('dummy', 'bundle')
        comm.mergeDirs(defaultPath, localPath, False, b._merger)

        # remove default
        bundle_paths.safe_remove(defaultPath)

        # move local to default
        comm.moveItem(localPath, defaultPath)
    
    return tmpPath
Exemplo n.º 5
0
    def install(self, cleanup=True):
        self._verify()
        if self.is_installed():
            return
        src = self.location()
        collision = get_bundle(self.name())            
        
        if collision is None:
            dst = make_bundle_install_path(self._rawname)
            if cleanup:
                comm.moveItem(src, dst)
            else:
                comm.mkdirItem(dst)
                comm.mergeDirs(src, dst)
        else:
            default_path = os.path.join(collision.location(), self._DEFAULT)
            default_path_bkup = "%s.old.%s" % (default_path, time.strftime("%Y%m%d-%H%M%S", time.localtime()))
            comm.moveItem(default_path, default_path_bkup)
            comm.mkdirItem(default_path)
            
            self._rearrange_conf_files(self._DEFAULT)
        
            comm.mergeDirs(src, collision.location())

            if cleanup:
                self.delete()
Exemplo n.º 6
0
 def migrate(self, dryRun=False):
     self._verify()
     if not self.is_legacy():
         return
     name = self.name()
     src = self.location()
     cleanup = True
     if (name == self._DEFAULT) or (name == "README"):
         logger.notice(lit("INFO_MIGRATE_OMIT__S") % name)
     elif name == self._LOCAL:
         if not dryRun:
             self._rearrange_conf_files(self._LOCAL)
         comm.mergeDirs(src, get_system_bundle_path(), dryRun, self._merger)
     else:
         if not dryRun:
             self._rearrange_conf_files(self._DEFAULT)
         collision = get_bundle(name)
         if collision is None:
             comm.moveItem(src, make_bundle_install_path(name), dryRun)
             cleanup = False
         else:
             logger.notice(lit("INFO_MIGRATE_COLLISION__S_S") %
                           (collision.name(), collision.location()))
             logger.notice(lit("INFO_MIGRATE_OMIT__S") % name)
     if cleanup and not dryRun:
         logger.info(lit("INFO_MIGRATE_CLEANUP__S") % src)
         self.delete()
Exemplo n.º 7
0
 def _rearrange_conf_files(self, dirname):
     self._verify()
     location = self.location()
     subdir = os.path.join(location, dirname)
     if os.path.lexists(subdir):
         if not os.path.isdir(subdir):
             raise OSError("Existing file not a directory: %s" % subdir)
     else:
         comm.mkdirItem(subdir)
     for f in glob.glob(os.path.join(location, "*.conf")):
         comm.moveItem(f, subdir)
Exemplo n.º 8
0
 def _rearrange_conf_files(self, dirname):
     self._verify()
     location = self.location()
     subdir = os.path.join(location, dirname)
     if os.path.lexists(subdir):
         if not os.path.isdir(subdir):
             raise OSError("Existing file not a directory: %s" % subdir)
     else:
         comm.mkdirItem(subdir)
     for f in glob.glob(os.path.join(location, "*.conf")):
         comm.moveItem(f, subdir)
Exemplo n.º 9
0
def firstTimeRun(args, fromCLI):
    """
  All of our first time run checks that used to happen in the former bin/splunk shell script.
  Does any number of things, such as config migration, directory validation, and so on.  For
  the most up to date info, read the code.  It tends to be fairly well documented.
  """

    paramReq = (
        ARG_DRYRUN,
        ARG_FRESHINST,
    )
    paramOpt = (ARG_LOGFILE, )
    comm.validateArgs(paramReq, paramOpt, args)

    isFirstInstall = comm.getBoolValue(ARG_FRESHINST, args[ARG_FRESHINST])
    isDryRun = comm.getBoolValue(ARG_DRYRUN, args[ARG_DRYRUN])
    retDict = {}

    # ...arg parsing done now.

    # NOTE:
    # none of the changes that are made in this function are subjected to isDryRun.
    # these things just have to be done - they're not considered to be migration.

    ##### if user doesn't have a ldap.conf, put our default in its place.
    if not os.path.exists(migration.PATH_LDAP_CONF):
        comm.copyItem(migration.PATH_LDAP_CONF_DEF, migration.PATH_LDAP_CONF)

    if not os.path.exists(PATH_AUDIT_PRIV_KEY) and not os.path.exists(
            PATH_AUDIT_PUB_KEY):
        kCmd = ["splunk", "createssl", "audit-keys"]
        kPriv, kPub, kDir = PATH_AUDIT_PRIV_KEY, PATH_AUDIT_PUB_KEY, PATH_AUDIT_KEY_DIR
        retCode = comm.runAndLog(kCmd + ["-p", kPriv, "-k", kPub, "-d", kDir])
        if 0 != retCode:
            raise cex.FilePath, "Could not create audit keys (returned %d)." % retCode

    try:
        keyScript = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                         "genKeyScript")
        keyCmdList = [
            os.path.expandvars(x.strip()) for x in keyScript.split(",")
            if len(x) > 0
        ]  # a,b,,d -> [a,b,d]
        pubFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                           "publicKey")
        privateFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                               "privateKey")
        certDir = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                       "certDir")
        certDir = os.path.expandvars(certDir)
        privateFilename = os.path.join(certDir, privateFilename)
        pubFilename = os.path.join(certDir, pubFilename)
        if not (os.path.exists(os.path.join(certDir, privateFilename))
                or os.path.exists(os.path.join(certDir, pubFilename))):
            cmdList = keyCmdList + [
                "-p", privateFilename, "-k", pubFilename, "-d", certDir
            ]
            success = comm.runAndLog(cmdList) == 0
            if not success:
                logger.warn("Unable to generate distributed search keys.")
                #TK mgn 06/19/09
                raise cex.FilePath, "Unable to generate distributed search keys."  #TK mgn 06/19/09
    except:
        logger.warn("Unable to generate distributed search keys.")
        #TK mgn 06/19/09
        raise

    if isFirstInstall:
        ##### if user doesn't have a ui modules dir, put our default in its place. only run this in this block - otherwise,
        #     in an upgrade, we run the same code during migration and show an incorrect warning ("oh noes dir is missing").
        if not os.path.exists(migration.PATH_UI_MOD_ACTIVE):
            comm.moveItem(migration.PATH_UI_MOD_NEW,
                          migration.PATH_UI_MOD_ACTIVE)
    ##### we're in an upgrade situation.
    else:
        ##### now do the actual migration (or fake it, if the user wants).
        #     upon faking, this function will throw an exception.
        if not ARG_LOGFILE in args:
            raise cex.ArgError, "Cannot migrate without the '%s' parameter." % ARG_LOGFILE
        migration.autoMigrate(args[ARG_LOGFILE], isDryRun)

    ##### FTR succeeded.  johnvey's never gonna have eggs. T_T

    # --- done w/ FTR, now i can has bucket?? ---
    return retDict
Exemplo n.º 10
0
def firstTimeRun(args, fromCLI):
  """
  All of our first time run checks that used to happen in the former bin/splunk shell script.
  Does any number of things, such as config migration, directory validation, and so on.  For
  the most up to date info, read the code.  It tends to be fairly well documented.
  """

  paramReq = (ARG_DRYRUN, ARG_FRESHINST,)
  paramOpt = (ARG_LOGFILE,)
  comm.validateArgs(paramReq, paramOpt, args)

  isFirstInstall = comm.getBoolValue(ARG_FRESHINST, args[ARG_FRESHINST])
  isDryRun = comm.getBoolValue(ARG_DRYRUN, args[ARG_DRYRUN])
  retDict  = {}

  # ...arg parsing done now.

  # NOTE:
  # none of the changes that are made in this function are subjected to isDryRun.
  # these things just have to be done - they're not considered to be migration.

  ##### if user doesn't have a ldap.conf, put our default in its place.
  if not os.path.exists(migration.PATH_LDAP_CONF):
    comm.copyItem(migration.PATH_LDAP_CONF_DEF, migration.PATH_LDAP_CONF)

  if not os.path.exists(PATH_AUDIT_PRIV_KEY) and not os.path.exists(PATH_AUDIT_PUB_KEY):
    kCmd = ["splunk", "createssl", "audit-keys"]
    kPriv, kPub, kDir = PATH_AUDIT_PRIV_KEY, PATH_AUDIT_PUB_KEY, PATH_AUDIT_KEY_DIR
    retCode = comm.runAndLog(kCmd + ["-p", kPriv, "-k", kPub, "-d", kDir])
    if 0 != retCode:
      raise cex.FilePath, "Could not create audit keys (returned %d)." % retCode

  try:    
    keyScript = comm.getConfKeyValue("distsearch", "tokenExchKeys", "genKeyScript" );
    keyCmdList = [os.path.expandvars(x.strip()) for x in keyScript.split(",") if len(x) > 0] # a,b,,d -> [a,b,d]
    pubFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys", "publicKey" );
    privateFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys", "privateKey" );
    certDir = comm.getConfKeyValue("distsearch", "tokenExchKeys", "certDir" )
    certDir = os.path.expandvars( certDir )
    privateFilename = os.path.join( certDir,privateFilename )
    pubFilename = os.path.join( certDir, pubFilename )
    if not ( os.path.exists( os.path.join( certDir,privateFilename ) ) or os.path.exists( os.path.join( certDir, pubFilename ) ) ):
      cmdList = keyCmdList + [ "-p", privateFilename, "-k", pubFilename,"-d", certDir ]
      success = comm.runAndLog( cmdList ) == 0
      if not success:
        logger.warn("Unable to generate distributed search keys."); #TK mgn 06/19/09
        raise cex.FilePath, "Unable to generate distributed search keys." #TK mgn 06/19/09
  except:
    logger.warn("Unable to generate distributed search keys."); #TK mgn 06/19/09
    raise 

  if isFirstInstall:
    ##### if user doesn't have a ui modules dir, put our default in its place. only run this in this block - otherwise,
    #     in an upgrade, we run the same code during migration and show an incorrect warning ("oh noes dir is missing").
    if not os.path.exists(migration.PATH_UI_MOD_ACTIVE):
      comm.moveItem(migration.PATH_UI_MOD_NEW, migration.PATH_UI_MOD_ACTIVE)
  ##### we're in an upgrade situation.
  else:
    ##### now do the actual migration (or fake it, if the user wants).
    #     upon faking, this function will throw an exception.
    if not ARG_LOGFILE in args:
      raise cex.ArgError, "Cannot migrate without the '%s' parameter." % ARG_LOGFILE
    migration.autoMigrate(args[ARG_LOGFILE], isDryRun)


  ##### FTR succeeded.  johnvey's never gonna have eggs. T_T

  # --- done w/ FTR, now i can has bucket?? ---
  return retDict