use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.
the class BakeryController method addBaseImage.
@RequestMapping(value = "/defaults/baseImage/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBaseImage) {
BaseImage baseImage = objectMapper.convertValue(rawBaseImage, Providers.translateBaseImageType(providerName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> baseImage.stageLocalFiles(configPath));
builder.setSeverity(severity);
// TODO(lwander): Would be good to indicate when an added base image id conflicts with an existing base image id.
builder.setUpdate(() -> bakeryService.addBaseImage(deploymentName, providerName, baseImage));
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> bakeryService.validateBaseImage(deploymentName, providerName, baseImage.getBaseImage().getId());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Add " + baseImage.getNodeName() + " base image");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.
the class GoogleAddBaseImageCommand method buildBaseImage.
@Override
protected BaseImage buildBaseImage(String baseImageId) {
GoogleBaseImage baseImage = new GoogleBaseImage();
GoogleBaseImage.GoogleImageSettings imageSettings = new GoogleBaseImage.GoogleImageSettings();
imageSettings.setImageFamily(isImageFamily);
baseImage.setBaseImage(imageSettings);
GoogleBaseImage.GoogleVirtualizationSettings virtualizationSettings = new GoogleBaseImage.GoogleVirtualizationSettings();
virtualizationSettings.setSourceImage(sourceImage);
virtualizationSettings.setSourceImageFamily(sourceImageFamily);
baseImage.setVirtualizationSettings(virtualizationSettings);
return baseImage;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.
the class AbstractAddBaseImageCommand method executeThis.
@Override
protected void executeThis() {
String baseImageId = getBaseImageId();
BaseImage baseImage = buildBaseImage(baseImageId);
BaseImage.ImageSettings imageSettings = baseImage.getBaseImage();
if (imageSettings == null) {
throw new RuntimeException("Provider " + getProviderName() + " must provide image settings when building a base image. This is a bug with this provider's implementation of halyard.");
}
imageSettings.setId(getBaseImageId());
imageSettings.setShortDescription(shortDescription);
imageSettings.setDetailedDescription(detailedDescription);
imageSettings.setPackageType(packageType);
imageSettings.setTemplateFile(templateFile);
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
new OperationHandler<Void>().setSuccessMessage("Successfully added base image " + baseImageId + " to " + providerName + "'s bakery.").setFailureMesssage("Failed to add base image " + baseImageId + " to " + providerName + "'s bakery.").setOperation(Daemon.addBaseImage(currentDeployment, providerName, !noValidate, baseImage)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.
the class AbstractEditBaseImageCommand method executeThis.
@Override
protected void executeThis() {
String baseImageId = getBaseImageId();
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
BaseImage baseImage = new OperationHandler<BaseImage>().setFailureMesssage("Failed to get base image " + baseImageId + " in" + providerName + "'s bakery.").setOperation(Daemon.getBaseImage(currentDeployment, providerName, baseImageId, false)).get();
int originalHash = baseImage.hashCode();
BaseImage.ImageSettings imageSettings = baseImage.getBaseImage();
if (imageSettings == null) {
throw new RuntimeException("Image settings cannot be deleted during an edit. This is a bug in the " + getProviderName() + " provider's implementation of halyard.");
}
imageSettings.setId(isSet(id) ? id : imageSettings.getId());
imageSettings.setShortDescription(isSet(shortDescription) ? shortDescription : imageSettings.getShortDescription());
imageSettings.setDetailedDescription(isSet(detailedDescription) ? detailedDescription : imageSettings.getDetailedDescription());
imageSettings.setPackageType(isSet(packageType) ? packageType : imageSettings.getPackageType());
imageSettings.setTemplateFile(isSet(templateFile) ? templateFile : imageSettings.getTemplateFile());
baseImage = editBaseImage((T) baseImage);
if (originalHash == baseImage.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setFailureMesssage("Failed to edit base image " + baseImageId + " in" + providerName + "'s bakery.").setSuccessMessage("Successfully edited base image " + baseImageId + " in" + providerName + "'s bakery.").setOperation(Daemon.setBaseImage(currentDeployment, providerName, baseImageId, !noValidate, baseImage)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.
the class BakeryService method addBaseImage.
public void addBaseImage(String deploymentName, String bakeryDefaultsName, BaseImage newBaseImage) {
BakeryDefaults bakeryDefaults = getBakeryDefaults(deploymentName, bakeryDefaultsName);
bakeryDefaults.getBaseImages().add(newBaseImage);
}
Aggregations