Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fcaa40a
api,server,ui: tagged resource limits
shwstppr Sep 22, 2023
bb4b1cf
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Dec 19, 2023
533be6e
add unit tests
shwstppr Dec 19, 2023
a1806bb
fix eof
shwstppr Dec 19, 2023
f423c5b
fix import
shwstppr Dec 19, 2023
596ac91
fix
shwstppr Dec 19, 2023
fa15616
build fix
shwstppr Dec 19, 2023
2f6df91
ui: fix templatetag required
shwstppr Dec 27, 2023
300e0be
api,server; allow template tag update
shwstppr Dec 27, 2023
06ef971
license
shwstppr Dec 27, 2023
28ce02f
eof
shwstppr Dec 27, 2023
9ebda78
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Jan 9, 2024
a52db17
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Jan 10, 2024
5cfe107
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Jan 22, 2024
e4538c8
show tagged capcity in ui
shwstppr Jan 25, 2024
87deba0
change for list for tag and type
shwstppr Jan 29, 2024
1037ef7
fix
shwstppr Jan 31, 2024
b7984ec
fix and refactor for clearing up of tagged limits and counts
shwstppr Feb 1, 2024
806ee61
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Feb 5, 2024
c4c6083
tests
shwstppr Feb 6, 2024
a04c253
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Feb 7, 2024
b0c0520
move schema changes to 4.20
shwstppr Feb 7, 2024
bfd2d32
build fix
shwstppr Feb 8, 2024
d504753
api,server: allow listing diskofferings with suitability for vm
shwstppr Feb 8, 2024
1dbce17
api,server: enable filtering service offerings with templateid
shwstppr Feb 8, 2024
8596354
api,server,ui: improve template tag functionality
shwstppr Feb 8, 2024
2dea392
fix
shwstppr Feb 8, 2024
6458311
fix failure
shwstppr Feb 8, 2024
06080f0
add test and a fix
shwstppr Feb 9, 2024
6ccb5b6
add tests
shwstppr Feb 9, 2024
72f0768
add license
shwstppr Feb 9, 2024
f4d9715
tests
shwstppr Feb 9, 2024
3a8dd5c
add tests
shwstppr Feb 11, 2024
ed927b5
api,server,ui: tagged resource limits
shwstppr Feb 8, 2024
67e6206
fix
shwstppr Feb 11, 2024
20a5555
test and fix
shwstppr Feb 11, 2024
a69798b
Merge branch 'serviceoffering-template-filtering' into add-resource-l…
shwstppr Feb 11, 2024
9762b8e
Merge branch 'listdiskofferings-vmsuitability' into add-resource-limi…
shwstppr Feb 11, 2024
ce37cab
Merge branch 'template-tag-enhancements' into add-resource-limit-tag
shwstppr Feb 11, 2024
e1d07cf
Merge branch 'feature-resource-limit-tag' into add-resource-limit-tag
shwstppr Feb 11, 2024
aab1df3
Merge branch 'main' into add-resource-limit-tag
shwstppr Feb 12, 2024
ef3d2fb
Merge branch 'main' into feature-resource-limit-tag
shwstppr Feb 12, 2024
9581f7a
more tests
shwstppr Feb 12, 2024
5fbf1d5
Merge branch 'feature-resource-limit-tag' into add-resource-limit-tag
shwstppr Feb 12, 2024
3c969a7
fix
shwstppr Feb 12, 2024
4474c87
address comments
shwstppr Feb 14, 2024
7a6442d
Merge remote-tracking branch 'shwstppr/feature-resource-limit-tag' in…
shwstppr Feb 14, 2024
5bab94f
address comment
shwstppr Feb 14, 2024
711d9cb
Merge remote-tracking branch 'apache/main' into add-resource-limit-tag
shwstppr Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// under the License.
package org.apache.cloudstack.api.command.user.template;

import org.apache.log4j.Logger;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
Expand All @@ -28,6 +26,7 @@
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.user.UserCmd;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.log4j.Logger;

import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
Expand All @@ -46,6 +45,9 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use
description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).")
private String templateType;

@Parameter(name = ApiConstants.TEMPLATE_TAG, type = CommandType.STRING, description = "the tag for this template.", since = "4.20.0")
private String templateTag;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -59,6 +61,10 @@ public String getTemplateType() {
return templateType;
}

