Skip to content

Commit 3f48c59

Browse files
committed
Merge pull request cloudify-cosmo#4 from cloudify-cosmo/feature/CFY-900-containing-host-ip
Containing host ip
2 parents 55f068e + 20b0550 commit 3f48c59

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

puppet_plugin/manager.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import urlparse
1313

1414
import requests
15-
15+
from cloudify.exceptions import NonRecoverableError
1616

1717
PUPPET_CONF_TPL = """# This file was generated by Cloudify
1818
[main]
@@ -76,28 +76,41 @@ class PuppetParamsError(PuppetError):
7676

7777

7878
def _context_to_struct(ctx):
79-
ret = {
79+
return {
8080
'node_id': ctx.node_id,
8181
'node_name': ctx.node_name,
8282
'blueprint_id': ctx.blueprint_id,
8383
'deployment_id': ctx.deployment_id,
8484
'properties': ctx.properties,
8585
'runtime_properties': ctx.runtime_properties,
86-
'capabilities': {},
86+
'capabilities': _try_extract_capabilities(ctx),
87+
'host_ip': _try_extract_host_ip(ctx)
8788
}
88-
if hasattr(ctx, 'capabilities'):
89-
ret['capabilities'] = ctx.capabilities.get_all()
90-
return ret
9189

9290

9391
def _related_to_struct(related):
9492
return {
9593
'node_id': related.node_id,
9694
'properties': related.properties,
97-
'runtime_properties': related.runtime_properties
95+
'runtime_properties': related.runtime_properties,
96+
'host_ip': _try_extract_host_ip(related)
9897
}
9998

10099

100+
def _try_extract_capabilities(ctx):
101+
try:
102+
return ctx.capabilities.get_all()
103+
except AttributeError:
104+
return {}
105+
106+
107+
def _try_extract_host_ip(ctx_or_related):
108+
try:
109+
return ctx_or_related.host_ip
110+
except NonRecoverableError:
111+
return None
112+
113+
101114
class PuppetManager(object):
102115

103116
# Copy+paste from Chef plugin - start

0 commit comments

Comments
 (0)