From 23ca4b577a3319c8fbbb8d473bf342c009d46a9b Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Fri, 7 Feb 2014 03:37:57 +0200 Subject: [PATCH] Adds support for additional Heat configurations Saves all parts with content type "text/x-cfninitdata" in the directory defined in the "heat_config_dir" option. --- .../plugins/windows/userdataplugins/heat.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cloudbaseinit/plugins/windows/userdataplugins/heat.py b/cloudbaseinit/plugins/windows/userdataplugins/heat.py index a20720b9..394ff7d1 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/heat.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/heat.py @@ -13,10 +13,21 @@ # License for the specific language governing permissions and limitations # under the License. +import os + +from cloudbaseinit.openstack.common import cfg from cloudbaseinit.openstack.common import log as logging from cloudbaseinit.plugins.windows.userdataplugins import base from cloudbaseinit.plugins.windows import userdatautils +opts = [ + cfg.StrOpt('heat_config_dir', default='C:\\cfn', help='The directory ' + 'where the Heat configuration files must be saved'), +] + +CONF = cfg.CONF +CONF.register_opts(opts) + LOG = logging.getLogger(__name__) @@ -26,8 +37,16 @@ class HeatPlugin(base.BaseUserDataPlugin): def __init__(self): super(HeatPlugin, self).__init__("text/x-cfninitdata") + def _check_heat_config_dir(self): + if not os.path.exists(CONF.heat_config_dir): + os.makedirs(CONF.heat_config_dir) + def process(self, part): + self._check_heat_config_dir() + + file_name = os.path.join(CONF.heat_config_dir, part.get_filename()) + with open(file_name, 'wb') as f: + f.write(part.get_payload()) + if part.get_filename() == self._heat_user_data_filename: return userdatautils.execute_user_data_script(part.get_payload()) - else: - LOG.info("Heat content not supported: %s" % part.get_filename())