コード例 #1
0
ファイル: purge_tables.py プロジェクト: pineunity/apmec-1
def purge_deleted(apmec_config, table_name, age, granularity='days'):
    try:
        age = int(age)
    except ValueError:
        msg = _("'%s' - age should be an integer") % age
        raise exceptions.InvalidInput(error_message=msg)
    if age < 0:
        msg = _("'%s' - age should be a positive integer") % age
        raise exceptions.InvalidInput(error_message=msg)

    if granularity not in GRANULARITY.keys():
        msg = _("'%s' granularity should be days, hours, minutes, "
                "or seconds") % granularity
        raise exceptions.InvalidInput(error_message=msg)

    age *= GRANULARITY[granularity]

    time_line = timeutils.utcnow() - datetime.timedelta(seconds=age)
    engine = get_engine(apmec_config)
    meta = sqlalchemy.MetaData()
    meta.bind = engine
    inspector = inspect(engine)
    assoc_map = _generate_associated_tables_map(inspector)

    if table_name == 'events':
        _purge_events_table(meta, engine, time_line)
    elif table_name == 'all':
        _purge_events_table(meta, engine, time_line)
        for t in ['mea', 'mead', 'vims']:
            _purge_resource_tables(t, meta, engine, time_line, assoc_map)
    else:
        _purge_resource_tables(table_name, meta, engine, time_line, assoc_map)
コード例 #2
0
def _validate_no_whitespace(data):
    """Validates that input has no whitespace."""
    if len(data.split()) > 1:
        msg = _("'%s' contains whitespace") % data
        LOG.debug(msg)
        raise n_exc.InvalidInput(error_message=msg)
    return data
コード例 #3
0
def convert_kvp_str_to_list(data):
    """Convert a value of the form 'key=value' to ['key', 'value'].

    :raises n_exc.InvalidInput: if any of the strings are malformed
                                (e.g. do not contain a key).
    """
    kvp = [x.strip() for x in data.split('=', 1)]
    if len(kvp) == 2 and kvp[0]:
        return kvp
    msg = _("'%s' is not of the form <key>=[value]") % data
    raise n_exc.InvalidInput(error_message=msg)
コード例 #4
0
def convert_to_boolean(data):
    if isinstance(data, six.string_types):
        val = data.lower()
        if val == "true" or val == "1":
            return True
        if val == "false" or val == "0":
            return False
    elif isinstance(data, bool):
        return data
    elif isinstance(data, int):
        if data == 0:
            return False
        elif data == 1:
            return True
    msg = _("'%s' cannot be converted to boolean") % data
    raise n_exc.InvalidInput(error_message=msg)
コード例 #5
0
def convert_to_int(data):
    try:
        return int(data)
    except (ValueError, TypeError):
        msg = _("'%s' is not an integer") % data
        raise n_exc.InvalidInput(error_message=msg)