-
Notifications
You must be signed in to change notification settings - Fork 1.3k
api/server: support deploy-as-is template as VNF template #12499
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
base: 4.20
Are you sure you want to change the base?
Changes from all commits
d64089d
3337808
74e3b55
fb012c8
0bfc65a
9889064
ed56c59
469df6b
4d9c382
976b969
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| // under the License. | ||
| package org.apache.cloudstack.storage.template; | ||
|
|
||
| import com.cloud.agent.api.to.deployasis.OVFNetworkTO; | ||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.network.VNF; | ||
| import com.cloud.storage.Storage; | ||
|
|
@@ -124,6 +125,9 @@ public static void validateVnfNics(List<VNF.VnfNic> nicsList) { | |
| public static void validateApiCommandParams(BaseCmd cmd, VirtualMachineTemplate template) { | ||
| if (cmd instanceof RegisterVnfTemplateCmd) { | ||
| RegisterVnfTemplateCmd registerCmd = (RegisterVnfTemplateCmd) cmd; | ||
| if (registerCmd.isDeployAsIs() && CollectionUtils.isNotEmpty(registerCmd.getVnfNics())) { | ||
| throw new InvalidParameterValueException("VNF nics cannot be specified when register a deploy-as-is Template. Please wait until Template settings are read from OVA."); | ||
| } | ||
| validateApiCommandParams(registerCmd.getVnfDetails(), registerCmd.getVnfNics(), registerCmd.getTemplateType()); | ||
| } else if (cmd instanceof UpdateVnfTemplateCmd) { | ||
| UpdateVnfTemplateCmd updateCmd = (UpdateVnfTemplateCmd) cmd; | ||
|
|
@@ -149,4 +153,18 @@ public static void validateVnfCidrList(List<String> cidrList) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| public static void validateDeployAsIsTemplateVnfNics(List<OVFNetworkTO> ovfNetworks, List<VNF.VnfNic> vnfNics) { | ||
| if (CollectionUtils.isEmpty(vnfNics)) { | ||
| return; | ||
| } | ||
| if (CollectionUtils.isEmpty(ovfNetworks)) { | ||
| throw new InvalidParameterValueException("The list of networks read from OVA is empty. Please wait until the template is fully downloaded and processed."); | ||
| } | ||
| for (VNF.VnfNic vnfNic : vnfNics) { | ||
| if (vnfNic.getDeviceId() < ovfNetworks.size() && !vnfNic.isRequired()) { | ||
| throw new InvalidParameterValueException(String.format("The VNF nic [device ID: %s ] is required as it is defined in the OVA template.", vnfNic.getDeviceId())); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+157
to
+169
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,7 @@ | |
| import com.cloud.agent.api.to.DiskTO; | ||
| import com.cloud.agent.api.to.NfsTO; | ||
| import com.cloud.agent.api.to.VirtualMachineTO; | ||
| import com.cloud.agent.api.to.deployasis.OVFNetworkTO; | ||
| import com.cloud.api.ApiDBUtils; | ||
| import com.cloud.api.query.dao.UserVmJoinDao; | ||
| import com.cloud.api.query.vo.UserVmJoinVO; | ||
|
|
@@ -131,6 +132,7 @@ | |
| import com.cloud.dc.DataCenterVO; | ||
| import com.cloud.dc.dao.DataCenterDao; | ||
| import com.cloud.deploy.DeployDestination; | ||
| import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao; | ||
| import com.cloud.domain.Domain; | ||
| import com.cloud.domain.dao.DomainDao; | ||
| import com.cloud.event.ActionEvent; | ||
|
|
@@ -313,6 +315,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, | |
| protected SnapshotHelper snapshotHelper; | ||
| @Inject | ||
| VnfTemplateManager vnfTemplateManager; | ||
| @Inject | ||
| TemplateDeployAsIsDetailsDao templateDeployAsIsDetailsDao; | ||
|
|
||
| @Inject | ||
| private SecondaryStorageHeuristicDao secondaryStorageHeuristicDao; | ||
|
|
@@ -2172,6 +2176,11 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) { | |
| templateType = validateTemplateType(cmd, isAdmin, template.isCrossZones()); | ||
| if (cmd instanceof UpdateVnfTemplateCmd) { | ||
| VnfTemplateUtils.validateApiCommandParams(cmd, template); | ||
| UpdateVnfTemplateCmd updateCmd = (UpdateVnfTemplateCmd) cmd; | ||
| if (template.isDeployAsIs() && CollectionUtils.isNotEmpty(updateCmd.getVnfNics())) { | ||
|
Contributor
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 is this parameter allowed on update but not on VM creation? (https://github.com/apache/cloudstack/pull/12499/files#diff-f5ab861d900497f6f7c83d03a840a7994f407c2dd52c237a4b560aaf9e75c202R128)
Member
Author
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. @nvazquez |
||
| List<OVFNetworkTO> ovfNetworks = templateDeployAsIsDetailsDao.listNetworkRequirementsByTemplateId(template.getId()); | ||
| VnfTemplateUtils.validateDeployAsIsTemplateVnfNics(ovfNetworks, updateCmd.getVnfNics()); | ||
| } | ||
| vnfTemplateManager.updateVnfTemplate(template.getId(), (UpdateVnfTemplateCmd) cmd); | ||
| } | ||
| templateTag = ((UpdateTemplateCmd)cmd).getTemplateTag(); | ||
|
|
||
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 validation logic has a flaw. It checks if
vnfNic.getDeviceId() < ovfNetworks.size() && !vnfNic.isRequired(), which throws an error if the vnfNic is NOT required. This is backwards - the error message says "The VNF nic [device ID: %s ] is required" but the condition checks!vnfNic.isRequired(). The logic should be: if the device ID corresponds to an OVF network, the VNF nic MUST be required. So the condition should be checking if it's defined in OVF but marked as not required in the VNF configuration.