@@ -1362,7 +1362,7 @@ public boolean attachIso(long isoId, long vmId, Boolean... extraParams) {
13621362 throw new InvalidParameterValueException ("Cannot attach VMware tools drivers to incompatible hypervisor " + vm .getHypervisorType ());
13631363 }
13641364 if (!isVirtualRouter ) {
1365- enforceCdromAttachLimits ((UserVm ) vm , isoId );
1365+ enforceCdromAttachLimits (vmId , (UserVm ) vm , isoId );
13661366 }
13671367 boolean result = attachISOToVM (vmId , userId , isoId , true , forced , isVirtualRouter );
13681368 if (result ) {
@@ -1449,51 +1449,51 @@ boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach, boolea
14491449 UserVmVO vm = _userVmDao .findById (vmId );
14501450 VMTemplateVO iso = _tmpltDao .findById (isoId );
14511451
1452- int targetSlot = attach ? chooseAttachSlot (vm ) : findAttachedSlot (vm , isoId );
1452+ int targetSlot = attach ? chooseAttachSlot (vmId , vm ) : findAttachedSlot (vmId , vm , isoId );
14531453 boolean success = attachISOToVM (vmId , isoId , targetSlot , attach , forced , isVirtualRouter );
14541454 if (!success || isVirtualRouter ) {
14551455 return success ;
14561456 }
14571457 if (attach ) {
1458- persistIsoAttachment (vm , iso , targetSlot );
1458+ persistIsoAttachment (vmId , vm , iso , targetSlot );
14591459 } else {
1460- persistIsoDetachment (vm , isoId , targetSlot );
1460+ persistIsoDetachment (vmId , vm , isoId , targetSlot );
14611461 }
14621462 return success ;
14631463 }
14641464
1465- private int chooseAttachSlot (UserVmVO vm ) {
1465+ private int chooseAttachSlot (long vmId , UserVmVO vm ) {
14661466 if (vm .getIsoId () == null ) {
14671467 return CDROM_PRIMARY_DEVICE_SEQ ;
14681468 }
1469- VmIsoMapVO highest = highestCdromMapEntry (vm . getId () );
1469+ VmIsoMapVO highest = highestCdromMapEntry (vmId );
14701470 return highest == null ? CDROM_PRIMARY_DEVICE_SEQ + 1 : highest .getDeviceSeq () + 1 ;
14711471 }
14721472
1473- private int findAttachedSlot (UserVmVO vm , long isoId ) {
1473+ private int findAttachedSlot (long vmId , UserVmVO vm , long isoId ) {
14741474 if (vm .getIsoId () != null && vm .getIsoId () == isoId ) {
14751475 return CDROM_PRIMARY_DEVICE_SEQ ;
14761476 }
1477- VmIsoMapVO entry = _vmIsoMapDao .findByVmIdIsoId (vm . getId () , isoId );
1477+ VmIsoMapVO entry = _vmIsoMapDao .findByVmIdIsoId (vmId , isoId );
14781478 return entry != null ? entry .getDeviceSeq () : CDROM_PRIMARY_DEVICE_SEQ ;
14791479 }
14801480
1481- private void persistIsoAttachment (UserVmVO vm , VMTemplateVO iso , int slot ) {
1481+ private void persistIsoAttachment (long vmId , UserVmVO vm , VMTemplateVO iso , int slot ) {
14821482 if (slot == CDROM_PRIMARY_DEVICE_SEQ ) {
14831483 vm .setIsoId (iso .getId ());
1484- _userVmDao .update (vm . getId () , vm );
1484+ _userVmDao .update (vmId , vm );
14851485 } else {
1486- _vmIsoMapDao .persist (new VmIsoMapVO (vm . getId () , iso .getId (), slot ));
1486+ _vmIsoMapDao .persist (new VmIsoMapVO (vmId , iso .getId (), slot ));
14871487 }
14881488 }
14891489
1490- private void persistIsoDetachment (UserVmVO vm , long isoId , int slot ) {
1490+ private void persistIsoDetachment (long vmId , UserVmVO vm , long isoId , int slot ) {
14911491 if (slot == CDROM_PRIMARY_DEVICE_SEQ ) {
14921492 vm .setIsoId (null );
1493- _userVmDao .update (vm . getId () , vm );
1493+ _userVmDao .update (vmId , vm );
14941494 return ;
14951495 }
1496- VmIsoMapVO entry = _vmIsoMapDao .findByVmIdIsoId (vm . getId () , isoId );
1496+ VmIsoMapVO entry = _vmIsoMapDao .findByVmIdIsoId (vmId , isoId );
14971497 if (entry != null ) {
14981498 _vmIsoMapDao .remove (entry .getId ());
14991499 }
@@ -1535,13 +1535,13 @@ boolean isIsoAlreadyAttached(long vmId, Long primaryIsoId, long isoId) {
15351535 return _vmIsoMapDao .findByVmIdIsoId (vmId , isoId ) != null ;
15361536 }
15371537
1538- private void enforceCdromAttachLimits (UserVm vm , long isoId ) {
1538+ private void enforceCdromAttachLimits (long vmId , UserVm vm , long isoId ) {
15391539 Long primaryIsoId = vm .getIsoId ();
1540- if (isIsoAlreadyAttached (vm . getId () , primaryIsoId , isoId )) {
1540+ if (isIsoAlreadyAttached (vmId , primaryIsoId , isoId )) {
15411541 throw new InvalidParameterValueException ("The specified ISO is already attached to this Instance." );
15421542 }
15431543 int effectiveMax = effectiveMaxCdroms (vm );
1544- int attached = (primaryIsoId != null ? 1 : 0 ) + _vmIsoMapDao .listByVmId (vm . getId () ).size ();
1544+ int attached = (primaryIsoId != null ? 1 : 0 ) + _vmIsoMapDao .listByVmId (vmId ).size ();
15451545 if (attached >= effectiveMax ) {
15461546 throw new InvalidParameterValueException (String .format (
15471547 "Instance has reached the maximum of %d attached CD-ROM(s); detach one before attaching another." , effectiveMax ));
0 commit comments