Skip to content

Commit

Permalink
add resource_id and is_external properties
Browse files Browse the repository at this point in the history
add resource_id and is_external properties

ok
  • Loading branch information
EarthmanT committed Feb 1, 2023
1 parent e690b2c commit 47a9cf7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
25 changes: 19 additions & 6 deletions cloudify/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
26 changes: 25 additions & 1 deletion cloudify/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Binary file not shown.
Empty file added dev-requirements.txt
Empty file.

0 comments on commit 47a9cf7

Please sign in to comment.