CLOUDSTACK-6358: As a part of supporting dynamic guest OS defined by user, removing the hard-coded dependencies.

This patch is for XenServer.

1. Local testing on XenServer 6.0.2
2. Successfully got up system VMs
3. Successfully created a CentOS VM
4. Created VM snapshot and reverted to snapshot
5. Manipulated guest_os_hypervisor table for mapping, and checked for correct propagation of platform emulator.

Signed off by :- Nitin Mehta<nitin.mehta@citrix.com>
This commit is contained in:
Amogh Vasekar 2014-05-07 14:53:07 -07:00 committed by Daan Hoogland
parent 70a3e581ee
commit 1fb358d004
19 changed files with 367 additions and 151 deletions

View File

@ -47,6 +47,7 @@ public class VirtualMachineTO {
String hostName;
String arch;
String os;
String platformEmulator;
String bootArgs;
String[] bootupScripts;
boolean rebootOnCrash;
@ -236,7 +237,7 @@ public class VirtualMachineTO {
}
public String getVncPassword() {
return this.vncPassword;
return vncPassword;
}
public void setVncPassword(String vncPassword) {
@ -244,7 +245,7 @@ public class VirtualMachineTO {
}
public String getVncAddr() {
return this.vncAddr;
return vncAddr;
}
public void setVncAddr(String vncAddr) {
@ -275,4 +276,12 @@ public class VirtualMachineTO {
this.gpuDevice = gpuDevice;
}
public String getPlatformEmulator() {
return platformEmulator;
}
public void setPlatformEmulator(String platformEmulator) {
this.platformEmulator = platformEmulator;
}
}

View File

@ -26,10 +26,11 @@ public class VMSnapshotBaseCommand extends Command {
protected VMSnapshotTO target;
protected String vmName;
protected String guestOSType;
protected String platformEmulator;
public VMSnapshotBaseCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType) {
this.vmName = vmName;
this.target = snapshot;
target = snapshot;
this.volumeTOs = volumeTOs;
this.guestOSType = guestOSType;
}
@ -70,4 +71,12 @@ public class VMSnapshotBaseCommand extends Command {
public void setGuestOSType(String guestOSType) {
this.guestOSType = guestOSType;
}
public String getPlatformEmulator() {
return platformEmulator;
}
public void setPlatformEmulator(String platformEmulator) {
this.platformEmulator = platformEmulator;
}
}

View File

@ -45,11 +45,15 @@ import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.GuestOSHypervisorVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
@ -73,6 +77,8 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
@Inject
GuestOSDao guestOSDao;
@Inject
GuestOSHypervisorDao guestOsHypervisorDao;
@Inject
UserVmDao userVmDao;
@Inject
VMSnapshotDao vmSnapshotDao;
@ -85,6 +91,8 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
VolumeDao volumeDao;
@Inject
DiskOfferingDao diskOfferingDao;
@Inject
HostDao hostDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@ -108,7 +116,6 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
boolean result = false;
try {
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
VMSnapshotTO current = null;
@ -126,7 +133,10 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
else
vmSnapshotVO.setParent(current.getId());
HostVO host = hostDao.findById(hostId);
GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), target, volumeTOs, guestOS.getDisplayName(), userVm.getState());
ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
ccmd.setWait(_wait);
answer = (CreateVMSnapshotAnswer)agentMgr.send(hostId, ccmd);
@ -334,7 +344,10 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
snapshot.getCurrent(), parent, true);
Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
HostVO host = hostDao.findById(hostId);
GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
revertToSnapshotCommand.setPlatformEmulator(guestOsMapping.getGuestOsName());
RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer)agentMgr.send(hostId, revertToSnapshotCommand);
if (answer != null && answer.getResult()) {

View File

@ -58,9 +58,14 @@ import com.cloud.agent.api.RevertToVMSnapshotAnswer;
import com.cloud.agent.api.VMSnapshotTO;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.GuestOSHypervisorVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CloudRuntimeException;
@ -83,9 +88,13 @@ public class VMSnapshotStrategyTest extends TestCase {
@Inject
GuestOSDao guestOSDao;
@Inject
GuestOSHypervisorDao guestOsHypervisorDao;
@Inject
AgentManager agentMgr;
@Inject
VMSnapshotDao vmSnapshotDao;
@Inject
HostDao hostDao;
@Override
@Before
@ -98,6 +107,9 @@ public class VMSnapshotStrategyTest extends TestCase {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
@ -108,7 +120,15 @@ public class VMSnapshotStrategyTest extends TestCase {
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.takeVMSnapshot(vmSnapshot);
@ -131,6 +151,9 @@ public class VMSnapshotStrategyTest extends TestCase {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
@ -141,12 +164,20 @@ public class VMSnapshotStrategyTest extends TestCase {
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
Mockito.when(vmSnapshot.getId()).thenReturn(1L);
Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.revertVMSnapshot(vmSnapshot);
@ -168,6 +199,9 @@ public class VMSnapshotStrategyTest extends TestCase {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
@ -178,13 +212,20 @@ public class VMSnapshotStrategyTest extends TestCase {
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
Mockito.when(vmSnapshot.getId()).thenReturn(1L);
Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
@ -227,6 +268,11 @@ public class VMSnapshotStrategyTest extends TestCase {
return Mockito.mock(GuestOSDao.class);
}
@Bean
public GuestOSHypervisorDao guestOsHypervisorDao() {
return Mockito.mock(GuestOSHypervisorDao.class);
}
@Bean
public UserVmDao userVmDao() {
return Mockito.mock(UserVmDao.class);
@ -256,5 +302,10 @@ public class VMSnapshotStrategyTest extends TestCase {
public DiskOfferingDao diskOfferingDao() {
return Mockito.mock(DiskOfferingDao.class);
}
@Bean
public HostDao hostDao() {
return Mockito.mock(HostDao.class);
}
}
}

View File

@ -44,8 +44,12 @@ import com.cloud.agent.api.VMSnapshotTO;
import com.cloud.agent.api.to.DataTO;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.GuestOSHypervisorVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine;
@ -60,9 +64,13 @@ public class HypervisorHelperImpl implements HypervisorHelper {
@Inject
GuestOSDao guestOSDao;
@Inject
GuestOSHypervisorDao guestOsHypervisorDao;
@Inject
ConfigurationDao configurationDao;
@Inject
AgentManager agentMgr;
@Inject
HostDao hostDao;
@Override
public DataTO introduceObject(DataTO object, Scope scope, Long storeId) {
@ -117,6 +125,9 @@ public class HypervisorHelperImpl implements HypervisorHelper {
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
CreateVMSnapshotCommand ccmd =
new CreateVMSnapshotCommand(virtualMachine.getInstanceName(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName(), virtualMachine.getState());
HostVO host = hostDao.findById(hostId);
GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
ccmd.setWait(wait);
try {
Answer answer = agentMgr.send(hostId, ccmd);

View File

@ -22,6 +22,16 @@ 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.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
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;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
import com.cloud.agent.api.to.DataStoreTO;
@ -32,30 +42,24 @@ import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.GuestOSHypervisorVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
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.hypervisor.xenserver.XenserverConfigs;
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
GuestOSDao _guestOsDao;
@Inject
GuestOSHypervisorDao _guestOsHypervisorDao;
@Inject
EndPointSelector endPointSelector;
@Inject
HostDao hostDao;
@ -87,6 +91,9 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
GuestOSHypervisorVO guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
to.setPlatformEmulator(guestOsMapping.getGuestOsName());
return to;
}

View File

@ -16,6 +16,77 @@
// under the License.
package com.cloud.hypervisor.xen.resource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.trilead.ssh2.SCPClient;
import com.xensource.xenapi.Bond;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Console;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.HostCpu;
import com.xensource.xenapi.HostMetrics;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.PIF;
import com.xensource.xenapi.Pool;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Session;
import com.xensource.xenapi.Task;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.VmPowerState;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VBD;
import com.xensource.xenapi.VBDMetrics;
import com.xensource.xenapi.VDI;
import com.xensource.xenapi.VGPU;
import com.xensource.xenapi.VIF;
import com.xensource.xenapi.VLAN;
import com.xensource.xenapi.VM;
import com.xensource.xenapi.VMGuestMetrics;
import com.xensource.xenapi.XenAPIObject;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AttachIsoCommand;
@ -177,73 +248,6 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.PowerState;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.snapshot.VMSnapshot;
import com.trilead.ssh2.SCPClient;
import com.xensource.xenapi.Bond;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Console;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.HostCpu;
import com.xensource.xenapi.HostMetrics;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.PIF;
import com.xensource.xenapi.Pool;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Session;
import com.xensource.xenapi.Task;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.VmPowerState;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VBD;
import com.xensource.xenapi.VBDMetrics;
import com.xensource.xenapi.VDI;
import com.xensource.xenapi.VGPU;
import com.xensource.xenapi.VIF;
import com.xensource.xenapi.VLAN;
import com.xensource.xenapi.VM;
import com.xensource.xenapi.VMGuestMetrics;
import com.xensource.xenapi.XenAPIObject;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.util.concurrent.TimeoutException;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
/**
* CitrixResourceBase encapsulates the calls to the XenServer Xapi process
@ -804,7 +808,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
try {
vm = getVM(conn, vmName);
} catch (Exception e) {
vm = createWorkingVM(conn, vmName, cmd.getGuestOSType(), listVolumeTo);
vm = createWorkingVM(conn, vmName, cmd.getGuestOSType(), cmd.getPlatformEmulator(), listVolumeTo);
}
if (vm == null) {
@ -1344,7 +1348,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException {
String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD);
String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName);
if ( templates == null || templates.isEmpty() ){
s_logger.debug("Cannot find template : " + guestOsTypeName + " on XS version: " + this.getClass().getName());
@ -1444,7 +1448,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
TemplateObjectTO iso = (TemplateObjectTO)disk.getData();
String osType = iso.getGuestOsType();
if (osType != null) {
String isoGuestOsName = getGuestOsType(osType, vmSpec.getBootloader() == BootloaderType.CD);
String isoGuestOsName = getGuestOsType(osType, vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
if (!isoGuestOsName.equals(guestOsTypeName)) {
vmSpec.setBootloader(BootloaderType.PyGrub);
}
@ -6437,6 +6441,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
List<VolumeObjectTO> listVolumeTo = cmd.getVolumeTOs();
VirtualMachine.State vmState = cmd.getVmState();
String guestOSType = cmd.getGuestOSType();
String platformEmulator = cmd.getPlatformEmulator();
boolean snapshotMemory = cmd.getTarget().getType() == VMSnapshot.Type.DiskAndMemory;
long timeout = cmd.getWait();
@ -6471,7 +6476,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vm = getVM(conn, vmName);
} catch (Exception e) {
if (!snapshotMemory) {
vm = createWorkingVM(conn, vmName, guestOSType, listVolumeTo);
vm = createWorkingVM(conn, vmName, guestOSType, platformEmulator, listVolumeTo);
}
}
@ -6559,9 +6564,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
}
private VM createWorkingVM(Connection conn, String vmName, String guestOSType, List<VolumeObjectTO> listVolumeTo) throws BadServerResponse, Types.VmBadPowerState, Types.SrFull,
private VM createWorkingVM(Connection conn, String vmName, String guestOSType, String platformEmulator, List<VolumeObjectTO> listVolumeTo) throws BadServerResponse,
Types.VmBadPowerState, Types.SrFull,
Types.OperationNotAllowed, XenAPIException, XmlRpcException {
String guestOsTypeName = getGuestOsType(guestOSType, false);
//below is redundant but keeping for consistency and code readabilty
String guestOsTypeName = platformEmulator;
if (guestOsTypeName == null) {
String msg =
" Hypervisor " + this.getClass().getName() + " doesn't support guest OS type " + guestOSType + ". you can choose 'Other install media' to run it as HVM";
@ -7145,7 +7152,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
/*Override by subclass*/
protected String getGuestOsType(String stdType, boolean bootFromCD) {
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
return stdType;
}

View File

@ -27,6 +27,15 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VBD;
import com.xensource.xenapi.VDI;
import com.xensource.xenapi.VM;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.NetworkUsageAnswer;
@ -40,14 +49,6 @@ import com.cloud.resource.ServerResource;
import com.cloud.storage.Storage;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VBD;
import com.xensource.xenapi.VDI;
import com.xensource.xenapi.VM;
@Local(value = ServerResource.class)
public class XcpOssResource extends CitrixResourceBase {
@ -78,6 +79,7 @@ public class XcpOssResource extends CitrixResourceBase {
return true;
}
@Override
protected StartupStorageCommand initializeLocalSR(Connection conn) {
SR extsr = getLocalEXTSR(conn);
if (extsr != null) {
@ -111,13 +113,17 @@ public class XcpOssResource extends CitrixResourceBase {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
return "Debian Squeeze 6.0 (64-bit)";
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
return "CentOS 5 (64-bit)";
} else {
return CitrixHelper.getXcpGuestOsType(stdType);
if (platformEmulator == null || platformEmulator.isEmpty()) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XCP's guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
}
return platformEmulator;
}
}

View File

@ -19,14 +19,20 @@
package com.cloud.hypervisor.xen.resource;
public class XcpServer16Resource extends XcpServerResource {
import org.apache.log4j.Logger;
public class XcpServer16Resource extends XcpServerResource {
private final static Logger s_logger = Logger.getLogger(XcpServer16Resource.class);
public XcpServer16Resource() {
super();
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXcp160GuestOsType(stdType);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XCP's guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
}
return platformEmulator;
}
}

View File

@ -71,8 +71,12 @@ public class XcpServerResource extends CitrixResourceBase {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXcpGuestOsType(stdType);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XCP's guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
}
return platformEmulator;
}
protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {

View File

@ -52,8 +52,17 @@ public class XenServer56FP1Resource extends XenServer56Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer56FP1GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 5.6 FP1 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 5.6 FP1 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -16,6 +16,25 @@
// under the License.
package com.cloud.hypervisor.xen.resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PIF;
import com.xensource.xenapi.Types.IpConfigurationMode;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VLAN;
import com.xensource.xenapi.VM;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckOnHostAnswer;
import com.cloud.agent.api.CheckOnHostCommand;
@ -29,22 +48,6 @@ import com.cloud.resource.ServerResource;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SSHCmdHelper;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PIF;
import com.xensource.xenapi.Types.IpConfigurationMode;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VLAN;
import com.xensource.xenapi.VM;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import javax.ejb.Local;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Local(value = ServerResource.class)
public class XenServer56Resource extends CitrixResourceBase {
@ -62,8 +65,17 @@ public class XenServer56Resource extends CitrixResourceBase {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServerGuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 5.6 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 5.6 doesn't support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -39,8 +39,17 @@ public class XenServer56SP2Resource extends XenServer56FP1Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer56SP2GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 5.6 SP2 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 5.6 SP2 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -37,8 +37,18 @@ public class XenServer600Resource extends XenServer56SP2Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer600GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.0.2 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.0.2 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -16,7 +16,9 @@
// under the License.
package com.cloud.hypervisor.xen.resource;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.resource.ServerResource;
@Local(value = ServerResource.class)
@ -28,8 +30,17 @@ public class XenServer602Resource extends XenServer600Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer602GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.0.2 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.0.2 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -73,8 +73,17 @@ public class XenServer610Resource extends XenServer602Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer610GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.1.0 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.1.0 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -15,16 +15,20 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.hypervisor.xen.resource;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.HostPatch;
import com.xensource.xenapi.PoolPatch;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.resource.ServerResource;
@ -37,8 +41,17 @@ public class XenServer620Resource extends XenServer610Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer620GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.2.0 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.2.0 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override
@ -89,6 +102,7 @@ public class XenServer620Resource extends XenServer610Resource {
return false;
}
@Override
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
super.fillHostInfo(conn, cmd);
Map<String, String> details = cmd.getHostDetails();

View File

@ -28,15 +28,6 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetGPUStatsAnswer;
import com.cloud.agent.api.GetGPUStatsCommand;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.VgpuTypesInfo;
import com.cloud.agent.api.to.GPUDeviceTO;
import com.cloud.resource.ServerResource;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.GPUGroup;
import com.xensource.xenapi.Host;
@ -47,6 +38,16 @@ import com.xensource.xenapi.VGPUType;
import com.xensource.xenapi.VGPUType.Record;
import com.xensource.xenapi.VM;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetGPUStatsAnswer;
import com.cloud.agent.api.GetGPUStatsCommand;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.VgpuTypesInfo;
import com.cloud.agent.api.to.GPUDeviceTO;
import com.cloud.resource.ServerResource;
@Local(value=ServerResource.class)
public class XenServer620SP1Resource extends XenServer620Resource {
private static final Logger s_logger = Logger.getLogger(XenServer620SP1Resource.class);
@ -159,8 +160,17 @@ public class XenServer620SP1Resource extends XenServer620Resource {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer620SP1GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.2.0 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.2.0 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override

View File

@ -50,8 +50,17 @@ public class Xenserver625Resource extends XenServerResourceNewBase {
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer625GuestOsType(stdType, bootFromCD);
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
if (platformEmulator == null) {
if (!bootFromCD) {
s_logger.debug("Can't find the guest os: " + stdType + " mapping into XenServer 6.2.5 guestOS type, start it as HVM guest");
platformEmulator = "Other install media";
} else {
String msg = "XenServer 6.2.5 DOES NOT support Guest OS type " + stdType;
s_logger.warn(msg);
}
}
return platformEmulator;
}
@Override