diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-16 10:56:08 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-16 10:56:08 -0700 |
commit | 5597e947248ee7fbda17d3876206f1d45f97bc00 (patch) | |
tree | 05f455f7626acc9baeb52934411530316245b597 /cloudinit/handlers/cloud_config.py | |
parent | 1e6455899af5532314d7244bbc660a0e34a84eff (diff) | |
download | vyos-cloud-init-5597e947248ee7fbda17d3876206f1d45f97bc00.tar.gz vyos-cloud-init-5597e947248ee7fbda17d3876206f1d45f97bc00.zip |
Make the top level __init__ similar to the other top level __inits__ where just util functions and base classes are defined there.
Diffstat (limited to 'cloudinit/handlers/cloud_config.py')
-rw-r--r-- | cloudinit/handlers/cloud_config.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/cloudinit/handlers/cloud_config.py b/cloudinit/handlers/cloud_config.py index 12d1bd96..f6d95244 100644 --- a/cloudinit/handlers/cloud_config.py +++ b/cloudinit/handlers/cloud_config.py @@ -20,8 +20,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from cloudinit import handlers from cloudinit import log as logging -from cloudinit import user_data as ud from cloudinit import util from cloudinit.settings import (PER_ALWAYS) @@ -29,28 +29,34 @@ from cloudinit.settings import (PER_ALWAYS) LOG = logging.getLogger(__name__) -class CloudConfigPartHandler(ud.PartHandler): +class CloudConfigPartHandler(handlers.Handler): def __init__(self, paths, **_kwargs): - ud.PartHandler.__init__(self, PER_ALWAYS) + handlers.Handler.__init__(self, PER_ALWAYS) self.cloud_buf = [] self.cloud_fn = paths.get_ipath("cloud_config") def list_types(self): return [ - ud.type_from_starts_with("#cloud-config"), + handlers.type_from_starts_with("#cloud-config"), ] + def _write_cloud_config(self, buf): + if not self.cloud_fn: + return + lines = [str(b) for b in buf] + payload = "\n".join(lines) + util.write_file(self.cloud_fn, payload, 0600) + def _handle_part(self, _data, ctype, filename, payload, _frequency): - if ctype == ud.CONTENT_START: + if ctype == handlers.CONTENT_START: self.cloud_buf = [] return - - if ctype == ud.CONTENT_END: - payload = "\n".join(self.cloud_buf) - util.write_file(self.cloud_fn, payload, 0600) + if ctype == handlers.CONTENT_END: + self._write_cloud_config(self.cloud_buf) self.cloud_buf = [] return filename = util.clean_filename(filename) - entry = "\n".join(["#%s" % (filename), str(payload)]) - self.cloud_buf.append(entry) + if not filename: + filename = '??' + self.cloud_buf.extend(["#%s" % (filename), str(payload)]) |