| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
import fnmatch |
| 14 |
import logging |
| 15 |
|
| 16 |
from heatclient._i18n import _ |
| 17 |
from heatclient import exc |
| 18 |
|
| 19 |
logger = logging.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
def clear_hook(hc, stack_id, resource_name, hook_type): |
| 23 |
try: |
| 24 |
hc.resources.signal( |
| 25 |
stack_id=stack_id, |
| 26 |
resource_name=resource_name, |
| 27 |
data={'unset_hook': hook_type}) |
| 28 |
except exc.HTTPNotFound: |
| 29 |
logger.error( |
| 30 |
"Stack %(stack)s or resource %(resource)s " |
| 31 |
"not found for hook %(hook_type)s", |
| 32 |
{'resource': resource_name, 'stack': stack_id, |
| 33 |
'hook_type': hook_type}) |
| 34 |
|
| 35 |
|
| 36 |
def clear_wildcard_hooks(hc, stack_id, stack_patterns, hook_type, |
| 37 |
resource_pattern): |
| 38 |
if stack_patterns: |
| 39 |
for resource in hc.resources.list(stack_id): |
| 40 |
res_name = resource.resource_name |
| 41 |
if fnmatch.fnmatchcase(res_name, stack_patterns[0]): |
| 42 |
nested_stack = hc.resources.get( |
| 43 |
stack_id=stack_id, |
| 44 |
resource_name=res_name) |
| 45 |
clear_wildcard_hooks( |
| 46 |
hc, |
| 47 |
nested_stack.physical_resource_id, |
| 48 |
stack_patterns[1:], hook_type, resource_pattern) |
| 49 |
else: |
| 50 |
for resource in hc.resources.list(stack_id): |
| 51 |
res_name = resource.resource_name |
| 52 |
if fnmatch.fnmatchcase(res_name, resource_pattern): |
| 53 |
clear_hook(hc, stack_id, res_name, hook_type) |
| 54 |
|
| 55 |
|
| 56 |
def get_hook_type_via_status(hc, stack_id): |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
try: |
| 61 |
stack = hc.stacks.get(stack_id=stack_id) |
| 62 |
except exc.HTTPNotFound: |
| 63 |
raise exc.CommandError(_('Stack not found: %s') % stack_id) |
| 64 |
else: |
| 65 |
if 'IN_PROGRESS' not in stack.stack_status: |
| 66 |
raise exc.CommandError(_('Stack status %s not IN_PROGRESS') % |
| 67 |
stack.stack_status) |
| 68 |
|
| 69 |
if 'CREATE' in stack.stack_status: |
| 70 |
hook_type = 'pre-create' |
| 71 |
elif 'UPDATE' in stack.stack_status: |
| 72 |
hook_type = 'pre-update' |
| 73 |
elif 'DELETE' in stack.stack_status: |
| 74 |
hook_type = 'pre-delete' |
| 75 |
else: |
| 76 |
raise exc.CommandError(_('Unexpected stack status %s, ' |
| 77 |
'only create, update and delete supported') |
| 78 |
% stack.stack_status) |
| 79 |
return hook_type |