Пример #1
0
def new_compute_rate():
    # Create a new Compute Chargeback rate
    try:
        desc = 'custom_' + fauxfactory.gen_alphanumeric()
        compute = rates.ComputeRate(description=desc,
                                    fields={
                                        'Used CPU': {
                                            'per_time': 'Hourly',
                                            'variable_rate': '3'
                                        },
                                        'Used Disk I/O': {
                                            'per_time': 'Hourly',
                                            'variable_rate': '2'
                                        },
                                        'Used Memory': {
                                            'per_time': 'Hourly',
                                            'variable_rate': '2'
                                        }
                                    })
        compute.create()
        if not BZ(1532368, forced_streams=['5.9']).blocks:
            storage = rates.StorageRate(description=desc,
                                        fields={
                                            'Used Disk Storage': {
                                                'per_time': 'Hourly',
                                                'variable_rate': '3'
                                            }
                                        })
            storage.create()
        yield desc
    finally:
        compute.delete()
        if not BZ(1532368, forced_streams=['5.9']).blocks:
            storage.delete()
Пример #2
0
def compute_rate(appliance, rate_type, interval):
    variable_rate = 1 if rate_type == 'variable' else 0
    description = 'custom_rate_' + fauxfactory.gen_alphanumeric()
    data = {
        'Used CPU Cores': {
            'per_time': interval,
            'fixed_rate': 1,
            'variable_rate': variable_rate
        },
        'Fixed Compute Cost 1': {
            'per_time': interval,
            'fixed_rate': 1
        },
        'Fixed Compute Cost 2': {
            'per_time': interval,
            'fixed_rate': 1
        },
        'Used Memory': {
            'per_time': interval,
            'fixed_rate': 1,
            'variable_rate': variable_rate
        },
        'Used Network I/O': {
            'per_time': interval,
            'fixed_rate': 1,
            'variable_rate': variable_rate
        }
    }
    ccb = rates.ComputeRate(description, fields=data, appliance=appliance)
    ccb.create()
    yield ccb
    ccb.delete()
Пример #3
0
def new_compute_rate(interval):
    """Create a new Compute Chargeback rate"""
    desc = 'custom_{}'.format(interval)
    compute = rates.ComputeRate(description=desc,
                                fields={
                                    'Used CPU': {
                                        'per_time': interval,
                                        'variable_rate': '720'
                                    },
                                    'Used Disk I/O': {
                                        'per_time': interval,
                                        'variable_rate': '720'
                                    },
                                    'Used Network I/O': {
                                        'per_time': interval,
                                        'variable_rate': '720'
                                    },
                                    'Used Memory': {
                                        'per_time': interval,
                                        'variable_rate': '720'
                                    }
                                })
    compute.create()
    storage = rates.StorageRate(description=desc,
                                fields={
                                    'Used Disk Storage': {
                                        'per_time': interval,
                                        'variable_rate': '720'
                                    }
                                })
    storage.create()
    yield desc

    compute.delete()
    storage.delete()
def new_chargeback_rate():
    """Create a new chargeback rate"""
    desc = 'custom_{}'.format(fauxfactory.gen_alphanumeric())
    compute = rates.ComputeRate(description=desc,
                                fields={
                                    'Allocated CPU Count': {
                                        'per_time': 'Hourly',
                                        'variable_rate': '2'
                                    },
                                    'Allocated Memory': {
                                        'per_time': 'Hourly',
                                        'variable_rate': '2'
                                    }
                                })
    compute.create()
    if not BZ(1532368, forced_streams=['5.9']).blocks:
        storage = rates.StorageRate(description=desc,
                                    fields={
                                        'Allocated Disk Storage': {
                                            'per_time': 'Hourly',
                                            'variable_rate': '3'
                                        }
                                    })
    storage.create()
    yield desc

    if compute.exists:
        compute.delete()
    if not BZ(1532368, forced_streams=['5.9']).blocks and storage.exists:
        storage.delete()
def new_chargeback_rate(appliance, include_variable_rates=True):

    # Create a new Chargeback compute rate

    def rand_float_str():
        return str(round(random() * fauxfactory.gen_integer(1, 20), 2))

    def gen_var_rate():
        return (rand_float_str() if include_variable_rates else 0)

    description = 'custom_rate_' + fauxfactory.gen_alphanumeric()
    data = {
        'Used CPU Cores': {'per_time': 'Hourly',
                           'fixed_rate': fauxfactory.gen_integer(1, 4),
                           'variable_rate': gen_var_rate()},
        'Fixed Compute Cost 1': {'per_time': 'Hourly',
                                 'fixed_rate': rand_float_str()},
        'Fixed Compute Cost 2': {'per_time': 'Hourly',
                                 'fixed_rate': rand_float_str()},
        'Used Memory': {'per_time': 'Hourly',
                        'fixed_rate': rand_float_str(),
                        'variable_rate': gen_var_rate()},
        'Used Network I/O': {'per_time': 'Hourly',
                             'fixed_rate': rand_float_str(),
                             'variable_rate': gen_var_rate()}
    }
    ccb = rates.ComputeRate(description, fields=data, appliance=appliance)
    ccb.create()
    return ccb
