示例#1
0
    # Parse local instance information (if it exists, otherwise create one).
    localInstanceInfo = None
    try:
        with open(instanceLocation + "/instanceInfo.json", 'r') as fp:
            localInstanceInfo = json.loads(fp.read())
    except:
        localInstanceInfo = {
            "files": {},
            "version": globalData.version,
            "rev": globalData.rev,
            "dependencies": {}
        }

    # create an updater process
    try:
        updater = Updater(updateServer, updatePort, updateLocation,
                          updateCaFile, globalData, localInstanceInfo)
    except:
        logging.exception("[%s]: Not able to create update object." % fileName)
        outputUpdateFailed()
        sys.exit(1)

    # Get new instance information.
    newInstanceInfo = updater.getInstanceInformation()

    # check if the received version is newer than the current one
    if (updater.newestVersion > globalData.version
            or (updater.newestRev > globalData.rev
                and updater.newestVersion == globalData.version)
            or options.force is True):

        if options.force is True:
示例#2
0
			if options.yes is False:
				if userConfirmation() is False:
					print "Bye."
					sys.exit(0)
			else:
				print "NOTE: Skipping confirmation."

	except Exception as e:
		logging.exception("[%s]: Could not parse config." % fileName)
		sys.exit(1)

	logging.info("[%s]: Current version: %.3f-%d." %
		(fileName, globalData.version, globalData.rev))

	# create an updater process
	updater = Updater(updateServer, updatePort, updateLocation,
		updateCaFile, globalData)

	# get newest version information
	if updater.getNewestVersionInformation() is False:
		sys.exit(1)

	# check if the received version is newer than the current one
	if (updater.newestVersion > globalData.version or
		(updater.newestRev > globalData.rev
		and updater.newestVersion == globalData.version)
		or options.force is True):

		if options.force is True:
			logging.info("[%s]: Forcing update of alertR instance."
				% fileName)
