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

This commit is contained in:
Mike Tutkowski 2014-01-09 22:02:43 -07:00
parent ae35782ccd
commit 6944bf9bba
6 changed files with 94 additions and 10 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

@ -485,6 +485,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,18 +16,17 @@
// under the License.
package com.cloud.hypervisor;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
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.ZoneScope;
import org.apache.cloudstack.storage.command.CopyCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.host.HostInfo;
@ -35,11 +34,24 @@ 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 {
@Inject
@ -48,6 +60,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();
@ -79,6 +97,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

@ -6537,9 +6537,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);
@ -6647,7 +6645,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

@ -423,7 +423,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

@ -150,4 +150,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;
}
}