6060import com .cloud .dc .dao .DataCenterDao ;
6161import com .cloud .exception .InsufficientCapacityException ;
6262import com .cloud .exception .InvalidParameterValueException ;
63+ import com .cloud .exception .PermissionDeniedException ;
6364import com .cloud .host .Host ;
6465import com .cloud .host .HostVO ;
6566import com .cloud .host .Status ;
@@ -143,6 +144,10 @@ public VmIngestionManagerImpl() {
143144
144145 @ Override
145146 public ListResponse <UnmanagedInstanceResponse > listUnmanagedInstances (ListUnmanagedInstancesCmd cmd ) {
147+ final Account caller = CallContext .current ().getCallingAccount ();
148+ if (caller .getType () != Account .ACCOUNT_TYPE_ADMIN ) {
149+ throw new PermissionDeniedException (String .format ("Cannot perform this operation, Calling account is not root admin: %s" , caller .getUuid ()));
150+ }
146151 final Long clusterId = cmd .getClusterId ();
147152 if (clusterId == null ) {
148153 throw new InvalidParameterValueException (String .format ("Cluster ID cannot be null!" ));
@@ -236,6 +241,10 @@ public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmana
236241
237242 @ Override
238243 public UserVmResponse importUnmanagedInstance (ImportUnmanageInstanceCmd cmd ) {
244+ final Account caller = CallContext .current ().getCallingAccount ();
245+ if (caller .getType () != Account .ACCOUNT_TYPE_ADMIN ) {
246+ throw new PermissionDeniedException (String .format ("Cannot perform this operation, Calling account is not root admin: %s" , caller .getUuid ()));
247+ }
239248 final Long clusterId = cmd .getClusterId ();
240249 if (clusterId == null ) {
241250 throw new InvalidParameterValueException (String .format ("Cluster ID cannot be null!" ));
@@ -252,7 +261,6 @@ public UserVmResponse importUnmanagedInstance(ImportUnmanageInstanceCmd cmd) {
252261 if (Strings .isNullOrEmpty (instanceName )) {
253262 throw new InvalidParameterValueException (String .format ("Instance name cannot be empty!" ));
254263 }
255- final Account caller = CallContext .current ().getCallingAccount ();
256264 final Account owner = accountService .getActiveAccountById (cmd .getEntityOwnerId ());
257265
258266 Long userId = null ;
0 commit comments