Search in sources :

Example 6 with BaseImage

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");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with BaseImage

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;
}
Also used : GoogleBaseImage(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage)

Example 8 with 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();
}
Also used : BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 9 with BaseImage

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();
}
Also used : BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 10 with BaseImage

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);
}
Also used : BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)

Aggregations

BaseImage (com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage)6 BakeryDefaults (com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)3 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)2 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)2 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)2 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)2 Path (java.nio.file.Path)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 GoogleBaseImage (com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage)1 OpenstackBaseImage (com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackBaseImage)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ArrayList (java.util.ArrayList)1