示例#1
0
def _GroupWatcher(opts):
    """Main function for per-group watcher process.

  """
    group_uuid = opts.nodegroup.lower()

    if not utils.UUID_RE.match(group_uuid):
        raise errors.GenericError(
            "Node group parameter (%s) must be given a UUID,"
            " got '%s'" % (cli.NODEGROUP_OPT_NAME, group_uuid))

    logging.info("Watcher for node group '%s'", group_uuid)

    known_groups = _LoadKnownGroups()

    # Check if node group is known
    if group_uuid not in known_groups:
        raise errors.GenericError("Node group '%s' is not known by ssconf" %
                                  group_uuid)

    # Group UUID has been verified and should not contain any dangerous
    # characters
    state_path = pathutils.WATCHER_GROUP_STATE_FILE % group_uuid
    inst_status_path = pathutils.WATCHER_GROUP_INSTANCE_STATUS_FILE % group_uuid

    logging.debug("Using state file %s", state_path)

    # Global watcher
    statefile = state.OpenStateFile(state_path)  # pylint: disable=E0602
    if not statefile:
        return constants.EXIT_FAILURE

    notepad = state.WatcherState(statefile)  # pylint: disable=E0602
    try:
        # Connect to master daemon
        client = GetLuxiClient(False)

        _CheckMaster(client)

        (nodes, instances, locks) = _GetGroupData(client, group_uuid)

        # Update per-group instance status file
        _UpdateInstanceStatus(inst_status_path, instances.values())

        _MergeInstanceStatus(pathutils.INSTANCE_STATUS_FILE,
                             pathutils.WATCHER_GROUP_INSTANCE_STATUS_FILE,
                             known_groups)

        restart_needed, started = _CheckInstances(client, notepad, instances,
                                                  locks)
        _CheckDisks(client, notepad, nodes, instances, started)
        if not opts.no_verify_disks:
            _VerifyDisks(client, group_uuid, nodes, instances)
    except Exception, err:
        logging.info("Not updating status file due to failure: %s", err)
        raise
示例#2
0
def _GroupWatcher(opts):
    """Main function for per-group watcher process.

  """
    group_uuid = opts.nodegroup.lower()

    if not utils.UUID_RE.match(group_uuid):
        raise errors.GenericError(
            "Node group parameter (%s) must be given a UUID,"
            " got '%s'" % (cli.NODEGROUP_OPT_NAME, group_uuid))

    logging.info("Watcher for node group '%s'", group_uuid)

    known_groups = _LoadKnownGroups()

    # Check if node group is known
    if group_uuid not in known_groups:
        raise errors.GenericError("Node group '%s' is not known by ssconf" %
                                  group_uuid)

    # Group UUID has been verified and should not contain any dangerous
    # characters
    state_path = pathutils.WATCHER_GROUP_STATE_FILE % group_uuid
    inst_status_path = pathutils.WATCHER_GROUP_INSTANCE_STATUS_FILE % group_uuid

    logging.debug("Using state file %s", state_path)

    # Global watcher
    statefile = state.OpenStateFile(state_path)  # pylint: disable=E0602
    if not statefile:
        return constants.EXIT_FAILURE

    notepad = state.WatcherState(statefile)  # pylint: disable=E0602
    try:
        # Connect to master daemon
        client = GetLuxiClient(False)

        _CheckMaster(client)

        (nodes, instances, locks) = _GetGroupData(client, group_uuid)

        # Update per-group instance status file
        _UpdateInstanceStatus(inst_status_path, list(instances.values()))

        _MergeInstanceStatus(pathutils.INSTANCE_STATUS_FILE,
                             pathutils.WATCHER_GROUP_INSTANCE_STATUS_FILE,
                             known_groups)

        started = _CheckInstances(client, notepad, instances, locks)
        _CheckDisks(client, notepad, nodes, instances, started)

        # Check if the nodegroup only has ext storage type
        only_ext = compat.all(i.disk_template == constants.DT_EXT
                              for i in instances.values())

        # We skip current NodeGroup verification if there are only external storage
        # devices. Currently we provide an interface for external storage provider
        # for disk verification implementations, however current ExtStorageDevice
        # does not provide an API for this yet.
        #
        # This check needs to be revisited if ES_ACTION_VERIFY on ExtStorageDevice
        # is implemented.
        if not opts.no_verify_disks and not only_ext:
            _VerifyDisks(client, group_uuid, nodes, instances)
    except Exception as err:
        logging.info("Not updating status file due to failure: %s", err)
        raise
    else:
        # Save changes for next run
        notepad.Save(state_path)

    return constants.EXIT_SUCCESS