Esempio n. 1
0
def _check_journal(old_foristor, new_foristor):

    check_journal = False

    # If required, update the new journal size.
    if 'journal_size_mib' in new_foristor:
        journal_size = new_foristor['journal_size_mib']
        check_journal = True
    else:
        journal_size = old_foristor['journal_size_mib']

    # If required, update the new journal location.
    if 'journal_location' in new_foristor:
        if not uuidutils.is_uuid_like(new_foristor['journal_location']):
            raise exception.InvalidUUID(uuid=new_foristor['journal_location'])
        journal_location = new_foristor['journal_location']
        check_journal = True
    else:
        journal_location = old_foristor['journal_location']

    # If modifications to the journal location or size have been made,
    # verify that they are valid.
    if check_journal:
        try:
            journal_istor = pecan.request.dbapi.istor_get(journal_location)
        except exception.ServerNotFound:
            raise wsme.exc.ClientSideError(_(
                "No journal stor with the provided uuid: %s" %
                journal_location))

        idisk = pecan.request.dbapi.idisk_get(journal_istor.idisk_uuid)

        _check_journal_location(journal_location,
                                new_foristor,
                                constants.ACTION_UPDATE_JOURNAL)

        if new_foristor['journal_location'] == \
                old_foristor['journal_location']:
            # journal location is the same - we are just updating the size.
            # In this case the old journal is removed and a new one is created.
            _check_journal_space(idisk.uuid, journal_location, journal_size,
                                 old_foristor['journal_size_mib'])
        elif new_foristor['journal_location'] != new_foristor['uuid']:
            # If a journal becomes external, check that the journal stor can
            # accommodate it.
            _check_journal_space(idisk.uuid, journal_location, journal_size)
Esempio n. 2
0
def _check_journal_location(journal_location, stor, action):
    """Chooses a valid journal location or returns a corresponding error."""

    if journal_location:
        if not uuidutils.is_uuid_like(journal_location):
            raise exception.InvalidUUID(uuid=journal_location)

    # If a journal location is provided by the user.
    if journal_location:
        # Check that the journal location is that of an existing stor object.
        try:
            requested_journal_onistor = pecan.request.dbapi.istor_get(
                journal_location)
        except exception.ServerNotFound:
            raise wsme.exc.ClientSideError(
                _("No journal stor with the provided uuid: %s" %
                  journal_location))

        # Check that the provided stor is assigned to the same host as the OSD.
        if (requested_journal_onistor.forihostid != stor['forihostid']):
            raise wsme.exc.ClientSideError(
                _("The provided stor belongs to another "
                  "host."))

        # If the action is journal create, don't let the journal be
        # collocated.
        if action == constants.ACTION_CREATE_JOURNAL:
            if (requested_journal_onistor.function !=
                    constants.STOR_FUNCTION_JOURNAL):
                raise wsme.exc.ClientSideError(
                    _("The provided uuid belongs to a stor "
                      "that is not of journal type."))

        # If the action is journal update:
        # - if the new journal location is not collocated, check that the
        #   location is of journal type.
        # - if the new journal location is collocated, allow it.
        if action == constants.ACTION_UPDATE_JOURNAL:
            if requested_journal_onistor.uuid != stor['uuid']:
                if (requested_journal_onistor.function !=
                        constants.STOR_FUNCTION_JOURNAL):
                    raise wsme.exc.ClientSideError(
                        _("The provided uuid belongs to a stor "
                          "that is not of journal type."))

    # If no journal location is provided by the user.
    else:
        # Check if there is a journal storage designated for the present host.
        existing_journal_stors = pecan.request.dbapi.istor_get_by_ihost_function(
            stor['forihostid'], constants.STOR_FUNCTION_JOURNAL)

        # If more than one journal stor is assigned to the host, the user
        # should choose only one journal location.
        #
        # If there is only one journal stor assigned to the host, then that's
        # where the journal will reside.
        #
        # If there are no journal stors assigned to the host, then the journal
        # is collocated.
        if 'uuid' in stor:
            if len(existing_journal_stors) > 1:
                available_journals = ""
                for stor_obj in existing_journal_stors:
                    available_journals = (available_journals + stor_obj.uuid +
                                          "\n")
                raise wsme.exc.ClientSideError(
                    _("Multiple journal stors are available. Choose from:\n%s"
                      % available_journals))
            elif len(existing_journal_stors) == 1:
                journal_location = existing_journal_stors[0].uuid
            elif len(existing_journal_stors) == 0:
                journal_location = stor['uuid']

    return journal_location
Esempio n. 3
0
 def validate(value):
     if not utils.is_uuid_like(value):
         raise exception.InvalidUUID(uuid=value)
     return value