Ejemplo n.º 1
0
    def get_capability(capability_path):
        shared_dep_id, element_id = capability_path[0], capability_path[1]

        deployment = storage_manager.get(Deployment, shared_dep_id)
        capability = deployment.capabilities.get(element_id)

        if not capability:
            raise FunctionsEvaluationError(
                'Requested capability `{0}` is not declared '
                'in deployment `{1}`'.format(element_id, shared_dep_id))

        # We need to evaluate any potential intrinsic functions in the
        # capability's value in the context of the *shared* deployment,
        # instead of the current deployment, so we manually call the function
        capability = evaluate_intrinsic_functions(payload=capability,
                                                  deployment_id=shared_dep_id)

        # If it's a nested property of the capability
        if len(capability_path) > 2:
            try:
                capability = \
                    functions.get_nested_attribute_value_of_capability(
                        capability['value'],
                        capability_path)
            except parser_exceptions.FunctionEvaluationError as e:
                raise FunctionsEvaluationError(str(e))

        return capability['value']
    def get_capability(capability_path):
        shared_dep_id, element_id = capability_path[0], capability_path[1]

        deployment = storage_manager.get(Deployment, shared_dep_id)
        capability = deployment.capabilities.get(element_id)

        if not capability:
            raise FunctionsEvaluationError(
                'Requested capability `{0}` is not declared '
                'in deployment `{1}`'.format(
                    element_id, shared_dep_id
                )
            )

        # We need to evaluate any potential intrinsic functions in the
        # capability's value in the context of the *shared* deployment,
        # instead of the current deployment, so we manually call the function
        capability = evaluate_intrinsic_functions(
            payload=capability,
            deployment_id=shared_dep_id
        )

        # If it's a nested property of the capability
        if len(capability_path) > 2:
            try:
                capability = \
                    functions.get_nested_attribute_value_of_capability(
                        capability['value'],
                        capability_path)
            except parser_exceptions.FunctionEvaluationError as e:
                raise FunctionsEvaluationError(str(e))

        return capability['value']
def get_capability(target_dep_id, capability, path, rest_client):
    """ Get a capability for deployment.
    :param target_dep_id: target deployment to get capability for.
    :type target_dep_id: str
    :param capability: capability name to get.
    :type capability: str
    :param path: a list of index -path- inside the capability.
    :type path: list
    :param rest_client: A Cloudify REST client.
    :type rest_client: cloudify_rest_client.client.CloudifyClient
    :return: The capability property value.
    :rtype: Any JSON serializable type.
    """
    deployment = {}
    try:
        deployment = rest_client.deployments.get(target_dep_id)
    except CloudifyClientError as e:
        if '404' in str(e):
            raise NonRecoverableError(
                'deployment [{0}] not found'.format(target_dep_id))
    root = deployment.capabilities.get(capability).get('value')
    if path:
        nested_val = get_nested_attribute_value_of_capability(root, path)
        return nested_val.get('value')
    return root
Ejemplo n.º 4
0
 def _get_capability_by_path(self, value, path):
     if len(path) <= 2:
         return value
     try:
         return functions.get_nested_attribute_value_of_capability(
             value, path)['value']
     except parser_exceptions.FunctionEvaluationError as e:
         raise FunctionsEvaluationError(str(e))