mirror of https://github.com/apache/cloudstack.git
api: userdata api access (#242)
* api: userdata api access Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add smoke test Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * address review comment Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
6161046ab1
commit
14e96552ba
|
|
@ -16,25 +16,27 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.userdata;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserData;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
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.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserData;
|
||||
|
||||
|
||||
@APICommand(name = "deleteUserData", description = "Deletes a userdata", responseObject = SuccessResponse.class, entityType = {UserData.class},
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18")
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18",
|
||||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class DeleteUserDataCmd extends BaseCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteUserDataCmd.class.getName());
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@
|
|||
|
||||
package org.apache.cloudstack.api.command.user.userdata;
|
||||
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserData;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
|
|
@ -33,8 +30,14 @@ import org.apache.cloudstack.api.response.TemplateResponse;
|
|||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserData;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@APICommand(name = "linkUserDataToTemplate", description = "Link or unlink a userdata to a template.", responseObject = TemplateResponse.class, responseView = ResponseObject.ResponseView.Restricted,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0")
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0",
|
||||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class LinkUserDataToTemplateCmd extends BaseCmd implements AdminCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(LinkUserDataToTemplateCmd.class.getName());
|
||||
|
||||
|
|
|
|||
|
|
@ -19,20 +19,21 @@ package org.apache.cloudstack.api.command.user.userdata;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.user.UserData;
|
||||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.UserData;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listUserData", description = "List registered userdatas", responseObject = UserDataResponse.class, entityType = {UserData.class},
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18")
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18",
|
||||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class ListUserDataCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListUserDataCmd.class.getName());
|
||||
private static final String s_name = "listuserdataresponse";
|
||||
|
|
|
|||
|
|
@ -16,14 +16,11 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.userdata;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.user.UserData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
|
|
@ -37,16 +34,22 @@ import org.apache.cloudstack.context.CallContext;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.user.UserData;
|
||||
|
||||
@APICommand(name = "registerUserData",
|
||||
description = "Register a new userdata.",
|
||||
since = "4.18",
|
||||
responseObject = SuccessResponse.class,
|
||||
requestHasSensitiveInfo = false,
|
||||
responseHasSensitiveInfo = false)
|
||||
responseHasSensitiveInfo = false,
|
||||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class RegisterUserDataCmd extends BaseCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(RegisterUserDataCmd.class.getName());
|
||||
|
|
|
|||
|
|
@ -763,4 +763,68 @@ class TestRegisteredUserdata(cloudstackTestCase):
|
|||
templateid=self.template.id
|
||||
)
|
||||
|
||||
@attr(tags=['advanced', 'simulator', 'basic', 'sg', 'testnow'], required_hardware=True)
|
||||
def test_user_userdata_crud(self):
|
||||
"""Test following operations as a normal user:
|
||||
1. Register userdata
|
||||
2. List userdata
|
||||
3. Link userdata to a template, unlink
|
||||
4. Delete userdata.
|
||||
"""
|
||||
self.user = self.account.user[0]
|
||||
self.userapiclient = self.testClient.getUserApiClient(
|
||||
self.user.username,
|
||||
self.domain.name)
|
||||
|
||||
self.userdata = UserData.register(
|
||||
self.userapiclient,
|
||||
name="UserdataName",
|
||||
userdata="VGVzdFVzZXJEYXRh",
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.cleanup.append(self.userdata)
|
||||
|
||||
list_userdata = UserData.list(self.apiclient, id=self.userdata.userdata.id, listall=True)
|
||||
self.assertNotEqual(
|
||||
len(list_userdata),
|
||||
0,
|
||||
"List userdata was empty"
|
||||
)
|
||||
userdata = list_userdata[0]
|
||||
self.assertEqual(
|
||||
userdata.id,
|
||||
self.userdata.userdata.id,
|
||||
"userdata ids do not match"
|
||||
)
|
||||
|
||||
self.template = Template.linkUserDataToTemplate(
|
||||
self.apiclient,
|
||||
templateid=self.template.id,
|
||||
userdataid=self.userdata.userdata.id
|
||||
)
|
||||
self.assertEqual(
|
||||
self.userdata.userdata.id,
|
||||
self.template.userdataid,
|
||||
"Match userdata id in template response"
|
||||
)
|
||||
self.assertEqual(
|
||||
self.template.userdatapolicy,
|
||||
"ALLOWOVERRIDE",
|
||||
"Match default userdata override policy in template response"
|
||||
)
|
||||
self.template = Template.linkUserDataToTemplate(
|
||||
self.apiclient,
|
||||
templateid=self.template.id
|
||||
)
|
||||
self.assertEqual(
|
||||
self.template.userdataid,
|
||||
None,
|
||||
"Check userdata id in template response is None"
|
||||
)
|
||||
|
||||
UserData.delete(
|
||||
self.userapiclient,
|
||||
id=self.userdata.userdata.id
|
||||
)
|
||||
self.cleanup.remove(self.userdata)
|
||||
|
|
|
|||
Loading…
Reference in New Issue