|
12 | 12 | import urlparse
|
13 | 13 |
|
14 | 14 | import requests
|
15 |
| - |
| 15 | +from cloudify.exceptions import NonRecoverableError |
16 | 16 |
|
17 | 17 | PUPPET_CONF_TPL = """# This file was generated by Cloudify
|
18 | 18 | [main]
|
@@ -76,28 +76,41 @@ class PuppetParamsError(PuppetError):
|
76 | 76 |
|
77 | 77 |
|
78 | 78 | def _context_to_struct(ctx):
|
79 |
| - ret = { |
| 79 | + return { |
80 | 80 | 'node_id': ctx.node_id,
|
81 | 81 | 'node_name': ctx.node_name,
|
82 | 82 | 'blueprint_id': ctx.blueprint_id,
|
83 | 83 | 'deployment_id': ctx.deployment_id,
|
84 | 84 | 'properties': ctx.properties,
|
85 | 85 | 'runtime_properties': ctx.runtime_properties,
|
86 |
| - 'capabilities': {}, |
| 86 | + 'capabilities': _try_extract_capabilities(ctx), |
| 87 | + 'host_ip': _try_extract_host_ip(ctx) |
87 | 88 | }
|
88 |
| - if hasattr(ctx, 'capabilities'): |
89 |
| - ret['capabilities'] = ctx.capabilities.get_all() |
90 |
| - return ret |
91 | 89 |
|
92 | 90 |
|
93 | 91 | def _related_to_struct(related):
|
94 | 92 | return {
|
95 | 93 | 'node_id': related.node_id,
|
96 | 94 | 'properties': related.properties,
|
97 |
| - 'runtime_properties': related.runtime_properties |
| 95 | + 'runtime_properties': related.runtime_properties, |
| 96 | + 'host_ip': _try_extract_host_ip(related) |
98 | 97 | }
|
99 | 98 |
|
100 | 99 |
|
| 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 | + |
101 | 114 | class PuppetManager(object):
|
102 | 115 |
|
103 | 116 | # Copy+paste from Chef plugin - start
|
|
0 commit comments