Search in sources :

Example 1 with BaseImage

use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.

the class BakeryController method setBaseImage.

@RequestMapping(value = "/defaults/baseImage/{baseImageId:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @PathVariable String baseImageId, @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.setUpdate(() -> bakeryService.setBaseImage(deploymentName, providerName, baseImageId, baseImage));
    builder.setSeverity(severity);
    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, "Edit " + baseImageId + " 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 2 with BaseImage

use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.

the class BakeryService method getAllBaseImages.

public List<BaseImage> getAllBaseImages(String deploymentName, String providerName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setProvider(providerName).setBakeryDefaults().withAnyBaseImage();
    List<BaseImage> matchingBaseImages = lookupService.getMatchingNodesOfType(filter, BaseImage.class);
    if (matchingBaseImages.size() == 0) {
        throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No base images could be found").build());
    } else {
        return matchingBaseImages;
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 3 with BaseImage

use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.

the class BakeryService method deleteBaseImage.

public void deleteBaseImage(String deploymentName, String bakeryDefaultsName, String baseImageId) {
    BakeryDefaults bakeryDefaults = getBakeryDefaults(deploymentName, bakeryDefaultsName);
    boolean removed = bakeryDefaults.getBaseImages().removeIf(baseImage -> ((BaseImage) baseImage).getBaseImage().getId().equals(baseImageId));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "BaseImage \"" + baseImageId + "\" wasn't found").build());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)

Example 4 with BaseImage

use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.

the class AbstractListBaseImagesCommand method executeThis.

@Override
protected void executeThis() {
    String providerName = getProviderName();
    String currentDeployment = getCurrentDeployment();
    BakeryDefaults bakeryDefaults = new OperationHandler<BakeryDefaults>().setFailureMesssage("Failed to get bakery defaults for " + providerName + "'s bakery.").setOperation(Daemon.getBakeryDefaults(currentDeployment, providerName, !noValidate)).get();
    List<BaseImage> baseImages = bakeryDefaults.getBaseImages();
    if (baseImages.isEmpty()) {
        AnsiUi.success("No configured base images for " + getProviderName() + ".");
    } else {
        AnsiUi.success("Base images for " + getProviderName() + ":");
        baseImages.forEach(baseImage -> AnsiUi.listItem(baseImage.getBaseImage().getId()));
    }
}
Also used : BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults) BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage)

Example 5 with BaseImage

use of com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage in project halyard by spinnaker.

the class OpenstackAddBaseImageCommand method buildBaseImage.

@Override
protected BaseImage buildBaseImage(String baseImageId) {
    OpenstackBaseImage baseImage = new OpenstackBaseImage();
    OpenstackBaseImage.OpenstackImageSettings imageSettings = new OpenstackBaseImage.OpenstackImageSettings();
    baseImage.setBaseImage(imageSettings);
    // TODO(edwinavalos) Support multiple virtualization settings
    List<OpenstackBaseImage.OpenstackVirtualizationSettings> vsList = new ArrayList<>();
    OpenstackBaseImage.OpenstackVirtualizationSettings virtualizationSettings = new OpenstackBaseImage.OpenstackVirtualizationSettings();
    virtualizationSettings.setSourceImageId(sourceImageId);
    virtualizationSettings.setRegion(region);
    virtualizationSettings.setInstanceType(instanceType);
    virtualizationSettings.setSshUserName(sshUserName);
    vsList.add(virtualizationSettings);
    baseImage.setVirtualizationSettings(vsList);
    return baseImage;
}
Also used : ArrayList(java.util.ArrayList) OpenstackBaseImage(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackBaseImage)

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