Due to CloudStack's account based tenant model VMs cannot be listed by the user who created them. The aim of this small feature is to add a user_id column in the vm_instance table and expose listing based on user ID.
The VMInstanceVO class was modified to accept userId parameter. The userId for systemvm is the system user, for others the userId is the calling user's ID. In case the calling user's account ID is not same as the owner ID (for example an admin launching VMs for a user), the userId is set to the first available user in the owner account. For example:
long userId = CallContext.current().getCallingUserId();
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
}
The listVM API now accepts a new "userid" parameter which if passed will return list of VMs searching for that particular userID.