Пример #6
0
def chargeback_compute_rate():
    return cb.ComputeRate(
        description='cb' + fauxfactory.gen_alphanumeric(),
        fields={
            'Allocated CPU Count': with_random_per_time(fixed_rate='1000'),
            'Used Disk I/O': with_random_per_time(fixed_rate='10'),
            'Fixed Compute Cost 1': with_random_per_time(fixed_rate='100'),
            'Used Memory': with_random_per_time(fixed_rate='6000'),
            'Used CPU Cores': {'variable_rate': '0.05'}
        })
Пример #7
0
def chargeback_compute_rate():
    # TODO add variable rate parametrization
    compute_rate = cb.ComputeRate(
        description='cb' + fauxfactory.gen_alphanumeric(),
        fields={
            'Allocated CPU Count': with_random_per_time(fixed_rate='1000'),
            'Used Disk I/O': with_random_per_time(fixed_rate='10'),
            'Fixed Compute Cost 1': with_random_per_time(fixed_rate='100'),
            'Used Memory': with_random_per_time(fixed_rate='6000'),
            'Used CPU Cores': {'variable_rate': '0.05'}
        })
    yield compute_rate
    if compute_rate.exists:
        compute_rate.delete()
Пример #8
0
def chargeback_rate(rate_resource, rate_type, rate_action, request):
    if 'fixed' in rate_type:
        rate = [{'fixed_rate': '6000'}, {'fixed_rate': '.1'}]
    elif 'variable' in rate_type:
        rate = [{'variable_rate': '2000'}, {'variable_rate': '.6'}]
    else:
        raise ValueError(
            'Compute rate type argument must be "fixed" or "variable"')

    if rate_resource == 'compute':
        rate = cb.ComputeRate(description='cb_{}_{}_{}_{}'.format(
            fauxfactory.gen_alphanumeric(), rate_type, rate_resource,
            rate_action),
                              fields={
                                  'Allocated CPU Count':
                                  with_random_per_time(fixed_rate='1000'),
                                  'Used Disk I/O':
                                  with_random_per_time(fixed_rate='10'),
                                  'Fixed Compute Cost 1':
                                  with_random_per_time(fixed_rate='100'),
                                  'Used Memory':
                                  with_random_per_time(**rate[0]),
                                  'Used CPU Cores':
                                  with_random_per_time(**rate[1]),
                              })

    elif rate_resource == 'storage':
        rate = cb.StorageRate(description='cb_{}_{}_{}_{}'.format(
            fauxfactory.gen_alphanumeric(), rate_type, rate_resource,
            rate_action),
                              fields={
                                  'Fixed Storage Cost 1':
                                  with_random_per_time(fixed_rate='100'),
                                  'Fixed Storage Cost 2':
                                  with_random_per_time(fixed_rate='300'),
                                  'Allocated Disk Storage':
                                  with_random_per_time(**rate[0]),
                                  'Used Disk Storage':
                                  with_random_per_time(**rate[1]),
                              })

    @request.addfinalizer
    def _cleanup():
        if rate.exists:
            rate.delete()

    return rate
def new_compute_rate(enable_candu):
    # Create a new Compute Chargeback rate
    desc = '{}custom_'.format(fauxfactory.gen_alphanumeric())
    compute = rates.ComputeRate(description=desc, fields={
        'Used CPU': {'per_time': 'Hourly', 'variable_rate': '3'},
        'Allocated CPU Count': {'per_time': 'Hourly', 'fixed_rate': '2'},
        'Used Disk I/O': {'per_time': 'Hourly', 'variable_rate': '2'},
        'Allocated Memory': {'per_time': 'Hourly', 'fixed_rate': '1'},
        'Used Memory': {'per_time': 'Hourly', 'variable_rate': '2'}})
    compute.create()
    storage = rates.StorageRate(description=desc, fields={
        'Used Disk Storage': {'per_time': 'Hourly', 'variable_rate': '3'},
        'Allocated Disk Storage': {'per_time': 'Hourly', 'fixed_rate': '3'}})
    storage.create()
    yield desc
    compute.delete()
    storage.delete()