@Override public void handle(EnvironmentEvent event) { if (event.type == KickstartEvent.KICKSTART_REQUESTED) { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("hostname", event.getHost().getHostname()); vars.put("ksip", storage.getIp()); vars.put("ksmount", storage.getMountPoint()); vars.put("configmgt-repos", configMgt.getKickstartYumRepos()); vars.put("configmgt-packages", configMgt.getKickstartPackages()); vars.put("configmgt-post", configMgt.getKickstartPost()); Template template = new VelocityTemplate(); String output = template.encode("templates/clients/kickstart.tmpl", vars); File kickstartFile = new File(baseDir + File.separator + event.getHost().getHostname() + ".ks"); try { FileUtils.writeStringToFile(kickstartFile, output); } catch (IOException e) { // TODO add exception text EnvironmentEvent done = new EnvironmentEvent.Builder(KickstartEvent.KICKSTART_WRITE_FAILED, event.environment) .build(); publisher.publish(done); return; } // TODO consider adding to version control. But this may be wasted // if users Cobbler or maybe OpenStack, so that would require an // integration EnvironmentEvent done = new EnvironmentEvent.Builder(KickstartEvent.KICKSTART_WRITTEN, event.environment).build(); publisher.publish(done); } }
public static KickstartTemplateService factory( EventPublisher publisher, Environment environment, String baseDir, Storage storage, ConfigurationManagement cm) { KickstartTemplateService service = new KickstartTemplateService(publisher, baseDir, storage, cm); EnvironmentEvent event = new EnvironmentEvent.Builder(KickstartEvent.KICKSTART_REQUESTED, environment).build(); publisher.addSubscriber(service, event); return service; }