本文整理匯總了Python中revizor2.api.Farm.add_role方法的典型用法代碼示例。如果您正苦於以下問題:Python Farm.add_role方法的具體用法?Python Farm.add_role怎麽用?Python Farm.add_role使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類revizor2.api.Farm
的用法示例。
在下文中一共展示了Farm.add_role方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_role_to_farm
# 需要導入模塊: from revizor2.api import Farm [as 別名]
# 或者: from revizor2.api.Farm import add_role [as 別名]
def add_role_to_farm(context: dict,
farm: Farm,
behavior: str = None,
dist: str = None,
role: Role = None,
role_name: str = None,
role_options: tp.List[str] = None,
alias: str = None) -> FarmRole:
behavior = (behavior or CONF.feature.behavior).strip()
role_name = (role_name or '').strip()
if role:
role_id = role.id #FIXME: Use Role object below
else:
role_id = CONF.feature.role_id or context.get(f'{role_name}_id', None)
if role_options:
LOG.debug(f'Additional role options: {role_options}')
if role_id:
if not isinstance(role_id, int) and not role_id.isdigit():
raise AssertionError('Role environment variable can\'t be only in digit format')
LOG.info(f'Get role by id: {role_id}')
role = IMPL.role.get(role_id)
else:
role = get_role_by_behavior(behavior, dist=dist)
if not role:
raise NotFound('Role with id or by mask "%s" not found in Scalr' % (
role_id or behavior))
# world.wrt(etree.Element('meta', name='role', value=role['name']))
# world.wrt(etree.Element('meta', name='dist', value=role['dist']))
previously_added_roles = [r.id for r in farm.roles]
alias = alias or role['name']
LOG.info(f'Add role {role["id"]} with alias {alias} to farm')
role_params = setup_farmrole_params(
context,
farm,
role_options=role_options,
alias=alias,
behaviors=behavior)
farm.add_role(role['id'], options=role_params.to_json())
time.sleep(5)
farm.roles.reload()
added_role = [r for r in farm.roles if r.id not in previously_added_roles]
if not added_role:
raise AssertionError(f'Added role "{role["name"]}" not found in farm')
LOG.debug(f'Save role object with name {added_role[0].alias}')
context[f'{added_role[0].alias}_role'] = added_role[0]
context[f'role_params_{added_role[0].id}'] = role_params
return added_role[0] #TODO: Scalr return addedFarmRoleIds