Skip to content

Commit 2580edb

Browse files
committed
CLOUDSTACK-7908: UserVmResponse returns userid/username information of the creator
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 2b7073c commit 2580edb

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

api/src/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
5252
@Param(description = "the account associated with the virtual machine")
5353
private String accountName;
5454

55+
@SerializedName(ApiConstants.USER_ID)
56+
@Param(description = "the user's ID who deployed the virtual machine")
57+
private String userId;
58+
59+
@SerializedName(ApiConstants.USERNAME)
60+
@Param(description = "the user's name who deployed the virtual machine")
61+
private String userName;
62+
5563
@SerializedName(ApiConstants.PROJECT_ID)
5664
@Param(description = "the project id of the vm")
5765
private String projectId;
@@ -315,6 +323,14 @@ public String getAccountName() {
315323
return accountName;
316324
}
317325

326+
public String getUserId() {
327+
return userId;
328+
}
329+
330+
public String getUserName() {
331+
return userName;
332+
}
333+
318334
public String getProjectId() {
319335
return projectId;
320336
}
@@ -535,6 +551,14 @@ public void setAccountName(String accountName) {
535551
this.accountName = accountName;
536552
}
537553

554+
public void setUserId(String userId) {
555+
this.userId = userId;
556+
}
557+
558+
public void setUserName(String userName) {
559+
this.userName = userName;
560+
}
561+
538562
@Override
539563
public void setDomainId(String domainId) {
540564
this.domainId = domainId;

server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import com.cloud.service.ServiceOfferingDetailsVO;
4949
import com.cloud.user.Account;
5050
import com.cloud.user.AccountManager;
51+
import com.cloud.user.User;
52+
import com.cloud.user.dao.UserDao;
5153
import com.cloud.uservm.UserVm;
5254
import com.cloud.utils.db.GenericDaoBase;
5355
import com.cloud.utils.db.SearchBuilder;
@@ -70,6 +72,8 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
7072
public AccountManager _accountMgr;
7173
@Inject
7274
private UserVmDetailsDao _userVmDetailsDao;
75+
@Inject
76+
private UserDao _userDao;
7377

7478
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
7579
private final SearchBuilder<UserVmJoinVO> activeVmByIsoSearch;
@@ -121,6 +125,11 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
121125
userVmResponse.setAccountName(userVm.getAccountName());
122126
}
123127

128+
User user = _userDao.getUser(userVm.getUserId());
129+
if (user != null) {
130+
userVmResponse.setUserId(user.getUuid());
131+
userVmResponse.setUserName(user.getUsername());
132+
}
124133
userVmResponse.setDomainId(userVm.getDomainUuid());
125134
userVmResponse.setDomainName(userVm.getDomainName());
126135

0 commit comments

Comments
 (0)