Skip to content

Commit e12a7e9

Browse files
committed
server: fix network access for addNicToVirtualMachine API
New NICs shouldn't added to VM with network from admin account, same as deployment. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent f286f01 commit e12a7e9

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
8282
import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
8383
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
84-
import com.cloud.agent.api.to.deployasis.OVFNetworkTO;
8584
import org.apache.cloudstack.backup.Backup;
8685
import org.apache.cloudstack.backup.BackupManager;
8786
import org.apache.cloudstack.backup.dao.BackupDao;
@@ -145,6 +144,7 @@
145144
import com.cloud.agent.api.to.DiskTO;
146145
import com.cloud.agent.api.to.NicTO;
147146
import com.cloud.agent.api.to.VirtualMachineTO;
147+
import com.cloud.agent.api.to.deployasis.OVFNetworkTO;
148148
import com.cloud.agent.api.to.deployasis.OVFPropertyTO;
149149
import com.cloud.agent.manager.Commands;
150150
import com.cloud.alert.AlertManager;
@@ -1310,12 +1310,8 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV
13101310
throw new InvalidParameterValueException("unable to find a network with id " + networkId);
13111311
}
13121312

1313-
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
1314-
if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain)
1315-
&& !(network.getAclType() == ACLType.Account && network.getAccountId() == vmInstance.getAccountId())) {
1316-
throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vmId: " + vmId);
1317-
}
1318-
}
1313+
Account vmOwner = _accountMgr.getAccount(vmInstance.getAccountId());
1314+
_networkModel.checkNetworkPermissions(vmOwner, network);
13191315

13201316
List<NicVO> allNics = _nicDao.listByVmId(vmInstance.getId());
13211317
for (NicVO nic : allNics) {

0 commit comments

Comments
 (0)