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.
This commit is contained in:
Alessandro Pilotti 2014-02-07 03:37:57 +02:00
parent 8ba9cbdaee
commit 23ca4b577a

View File

@ -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())