public void shutdown() {
log.info("shutdown: " + this);
}
public ControlResults invoke(String name, Configuration parameters) {
ControlResults controlResults = new ControlResults();
try {
if (name.equals("getCobblerDistros")) {
String searchRegex = parameters.getSimpleValue("searchRegex", null);
Pattern pattern = null;
if (searchRegex != null) {
pattern = Pattern.compile(searchRegex);
}
Configuration results = controlResults.getComplexResults();
PropertyList list = new PropertyList("distros");
results.put(list);
Collection<Distro> distros = getAllCobblerDistros().values();
for (Distro d : distros) {
if (pattern == null || pattern.matcher(d.getName()).matches()) {
PropertyMap map = new PropertyMap("distro");
map.put(new PropertySimple("name", d.getName()));
map.put(new PropertySimple("breed", d.getBreed()));
map.put(new PropertySimple("osversion", d.getOsVersion()));
map.put(new PropertySimple("arch", d.getArch()));
map.put(new PropertySimple("initrd", d.getInitrd()));
map.put(new PropertySimple("kernel", d.getKernel()));
list.add(map);
}
}
} else if (name.equals("getCobblerProfiles")) {
String searchRegex = parameters.getSimpleValue("searchRegex", null);
Pattern pattern = null;
if (searchRegex != null) {
pattern = Pattern.compile(searchRegex);
}
Configuration results = controlResults.getComplexResults();
PropertyList list = new PropertyList("profiles");
results.put(list);
List<Profile> profiles = getAllCobblerProfiles();
for (Profile p : profiles) {
if (pattern == null || pattern.matcher(p.getName()).matches()) {
PropertyMap map = new PropertyMap("profile");
map.put(new PropertySimple("name", p.getName()));
map.put(new PropertySimple("distro", p.getDistro()));
map.put(new PropertySimple("kickstart", p.getKickstart()));
list.add(map);
}
}
} else if (name.equals("removeCobblerDistros")) {
String searchRegex = parameters.getSimpleValue("searchRegex", null);
Pattern pattern = null;
if (searchRegex != null) {
pattern = Pattern.compile(searchRegex);
}
if (!this.syncInProgress) {
Collection<Distro> distros = getAllCobblerDistros().values();
for (Distro d : distros) {
if (pattern == null || pattern.matcher(d.getName()).matches()) {
if (d.getComment().startsWith(COMMENT_MARKER)) {
d.remove();
}
}
}
} else {
controlResults.setError("A synchronize is currently in progress - please wait for it to finish");
}
} else {
controlResults.setError("Unknown operation name: " + name);
}
} catch (Exception e) {
controlResults.setError(e);
}
return controlResults;
}