Skip to content

Commit 82f6761

Browse files
committed
add resource_id and is_external properties
1 parent c058f39 commit 82f6761

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

cloudify/context.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
# * See the License for the specific language governing permissions and
1414
# * limitations under the License.
1515

16-
import errno
1716
import os
17+
import errno
1818
import warnings
1919
from contextlib import contextmanager
2020

21-
from cloudify_rest_client.exceptions import CloudifyClientError
22-
from cloudify.endpoint import ManagerEndpoint, LocalEndpoint
23-
from cloudify.logs import init_cloudify_logger
21+
from cloudify import utils
2422
from cloudify import constants
2523
from cloudify import exceptions
26-
from cloudify import utils
24+
from cloudify.logs import init_cloudify_logger
25+
from cloudify.endpoint import ManagerEndpoint, LocalEndpoint
26+
from cloudify_rest_client.exceptions import CloudifyClientError
2727
from cloudify.constants import DEPLOYMENT, NODE_INSTANCE, RELATIONSHIP_INSTANCE
2828

2929

@@ -424,6 +424,16 @@ def number_of_instances(self):
424424
self._get_node_if_needed()
425425
return self._node.number_of_instances
426426

427+
@property
428+
def is_external(self) -> bool:
429+
"""If this is a resource that Cloudify manages or not"""
430+
return self._properties.get('use_external_resource', False)
431+
432+
@property
433+
def resource_id(self):
434+
"""The resource's ID outside of Cloudify"""
435+
return self._properties.get('resource_id')
436+
427437

428438
class NodeInstanceContext(EntityContext):
429439
def __init__(self, *args, **kwargs):

cloudify/tests/test_context.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def setUp(self):
5454
os.environ[constants.LOCAL_RESOURCES_ROOT_ENV_KEY] = '/tmp/resources'
5555
self.context = context.CloudifyContext({
5656
'blueprint_id': '',
57-
'tenant': {'name': 'default_tenant'}
57+
'tenant': {'name': 'default_tenant'},
58+
'properties': {
59+
'use_external_resource': False,
60+
'resource_id': 'foo'
61+
}
5862
})
5963
# the context logger will try to publish messages to rabbit, which is
6064
# not available here. instead, we redirect the output to stdout.
@@ -318,6 +322,20 @@ def test_source_target_not_in_relationship(self):
318322
'relationship-instance context but used in a '
319323
'deployment context.', str(cm.exception))
320324

325+
def test_node_ctx_properties(self):
326+
ctx_node = context.NodeContext(
327+
{
328+
'node': {
329+
'properties': {
330+
'use_external_resource': False,
331+
'resource_id': 'foo'
332+
}
333+
}
334+
}
335+
)
336+
self.assertFalse(ctx_node.is_external)
337+
self.assertEqual(ctx_node.resource_id, 'foo')
338+
321339
def test_ctx_type(self):
322340
ctx = context.CloudifyContext({})
323341
self.assertEqual(constants.DEPLOYMENT, ctx.type)

0 commit comments

Comments
 (0)