4444import com .cloud .agent .api .CreatePrivateTemplateFromVolumeCommand ;
4545import com .cloud .agent .api .GetVmStatsAnswer ;
4646import com .cloud .agent .api .GetVmStatsCommand ;
47- import com .cloud .agent .api .RebootAnswer ;
48- import com .cloud .agent .api .RebootCommand ;
4947import com .cloud .agent .api .SnapshotCommand ;
5048import com .cloud .agent .api .StopAnswer ;
5149import com .cloud .agent .api .StopCommand ;
8583import com .cloud .dc .DataCenterVO ;
8684import com .cloud .dc .HostPodVO ;
8785import com .cloud .dc .dao .AccountVlanMapDao ;
86+ import com .cloud .dc .dao .ClusterDao ;
8887import com .cloud .dc .dao .DataCenterDao ;
8988import com .cloud .dc .dao .HostPodDao ;
9089import com .cloud .dc .dao .VlanDao ;
@@ -237,6 +236,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
237236 @ Inject AccountService _accountService ;
238237 @ Inject AsyncJobManager _asyncMgr ;
239238 @ Inject VlanDao _vlanDao ;
239+ @ Inject ClusterDao _clusterDao ;
240240 @ Inject AccountVlanMapDao _accountVlanMapDao ;
241241 @ Inject StoragePoolDao _storagePoolDao ;
242242 @ Inject VMTemplateHostDao _vmTemplateHostDao ;
@@ -281,7 +281,7 @@ public List<? extends UserVm> getVirtualMachines(long hostId) {
281281 }
282282
283283 @ Override
284- public UserVm resetVMPassword (ResetVMPasswordCmd cmd , String password ){
284+ public UserVm resetVMPassword (ResetVMPasswordCmd cmd , String password ) throws ResourceUnavailableException , InsufficientCapacityException {
285285 Account account = UserContext .current ().getCaller ();
286286 Long userId = UserContext .current ().getCallerUserId ();
287287 Long vmId = cmd .getId ();
@@ -313,7 +313,8 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password){
313313 return userVm ;
314314 }
315315
316- private boolean resetVMPasswordInternal (ResetVMPasswordCmd cmd , String password ) {
316+ private boolean resetVMPasswordInternal (ResetVMPasswordCmd cmd , String password ) throws ResourceUnavailableException , InsufficientCapacityException {
317+
317318 return true ;
318319// Long vmId = cmd.getId();
319320// Long userId = UserContext.current().getCallerUserId();
@@ -331,7 +332,7 @@ private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd, String password)
331332// }
332333// if (_routerMgr.savePasswordToRouter(vmInstance.getDomainRouterId(), vmInstance.getPrivateIpAddress(), password)) {
333334// // Need to reboot the virtual machine so that the password gets redownloaded from the DomR, and reset on the VM
334- // if (! rebootVirtualMachine(userId, vmId)) {
335+ // if (rebootVirtualMachine(userId, vmId) == null ) {
335336// if (vmInstance.getState() == State.Stopped) {
336337// return true;
337338// }
@@ -785,25 +786,21 @@ public boolean attachISOToVM(long vmId, long isoId, boolean attach) {
785786 }
786787
787788
788- private boolean rebootVirtualMachine (long userId , long vmId ) {
789+ private UserVm rebootVirtualMachine (long userId , long vmId ) throws InsufficientCapacityException , ResourceUnavailableException {
789790 UserVmVO vm = _vmDao .findById (vmId );
791+ User caller = _accountMgr .getActiveUser (userId );
792+ Account owner = _accountMgr .getAccount (vm .getAccountId ());
790793
791794 if (vm == null || vm .getState () == State .Destroyed || vm .getState () == State .Expunging || vm .getRemoved () != null ) {
792- return false ;
795+ s_logger .warn ("Vm id=" + vmId + " doesn't exist" );
796+ return null ;
793797 }
794798
795799 if (vm .getState () == State .Running && vm .getHostId () != null ) {
796- RebootCommand cmd = new RebootCommand (vm .getInstanceName ());
797- RebootAnswer answer = (RebootAnswer )_agentMgr .easySend (vm .getHostId (), cmd );
798-
799- if (answer != null ) {
800- return true ;
801- } else {
802- return false ;
803- }
800+ return _itMgr .reboot (vm , null , caller , owner );
804801 } else {
805802 s_logger .error ("Vm id=" + vmId + " is not in Running state, failed to reboot" );
806- return false ;
803+ return null ;
807804 }
808805 }
809806 @ Override
@@ -1142,9 +1139,17 @@ public UserVm startUserVm(long vmId) throws ConcurrentOperationException, Execut
11421139 public boolean expunge (UserVmVO vm , long callerUserId , Account caller ) {
11431140 try {
11441141
1145- //Cleanup LB/PF rules before expunging the vm
1146- long vmId = vm .getId ();
1147- //cleanup port forwarding rules
1142+ if (!_itMgr .advanceExpunge (vm , _accountMgr .getSystemUser (), caller )) {
1143+ s_logger .info ("Did not expunge " + vm );
1144+ return false ;
1145+ }
1146+
1147+ _networkGroupMgr .removeInstanceFromGroups (vm .getId ());
1148+ removeInstanceFromGroup (vm .getId ());
1149+
1150+ //Cleanup LB/PF rules before expunging the vm
1151+ long vmId = vm .getId ();
1152+ //cleanup port forwarding rules
11481153 if (_rulesMgr .revokePortForwardingRule (vmId )) {
11491154 s_logger .debug ("Port forwarding rules are removed successfully as a part of vm id=" + vmId + " expunge" );
11501155 } else {
@@ -1157,16 +1162,7 @@ public boolean expunge(UserVmVO vm, long callerUserId, Account caller) {
11571162 } else {
11581163 s_logger .warn ("Fail to remove lb rules as a part of vm id=" + vmId + " expunge" );
11591164 }
1160-
1161-
1162- if (!_itMgr .advanceExpunge (vm , _accountMgr .getSystemUser (), caller )) {
1163- s_logger .info ("Did not expunge " + vm );
1164- return false ;
1165- }
1166-
1167- _networkGroupMgr .removeInstanceFromGroups (vm .getId ());
1168- removeInstanceFromGroup (vm .getId ());
1169-
1165+
11701166 _itMgr .remove (vm , _accountMgr .getSystemUser (), caller );
11711167 return true ;
11721168 } catch (ResourceUnavailableException e ) {
@@ -1622,7 +1618,7 @@ public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, Con
16221618 }
16231619
16241620 @ Override
1625- public UserVm rebootVirtualMachine (RebootVMCmd cmd ) {
1621+ public UserVm rebootVirtualMachine (RebootVMCmd cmd ) throws InsufficientCapacityException , ResourceUnavailableException {
16261622 Account account = UserContext .current ().getCaller ();
16271623 Long userId = UserContext .current ().getCallerUserId ();
16281624 Long vmId = cmd .getId ();
@@ -1635,14 +1631,7 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) {
16351631
16361632 userId = accountAndUserValidation (vmId , account , userId , vmInstance );
16371633
1638- boolean status = rebootVirtualMachine (userId , vmId );
1639-
1640- if (status ) {
1641- return _vmDao .findById (vmId );
1642- } else {
1643- s_logger .warn ("Failed to reboot vm with id: " + vmId );
1644- return null ;
1645- }
1634+ return rebootVirtualMachine (userId , vmId );
16461635 }
16471636
16481637 @ Override
0 commit comments