CLOUDSTACK-5662: XenServer can't discover iSCSI targets with different credentials

This commit is contained in:
Mike Tutkowski 2013-12-27 23:00:00 -07:00
parent dc303fda6e
commit 8eb430f602
6 changed files with 88 additions and 5 deletions

View File

@ -75,4 +75,6 @@ public interface HypervisorGuru extends Adapter {
*
*/
List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics);
List<Command> finalizeExpungeVolumes(VirtualMachine vm);
}

View File

@ -479,6 +479,34 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
List<Command> nicExpungeCommands = hvGuru.finalizeExpungeNics(vm, profile.getNics());
_networkMgr.cleanupNics(profile);
s_logger.debug("Cleaning up hypervisor data structures (ex. SRs in XenServer) for managed storage");
List<Command> volumeExpungeCommands = hvGuru.finalizeExpungeVolumes(vm);
if (volumeExpungeCommands != null) {
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (hostId != null) {
Commands cmds = new Commands(Command.OnError.Stop);
for (Command volumeExpungeCommand : volumeExpungeCommands) {
cmds.addCommand(volumeExpungeCommand);
}
_agentMgr.send(hostId, cmds);
if (!cmds.isSuccessful()) {
for (Answer answer : cmds.getAnswers()) {
if (!answer.getResult()) {
s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
}
}
}
}
}
// Clean up volumes based on the vm's instance id
volumeMgr.cleanupVolumes(vm.getId());

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.hypervisor;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
@ -26,14 +29,22 @@ import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@Local(value=HypervisorGuru.class)
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru {
@ -42,6 +53,12 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
EndPointSelector endPointSelector;
@Inject
HostDao hostDao;
@Inject
VolumeDao _volumeDao;
@Inject
PrimaryDataStoreDao _storagePoolDao;
@Inject
VolumeDataFactory _volFactory;
protected XenServerGuru() {
super();
@ -73,6 +90,39 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
return true;
}
@Override
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
List<Command> commands = new ArrayList<Command>();
List<VolumeVO> volumes = _volumeDao.findByInstance(vm.getId());
if (volumes != null) {
for (VolumeVO volume : volumes) {
if (volume.getVolumeType() == Volume.Type.DATADISK) {
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
if (storagePool.isManaged()) {
DataTO volTO = _volFactory.getVolume(volume.getId()).getTO();
DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());
DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName());
cmd.setManaged(true);
cmd.setStorageHost(storagePool.getHostAddress());
cmd.setStoragePort(storagePool.getPort());
cmd.set_iScsiName(volume.get_iScsiName());
commands.add(cmd);
}
}
}
}
return commands;
}
@Override
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
if (cmd instanceof CopyCommand) {

View File

@ -6504,9 +6504,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return vdi;
}
protected void handleSrAndVdiDetach(String iqn) throws Exception {
Connection conn = getConnection();
protected void handleSrAndVdiDetach(String iqn, Connection conn) throws Exception {
SR sr = getStorageRepository(conn, iqn);
removeSR(conn, sr);
@ -6614,7 +6612,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vdi.setNameLabel(conn, "detached");
if (cmd.isManaged()) {
handleSrAndVdiDetach(cmd.get_iScsiName());
handleSrAndVdiDetach(cmd.get_iScsiName(), conn);
}
return new AttachVolumeAnswer(cmd);

View File

@ -425,7 +425,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
}
if (cmd.isManaged()) {
hypervisorResource.handleSrAndVdiDetach(cmd.get_iScsiName());
hypervisorResource.handleSrAndVdiDetach(cmd.get_iScsiName(), conn);
}
return new DettachAnswer(disk);

View File

@ -144,4 +144,9 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
public List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics) {
return null;
}
@Override
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
return null;
}
}