示例#3
0
        (fileName, globalData.version, globalData.rev))

    # Parse local instance information (if it exists, otherwise create one).
    localInstanceInfo = None
    try:
        with open(instanceLocation + "/instanceInfo.json", 'r') as fp:
            localInstanceInfo = json.loads(fp.read())
    except:
        localInstanceInfo = {"files": {},
            "version": globalData.version,
            "rev": globalData.rev,
            "dependencies": {}}

    # create an updater process
    try:
        updater = Updater(updateServer, updatePort, updateLocation,
            updateCaFile, globalData, localInstanceInfo)
    except:
        logging.exception("[%s]: Not able to create update object."
            % fileName)
        outputUpdateFailed()
        sys.exit(1)

    # Get new instance information.
    newInstanceInfo = updater.getInstanceInformation()

    logging.info("[%s]: Newest version available: %.3f-%d." %
        (fileName, updater.newestVersion, updater.newestRev))

    # check if the received version is newer than the current one
    if (updater.newestVersion > globalData.version or
        (updater.newestRev > globalData.rev
示例#4
0
    # Parse local instance information (if it exists, otherwise create one).
    localInstanceInfo = None
    try:
        with open(instanceLocation + "/instanceInfo.json", 'r') as fp:
            localInstanceInfo = json.loads(fp.read())
    except Exception as e:
        localInstanceInfo = {
            "files": {},
            "version": globalData.version,
            "rev": globalData.rev,
            "dependencies": {}
        }

    # create an updater process
    try:
        updater = Updater(updateUrl, globalData, localInstanceInfo)
    except:
        logging.exception("[%s]: Not able to create update object." % fileName)
        outputUpdateFailed()
        sys.exit(1)

    # Get new instance information.
    newInstanceInfo = updater.getInstanceInformation()

    logging.info("[%s]: Newest version available: %.3f-%d." %
                 (fileName, updater.newestVersion, updater.newestRev))

    # check if the received version is newer than the current one
    if (updater.newestVersion > globalData.version
            or (updater.newestRev > globalData.rev
                and updater.newestVersion == globalData.version)
示例#5
0
            if options.yes is False:
                if userConfirmation() is False:
                    print "Bye."
                    sys.exit(0)
            else:
                print "NOTE: Skipping confirmation."

    except Exception as e:
        logging.exception("[%s]: Could not parse config." % fileName)
        sys.exit(1)

    logging.info("[%s]: Current version: %.3f-%d." %
                 (fileName, globalData.version, globalData.rev))

    # create an updater process
    updater = Updater(updateServer, updatePort, updateLocation, updateCaFile,
                      globalData)

    # get newest version information
    if updater.getNewestVersionInformation() is False:
        sys.exit(1)

    # check if the received version is newer than the current one
    if (updater.newestVersion > globalData.version
            or (updater.newestRev > globalData.rev
                and updater.newestVersion == globalData.version)
            or options.force is True):

        if options.force is True:
            logging.info("[%s]: Forcing update of alertR instance." % fileName)

        # check if the update changes the protocol
示例#6
0
def chooseNodeTypeAndInstance(updater: Updater) -> Tuple[str, str]:
    """
    Function that asks user for node type and instance.

    :param updater:
    :return:
    """
    nodeType = None
    instance = None

    # Only contact online repository when we are not set as working offline.
    repoInfo = {"instances": {}}
    if updater is not None:
        try:
            repoInfo = updater.getRepositoryInformation()

        except Exception as e:
            logging.exception("[%s]: Not able to contact online repository." %
                              fileName)

        choiceList = [
            x for x in list(repoInfo["instances"].keys())
            if x.lower() != "server"
        ]
        choiceList.sort()

        alerts = list()
        managers = list()
        sensors = list()
        others = list()
        for instanceIter in choiceList:
            currType = repoInfo["instances"][instanceIter]["type"]
            if currType == "alert":
                alerts.append(instanceIter)

            elif currType == "manager":
                managers.append(instanceIter)

            elif currType == "sensor":
                sensors.append(instanceIter)

            else:
                others.append(instanceIter)

        # Create a list of all instances in the exact order in which
        # we output them.
        allInstances = list()

        print("#" * 100)
        print("No.".ljust(5) + "| Option")
        print("#" * 100)

        ctr = 1
        headline = " Type: alert "
        print("-" * 40 + headline + "-" * (60 - len(headline)))
        for instanceIter in alerts:
            output = "%d." % ctr
            output = output.ljust(5) + "| "
            output += "Use instance '%s'." % instanceIter
            print(output)
            ctr += 1
            allInstances.append(instanceIter)

        headline = " Type: manager "
        print("-" * 40 + headline + "-" * (60 - len(headline)))
        for instanceIter in managers:
            output = "%d." % ctr
            output = output.ljust(5) + "| "
            output += "Use instance '%s'." % instanceIter
            print(output)
            ctr += 1
            allInstances.append(instanceIter)

        headline = " Type: sensor "
        print("-" * 40 + headline + "-" * (60 - len(headline)))
        for instanceIter in sensors:
            output = "%d." % ctr
            output = output.ljust(5) + "| "
            output += "Use instance '%s'." % instanceIter
            print(output)
            ctr += 1
            allInstances.append(instanceIter)

        headline = " Type: other "
        print("-" * 40 + headline + "-" * (60 - len(headline)))
        for instanceIter in others:
            output = "%d." % ctr
            output = output.ljust(5) + "| "
            output += "Use instance '%s'." % instanceIter
            print(output)
            ctr += 1
            allInstances.append(instanceIter)

        print("%d. Enter instance and node type manually." % ctr)
        manualOption = ctr

        while True:
            userOptionStr = input("Please choose an option: ")
            userOption = 0
            try:
                userOption = int(userOptionStr)

            except Exception:
                pass

            if userOption == manualOption:
                break

            elif 0 < userOption < manualOption:
                instance = allInstances[userOption - 1]
                nodeType = repoInfo["instances"][instance]["type"]
                break

            else:
                print("Invalid option. Please retry.")

    # If no node type and instance is chosen until now, ask user.
    if nodeType not in validNodeTypes:
        while True:
            nodeType = input("Please enter node type:\n").lower()
            if nodeType in validNodeTypes:
                break

            else:
                print(
                    "Only valid node types are: 'sensor', 'manager', 'alert'. Please retry."
                )

    if instance is None:
        instance = input("Please enter instance:\n")

    return nodeType, instance
示例#7
0
        globalData.userBackend = CSVBackend(globalData,
                                            globalData.userBackendCsvFile)

    except Exception as e:
        logging.exception("[%s]: Could not parse config." % fileName)
        sys.exit(1)

    # Create updater object only if we should contact the repository.
    updater = None
    if options.offline is False:

        # Create an updater process.
        try:
            updater = Updater(updateUrl,
                              globalData,
                              None,
                              retrieveInfo=False,
                              timeout=5)

        except Exception as e:
            logging.exception("[%s]: Not able to create updater object." %
                              fileName)

    if options.add:
        addUser(globalData.userBackend, options.username, options.password,
                options.type, options.instance, options.yes, updater)

    elif options.delete:
        deleteUser(globalData.userBackend, options.username, options.yes)

    elif options.modify:
示例#8
0
            raise ValueError("No valid user backend method in config file.")

    except Exception as e:
        logging.exception("[%s]: Could not parse config." % fileName)
        sys.exit(1)

    # Create updater object only if we should contact the repository.
    updater = None
    if options.offline is False:

        # Create an updater process.
        try:
            updater = Updater(updateServer,
                              updatePort,
                              updateLocation,
                              updateCaFile,
                              globalData,
                              None,
                              retrieveInfo=False,
                              timeout=5)
        except Exception as e:
            logging.exception("[%s]: Not able create updater object." %
                              fileName)

    if options.add:
        addUser(globalData.userBackend, options.username, options.password,
                options.type, options.instance, options.yes, updater)
    elif options.delete:
        deleteUser(globalData.userBackend, options.username, options.yes)
    elif options.modify:
        modifyUser(globalData.userBackend, options.username, options.password,
                   options.type, options.instance, options.yes, updater)