Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
Systemvm template api#45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
584ae3fb9630bf6d589961936846956c841fdbcdd5521bb7370ea63265dce087ed5dd20f9aa3bb49c9849b9cdf5f671671390af0a85844499b1c4736cb5bb9e7861746775bc9bf2a7b69aa349d628bf7f3b7caeaa2f10adffb9e9a97ef4d3c769819c164a964a01d456c9bec974b4e51028bfb69af3ed80b7bf735576d47a02b6915e867c8409be2c4505d8d0ed7d4901de58a56fa6e5ad705aca5b8d96829acb7ee78a9bb955f08d04551b3f1bcae8b3950c00e5ba3e5b4ae9681b759499c0d9a643c0e22a1a90753c2bfc9912b76ad6baf2a9fc861dd3f1d4b4ffa1e4f32564a586bcaf510367fa49b562cd45a1b6e5520ed43f4db5cff5559a38ac706e3bd02e3924a29de4eaf03039133d046c69a96c6b95c1d22f341051f5e47af02f117736881066601b423f33909d04fcea0ec25df90fed8532b9c8c1130File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.admin.storage; | ||
| import java.util.HashSet; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.SeedSystemVMTemplateResponse; | ||
| import org.apache.cloudstack.api.response.ZoneResponse; | ||
| import com.cloud.user.Account; | ||
| @APICommand(name = "seedSystemVMTemplate", description = "Copies a system vm template into secondary storage", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have two separate APIs for the same thing? Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we? | ||
| responseObject = ZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.13", | ||
| authorized = {RoleType.Admin}) | ||
| public class SeedSystemVMTemplateCmd extends BaseCmd { | ||
| private static final String s_name = "seedsystemvmtemplateresponse"; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better use a name without response, use it in the annotation parameter APICommand.name and construct the commandsname with s_name (NAME is a better name) .toLower() + "response". | ||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the zone") | ||
| private Long zoneId; | ||
| @Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "The template download url") | ||
| private String url; | ||
| @Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, required = true, description = "The Hypervisor to register this template for") | ||
| private String hypervisor; | ||
| @Parameter(name = ApiConstants.FILE_UUID, type = CommandType.STRING, description = "File uuid.") | ||
| private String fileUUID; | ||
| @Parameter(name = ApiConstants.LOCAL_FILE, type = CommandType.BOOLEAN, required = true, description = "Local file or url") | ||
| private Boolean localFile; | ||
| @Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.STRING, required = true, description = "The id of a specific template") | ||
| private String templateId; | ||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| public Long getZoneId() { | ||
| return zoneId; | ||
| } | ||
| public void setZoneId(Long zoneId) { | ||
| this.zoneId = zoneId; | ||
| } | ||
| public String getUrl() { | ||
| return url; | ||
| } | ||
| public void setUrl(String url) { | ||
| this.url = url; | ||
| } | ||
| public String getHypervisor() { | ||
| return hypervisor; | ||
| } | ||
| public void setHypervisor(String hypervisor) { | ||
| this.hypervisor = hypervisor; | ||
| } | ||
| public String getFileUUID() { | ||
| return fileUUID; | ||
| } | ||
| public void setFileUUID(String fileUUID) { | ||
| this.fileUUID = fileUUID; | ||
| } | ||
| public Boolean getLocalFile() { | ||
| return localFile; | ||
| } | ||
| public void setLocalFile(Boolean localFile) { | ||
| this.localFile = localFile; | ||
| } | ||
| public String getTemplateId() { | ||
| return templateId; | ||
| } | ||
| public void setTemplateId(String templateId) { | ||
| this.templateId = templateId; | ||
| } | ||
| ///////////////////////////////////////////////////// | ||
| /////////////// API Implementation/////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @Override | ||
| public String getCommandName() { | ||
| return s_name; | ||
| } | ||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| @Override | ||
| public void execute(){ | ||
| // we need to get secondary storage for this zone. | ||
| HashSet<String> imageStores = _queryService.searchForImageStores(this); | ||
| _templateService.seedSystemVMTemplate(imageStores, this); | ||
| SeedSystemVMTemplateResponse response = new SeedSystemVMTemplateResponse(); | ||
| response.setResult("Done"); | ||
| response.setResponseName(getCommandName()); | ||
| response.setObjectName(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.admin.template; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiArgValidator; | ||
| import org.apache.cloudstack.api.ApiCommandJobType; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.ActivateSystemVMTemplateResponse; | ||
| import org.apache.cloudstack.api.response.TemplateResponse; | ||
| import org.apache.log4j.Logger; | ||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.template.VirtualMachineTemplate; | ||
| import com.cloud.user.Account; | ||
| @APICommand(name = ActivateSystemVMTemplateCmd.APINAME, | ||
| description = "Activates an existing system virtual machine template to be used by CloudStack to create system virtual machines.", | ||
| responseObject = ActivateSystemVMTemplateResponse.class, | ||
| authorized = {RoleType.Admin}) | ||
| public class ActivateSystemVMTemplateCmd extends BaseCmd { | ||
Comment on lines
+40
to
+44
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there (a plan for) a deactive. Deleting templates is not trivial as these may be used still but still we want to make sure we can in the long run. | ||
| public static final Logger LOGGER = Logger.getLogger(ActivateSystemVMTemplateCmd.class.getName()); | ||
| public static final String APINAME = "activateSystemVMTemplate"; | ||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @Parameter(name = ApiConstants.ID, | ||
| type = CommandType.UUID, | ||
| entityType = TemplateResponse.class, | ||
| validations = {ApiArgValidator.PositiveNumber}, | ||
| description = "The template ID of the System VM Template to activate.") | ||
| private Long id; | ||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Implementation ////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| VirtualMachineTemplate template = _templateService.activateSystemVMTemplate(id); | ||
| if (template != null) { | ||
| ActivateSystemVMTemplateResponse response = new ActivateSystemVMTemplateResponse(); | ||
| response.setResult("success"); | ||
| response.setObjectName(getCommandName()); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } else { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate template."); | ||
| } | ||
| } | ||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; | ||
| } | ||
| public ApiCommandJobType getInstanceType() { | ||
| return ApiCommandJobType.Template; | ||
| } | ||
| @Override | ||
| public long getEntityOwnerId() { | ||
| VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, id); | ||
| if (template != null) { | ||
| return template.getAccountId(); | ||
| } | ||
| // bad id given, parent this command to SYSTEM so ERROR events are tracked | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we're adding new template filters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "system" filter is used to get the system template id for seeding.
The "inactive" filter is used to list all inactive system vm templates. The list is used on the front end to list other system vm templates that are not currently used. We needed this view because the "all" filter doesn't show inactive system vm templates.