|
| 1 | +import os |
| 2 | + |
| 3 | +import cloudify_common_sdk.iso9660 as iso9660 |
| 4 | +from cloudify.decorators import operation |
| 5 | + |
| 6 | + |
| 7 | +def _get_parameters(properties, kwargs): |
| 8 | + for k, v in properties.items(): |
| 9 | + if k not in kwargs: |
| 10 | + kwargs[k] = v |
| 11 | + |
| 12 | + return kwargs |
| 13 | + |
| 14 | + |
| 15 | +@operation(resumable=True) |
| 16 | +def modify_iso(ctx, **kwargs): |
| 17 | + parameters = _get_parameters(ctx.node.properties, kwargs) |
| 18 | + log = 'ISO: {0} will be created based on {1} with new directories:' \ |
| 19 | + '\n{2}\nand new files:\n{3}' |
| 20 | + output_iso_path = parameters.get('output_iso_path') |
| 21 | + iso_path = parameters.get('iso_path') |
| 22 | + new_directories = parameters.get('new_directories') |
| 23 | + new_files = parameters.get('new_files') |
| 24 | + output_iso_path = output_iso_path if output_iso_path else\ |
| 25 | + '{0}.modified'.format(iso_path) |
| 26 | + ctx.logger.info(log.format( |
| 27 | + output_iso_path, iso_path, new_directories, new_files) |
| 28 | + ) |
| 29 | + |
| 30 | + iso9660.modify_iso( |
| 31 | + iso_path=iso_path, |
| 32 | + output_iso_path=output_iso_path, |
| 33 | + new_directories=new_directories, |
| 34 | + new_files=new_files |
| 35 | + ) |
| 36 | + ctx.instance.runtime_properties['modified_iso_path'] = output_iso_path |
| 37 | + |
| 38 | + |
| 39 | +@operation(resumable=True) |
| 40 | +def delete_iso(ctx): |
| 41 | + file_path = ctx.instance.runtime_properties.get('modified_iso_path') |
| 42 | + os.remove(file_path) |
| 43 | + ctx.logger.info('{0} removed'.format(file_path)) |
0 commit comments