public String getTemplateTag() {
return templateTag;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.apache.cloudstack.api.command.user.template;
Comment thread
shwstppr marked this conversation as resolved.

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import com.cloud.storage.Storage;

@RunWith(MockitoJUnitRunner.class)
public class UpdateTemplateCmdTest {

@Test
public void testGetTemplateType() {
UpdateTemplateCmd cmd = new UpdateTemplateCmd();
ReflectionTestUtils.setField(cmd, "templateType", null);
Assert.assertNull(cmd.getTemplateType());
String type = Storage.TemplateType.ROUTING.toString();
ReflectionTestUtils.setField(cmd, "templateTag", type);
Assert.assertEquals(type, cmd.getTemplateTag());
}

@Test
public void testGetTemplateTag() {
UpdateTemplateCmd cmd = new UpdateTemplateCmd();
ReflectionTestUtils.setField(cmd, "templateTag", null);
Assert.assertNull(cmd.getTemplateTag());
String tag = "ABC";
ReflectionTestUtils.setField(cmd, "templateTag", tag);
Assert.assertEquals(tag, cmd.getTemplateTag());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2137,13 +2137,15 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {

// update template type
TemplateType templateType = null;
String templateTag = null;
if (cmd instanceof UpdateTemplateCmd) {
boolean isAdmin = _accountMgr.isAdmin(account.getId());
templateType = validateTemplateType(cmd, isAdmin, template.isCrossZones());
if (cmd instanceof UpdateVnfTemplateCmd) {
VnfTemplateUtils.validateApiCommandParams(cmd, template);
vnfTemplateManager.updateVnfTemplate(template.getId(), (UpdateVnfTemplateCmd) cmd);
}
templateTag = ((UpdateTemplateCmd)cmd).getTemplateTag();
}

// update is needed if any of the fields below got filled by the user
Expand All @@ -2160,6 +2162,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
isDynamicallyScalable == null &&
isRoutingTemplate == null &&
templateType == null &&
templateTag == null &&
(! cleanupDetails && details == null) //update details in every case except this one
);
if (!updateNeeded) {
Expand Down Expand Up @@ -2245,6 +2248,9 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
} else if (templateType != null) {
template.setTemplateType(templateType);
}
if (templateTag != null) {
template.setTemplateTag(org.apache.commons.lang3.StringUtils.trimToNull(templateTag));
}

validateDetails(template, details);

Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/image/RegisterOrUploadTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
</a-select-option>
</a-select>
</a-form-item>
<a-form-item ref="templatetag" name="name" v-if="isAdminRole">
<a-form-item ref="templatetag" name="templatetag" v-if="isAdminRole">
<template #label>
<tooltip-label :title="$t('label.templatetag')" :tooltip="apiParams.templatetag.description"/>
</template>
Expand Down
14 changes: 14 additions & 0 deletions ui/src/views/image/UpdateTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
</a-select-option>
</a-select>
</a-form-item>
<a-form-item ref="templatetag" name="templatetag" v-if="isAdmin">
<template #label>
<tooltip-label :title="$t('label.templatetag')" :tooltip="apiParams.templatetag.description"/>
</template>
<a-input
v-model:value="form.templatetag"
:placeholder="apiParams.templatetag.description"
v-focus="currentForm !== 'Create'"/>
</a-form-item>

<div :span="24" class="action-button">
<a-button @click="closeAction">{{ $t('label.cancel') }}</a-button>
Expand Down Expand Up @@ -206,6 +215,7 @@ export default {
data () {
return {
templatetypes: ['BUILTIN', 'USER', 'SYSTEM', 'ROUTING', 'VNF'],
emptyAllowedFields: ['templatetag'],
rootDisk: {},
nicAdapterType: {},
keyboardType: {},
Expand Down Expand Up @@ -247,6 +257,7 @@ export default {
const resourceFields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable', 'userdataid', 'userdatapolicy']
if (this.isAdmin) {
resourceFields.push('templatetype')
resourceFields.push('templatetag')
}
for (var field of resourceFields) {
var fieldValue = this.resource[field]
Expand Down Expand Up @@ -286,6 +297,9 @@ export default {
this.fetchUserdataPolicy()
},
isValidValueForKey (obj, key) {
if (this.emptyAllowedFields.includes(key) && obj[key] === '') {
return true
}
return key in obj && obj[key] != null && obj[key] !== undefined && obj[key] !== ''
},
fetchOsTypes () {
Expand Down