def configure(self): """ Configure Pool, based on config content. """ config = common.CONFIG_STORE cores = config.get_pool_attr('cores', self.pool) self.cores_set(cores) if caps.cat_supported(): cbm = config.get_pool_attr('cbm', self.pool) self.cbm_set(cbm) if caps.mba_supported(): mba = config.get_pool_attr('mba', self.pool) self.mba_set(mba) apps = config.get_pool_attr('apps', self.pool) if apps is not None: pids = [] for app in apps: app_pids = config.get_app_attr('pids', app) if app_pids: pids.extend(app_pids) self.pids_set(pids) return Pool.apply(self.pool)
def add_default_pool(data): """ Update config with "Default" pool """ # no Default pool configured default_pool = {} default_pool['id'] = 0 if caps.mba_supported(): if caps.mba_bw_enabled(): default_pool['mba_bw'] = 2**32 - 1 else: default_pool['mba'] = 100 if caps.cat_supported(): default_pool['cbm'] = common.PQOS_API.get_max_l3_cat_cbm() default_pool['name'] = "Default" # Use all unallocated cores default_pool['cores'] = list(range(common.PQOS_API.get_num_cores())) for pool in data['pools']: default_pool['cores'] = \ [core for core in default_pool['cores'] if core not in pool['cores']] data['pools'].append(default_pool)
def _validate_rdt(data): """ Validate RDT configuration (including MBA CTRL) configuration Parameters data: configuration (dict) """ # if data to be validated does not contain RDT iface and/or MBA CTRL info # get missing info from current configuration rdt_iface = data['rdt_iface']['interface'] if 'rdt_iface' in data\ else common.CONFIG_STORE.get_rdt_iface() mba_ctrl_enabled = data['mba_ctrl']['enabled'] if 'mba_ctrl' in data\ else common.CONFIG_STORE.get_mba_ctrl_enabled() if mba_ctrl_enabled and rdt_iface != "os": raise ValueError( "RDT Configuration. MBA CTRL requires RDT OS interface!") if mba_ctrl_enabled and not caps.mba_bw_supported(): raise ValueError( "RDT Configuration. MBA CTRL requested but not supported!") if not 'pools' in data: return mba_pool_ids = [] mba_bw_pool_ids = [] for pool in data['pools']: if 'cbm' in pool: result = re.search('1{1,32}0{1,32}1{1,32}', bin(pool['cbm'])) if result or pool['cbm'] == 0: raise ValueError("Pool {}, CBM {}/{} is not contiguous."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if not caps.cat_supported(): raise ValueError("Pool {}, CBM {}/{}, CAT is not supported."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if 'mba' in pool: mba_pool_ids.append(pool['id']) if 'mba_bw' in pool: mba_bw_pool_ids.append(pool['id']) if (mba_pool_ids or mba_bw_pool_ids) and not caps.mba_supported(): raise ValueError("Pools {}, MBA is not supported."\ .format(mba_pool_ids + mba_bw_pool_ids)) if mba_bw_pool_ids and not mba_ctrl_enabled: raise ValueError("Pools {}, MBA BW is not enabled/supported."\ .format(mba_bw_pool_ids)) if mba_pool_ids and mba_ctrl_enabled: raise ValueError("Pools {}, MBA % is not enabled. Disable MBA BW and try again."\ .format(mba_pool_ids)) return
def _validate_pools(data): """ Validate Pools configuration Parameters data: configuration (dict) """ if not 'pools' in data: return # verify pools cores = set() pool_ids = [] for pool in data['pools']: # id if pool['id'] in pool_ids: raise ValueError( "Pool {}, multiple pools with same id.".format(pool['id'])) pool_ids.append(pool['id']) # pool cores for core in pool['cores']: if not common.PQOS_API.check_core(core): raise ValueError("Pool {}, Invalid core {}.".format( pool['id'], core)) if cores.intersection(pool['cores']): raise ValueError("Pool {}, Cores {} already assigned to another pool."\ .format(pool['id'], cores.intersection(pool['cores']))) cores |= set(pool['cores']) # check app reference if 'apps' in pool: for app_id in pool['apps']: ConfigStore.get_app(data, app_id) if 'cbm' in pool: result = re.search('1{1,32}0{1,32}1{1,32}', bin(pool['cbm'])) if result or pool['cbm'] == 0: raise ValueError("Pool {}, CBM {}/{} is not contiguous."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if not caps.cat_supported(): raise ValueError("Pool {}, CBM {}/{}, CAT is not supported."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if 'mba' in pool: if pool['mba'] > 100 or pool['mba'] <= 0: raise ValueError("Pool {}, MBA rate {} out of range! (1-100)."\ .format(pool['id'], pool['mba'])) if not caps.mba_supported(): raise ValueError("Pool {}, MBA rate {}, MBA is not supported."\ .format(pool['id'], pool['mba'])) # check power profile reference if 'power_profile' in pool: ConfigStore.get_power(data, pool['power_profile'])
def check_alloc_tech(pool_id, json_data): if 'cbm' in json_data: if not caps.cat_supported(): raise BadRequest("System does not support CAT!") if pool_id > common.PQOS_API.get_max_cos_id([common.CAT_CAP]): raise BadRequest("Pool {} does not support CAT".format(pool_id)) if 'mba' in json_data: if not caps.mba_supported(): raise BadRequest("System does not support MBA!") if pool_id > common.PQOS_API.get_max_cos_id([common.MBA_CAP]): raise BadRequest("Pool {} does not support MBA".format(pool_id))
def _validate_rdt(data): """ Validate RDT configuration (including MBA CTRL) configuration Parameters data: configuration (dict) """ if 'mba_ctrl' in data and data['mba_ctrl']['enabled']\ and (not 'rdt_iface' in data or data['rdt_iface']['interface'] != "os"): raise ValueError( "RDT Configuration. MBA CTRL requires RDT OS interface!") if not 'pools' in data: return mba_pool_ids = [] mba_bw_pool_ids = [] for pool in data['pools']: if 'cbm' in pool: result = re.search('1{1,32}0{1,32}1{1,32}', bin(pool['cbm'])) if result or pool['cbm'] == 0: raise ValueError("Pool {}, CBM {}/{} is not contiguous."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if not caps.cat_supported(): raise ValueError("Pool {}, CBM {}/{}, CAT is not supported."\ .format(pool['id'], hex(pool['cbm']), bin(pool['cbm']))) if 'mba' in pool: mba_pool_ids.append(pool['id']) if 'mba_bw' in pool: mba_bw_pool_ids.append(pool['id']) if mba_bw_pool_ids and mba_pool_ids: raise ValueError("It is not allowed to mix MBA (Pools: {}) "\ "and MBA BW (Pools {}), configurations."\ .format(mba_pool_ids, mba_bw_pool_ids)) if (mba_pool_ids or mba_bw_pool_ids) and not caps.mba_supported(): raise ValueError("Pools {}, MBA is not supported."\ .format(mba_pool_ids + mba_bw_pool_ids)) if mba_bw_pool_ids and not caps.mba_bw_enabled(): raise ValueError("Pools {}, MBA BW is not enabled/supported."\ .format(mba_bw_pool_ids)) return
def check_alloc_tech(pool_id, json_data): if 'cbm' in json_data: if not caps.cat_supported(): raise BadRequest("System does not support CAT!") if pool_id > common.PQOS_API.get_max_cos_id([common.CAT_CAP]): raise BadRequest( "Pool {} does not support CAT".format(pool_id)) if 'mba' in json_data or 'mba_bw' in json_data: if not caps.mba_supported(): raise BadRequest("System does not support MBA!") if pool_id > common.PQOS_API.get_max_cos_id([common.MBA_CAP]): raise BadRequest( "Pool {} does not support MBA".format(pool_id)) if 'mba_bw' in json_data and not caps.mba_bw_enabled(): raise BadRequest("MBA CTRL is not {}!"\ .format("enabled" if caps.mba_bw_supported() else "supported")) if 'mba' in json_data and caps.mba_bw_enabled(): raise BadRequest( "MBA RATE is disabled! Disable MBA CTRL and try again.")
def add_default_pool(data): """ Update config with "Default" pool """ # no Default pool configured default_pool = {} default_pool['id'] = 0 if caps.mba_supported(): default_pool['mba'] = 100 if caps.cat_supported(): default_pool['cbm'] = common.PQOS_API.get_max_l3_cat_cbm() default_pool['name'] = "Default" default_pool['cores'] = list(range(common.PQOS_API.get_num_cores())) for pool in data['pools']: default_pool['cores'] = \ [core for core in default_pool['cores'] if core not in pool['cores']] data['pools'].append(default_pool)