diff --git a/cloudify/context.py b/cloudify/context.py index 8a6769f20..9ce8d6974 100644 --- a/cloudify/context.py +++ b/cloudify/context.py @@ -13,17 +13,17 @@ # * See the License for the specific language governing permissions and # * limitations under the License. -import errno import os +import errno import warnings from contextlib import contextmanager -from cloudify_rest_client.exceptions import CloudifyClientError -from cloudify.endpoint import ManagerEndpoint, LocalEndpoint -from cloudify.logs import init_cloudify_logger +from cloudify import utils from cloudify import constants from cloudify import exceptions -from cloudify import utils +from cloudify.logs import init_cloudify_logger +from cloudify.endpoint import ManagerEndpoint, LocalEndpoint +from cloudify_rest_client.exceptions import CloudifyClientError from cloudify.constants import DEPLOYMENT, NODE_INSTANCE, RELATIONSHIP_INSTANCE @@ -404,7 +404,10 @@ def properties(self): These properties are the properties specified in the blueprint. """ self._get_node_if_needed() - return self._node.properties + try: + return self._node.properties + except AttributeError: + return self._node.get('properties') @property def type(self): @@ -424,6 +427,16 @@ def number_of_instances(self): self._get_node_if_needed() return self._node.number_of_instances + @property + def is_external(self) -> bool: + """If this is a resource that Cloudify manages or not""" + return self.properties.get('use_external_resource', False) + + @property + def resource_id(self): + """The resource's ID outside of Cloudify""" + return self.properties.get('resource_id') + class NodeInstanceContext(EntityContext): def __init__(self, *args, **kwargs): diff --git a/cloudify/tests/test_context.py b/cloudify/tests/test_context.py index ff42f7936..670d8e6b5 100644 --- a/cloudify/tests/test_context.py +++ b/cloudify/tests/test_context.py @@ -54,7 +54,11 @@ def setUp(self): os.environ[constants.LOCAL_RESOURCES_ROOT_ENV_KEY] = '/tmp/resources' self.context = context.CloudifyContext({ 'blueprint_id': '', - 'tenant': {'name': 'default_tenant'} + 'tenant': {'name': 'default_tenant'}, + 'properties': { + 'use_external_resource': False, + 'resource_id': 'foo' + } }) # the context logger will try to publish messages to rabbit, which is # not available here. instead, we redirect the output to stdout. @@ -318,6 +322,26 @@ def test_source_target_not_in_relationship(self): 'relationship-instance context but used in a ' 'deployment context.', str(cm.exception)) + def test_node_ctx_properties(self): + + def get_node_mock(*_, **__): + return { + 'properties': { + 'use_external_resource': False, + 'resource_id': 'foo' + } + } + + endpoint = Mock() + endpoint.get_node = get_node_mock + kwargs = { + 'endpoint': endpoint, + 'context': {'node_id': 'node_id'}, + } + ctx_node = context.NodeContext(**kwargs) + self.assertFalse(ctx_node.is_external) + self.assertEqual(ctx_node.resource_id, 'foo') + def test_ctx_type(self): ctx = context.CloudifyContext({}) self.assertEqual(constants.DEPLOYMENT, ctx.type) diff --git a/cloudify_common-6.4.0-centos-Core-py36-none-linux_aarch64.wgn b/cloudify_common-6.4.0-centos-Core-py36-none-linux_aarch64.wgn new file mode 100644 index 000000000..0b14e0810 Binary files /dev/null and b/cloudify_common-6.4.0-centos-Core-py36-none-linux_aarch64.wgn differ diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 000000000..e69de29bb