removed a bunch of old code

This commit is contained in:
Alex Huang 2010-12-16 01:15:27 -08:00
parent 39cc371e78
commit 65d0b32182
19 changed files with 224 additions and 5017 deletions

View File

@ -123,14 +123,6 @@ import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.RebootRouterCommand;
import com.cloud.agent.api.Start2Answer;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.StartAnswer;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartConsoleProxyAnswer;
import com.cloud.agent.api.StartConsoleProxyCommand;
import com.cloud.agent.api.StartRouterAnswer;
import com.cloud.agent.api.StartRouterCommand;
import com.cloud.agent.api.StartSecStorageVmAnswer;
import com.cloud.agent.api.StartSecStorageVmCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StopAnswer;
@ -145,16 +137,15 @@ import com.cloud.agent.api.routing.RoutingCommand;
import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.api.to.VirtualMachineTO.Monitor;
import com.cloud.agent.api.to.VirtualMachineTO.SshMonitor;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.resource.computing.KVMHABase.NfsStoragePool;
import com.cloud.agent.resource.computing.KVMHABase.PoolType;
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.poolType;
@ -175,10 +166,9 @@ import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
import com.cloud.exception.InternalErrorException;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy;
import com.cloud.network.router.VirtualRouter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.ServerResourceBase;
import com.cloud.storage.Storage;
@ -202,9 +192,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.State;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineName;
@ -261,8 +249,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
int numLines=0;
while ((line = reader.readLine()) != null) {
String [] toks = line.trim().split("=");
if (toks.length < 2) s_logger.warn("Failed to parse Script output: " + line);
else map.put(toks[0].trim(), toks[1].trim());
if (toks.length < 2) {
s_logger.warn("Failed to parse Script output: " + line);
} else {
map.put(toks[0].trim(), toks[1].trim());
}
numLines++;
}
if (numLines == 0) {
@ -544,8 +535,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean success = super.configure(name, params);
if (! success)
return false;
if (! success) {
return false;
}
_virtRouterResource = new VirtualRoutingResource();
// Set the domr scripts directory
@ -857,9 +849,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
boolean isDirectAttachedNetwork(String type) {
if ("untagged".equalsIgnoreCase(type))
return true;
else {
if ("untagged".equalsIgnoreCase(type)) {
return true;
} else {
try {
Long vnetId = Long.valueOf(type);
} catch (NumberFormatException e) {
@ -869,132 +861,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
protected synchronized String startDomainRouter(StartRouterCommand cmd) {
VirtualRouter router = cmd.getRouter();
List<InterfaceDef> nics = null;
try {
nics = createRouterVMNetworks(cmd);
List<DiskDef> disks = createSystemVMDisk(cmd.getVolumes());
String dataDiskPath = null;
for (DiskDef disk : disks) {
if (disk.getDiskLabel().equalsIgnoreCase("vdb")) {
dataDiskPath = disk.getDiskPath();
}
}
String vmName = cmd.getVmName();
patchSystemVm(cmd.getBootArgs(), dataDiskPath, vmName);
String uuid = UUID.nameUUIDFromBytes(vmName.getBytes()).toString();
String domXML = defineVMXML(cmd.getVmName(), uuid, router.getRamSize(), 1, _domrArch, nics, disks, router.getVncPassword(), cmd.getGuestOSDescription());
s_logger.debug(domXML);
startDomain(vmName, domXML);
for (InterfaceDef nic : nics) {
if (nic.getHostNetType() == hostNicType.VNET) {
disableBridgeForwardding(nic.getBrName());
}
}
/*if (isDirectAttachedNetwork(router.getVlanId()))
default_network_rules_for_systemvm(vmName);*/
} catch (LibvirtException e) {
if (nics != null) {
cleanupVMNetworks(nics);
}
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}catch (InternalErrorException e) {
if (nics != null) {
cleanupVMNetworks(nics);
}
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}
return null;
}
protected synchronized String startConsoleProxy(StartConsoleProxyCommand cmd) {
ConsoleProxyVO console = cmd.getProxy();
List<InterfaceDef> nics = null;
try {
nics = createSysVMNetworks(console.getGuestMacAddress(), console.getPrivateMacAddress(), console.getPublicMacAddress(), console.getVlanId());
List<DiskDef> disks = createSystemVMDisk(cmd.getVolumes());
String dataDiskPath = null;
for (DiskDef disk : disks) {
if (disk.getDiskLabel().equalsIgnoreCase("vdb")) {
dataDiskPath = disk.getDiskPath();
}
}
String bootArgs = cmd.getBootArgs() + " zone=" + _dcId;
bootArgs += " pod=" + _pod;
bootArgs += " guid=Proxy." + console.getId();
bootArgs += " proxy_vm=" + console.getId();
bootArgs += " localgw=" + _localGateway;
String vmName = cmd.getVmName();
patchSystemVm(bootArgs, dataDiskPath, vmName);
String uuid = UUID.nameUUIDFromBytes(vmName.getBytes()).toString();
String domXML = defineVMXML(cmd.getVmName(), uuid, console.getRamSize(), 1, _domrArch, nics, disks, console.getVncPassword(), "Fedora 12");
s_logger.debug(domXML);
startDomain(vmName, domXML);
} catch (LibvirtException e) {
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}catch (InternalErrorException e) {
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}
return null;
}
protected String startSecStorageVM(StartSecStorageVmCommand cmd) {
SecondaryStorageVmVO secVm = cmd.getSecondaryStorageVmVO();
List<InterfaceDef> nics = null;
try {
nics = createSysVMNetworks(secVm.getGuestMacAddress(), secVm.getPrivateMacAddress(), secVm.getPublicMacAddress(), secVm.getVlanId());
List<DiskDef> disks = createSystemVMDisk(cmd.getVolumes());
String dataDiskPath = null;
for (DiskDef disk : disks) {
if (disk.getDiskLabel().equalsIgnoreCase("vdb")) {
dataDiskPath = disk.getDiskPath();
}
}
String vmName = cmd.getVmName();
String bootArgs = cmd.getBootArgs();
bootArgs += " zone=" + _dcId;
bootArgs += " pod=" + _pod;
bootArgs += " localgw=" + _localGateway;
patchSystemVm(bootArgs, dataDiskPath, vmName);
String uuid = UUID.nameUUIDFromBytes(vmName.getBytes()).toString();
String domXML = defineVMXML(cmd.getVmName(), uuid, secVm.getRamSize(), 1, _domrArch, nics, disks, secVm.getVncPassword(), cmd.getGuestOSDescription());
s_logger.debug(domXML);
startDomain(vmName, domXML);
} catch (LibvirtException e) {
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}catch (InternalErrorException e) {
s_logger.debug("Failed to start domr: " + e.toString());
return e.toString();
}
return null;
}
private String defineVMXML(String vmName, String uuid, int memSize, int cpus, String arch, List<InterfaceDef> nics, List<DiskDef> disks, String vncPaswd, String guestOSType) {
LibvirtVMDef vm = new LibvirtVMDef();
vm.setHvsType(_hypervisorType);
@ -1036,8 +902,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
for (DiskDef disk : disks) {
if (!disk.isAttachDeferred())
devices.addDevice(disk);
if (!disk.isAttachDeferred()) {
devices.addDevice(disk);
}
}
SerialDef serial = new SerialDef("pty", null, (short)0);
@ -1071,8 +938,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
failed = true;
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
@ -1095,10 +963,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
throw new InternalErrorException(e.toString());
} finally {
try {
if (dmOld != null)
dmOld.free();
if (dmNew != null)
dmNew.free();
if (dmOld != null) {
dmOld.free();
}
if (dmNew != null) {
dmNew.free();
}
} catch (final LibvirtException e) {
}
@ -1113,8 +983,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
throw e;
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
@ -1157,9 +1028,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
public Answer executeRequest(Command cmd) {
try {
if (cmd instanceof StartCommand) {
return execute((StartCommand)cmd);
} else if (cmd instanceof StopCommand) {
if (cmd instanceof StopCommand) {
return execute((StopCommand)cmd);
} else if (cmd instanceof GetVmStatsCommand) {
return execute((GetVmStatsCommand)cmd);
@ -1185,12 +1054,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return execute((CheckVirtualMachineCommand)cmd);
} else if (cmd instanceof ReadyCommand) {
return execute((ReadyCommand)cmd);
} else if (cmd instanceof StartRouterCommand) {
return execute((StartRouterCommand)cmd);
} else if(cmd instanceof StartConsoleProxyCommand) {
return execute((StartConsoleProxyCommand)cmd);
} else if(cmd instanceof StartSecStorageVmCommand) {
return execute((StartSecStorageVmCommand)cmd);
} else if (cmd instanceof AttachIsoCommand) {
return execute((AttachIsoCommand) cmd);
} else if (cmd instanceof AttachVolumeCommand) {
@ -1737,8 +1600,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
int index = tmplturl.lastIndexOf("/");
String mountpoint = tmplturl.substring(0, index);
String tmpltname = null;
if (index < tmplturl.length() - 1)
tmpltname = tmplturl.substring(index + 1);
if (index < tmplturl.length() - 1) {
tmpltname = tmplturl.substring(index + 1);
}
StoragePool secondaryPool = null;
StoragePool primaryPool = null;
@ -1954,8 +1818,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
final StringBuilder sb2 = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null)
sb2.append(line + "\n");
while ((line = reader.readLine()) != null) {
sb2.append(line + "\n");
}
result = sb2.toString();
} catch (final IOException e) {
success = false;
@ -1975,73 +1840,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
}
private Answer execute(StartConsoleProxyCommand cmd) {
final ConsoleProxyVO router = cmd.getProxy();
String result = null;
State state = State.Stopped;
synchronized(_vms) {
_vms.put(cmd.getVmName(), State.Starting);
}
try {
result = startConsoleProxy(cmd);
if (result != null) {
throw new ExecutionException(result, null);
}
result = _virtRouterResource.connect(router.getGuestIpAddress(), cmd.getProxyCmdPort());
if (result != null) {
throw new ExecutionException(result, null);
}
state = State.Running;
return new StartConsoleProxyAnswer(cmd);
} catch (final ExecutionException e) {
return new Answer(cmd, false, e.getMessage());
} catch (final Throwable th) {
s_logger.warn("Exception while starting router.", th);
return createErrorAnswer(cmd, "Unable to start router", th);
} finally {
synchronized(_vms) {
_vms.put(cmd.getVmName(), state);
}
}
}
private Answer execute(StartSecStorageVmCommand cmd) {
final SecondaryStorageVmVO secVm = cmd.getSecondaryStorageVmVO();
String result = null;
State state = State.Stopped;
synchronized(_vms) {
_vms.put(cmd.getVmName(), State.Starting);
}
try {
result = startSecStorageVM(cmd);
if (result != null) {
throw new ExecutionException(result, null);
}
result = _virtRouterResource.connect(secVm.getGuestIpAddress(), cmd.getProxyCmdPort());
if (result != null) {
throw new ExecutionException(result, null);
}
state = State.Running;
return new StartSecStorageVmAnswer(cmd);
} catch (final ExecutionException e) {
return new Answer(cmd, false, e.getMessage());
} catch (final Throwable th) {
s_logger.warn("Exception while starting router.", th);
return createErrorAnswer(cmd, "Unable to start router", th);
} finally {
synchronized(_vms) {
_vms.put(cmd.getVmName(), state);
}
}
}
private Answer execute(AttachIsoCommand cmd) {
try {
attachOrDetachISO(cmd.getVmName(), cmd.getIsoPath(), cmd.isAttach());
@ -2071,55 +1869,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected static List<VolumeVO> findVolumes(final List<VolumeVO> volumes, final Volume.VolumeType vType, boolean singleVolume) {
List<VolumeVO> filteredVolumes = new ArrayList<VolumeVO>();
if (volumes == null)
return filteredVolumes;
if (volumes == null) {
return filteredVolumes;
}
for (final VolumeVO v: volumes) {
if (v.getVolumeType() == vType) {
filteredVolumes.add(v);
if(singleVolume)
return filteredVolumes;
if(singleVolume) {
return filteredVolumes;
}
}
}
return filteredVolumes;
}
private Answer execute(StartRouterCommand cmd) {
final VirtualRouter router = cmd.getRouter();
String result = null;
State state = State.Stopped;
synchronized(_vms) {
_vms.put(cmd.getVmName(), State.Starting);
}
try {
result = startDomainRouter(cmd);
if (result != null) {
throw new ExecutionException(result, null);
}
result = _virtRouterResource.connect(router.getPrivateIpAddress());
if (result != null) {
throw new ExecutionException(result, null);
}
state = State.Running;
return new StartRouterAnswer(cmd);
} catch (final ExecutionException e) {
return new Answer(cmd, false, e.getMessage());
} catch (final Throwable th) {
return createErrorAnswer(cmd, "Unable to start router", th);
} finally {
synchronized(_vms) {
_vms.put(cmd.getVmName(), state);
}
}
}
private Answer execute(ReadyCommand cmd) {
return new ReadyAnswer(cmd);
}
@ -2228,12 +1994,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
result = e.getMessage();
} finally {
try {
if (dm != null)
dm.free();
if (dconn != null)
dconn.close();
if (destDomain != null)
destDomain.free();
if (dm != null) {
dm.free();
}
if (dconn != null) {
dconn.close();
}
if (destDomain != null) {
destDomain.free();
}
} catch (final LibvirtException e) {
}
@ -2398,8 +2167,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
for (String vmName : vmNames) {
VmStatsEntry statEntry = getVmStat(vmName);
if( statEntry == null )
continue;
if( statEntry == null ) {
continue;
}
vmStatsNameMap.put(vmName, statEntry);
}
@ -2516,33 +2286,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
script.execute();
}
if (result != null)
return new Answer(cmd, false, result);
else
return new Answer(cmd, true, null);
}
protected StartAnswer execute(StartCommand cmd) {
final String vmName = cmd.getVmName();
String result = null;
State state = State.Stopped;
synchronized(_vms) {
_vms.put(vmName, State.Starting);
}
try {
result = startVM(cmd);
if (result != null) {
return new StartAnswer(cmd, result);
}
state = State.Running;
return new StartAnswer(cmd);
} finally {
synchronized(_vms) {
_vms.put(vmName, state);
}
if (result != null) {
return new Answer(cmd, false, result);
} else {
return new Answer(cmd, true, null);
}
}
@ -2562,68 +2309,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
throw e;
} finally {
try {
if (sp != null)
sp.free();
if (sp != null) {
sp.free();
}
} catch (LibvirtException e) {
}
}
}
protected synchronized String startVM(StartCommand cmd) {
List<InterfaceDef> nics = null;
try {
String uuid = UUID.nameUUIDFromBytes(cmd.getVmName().getBytes()).toString();
nics = createUserVMNetworks(cmd);
List<DiskDef> disks = createVMDisk(cmd.getVolumes(), cmd.getGuestOSDescription(), cmd.getISOPath());
String vmDomainXML = defineVMXML(cmd.getVmName(), uuid, cmd.getRamSize(), cmd.getCpu(), cmd.getArch(),
nics, disks, cmd.getVncPassword(),
cmd.getGuestOSDescription());
s_logger.debug(vmDomainXML);
// Start the domain
startDomain(cmd.getVmName(), vmDomainXML);
// Attach each data volume to the VM, if there is a deferred attached disk
for (DiskDef disk : disks) {
if (disk.isAttachDeferred()) {
attachOrDetachDisk(true, cmd.getVmName(), disk.getDiskPath());
}
}
/*if (isDirectAttachedNetwork(cmd.getGuestNetworkId()))
default_network_rules(cmd.getVmName(), cmd.getGuestIpAddress());*/
return null;
} catch(LibvirtException e) {
if (nics != null)
cleanupVMNetworks(nics);
s_logger.error("Unable to start VM: ", e);
return "Unable to start VM due to: " + e.getMessage();
} catch (InternalErrorException e) {
if (nics != null)
cleanupVMNetworks(nics);
s_logger.error("Unable to start VM: ", e);
return "Unable to start VM due to: " + e.getMessage();
} catch (URISyntaxException e) {
if (nics != null)
cleanupVMNetworks(nics);
s_logger.error("Unable to start VM: ", e);
return "Unable to start VM due to: " + e.getMessage();
}
}
private void handleVmStartFailure(String vmName, LibvirtVMDef vm) {
if (vm != null && vm.getDevices() != null)
cleanupVMNetworks(vm.getDevices().getInterfaces());
if (vm != null && vm.getDevices() != null) {
cleanupVMNetworks(vm.getDevices().getInterfaces());
}
}
private LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO) {
@ -2684,8 +2382,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
NicTO[] nics = vmSpec.getNics();
for (int i = 0; i < nics.length; i++) {
for (NicTO nic : vmSpec.getNics()) {
if (nic.getDeviceId() == i)
createVif(vm, nic);
if (nic.getDeviceId() == i) {
createVif(vm, nic);
}
}
}
}
@ -2979,10 +2678,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
dm.detachDevice(xml);
}
} catch (LibvirtException e) {
if (attach)
s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
else
s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
if (attach) {
s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
} else {
s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
}
throw e;
} catch (Exception e) {
throw new InternalErrorException(e.toString());
@ -3157,8 +2857,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.trace(e.getMessage());
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
@ -3200,8 +2901,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.warn("Unable to get vms", e);
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
@ -3247,8 +2949,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.warn("Unable to get vms", e);
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException e) {
}
@ -3272,8 +2975,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.warn("Unable to get vms", e);
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException e) {
}
@ -3298,10 +3002,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
parser.parseCapabilitiesXML(_conn.getCapabilities());
ArrayList<String> oss = parser.getGuestOsType();
for(String s : oss)
/*Even host supports guest os type more than hvm, we only report hvm to management server*/
if (s.equalsIgnoreCase("hvm"))
osType = "hvm";
for(String s : oss) {
/*Even host supports guest os type more than hvm, we only report hvm to management server*/
if (s.equalsIgnoreCase("hvm")) {
osType = "hvm";
}
}
} catch (LibvirtException e) {
}
@ -3320,8 +3026,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected void cleanupVM(final String vmName, final String vnet) {
s_logger.debug("Trying to cleanup the vnet: " + vnet);
if (vnet != null)
cleanupVnet(vnet);
if (vnet != null) {
cleanupVnet(vnet);
}
_vmStats.remove(vmName);
}
@ -3344,8 +3051,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
msg = e.getMessage();
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException e) {
}
@ -3378,8 +3086,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.debug("Failed to get vm status:" + e.getMessage());
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException l) {
}
@ -3408,8 +3117,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException l) {
}
@ -3452,8 +3162,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return e.getMessage();
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException e) {
}
}
@ -3463,8 +3174,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
public synchronized String cleanupVnet(final String vnetId) {
// VNC proxy VMs do not have vnet
if(vnetId == null || vnetId.isEmpty() || isDirectAttachedNetwork(vnetId))
return null;
if(vnetId == null || vnetId.isEmpty() || isDirectAttachedNetwork(vnetId)) {
return null;
}
final List<String> names = getAllVmNames();
@ -3494,8 +3206,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
throw new InternalErrorException("Can't get vnc port: " + e);
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException l) {
}
@ -3531,8 +3244,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
parser.parseCapabilitiesXML(_conn.getCapabilities());
ArrayList<String> osTypes = parser.getGuestOsType();
for (String o : osTypes) {
if (o.equalsIgnoreCase("hvm"))
return true;
if (o.equalsIgnoreCase("hvm")) {
return true;
}
}
} catch (LibvirtException e) {
@ -3545,8 +3259,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
if (f.exists()) {
return "/usr/bin/cloud-qemu-system-x86_64";
} else {
if (_conn == null)
return null;
if (_conn == null) {
return null;
}
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
try {
@ -3572,8 +3287,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return null;
} finally {
try {
if (dm != null)
dm.free();
if (dm != null) {
dm.free();
}
} catch (LibvirtException l) {
}
@ -3581,8 +3297,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
private boolean isGuestPVEnabled(String guestOS) {
if (guestOS == null)
return false;
if (guestOS == null) {
return false;
}
String guestOSName = KVMGuestOsMapper.getGuestOsName(guestOS);
if (guestOSName.startsWith("Ubuntu 10.04") ||
guestOSName.startsWith("Ubuntu 9") ||
@ -3600,17 +3317,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
guestOSName.startsWith("Red Hat Enterprise Linux 5.5") ||
guestOSName.startsWith("Red Hat Enterprise Linux 6") ||
guestOSName.startsWith("Debian GNU/Linux")
)
return true;
else
return false;
) {
return true;
} else {
return false;
}
}
private boolean isCentosHost() {
if (_hvVersion <=9 ) {
return true;
} else
return false;
} else {
return false;
}
}
private StorageVol createTmplDataDisk(String rootkPath, long size) throws LibvirtException, InternalErrorException {
@ -3653,105 +3372,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
private String getVnetIdFromBrName(String vnetBrName) {
return vnetBrName.replaceAll("cloudVirBr", "");
}
private List<InterfaceDef> createUserVMNetworks(StartCommand cmd) throws InternalErrorException {
List<InterfaceDef> nics = new ArrayList<InterfaceDef>();
InterfaceDef.nicModel nicModel = getGuestNicModel(cmd.getGuestOSDescription());
String guestMac = cmd.getGuestMacAddress();
String brName;
InterfaceDef pubNic = new InterfaceDef();
if (cmd.getGuestIpAddress() == null) {
/*guest network is direct attached without external DHCP server*/
brName = _privBridgeName;
pubNic.setHostNetType(hostNicType.DIRECT_ATTACHED_WITHOUT_DHCP);
} else if ("untagged".equalsIgnoreCase(cmd.getGuestNetworkId())){
/*guest network is direct attached with domr DHCP server*/
brName = _privBridgeName;
pubNic.setHostNetType(hostNicType.DIRECT_ATTACHED_WITH_DHCP);
} else {
/*guest network is vnet*/
String vnetId = getVnetId(cmd.getGuestNetworkId());
brName = setVnetBrName(vnetId);
createVnet(vnetId, _pifs.first());
pubNic.setHostNetType(hostNicType.VLAN);
}
pubNic.defBridgeNet(brName, null, guestMac, nicModel);
nics.add(pubNic);
return nics;
}
private List<InterfaceDef> createRouterVMNetworks(StartRouterCommand cmd) throws InternalErrorException {
List<InterfaceDef> nics = new ArrayList<InterfaceDef>();
VirtualRouter router = cmd.getRouter();
String guestMac = router.getGuestMacAddress();
String privateMac = router.getPrivateMacAddress();
String pubMac = router.getPublicMacAddress();
String brName;
InterfaceDef pubNic = new InterfaceDef();
InterfaceDef privNic = new InterfaceDef();
InterfaceDef vnetNic = new InterfaceDef();
/*nic 0, guest network*/
if ("untagged".equalsIgnoreCase(router.getVnet())){
vnetNic.defBridgeNet(_privBridgeName, null, guestMac, InterfaceDef.nicModel.VIRTIO);
} else {
String vnetId = getVnetId(router.getVnet());
brName = setVnetBrName(vnetId);
String vnetDev = "vtap" + vnetId;
createVnet(vnetId, _pifs.first());
vnetNic.defBridgeNet(brName, null, guestMac, InterfaceDef.nicModel.VIRTIO);
}
nics.add(vnetNic);
/*nic 1: link local*/
privNic.defPrivateNet(_privNwName, null, privateMac, InterfaceDef.nicModel.VIRTIO);
nics.add(privNic);
/*nic 2: public */
if ("untagged".equalsIgnoreCase(router.getVlanId())) {
pubNic.defBridgeNet(_publicBridgeName, null, pubMac, InterfaceDef.nicModel.VIRTIO);
} else {
String vnetId = getVnetId(router.getVlanId());
brName = setVnetBrName(vnetId);
String vnetDev = "vtap" + vnetId;
createVnet(vnetId, _pifs.second());
pubNic.defBridgeNet(brName, null, pubMac, InterfaceDef.nicModel.VIRTIO);
}
nics.add(pubNic);
return nics;
}
private List<InterfaceDef> createSysVMNetworks(String guestMac, String privMac, String pubMac, String vlanId) throws InternalErrorException {
List<InterfaceDef> nics = new ArrayList<InterfaceDef>();
String brName;
InterfaceDef pubNic = new InterfaceDef();
InterfaceDef privNic = new InterfaceDef();
InterfaceDef vnetNic = new InterfaceDef();
/*nic 0: link local*/
privNic.defPrivateNet(_privNwName, null, guestMac, InterfaceDef.nicModel.VIRTIO);
nics.add(privNic);
/*nic 1, priv network*/
vnetNic.defBridgeNet(_privBridgeName, null, privMac, InterfaceDef.nicModel.VIRTIO);
nics.add(vnetNic);
/*nic 2: public */
if ("untagged".equalsIgnoreCase(vlanId)) {
pubNic.defBridgeNet(_publicBridgeName, null, pubMac, InterfaceDef.nicModel.VIRTIO);
} else {
String vnetId = getVnetId(vlanId);
brName = setVnetBrName(vnetId);
String vnetDev = "vtap" + vnetId;
createVnet(vnetId, _pifs.second());
pubNic.defBridgeNet(brName, null, pubMac, InterfaceDef.nicModel.VIRTIO);
}
nics.add(pubNic);
return nics;
}
private void cleanupVMNetworks(List<InterfaceDef> nics) {
for (InterfaceDef nic : nics) {
if (nic.getHostNetType() == hostNicType.VNET) {
@ -3807,14 +3427,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
StorageVol isoVol = getVolume(_conn, isoURI);
if (isoVol != null) {
isoPath = isoVol.getPath();
} else
throw new InternalErrorException("Can't find iso volume");
} else {
throw new InternalErrorException("Can't find iso volume");
}
}
List<VolumeVO> dataVolumes = findVolumes(vols, VolumeType.DATADISK, false);
VolumeVO dataVolume = null;
if (dataVolumes.size() > 0)
dataVolume = dataVolumes.get(0);
if (dataVolumes.size() > 0) {
dataVolume = dataVolumes.get(0);
}
DiskDef.diskBus diskBusType = getGuestDiskModel(guestOSType);
@ -4030,10 +3652,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
String[] lines = parser.getLines().split("\\n");
for (String line : lines) {
String[] tokens = line.split(" ");
if (!tokens[2].equalsIgnoreCase(linkLocalBr))
Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR());
else
foundLinkLocalBr = true;
if (!tokens[2].equalsIgnoreCase(linkLocalBr)) {
Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR());
} else {
foundLinkLocalBr = true;
}
}
}
if (!foundLinkLocalBr) {

View File

@ -1,37 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
/**
* @author ahuang
*
*/
public class StartAnswer extends Answer {
protected StartAnswer() {
}
public StartAnswer(StartCommand cmd) {
super(cmd);
}
public StartAnswer(StartCommand cmd, String details) {
super(cmd, false, details);
}
}

View File

@ -1,195 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
import java.util.List;
import com.cloud.network.router.VirtualRouter;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.VolumeVO;
import com.cloud.uservm.UserVm;
import com.cloud.vm.UserVmVO;
public class StartCommand extends AbstractStartCommand {
long id;
String guestIpAddress;
String gateway;
int ramSize;
String imagePath;
String guestNetworkId;
String guestMacAddress;
String vncPassword;
String externalVlan;
String externalMacAddress;
int utilization;
int cpuWeight;
int cpu;
int networkRateMbps;
int networkRateMulticastMbps;
String hostName;
String arch;
String isoPath;
boolean bootFromISO;
String guestOSDescription;
public StartCommand(UserVm vm, String vmName, ServiceOffering offering, int networkRate, int multicastRate, VirtualRouter router, String storageHost, String imagePath, String guestNetworkId, int utilization, int cpuWeight, List<VolumeVO> vols, int bits, String isoPath, boolean bootFromISO, String guestOSDescription) {
super(vmName, storageHost, vols);
initialize(vm, offering, networkRate, multicastRate, router, imagePath, guestNetworkId, utilization, cpuWeight, bits, isoPath, bootFromISO, guestOSDescription);
}
private void initialize(UserVm vm,
ServiceOffering offering, int networkRate, int multicastRate, VirtualRouter router, String imagePath,
String guestNetworkId, int utilization, int cpuWeight, int bits, String isoPath, boolean bootFromISO, String guestOSDescription) {
id = vm.getId();
guestIpAddress = vm.getGuestIpAddress();
if (router != null)
gateway = router.getPrivateIpAddress();
ramSize = offering.getRamSize();
cpu = offering.getCpu();
this.utilization= utilization;
this.cpuWeight = cpuWeight;
this.imagePath = imagePath;
this.guestNetworkId = guestNetworkId;
guestMacAddress = vm.getGuestMacAddress();
vncPassword = vm.getVncPassword();
hostName = vm.getName();
networkRateMbps = networkRate;
networkRateMulticastMbps = multicastRate;
if (bits == 32) {
arch = "i686";
} else {
arch = "x86_64";
}
this.isoPath = isoPath;
this.bootFromISO = bootFromISO;
this.guestOSDescription = guestOSDescription;
}
public String getArch() {
return arch;
}
public String getHostName() {
return hostName;
}
protected StartCommand() {
super();
}
public StartCommand(UserVmVO vm, String vmName, ServiceOffering offering, int networkRate, int multicastRate,
VirtualRouter router, String[] storageIps, String imagePath,
String guestNetworkId, int utilization, int cpuWeight, List<VolumeVO> vols,
boolean mirroredVols, int bits, String isoPath, boolean bootFromISO, String guestOSDescription) {
super(vmName, storageIps, vols, mirroredVols);
initialize(vm, offering, networkRate, multicastRate, router, imagePath, guestNetworkId, utilization, cpuWeight, bits, isoPath, bootFromISO, guestOSDescription);
}
@Override
public boolean executeInSequence() {
return true;
}
public int getCpu() {
return cpu;
}
public int getUtilization() {
return utilization;
}
public int getCpuWeight() {
return cpuWeight;
}
public long getId() {
return id;
}
public String getGuestIpAddress() {
return guestIpAddress;
}
public String getGuestMacAddress() {
return guestMacAddress;
}
public String getVncPassword() {
return vncPassword;
}
public String getGateway() {
return gateway;
}
public String getGuestNetworkId() {
return guestNetworkId;
}
public int getRamSize() {
return ramSize;
}
public String getImagePath() {
return imagePath;
}
public int getNetworkRateMbps() {
return networkRateMbps;
}
public int getNetworkRateMulticastMbps() {
return networkRateMulticastMbps;
}
public String getISOPath() {
return isoPath;
}
public boolean getBootFromISO() {
return bootFromISO;
}
public void setExternalVlan(String vlanId) {
this.externalVlan = vlanId;
}
public String getExternalVlan() {
return externalVlan;
}
public String getExternalMacAddress() {
return externalMacAddress;
}
public void setExternalMacAddress(String externalMacAddress) {
this.externalMacAddress = externalMacAddress;
}
public String getGuestOSDescription() {
return this.guestOSDescription;
}
public void setGuestOSDescription(String guestOSDescription) {
this.guestOSDescription = guestOSDescription;
}
}

View File

@ -1,49 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
public class StartConsoleProxyAnswer extends Answer {
String privateIpAddress;
String privateMacAddress;
protected StartConsoleProxyAnswer() {
}
public StartConsoleProxyAnswer(StartConsoleProxyCommand cmd) {
super(cmd);
}
public StartConsoleProxyAnswer(StartConsoleProxyCommand cmd, String privateIp, String privateMac) {
super(cmd);
this.privateIpAddress = privateIp;
this.privateMacAddress = privateMac;
}
public String getPrivateIpAddress() {
return privateIpAddress;
}
public String getPrivateMacAddress() {
return privateMacAddress;
}
public StartConsoleProxyAnswer(StartConsoleProxyCommand cmd, String details) {
super(cmd, false, details);
}
}

View File

@ -1,122 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
import java.util.List;
import com.cloud.storage.VolumeVO;
import com.cloud.vm.ConsoleProxyVO;
public class StartConsoleProxyCommand extends AbstractStartCommand {
private ConsoleProxyVO proxy;
int networkRateMbps;
int networkRateMulticastMbps;
private int proxyCmdPort;
private String vncPort;
private String urlPort;
private String mgmt_host;
private int mgmt_port;
private boolean sslEnabled;
private String guestOSDescription;
protected StartConsoleProxyCommand() {
}
public StartConsoleProxyCommand(int networkRateMbps, int networkRateMulticastMbps, int proxyCmdPort,
ConsoleProxyVO proxy, String vmName, String storageHost,
List<VolumeVO> vols, String vncPort, String urlPort, String mgmtHost, int mgmtPort,
boolean sslEnabled, String guestOSDescription) {
super(vmName, storageHost, vols);
this.networkRateMbps = networkRateMbps;
this.networkRateMulticastMbps = networkRateMulticastMbps;
this.proxyCmdPort = proxyCmdPort;
this.proxy = new ConsoleProxyVO(proxy);
this.vncPort = vncPort;
this.urlPort = urlPort;
this.mgmt_host = mgmtHost;
this.mgmt_port = mgmtPort;
this.sslEnabled = sslEnabled;
this.guestOSDescription = guestOSDescription;
}
@Override
public boolean executeInSequence() {
return true;
}
public ConsoleProxyVO getProxy() {
return proxy;
}
public int getNetworkRateMbps() {
return networkRateMbps;
}
public String getGuestOSDescription() {
return guestOSDescription;
}
public int getNetworkRateMulticastMbps() {
return networkRateMulticastMbps;
}
public int getProxyCmdPort() {
return proxyCmdPort;
}
public String getVNCPort() {
return this.vncPort;
}
public String getURLPort() {
return this.urlPort;
}
public String getManagementHost() {
return mgmt_host;
}
public int getManagementPort() {
return mgmt_port;
}
public String getBootArgs() {
String eth1Ip = (proxy.getPrivateIpAddress() == null)? "0.0.0.0":proxy.getPrivateIpAddress();
String eth1NetMask = (proxy.getPrivateNetmask() == null) ? "0.0.0.0":proxy.getPrivateNetmask();
String eth2Ip = (proxy.getPublicIpAddress() == null)?"0.0.0.0" : proxy.getPublicIpAddress();
String eth2NetMask = (proxy.getPublicNetmask() == null) ? "0.0.0.0":proxy.getPublicNetmask();
String gateWay = (proxy.getGateway() == null) ? "0.0.0.0" : proxy.getGateway();
String basic = " eth0ip=" + proxy.getGuestIpAddress() + " eth0mask=" + proxy.getGuestNetmask() + " eth1ip="
+ eth1Ip + " eth1mask=" + eth1NetMask + " eth2ip="
+ eth2Ip + " eth2mask=" + eth2NetMask + " gateway=" + gateWay
+ " dns1=" + proxy.getDns1() + " type=consoleproxy"+ " name=" + proxy.getName() + " template=domP";
if (proxy.getDns2() != null) {
basic = basic + " dns2=" + proxy.getDns2();
}
basic = basic + " host=" + mgmt_host + " port=" + mgmt_port;
if(sslEnabled)
basic = basic + " premium=true";
if (proxy.getPrivateIpAddress() == null || proxy.getPublicIpAddress() == null) {
basic = basic + " bootproto=dhcp";
}
return basic;
}
}

View File

@ -1,54 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
/**
* @author chiradeep
*
*/
public class StartRouterAnswer extends Answer {
String privateIpAddress;
String privateMacAddress;
protected StartRouterAnswer() {
}
public StartRouterAnswer(StartRouterCommand cmd) {
super(cmd);
}
public StartRouterAnswer(StartRouterCommand cmd, String privateIp, String privateMac) {
super(cmd);
this.privateIpAddress = privateIp;
this.privateMacAddress = privateMac;
}
public String getPrivateIpAddress() {
return privateIpAddress;
}
public String getPrivateMacAddress() {
return privateMacAddress;
}
public StartRouterAnswer(StartRouterCommand cmd, String details) {
super(cmd, false, details);
}
}

View File

@ -1,112 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
import java.util.List;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.storage.VolumeVO;
import com.cloud.vm.DomainRouterVO;
public class StartRouterCommand extends AbstractStartCommand {
DomainRouterVO router;
int networkRateMbps;
int networkRateMulticastMbps;
private String guestOSDescription;
private String mgmt_host;
protected StartRouterCommand() {
super();
}
@Override
public boolean executeInSequence() {
return true;
}
public StartRouterCommand(DomainRouterVO router, int networkRateMbps, int networkRateMulticastMbps,
String routerName, String[] storageIps, List<VolumeVO> vols, boolean mirroredVols,
String guestOSDescription, String mgmtHost) {
super(routerName, storageIps, vols, mirroredVols);
this.router = new DomainRouterVO(router);
this.networkRateMbps = networkRateMbps;
this.networkRateMulticastMbps = networkRateMulticastMbps;
this.guestOSDescription = guestOSDescription;
this.mgmt_host = mgmtHost;
}
public VirtualRouter getRouter() {
return router;
}
public int getNetworkRateMbps() {
return networkRateMbps;
}
public String getGuestOSDescription() {
return guestOSDescription;
}
public int getNetworkRateMulticastMbps() {
return networkRateMulticastMbps;
}
public String getManagementHost() {
return mgmt_host;
}
public String getBootArgs() {
String eth2Ip = router.getPublicIpAddress()==null?"0.0.0.0":router.getPublicIpAddress();
String basic = " eth0ip=" + router.getGuestIpAddress() + " eth0mask=" + router.getGuestNetmask() + " eth1ip="
+ router.getPrivateIpAddress() + " eth1mask=" + router.getPrivateNetmask() + " gateway=" + router.getGateway()
+ " dns1=" + router.getDns1() + " name=" + router.getName() + " mgmtcidr=" + mgmt_host;
if (!router.getPublicMacAddress().equalsIgnoreCase("FE:FF:FF:FF:FF:FF")) {
basic = basic + " eth2ip=" + eth2Ip + " eth2mask=" + router.getPublicNetmask();
}
if (router.getDns2() != null) {
basic = basic + " dns2=" + router.getDns2();
}
if (getDhcpRange() != null) {
basic = basic + " dhcprange=" + getDhcpRange();
}
if (router.getRole() == Role.DHCP_FIREWALL_LB_PASSWD_USERDATA) {
basic = basic + " type=router";
} else if (router.getRole() == Role.DHCP_USERDATA) {
basic = basic + " type=dhcpsrvr";
}
if(router.getDomain() != null){
basic += " domain="+router.getDomain();
}
return basic;
}
public String getDhcpRange() {
String [] range = router.getDhcpRange();
String result = null;
if (range[0] != null) {
result = range[0];
}
return result;
}
}

View File

@ -1,48 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
public class StartSecStorageVmAnswer extends Answer {
String privateIpAddress;
String privateMacAddress;
protected StartSecStorageVmAnswer() {
}
public StartSecStorageVmAnswer(StartSecStorageVmCommand cmd) {
super(cmd);
}
public StartSecStorageVmAnswer(StartSecStorageVmCommand cmd, String privateIp, String privateMac) {
super(cmd);
this.privateIpAddress = privateIp;
this.privateMacAddress = privateMac;
}
public String getPrivateIpAddress() {
return privateIpAddress;
}
public String getPrivateMacAddress() {
return privateMacAddress;
}
public StartSecStorageVmAnswer(StartSecStorageVmCommand cmd, String details) {
super(cmd, false, details);
}
}

View File

@ -1,121 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
import java.net.URISyntaxException;
import java.util.List;
import com.cloud.storage.VolumeVO;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NfsUtils;
import com.cloud.vm.SecondaryStorageVmVO;
public class StartSecStorageVmCommand extends AbstractStartCommand {
private SecondaryStorageVmVO secStorageVm;
int networkRateMbps;
int networkRateMulticastMbps;
private int proxyCmdPort;
private String mgmt_host;
private int mgmt_port;
private boolean sslCopy;
private String guestOSDescription;
protected StartSecStorageVmCommand() {
}
public StartSecStorageVmCommand(int networkRateMbps, int networkRateMulticastMbps, int proxyCmdPort,
SecondaryStorageVmVO secStorageVm, String vmName, String storageHost,
List<VolumeVO> vols, String mgmtHost, int mgmtPort, boolean sslCopy, String guestOSDescription) {
super(vmName, storageHost, vols);
this.networkRateMbps = networkRateMbps;
this.networkRateMulticastMbps = networkRateMulticastMbps;
this.proxyCmdPort = proxyCmdPort;
this.secStorageVm = new SecondaryStorageVmVO(secStorageVm);
this.mgmt_host = mgmtHost;
this.mgmt_port = mgmtPort;
this.sslCopy = sslCopy;
this.guestOSDescription = guestOSDescription;
}
@Override
public boolean executeInSequence() {
return true;
}
public SecondaryStorageVmVO getSecondaryStorageVmVO() {
return secStorageVm;
}
public int getNetworkRateMbps() {
return networkRateMbps;
}
public String getGuestOSDescription() {
return guestOSDescription;
}
public int getNetworkRateMulticastMbps() {
return networkRateMulticastMbps;
}
public int getProxyCmdPort() {
return proxyCmdPort;
}
public String getManagementHost() {
return mgmt_host;
}
public int getManagementPort() {
return mgmt_port;
}
public String getBootArgs() {
String eth1Ip = (secStorageVm.getPrivateIpAddress() == null)? "0.0.0.0":secStorageVm.getPrivateIpAddress();
String eth1NetMask = (secStorageVm.getPrivateNetmask() == null) ? "0.0.0.0":secStorageVm.getPrivateNetmask();
String eth2Ip = (secStorageVm.getPublicIpAddress() == null)?"0.0.0.0" : secStorageVm.getPublicIpAddress();
String eth2NetMask = (secStorageVm.getPublicNetmask() == null) ? "0.0.0.0":secStorageVm.getPublicNetmask();
String gateWay = (secStorageVm.getGateway() == null) ? "0.0.0.0" : secStorageVm.getGateway();
String basic = " eth0ip=" + secStorageVm.getGuestIpAddress() + " eth0mask=" + secStorageVm.getGuestNetmask() + " eth1ip="
+ eth1Ip + " eth1mask=" + eth1NetMask + " eth2ip="
+ eth2Ip + " eth2mask=" + eth2NetMask + " gateway=" + gateWay
+ " dns1=" + secStorageVm.getDns1() + " type=secstorage" + " name=" + secStorageVm.getName() + " template=domP";
if (secStorageVm.getDns2() != null) {
basic = basic + " dns2=" + secStorageVm.getDns2();
}
basic = basic + " host=" + mgmt_host + " port=" + mgmt_port;
String mountStr = null;
try {
mountStr = NfsUtils.url2Mount(secStorageVm.getNfsShare());
} catch (URISyntaxException e1) {
throw new CloudRuntimeException("NFS url malformed in database? url=" + secStorageVm.getNfsShare());
}
basic = basic + " mount.path=" + mountStr + " guid=" + secStorageVm.getGuid();
basic = basic + " resource=com.cloud.storage.resource.NfsSecondaryStorageResource";
basic = basic + " instance=SecStorage";
basic = basic + " sslcopy=" + Boolean.toString(sslCopy);
if (secStorageVm.getPrivateIpAddress() == null || secStorageVm.getPublicIpAddress() == null) {
basic = basic + " bootproto=dhcp";
}
return basic;
}
}

View File

@ -108,14 +108,6 @@ import com.cloud.agent.api.SetupAnswer;
import com.cloud.agent.api.SetupCommand;
import com.cloud.agent.api.Start2Answer;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.StartAnswer;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartConsoleProxyAnswer;
import com.cloud.agent.api.StartConsoleProxyCommand;
import com.cloud.agent.api.StartRouterAnswer;
import com.cloud.agent.api.StartRouterCommand;
import com.cloud.agent.api.StartSecStorageVmAnswer;
import com.cloud.agent.api.StartSecStorageVmCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupStorageCommand;
@ -159,7 +151,6 @@ import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter;
import com.cloud.resource.ServerResource;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
@ -178,9 +169,7 @@ import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.State;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineName;
@ -374,10 +363,6 @@ public abstract class CitrixResourceBase implements ServerResource {
return execute((DhcpEntryCommand) cmd);
} else if (cmd instanceof VmDataCommand) {
return execute((VmDataCommand) cmd);
} else if (cmd instanceof StartCommand) {
return execute((StartCommand) cmd);
} else if (cmd instanceof StartRouterCommand) {
return execute((StartRouterCommand) cmd);
} else if (cmd instanceof ReadyCommand) {
return execute((ReadyCommand) cmd);
} else if (cmd instanceof GetHostStatsCommand) {
@ -430,10 +415,6 @@ public abstract class CitrixResourceBase implements ServerResource {
return execute((GetStorageStatsCommand) cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
return execute((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof StartConsoleProxyCommand) {
return execute((StartConsoleProxyCommand) cmd);
} else if (cmd instanceof StartSecStorageVmCommand) {
return execute((StartSecStorageVmCommand) cmd);
} else if (cmd instanceof GetVncPortCommand) {
return execute((GetVncPortCommand) cmd);
} else if (cmd instanceof SetupCommand) {
@ -554,9 +535,9 @@ public abstract class CitrixResourceBase implements ServerResource {
VBD.Record vbdr = new VBD.Record();
vbdr.VM = vm;
if (vdi != null)
vbdr.VDI = vdi;
else {
if (vdi != null) {
vbdr.VDI = vdi;
} else {
vbdr.empty = true;
}
if (type == VolumeType.ROOT && bootLoaderType == BootloaderType.PyGrub) {
@ -962,31 +943,6 @@ public abstract class CitrixResourceBase implements ServerResource {
return new SetupAnswer(cmd);
}
protected Answer execute(StartSecStorageVmCommand cmd) {
Connection conn = getConnection();
final String vmName = cmd.getVmName();
SecondaryStorageVmVO storage = cmd.getSecondaryStorageVmVO();
try {
Network network = Network.getByUuid(conn, _host.privateNetwork);
String bootArgs = cmd.getBootArgs();
bootArgs += " zone=" + _dcId;
bootArgs += " pod=" + _pod;
bootArgs += " localgw=" + _localGateway;
String result = startSystemVM(conn, vmName, storage.getVlanId(), network, cmd.getVolumes(), bootArgs, storage.getGuestMacAddress(), storage.getGuestIpAddress(), storage
.getPrivateMacAddress(), storage.getPublicMacAddress(), cmd.getProxyCmdPort(), storage.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps());
if (result == null) {
return new StartSecStorageVmAnswer(cmd);
}
return new StartSecStorageVmAnswer(cmd, result);
} catch (Exception e) {
String msg = "Exception caught while starting router vm " + vmName + " due to " + e.getMessage();
s_logger.warn(msg, e);
return new StartSecStorageVmAnswer(cmd, msg);
}
}
protected SetPortForwardingRulesAnswer execute(SetPortForwardingRulesCommand cmd) {
Connection conn = getConnection();
String args;
@ -2430,32 +2386,6 @@ public abstract class CitrixResourceBase implements ServerResource {
return answer;
}
protected VM createVmFromTemplate(Connection conn, StartCommand cmd) throws XenAPIException, XmlRpcException {
Set<VM> templates;
VM vm = null;
String stdType = cmd.getGuestOSDescription();
String guestOsTypeName = getGuestOsType(stdType, cmd.getBootFromISO());
templates = VM.getByNameLabel(conn, guestOsTypeName);
assert templates.size() == 1 : "Should only have 1 template but found " + templates.size();
VM template = templates.iterator().next();
vm = template.createClone(conn, cmd.getVmName());
vm.removeFromOtherConfig(conn, "disks");
if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) {
if (cmd.getBootFromISO()) {
vm.setPVBootloader(conn, "eliloader");
Map<String, String> otherConfig = vm.getOtherConfig(conn);
otherConfig.put( "install-repository", "cdrom");
vm.setOtherConfig(conn, otherConfig);
} else {
vm.setPVBootloader(conn, "pygrub");
}
}
return vm;
}
public boolean joinPool(String masterIp, String username, String password) {
Connection hostConn = null;
Connection poolConn = null;
@ -2617,142 +2547,6 @@ public abstract class CitrixResourceBase implements ServerResource {
vm.setMemoryStaticMax(conn, memsize);
}
protected StartAnswer execute(StartCommand cmd) {
Connection conn = getConnection();
State state = State.Stopped;
VM vm = null;
SR isosr = null;
List<Ternary<SR, VDI, VolumeVO>> mounts = null;
try {
synchronized (_vms) {
_vms.put(cmd.getVmName(), State.Starting);
}
List<VolumeVO> vols = cmd.getVolumes();
mounts = mount(conn, vols);
vm = createVmFromTemplate(conn, cmd);
long memsize = cmd.getRamSize() * 1024L * 1024L;
setMemory(conn, vm, memsize);
vm.setIsATemplate(conn, false);
vm.setVCPUsMax(conn, (long) cmd.getCpu());
vm.setVCPUsAtStartup(conn, (long) cmd.getCpu());
Host host = Host.getByUuid(conn, _host.uuid);
vm.setAffinity(conn, host);
Map<String, String> vcpuparam = new HashMap<String, String>();
vcpuparam.put("weight", Integer.toString(cmd.getCpuWeight()));
vcpuparam.put("cap", Integer.toString(cmd.getUtilization()));
vm.setVCPUsParams(conn, vcpuparam);
boolean bootFromISO = cmd.getBootFromISO();
/* create root VBD */
VBD.Record vbdr = new VBD.Record();
Ternary<SR, VDI, VolumeVO> mount = mounts.get(0);
vbdr.VM = vm;
vbdr.VDI = mount.second();
vbdr.bootable = !bootFromISO;
vbdr.userdevice = "0";
vbdr.mode = Types.VbdMode.RW;
vbdr.type = Types.VbdType.DISK;
VBD.create(conn, vbdr);
/* create data VBDs */
for (int i = 1; i < mounts.size(); i++) {
mount = mounts.get(i);
// vdi.setNameLabel(conn, cmd.getVmName() + "-DATA");
vbdr.VM = vm;
vbdr.VDI = mount.second();
vbdr.bootable = false;
vbdr.userdevice = Long.toString(mount.third().getDeviceId());
vbdr.mode = Types.VbdMode.RW;
vbdr.type = Types.VbdType.DISK;
vbdr.unpluggable = true;
VBD.create(conn, vbdr);
}
/* create CD-ROM VBD */
VBD.Record cdromVBDR = new VBD.Record();
cdromVBDR.VM = vm;
cdromVBDR.empty = true;
cdromVBDR.bootable = bootFromISO;
cdromVBDR.userdevice = "3";
cdromVBDR.mode = Types.VbdMode.RO;
cdromVBDR.type = Types.VbdType.CD;
VBD cdromVBD = VBD.create(conn, cdromVBDR);
/* insert the ISO VDI if isoPath is not null */
String isopath = cmd.getISOPath();
if (isopath != null) {
int index = isopath.lastIndexOf("/");
String mountpoint = isopath.substring(0, index);
URI uri = new URI(mountpoint);
isosr = createIsoSRbyURI(conn, uri, cmd.getVmName(), false);
String isoname = isopath.substring(index + 1);
VDI isovdi = getVDIbyLocationandSR(conn, isoname, isosr);
if (isovdi == null) {
String msg = " can not find ISO " + cmd.getISOPath();
s_logger.warn(msg);
return new StartAnswer(cmd, msg);
} else {
cdromVBD.insert(conn, isovdi);
}
}
createVIF(conn, vm, cmd.getGuestMacAddress(), cmd.getGuestNetworkId(), cmd.getNetworkRateMbps(), "0", false);
if (cmd.getExternalMacAddress() != null && cmd.getExternalVlan() != null) {
createVIF(conn, vm, cmd.getExternalMacAddress(), cmd.getExternalVlan(), 0, "1", true);
}
/* set action after crash as destroy */
vm.setActionsAfterCrash(conn, Types.OnCrashBehaviour.DESTROY);
vm.start(conn, false, true);
if (_canBridgeFirewall) {
String result = callHostPlugin(conn, "vmops", "default_network_rules",
"vmName", cmd.getVmName(),
"vmIP", cmd.getGuestIpAddress(),
"vmMAC", cmd.getGuestMacAddress(),
"vmID", Long.toString(cmd.getId()));
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program default network rules for vm " + cmd.getVmName());
} else {
s_logger.info("Programmed default network rules for vm " + cmd.getVmName());
}
}
state = State.Running;
return new StartAnswer(cmd);
} catch (Exception e) {
String msg = "Catch Exception: " + e.getClass().getName() + " due to " + e.toString();
s_logger.warn(msg, e);
startvmfailhandle(conn, vm, mounts);
removeSR(conn, isosr);
state = State.Stopped;
return new StartAnswer(cmd, msg);
} finally {
synchronized (_vms) {
_vms.put(cmd.getVmName(), state);
}
}
}
protected VIF createVIF(Connection conn, VM vm, String mac, int rate, String devNum, Network network) throws XenAPIException, XmlRpcException,
InternalErrorException {
VIF.Record vifr = new VIF.Record();
@ -2985,216 +2779,6 @@ public abstract class CitrixResourceBase implements ServerResource {
return connect(conn, vmname, ipAddress, 3922);
}
protected StartRouterAnswer execute(StartRouterCommand cmd) {
Connection conn = getConnection();
final String vmName = cmd.getVmName();
final VirtualRouter router = cmd.getRouter();
try {
String tag = router.getVnet();
Network network = null;
if ("untagged".equalsIgnoreCase(tag)) {
network = Network.getByUuid(conn, _host.guestNetwork);
} else {
network = enableVlanNetwork(conn, Long.parseLong(tag), _host.guestPif);
}
if (network == null) {
throw new InternalErrorException("Failed to enable VLAN network with tag: " + tag);
}
String bootArgs = cmd.getBootArgs();
String result = startSystemVM(conn, vmName, router.getVlanId(), network, cmd.getVolumes(), bootArgs, router.getGuestMacAddress(), router.getPrivateIpAddress(), router
.getPrivateMacAddress(), router.getPublicMacAddress(), 3922, router.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps());
if (result == null) {
networkUsage(conn, router.getPrivateIpAddress(), "create", null);
return new StartRouterAnswer(cmd);
}
return new StartRouterAnswer(cmd, result);
} catch (Exception e) {
String msg = "Exception caught while starting router vm " + vmName + " due to " + e.getMessage();
s_logger.warn(msg, e);
return new StartRouterAnswer(cmd, msg);
}
}
protected String startSystemVM(Connection conn, String vmName, String vlanId, Network nw0, List<VolumeVO> vols, String bootArgs, String guestMacAddr, String privateIp, String privateMacAddr,
String publicMacAddr, int cmdPort, long ramSize, String getGuestOSDescription, int networkRateMbps) {
setupLinkLocalNetwork(conn);
VM vm = null;
List<Ternary<SR, VDI, VolumeVO>> mounts = null;
State state = State.Stopped;
try {
synchronized (_vms) {
_vms.put(vmName, State.Starting);
}
mounts = mount(conn, vols);
assert mounts.size() == 1 : "System VMs should have only 1 partition but we actually have " + mounts.size();
Ternary<SR, VDI, VolumeVO> mount = mounts.get(0);
Set<VM> templates = VM.getByNameLabel(conn, getGuestOsType(getGuestOSDescription, false));
if (templates.size() == 0) {
String msg = " can not find systemvm template " + getGuestOsType(getGuestOSDescription, false) ;
s_logger.warn(msg);
return msg;
}
VM template = templates.iterator().next();
vm = template.createClone(conn, vmName);
vm.removeFromOtherConfig(conn, "disks");
vm.setPVBootloader(conn, "pygrub");
long memsize = ramSize * 1024L * 1024L;
setMemory(conn, vm, memsize);
vm.setIsATemplate(conn, false);
vm.setVCPUsAtStartup(conn, 1L);
Host host = Host.getByUuid(conn, _host.uuid);
vm.setAffinity(conn, host);
/* create VBD */
VBD.Record vbdr = new VBD.Record();
vbdr.VM = vm;
vbdr.VDI = mount.second();
vbdr.bootable = true;
vbdr.userdevice = "0";
vbdr.mode = Types.VbdMode.RW;
vbdr.type = Types.VbdType.DISK;
VBD.create(conn, vbdr);
/* create CD-ROM VBD */
createPatchVbd(conn, vmName, vm);
/* create VIF0 */
Network network = null;
if (VirtualMachineName.isValidConsoleProxyName(vmName) || VirtualMachineName.isValidSecStorageVmName(vmName, null)) {
network = Network.getByUuid(conn, _host.linkLocalNetwork);
} else {
network = nw0;
}
createVIF(conn, vm, guestMacAddr, networkRateMbps, "0", network);
/* create VIF1 */
/* For routing vm, set its network as link local bridge */
if (VirtualMachineName.isValidRouterName(vmName) && privateIp.startsWith("169.254")) {
network = Network.getByUuid(conn, _host.linkLocalNetwork);
} else {
network = Network.getByUuid(conn, _host.privateNetwork);
}
createVIF(conn, vm, privateMacAddr, networkRateMbps, "1", network);
/* create VIF2 */
if( !publicMacAddr.equalsIgnoreCase("FE:FF:FF:FF:FF:FF") ) {
network = null;
if ("untagged".equalsIgnoreCase(vlanId)) {
network = Network.getByUuid(conn, _host.publicNetwork);
} else {
network = enableVlanNetwork(conn, Long.valueOf(vlanId), _host.publicPif);
if (network == null) {
throw new InternalErrorException("Failed to enable VLAN network with tag: " + vlanId);
}
}
createVIF(conn, vm, publicMacAddr, networkRateMbps, "2", network);
}
/* set up PV dom argument */
String pvargs = vm.getPVArgs(conn);
pvargs = pvargs + bootArgs;
if (s_logger.isInfoEnabled()) {
s_logger.info("PV args for system vm are " + pvargs);
}
vm.setPVArgs(conn, pvargs);
/* destroy console */
Set<Console> consoles = vm.getRecord(conn).consoles;
for (Console console : consoles) {
console.destroy(conn);
}
/* set action after crash as destroy */
vm.setActionsAfterCrash(conn, Types.OnCrashBehaviour.DESTROY);
vm.start(conn, false, true);
if (_canBridgeFirewall) {
String result = callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", vmName);
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program default system vm network rules for " + vmName);
} else {
s_logger.info("Programmed default system vm network rules for " + vmName);
}
}
if (s_logger.isInfoEnabled()) {
s_logger.info("Ping system vm command port, " + privateIp + ":" + cmdPort);
}
state = State.Running;
String result = connect(conn, vmName, privateIp, cmdPort);
if (result != null) {
String msg = "Can not ping System vm " + vmName + "due to:" + result;
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
} else {
if (s_logger.isInfoEnabled()) {
s_logger.info("Ping system vm command port succeeded for vm " + vmName);
}
}
return null;
} catch (Exception e) {
String msg = "Catch Exception: " + e.getClass().getName() + " while starting System vm " + vmName + " due to " + e.toString();
s_logger.warn(msg, e);
startvmfailhandle(conn, vm, mounts);
state = State.Stopped;
return msg;
} finally {
synchronized (_vms) {
_vms.put(vmName, state);
}
}
}
// TODO : need to refactor it to reuse code with StartRouter
protected Answer execute(final StartConsoleProxyCommand cmd) {
Connection conn = getConnection();
final String vmName = cmd.getVmName();
final ConsoleProxyVO proxy = cmd.getProxy();
try {
Network network = Network.getByUuid(conn, _host.privateNetwork);
String bootArgs = cmd.getBootArgs();
bootArgs += " zone=" + _dcId;
bootArgs += " pod=" + _pod;
bootArgs += " guid=Proxy." + proxy.getId();
bootArgs += " proxy_vm=" + proxy.getId();
bootArgs += " localgw=" + _localGateway;
String result = startSystemVM(conn, vmName, proxy.getVlanId(), network, cmd.getVolumes(), bootArgs, proxy.getGuestMacAddress(), proxy.getGuestIpAddress(), proxy
.getPrivateMacAddress(), proxy.getPublicMacAddress(), cmd.getProxyCmdPort(), proxy.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps());
if (result == null) {
return new StartConsoleProxyAnswer(cmd);
}
return new StartConsoleProxyAnswer(cmd, result);
} catch (Exception e) {
String msg = "Exception caught while starting router vm " + vmName + " due to " + e.getMessage();
s_logger.warn(msg, e);
return new StartConsoleProxyAnswer(cmd, msg);
}
}
protected boolean isDeviceUsed(Connection conn, VM vm, Long deviceId) {
// Figure out the disk number to attach the VM to

View File

@ -40,8 +40,7 @@ import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.PingTestCommand;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartRouterCommand;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.transport.Request;
@ -101,7 +100,7 @@ public abstract class AgentAttache {
public final static String[] s_commandsAllowedInMaintenanceMode =
new String[] { MaintainCommand.class.toString(), MigrateCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), ReadyCommand.class.toString() };
protected final static String[] s_commandsNotAllowedInConnectingMode =
new String[] { StartCommand.class.toString(), StartRouterCommand.class.toString(), CreateCommand.class.toString() };
new String[] { Start2Command.class.toString(), CreateCommand.class.toString() };
static {
Arrays.sort(s_commandsAllowedInMaintenanceMode);
Arrays.sort(s_commandsNotAllowedInConnectingMode);

View File

@ -1,57 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.async.executor;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobVO;
import com.cloud.serializer.GsonHelper;
import com.google.gson.Gson;
public class StartVMExecutor extends VMOperationExecutor {
public static final Logger s_logger = Logger.getLogger(StartVMExecutor.class.getName());
public boolean execute() {
Gson gson = GsonHelper.getBuilder().create();
AsyncJobManager asyncMgr = getAsyncJobMgr();
AsyncJobVO job = getJob();
if(getSyncSource() == null) {
VMOperationParam param = gson.fromJson(job.getCmdInfo(), VMOperationParam.class);
asyncMgr.syncAsyncJobExecution(job, "UserVM", param.getVmId());
// always true if it does not have sync-source
return true;
} else {
VMOperationParam param = gson.fromJson(job.getCmdInfo(), VMOperationParam.class);
return asyncMgr.getExecutorContext().getVmMgr().executeStartVM(this, param);
}
}
public void processAnswer(VMOperationListener listener, long agentId, long seq, Answer answer) {
}
public void processDisconnect(VMOperationListener listener, long agentId) {
}
public void processTimeout(VMOperationListener listener, long agentId, long seq) {
}
}

View File

@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -52,8 +51,6 @@ import com.cloud.agent.api.ConsoleProxyLoadReportCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.StartConsoleProxyAnswer;
import com.cloud.agent.api.StartConsoleProxyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupProxyCommand;
import com.cloud.agent.api.StopAnswer;
@ -79,7 +76,6 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.event.Event;
@ -107,11 +103,9 @@ import com.cloud.info.RunningHostInfoAgregator;
import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
import com.cloud.maid.StackMaid;
import com.cloud.network.IpAddrAllocator;
import com.cloud.network.IpAddrAllocator.networkInfo;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
@ -119,7 +113,6 @@ import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.servlet.ConsoleProxyServlet;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateHostVO;
@ -149,7 +142,6 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.events.SubscriptionMgr;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
@ -189,7 +181,6 @@ import com.google.gson.GsonBuilder;
public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProxyService, Manager, AgentHook, VirtualMachineGuru<ConsoleProxyVO> {
private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class);
private static final int DEFAULT_FIND_HOST_RETRY_COUNT = 2;
private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30
// seconds
private static final int EXECUTOR_SHUTDOWN_TIMEOUT = 1000; // 1 second
@ -217,12 +208,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
@Inject
private DataCenterDao _dcDao;
@Inject
private VlanDao _vlanDao;
@Inject
private VMTemplateDao _templateDao;
@Inject
private IPAddressDao _ipAddressDao;
@Inject
private VolumeDao _volsDao;
@Inject
private HostPodDao _podDao;
@ -239,7 +226,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
@Inject private VMTemplateHostDao _vmTemplateHostDao;
@Inject private AgentManager _agentMgr;
@Inject private StorageManager _storageMgr;
@Inject private HighAvailabilityManager _haMgr;
@Inject NetworkManager _networkMgr;
@Inject AccountService _accountMgr;
@Inject private EventDao _eventDao;
@ -253,8 +239,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
private ConsoleProxyListener _listener;
private ServiceOfferingVO _serviceOffering;
private int _networkRate;
private int _multicastRate;
private VMTemplateVO _template;
NetworkOfferingVO _publicNetworkOffering;
@ -267,9 +251,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
@Inject
private VirtualMachineManager _itMgr;
@Inject
private ClusterManager _clMgr;
private final ScheduledExecutorService _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("CP-Scan"));
private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new NamedThreadFactory("Request-handler"));
@ -278,7 +259,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
private int _standbyCapacity = ConsoleProxyManager.DEFAULT_STANDBY_CAPACITY;
private int _proxyRamSize;
private int _find_host_retry = DEFAULT_FIND_HOST_RETRY_COUNT;
private int _ssh_retry;
private int _ssh_sleep;
private boolean _use_lvm;
@ -287,8 +267,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
private String _domain;
private String _instance;
private boolean _useNewNetworking = false;
// private String _privateNetmask;
private int _proxyCmdPort = DEFAULT_PROXY_CMD_PORT;
private int _proxySessionTimeoutValue = DEFAULT_PROXY_SESSION_TIMEOUT;
@ -556,7 +534,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
@Override
public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) {
try {
return start2(proxyVmId, startEventId);
return start(proxyVmId, startEventId);
} catch (StorageUnavailableException e) {
s_logger.warn("Exception while trying to start console proxy", e);
return null;
@ -569,301 +547,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
}
public ConsoleProxyVO start2(long proxyVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException {
if (!_useNewNetworking) {
return start(proxyVmId, startEventId);
}
@Override
public ConsoleProxyVO start(long proxyVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException {
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
Account systemAcct = _accountMgr.getSystemAccount();
User systemUser = _accountMgr.getSystemUser();
return _itMgr.start(proxy, null, systemUser, systemAcct, null);
}
@Override
@DB
public ConsoleProxyVO start(long proxyId, long startEventId) throws InsufficientCapacityException,
StorageUnavailableException {
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
if (asyncExecutor != null) {
AsyncJobVO job = asyncExecutor.getJob();
if (s_logger.isInfoEnabled()) {
s_logger.info("Start console proxy " + proxyId + ", update async job-" + job.getId());
}
_asyncMgr.updateAsyncJobAttachment(job.getId(), "console_proxy", proxyId);
}
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyId);
if (proxy == null || proxy.getRemoved() != null) {
s_logger.debug("proxy is not found: " + proxyId);
return null;
}
/*
* // don't insert event here, it may be called multiple times!
* saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM,
* EventTypes.EVENT_PROXY_START, "Starting console proxy with Id: " +
* proxyId, startEventId);
*/
if (s_logger.isTraceEnabled()) {
s_logger.trace("Starting console proxy if it is not started, proxy vm id : " + proxyId);
}
for (int i = 0; i < 2; i++) {
State state = proxy.getState();
if (state == State.Starting /* || state == State.Migrating */) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Waiting console proxy to be ready, proxy vm id : " + proxyId + " proxy VM state : " + state.toString());
}
if (proxy.getPrivateIpAddress() == null || connect(proxy.getPrivateIpAddress(), _proxyCmdPort) != null) {
if (proxy.getPrivateIpAddress() == null) {
s_logger.warn("Retruning a proxy that is being started but private IP has not been allocated yet, proxy vm id : " + proxyId);
} else {
s_logger.warn("Waiting console proxy to be ready timed out, proxy vm id : " + proxyId);
}
// TODO, it is very tricky here, if the startup process
// takes too long and it timed out here,
// we may give back a proxy that is not fully ready for
// functioning
}
return proxy;
}
if (state == State.Running) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Console proxy is already started: " + proxy.getName());
}
return proxy;
}
DataCenterVO dc = _dcDao.findById(proxy.getDataCenterId());
HostPodVO pod = _podDao.findById(proxy.getPodId());
StoragePoolVO sp = _storageMgr.getStoragePoolForVm(proxy.getId());
HashSet<Host> avoid = new HashSet<Host>();
HostVO routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _serviceOffering, _template, proxy, null, avoid);
if (routingHost == null) {
if (s_logger.isDebugEnabled()) {
String msg = "Unable to find a routing host for " + proxy.toString() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
}
// to ensure atomic state transition to Starting state
if (!_itMgr.stateTransitTo(proxy, com.cloud.vm.VirtualMachine.Event.StartRequested, routingHost.getId())) {
if (s_logger.isDebugEnabled()) {
ConsoleProxyVO temp = _consoleProxyDao.findById(proxyId);
s_logger.debug("Unable to start console proxy " + proxy.getName() + " because it is not in a startable state : "
+ ((temp != null) ? temp.getState().toString() : "null"));
}
continue;
}
try {
Answer answer = null;
int retry = _find_host_retry;
// Console proxy VM will be running at routing hosts as routing
// hosts have public access to outside network
do {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to start console proxy on host " + routingHost.getName());
}
String privateIpAddress = allocPrivateIpAddress(proxy.getDataCenterId(), routingHost.getPodId(), proxy.getId(),
proxy.getPrivateMacAddress());
if (privateIpAddress == null && (_IpAllocator != null && !_IpAllocator.exteralIpAddressAllocatorEnabled())) {
String msg = "Unable to allocate private ip addresses for " + proxy.getName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
proxy.setPrivateIpAddress(privateIpAddress);
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(proxy.getDataCenterId(), routingHost.getPodId(), proxy.getId(), null);
proxy.setGuestIpAddress(guestIpAddress);
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.OperationRetry, routingHost.getId());
proxy = _consoleProxyDao.findById(proxy.getId());
List<VolumeVO> vols = _storageMgr.prepare(proxy, routingHost);
if (vols == null || vols.size() == 0) {
String msg = "Unable to prepare storage for " + proxy.getName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
// Determine the VM's OS description
String guestOSDescription;
GuestOSVO guestOS = _guestOSDao.findById(proxy.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ proxy.getGuestOSId() + " for vm: " + proxy.getName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
guestOSDescription = guestOS.getDisplayName();
}
// _storageMgr.share(proxy, vols, null, true);
// carry the console proxy port info over so that we don't
// need to configure agent on this
StartConsoleProxyCommand cmdStart = new StartConsoleProxyCommand(_networkRate, _multicastRate,
_proxyCmdPort, proxy, proxy.getName(), "", vols, Integer.toString(_consoleProxyPort),
Integer.toString(_consoleProxyUrlPort), _mgmt_host, _mgmt_port, _sslEnabled, guestOSDescription);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending start command for console proxy " + proxy.getName() + " to " + routingHost.getName());
}
try {
answer = _agentMgr.send(routingHost.getId(), cmdStart);
s_logger.debug("StartConsoleProxy Answer: " + (answer != null ? answer : "null"));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Received answer on starting console proxy " + proxy.getName() + " on " + routingHost.getName());
}
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy " + proxy.getName() + " started on " + routingHost.getName());
}
if (answer instanceof StartConsoleProxyAnswer) {
StartConsoleProxyAnswer rAnswer = (StartConsoleProxyAnswer) answer;
if (rAnswer.getPrivateIpAddress() != null) {
proxy.setPrivateIpAddress(rAnswer.getPrivateIpAddress());
}
if (rAnswer.getPrivateMacAddress() != null) {
proxy.setPrivateMacAddress(rAnswer.getPrivateMacAddress());
}
}
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_START);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Console proxy started - " + proxy.getName());
_eventDao.persist(event);
break;
}
s_logger.debug("Unable to start " + proxy.toString() + " on host " + routingHost.toString() + " due to "
+ answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + proxy.getName()
+ " due to operation timed out and it is active so scheduling a restart.");
_haMgr.scheduleRestart(proxy, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + proxy.getName());
}
avoid.add(routingHost);
proxy.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
proxy.setGuestIpAddress(null);
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId());
_storageMgr.unshare(proxy, vols, routingHost);
} while (--retry > 0
&& (routingHost = (HostVO) _agentMgr
.findHost(Host.Type.Routing, dc, pod, sp, _serviceOffering, _template, proxy, null, avoid)) != null);
if (routingHost == null || retry <= 0) {
SubscriptionMgr.getInstance().notifySubscribers(
ConsoleProxyManager.ALERT_SUBJECT,
this,
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_START_FAILURE, proxy.getDataCenterId(), proxy.getId(),
proxy, "Unable to find a routing host to run"));
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting console proxy failed due to unable to find a host - " + proxy.getName());
_eventDao.persist(event);
throw new ExecutionException("Couldn't find a routingHost to run console proxy");
}
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.OperationSucceeded, routingHost.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy is now started, vm id : " + proxy.getId());
}
// If starting the console proxy failed due to the external
// firewall not being reachable, send an alert.
if (answer != null && answer.getDetails() != null && answer.getDetails().equals("firewall")) {
SubscriptionMgr.getInstance().notifySubscribers(
ConsoleProxyManager.ALERT_SUBJECT,
this,
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_FIREWALL_ALERT, proxy.getDataCenterId(), proxy.getId(),
proxy, null));
}
SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this,
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_UP, proxy.getDataCenterId(), proxy.getId(), proxy, null));
return proxy;
} catch (Throwable thr) {
s_logger.warn("Unexpected exception: ", thr);
SubscriptionMgr.getInstance().notifySubscribers(
ConsoleProxyManager.ALERT_SUBJECT,
this,
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_START_FAILURE, proxy.getDataCenterId(), proxy.getId(), proxy,
"Unexpected exception: " + thr.getMessage()));
/*
* final EventVO event = new EventVO();
* event.setUserId(User.UID_SYSTEM);
* event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
* event.setType(EventTypes.EVENT_PROXY_START);
* event.setLevel(EventVO.LEVEL_ERROR);
* event.setStartId(startEventId); event.setDescription(
* "Starting console proxy failed due to unhandled exception - "
* + proxy.getName()); _eventDao.persist(event);
*/
Transaction txn = Transaction.currentTxn();
try {
txn.start();
String privateIpAddress = proxy.getPrivateIpAddress();
if (privateIpAddress != null) {
proxy.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
}
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.OperationFailed, null);
txn.commit();
} catch (Exception e) {
s_logger.error("Caught exception during error recovery");
}
if (thr instanceof StorageUnavailableException) {
throw (StorageUnavailableException) thr;
} else if (thr instanceof ExecutionException) {
s_logger.error("Error while starting console proxy due to " + thr.getMessage());
} else {
s_logger.error("Error while starting console proxy ", thr);
}
return null;
}
}
s_logger.warn("Starting console proxy encounters non-startable situation");
return null;
}
public ConsoleProxyVO assignProxyFromRunningPool(long dataCenterId) {
if (s_logger.isTraceEnabled()) {
@ -915,7 +606,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
}
Map<String, Object> context = _useNewNetworking ? createProxyInstance2(dataCenterId) : createProxyInstance(dataCenterId);
Map<String, Object> context = createProxyInstance(dataCenterId);
long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
@ -923,11 +614,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.trace("Creating proxy instance failed, data center id : " + dataCenterId);
}
// release critical system resource on failure
if (context.get("publicIpAddress") != null) {
freePublicIpAddress((String) context.get("publicIpAddress"), dataCenterId, 0);
}
return null;
}
@ -959,7 +645,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
}
Map<String, Object> context = _useNewNetworking ? createProxyInstance2(dataCenterId) : createProxyInstance(dataCenterId);
Map<String, Object> context = createProxyInstance(dataCenterId);
long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
@ -967,11 +653,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.trace("Creating proxy instance failed, data center id : " + dataCenterId);
}
// release critical system resource on failure
if (context.get("publicIpAddress") != null) {
freePublicIpAddress((String) context.get("publicIpAddress"), dataCenterId, 0);
}
return null;
}
@ -997,102 +678,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
return null;
}
@DB
protected Map<String, Object> createProxyInstance(long dataCenterId) {
Map<String, Object> context = new HashMap<String, Object>();
String publicIpAddress = null;
Transaction txn = Transaction.currentTxn();
try {
DataCenterVO dc = _dcDao.findById(dataCenterId);
assert (dc != null);
context.put("dc", dc);
// this will basically allocate the pod based on data center id as
// we use system user id here
Set<Long> avoidPods = new HashSet<Long>();
Pair<HostPodVO, Long> pod = null;
networkInfo publicIpAndVlan = null;
// About MAC address allocation
// MAC address used by User VM is inherited from DomR MAC address,
// with the least 16 bits overrided. to avoid
// potential conflicts, domP will mask bit 31
//
String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(dataCenterId, (1L << 31));
String privateMacAddress = macAddresses[0];
String publicMacAddress = macAddresses[1];
macAddresses = _dcDao.getNextAvailableMacAddressPair(dataCenterId, (1L << 31));
String guestMacAddress = macAddresses[0];
while ((pod = _agentMgr.findPod(_template, _serviceOffering, dc, Account.ACCOUNT_ID_SYSTEM, avoidPods)) != null) {
publicIpAndVlan = allocPublicIpAddress(dataCenterId, pod.first().getId(), publicMacAddress);
if (publicIpAndVlan == null) {
s_logger.warn("Unable to allocate public IP address for console proxy vm in data center : " + dataCenterId + ", pod="
+ pod.first().getId());
avoidPods.add(pod.first().getId());
} else {
break;
}
}
if (pod == null || publicIpAndVlan == null) {
String msg = "Unable to allocate pod for console proxy vm in data center : " + dataCenterId;
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
context.put("publicIpAddress", publicIpAndVlan._ipAddr);
context.put("pod", pod);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Pod allocated " + pod.first().getName());
}
String cidrNetmask = NetUtils.getCidrNetmask(pod.first().getCidrSize());
// Find the VLAN ID, VLAN gateway, and VLAN netmask for
// publicIpAddress
publicIpAddress = publicIpAndVlan._ipAddr;
String vlanGateway = publicIpAndVlan._gateWay;
String vlanNetmask = publicIpAndVlan._netMask;
Account systemAccount = _accountMgr.getSystemAccount();
txn.start();
ConsoleProxyVO proxy;
String name = VirtualMachineName.getConsoleProxyName(id, _instance).intern();
proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), privateMacAddress, null, cidrNetmask,
_template.getId(), _template.getGuestOSId(), publicMacAddress, publicIpAddress, vlanNetmask, publicIpAndVlan._vlanDbId,
publicIpAndVlan._vlanid, pod.first().getId(), dataCenterId, systemAccount.getDomainId(), systemAccount.getId(), vlanGateway, null, dc.getDns1(), dc.getDns2(), _domain,
_proxyRamSize, 0);
proxy.setLastHostId(pod.second());
proxy = _consoleProxyDao.persist(proxy);
long proxyVmId = proxy.getId();
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_CREATE);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("New console proxy created - " + proxy.getName());
_eventDao.persist(event);
txn.commit();
context.put("proxyVmId", proxyVmId);
return context;
} catch (Throwable e) {
s_logger.error("Unexpected exception : ", e);
context.put("proxyVmId", (long) 0);
return context;
}
}
protected Map<String, Object> createProxyInstance2(long dataCenterId) throws ConcurrentOperationException {
protected Map<String, Object> createProxyInstance(long dataCenterId) throws ConcurrentOperationException {
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
String name = VirtualMachineName.getConsoleProxyName(id, _instance);
@ -1172,56 +758,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
}
private networkInfo allocPublicIpAddress(long dcId, long podId, String macAddr) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
IpAddrAllocator.IpAddr ip = _IpAllocator.getPublicIpAddress(macAddr, dcId, podId);
networkInfo net = new networkInfo(ip.ipaddr, ip.netMask, ip.gateway, null, "untagged");
return net;
}
// Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN, VlanType.VirtualNetwork,
// true);
//
// if (ipAndVlan == null) {
// s_logger.debug("Unable to get public ip address (type=Virtual) for console proxy vm for data center : " + dcId);
// ipAndVlan = _vlanDao.assignPodDirectAttachIpAddress(dcId, podId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN);
// if (ipAndVlan == null) {
// s_logger.debug("Unable to get public ip address (type=DirectAttach) for console proxy vm for data center : " + dcId);
// }
// }
// if (ipAndVlan != null) {
// VlanVO vlan = ipAndVlan.second();
// networkInfo net = new networkInfo(ipAndVlan.first(), vlan.getVlanNetmask(), vlan.getVlanGateway(), vlan.getId(), vlan.getVlanId());
// return net;
// }
return null;
}
private String allocPrivateIpAddress(Long dcId, Long podId, Long proxyId, String macAddr) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
} else {
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId, null).first();
}
}
private void freePrivateIpAddress(String ipAddress, Long dcId, Long podId) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
_IpAllocator.releasePrivateIpAddress(ipAddress, dcId, podId);
} else {
_dcDao.releasePrivateIpAddress(ipAddress, dcId, podId);
}
}
private void freePublicIpAddress(String ipAddress, long dcId, long podId) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
_IpAllocator.releasePublicIpAddress(ipAddress, dcId, podId);
} else {
_ipAddressDao.unassignIpAddress(ipAddress);
}
}
private ConsoleProxyAllocator getCurrentAllocator() {
// for now, only one adapter is supported
Enumeration<ConsoleProxyAllocator> it = _consoleProxyAllocators.enumeration();
@ -1526,7 +1062,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
try {
if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
readyProxy = start2(readyProxy.getId(), 0);
readyProxy = start(readyProxy.getId(), 0);
} finally {
proxyLock.unlock();
}
@ -1888,7 +1424,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
String privateIpAddress = proxy.getPrivateIpAddress();
if (privateIpAddress != null) {
proxy.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
// freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
}
String guestIpAddress = proxy.getGuestIpAddress();
if (guestIpAddress != null) {
@ -2080,7 +1616,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
// release critical system resources used by the VM before we
// delete them
if (vm.getPublicIpAddress() != null) {
freePublicIpAddress(vm.getPublicIpAddress(), vm.getDataCenterId(), vm.getPodId());
// freePublicIpAddress(vm.getPublicIpAddress(), vm.getDataCenterId(), vm.getPodId());
}
vm.setPublicIpAddress(null);
@ -2116,7 +1652,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId);
if (proxy != null) {
if (proxy.getPublicIpAddress() != null) {
freePublicIpAddress(proxy.getPublicIpAddress(), proxy.getDataCenterId(), proxy.getPodId());
// freePublicIpAddress(proxy.getPublicIpAddress(), proxy.getDataCenterId(), proxy.getPodId());
}
_consoleProxyDao.remove(vmId);
@ -2362,10 +1898,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_proxyRamSize = NumbersUtil.parseInt(configs.get("consoleproxy.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
String value = configs.get("start.retry");
_find_host_retry = NumbersUtil.parseInt(value, DEFAULT_FIND_HOST_RETRY_COUNT);
value = configs.get("consoleproxy.cmd.port");
String value = configs.get("consoleproxy.cmd.port");
_proxyCmdPort = NumbersUtil.parseInt(value, DEFAULT_PROXY_CMD_PORT);
value = configs.get("consoleproxy.sslEnabled");
@ -2400,8 +1933,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_use_storage_vm = true;
}
_useNewNetworking = Boolean.parseBoolean(configs.get("use.new.networking"));
if (s_logger.isInfoEnabled()) {
s_logger.info("Console proxy max session soft limit : " + _capacityPerProxy);
s_logger.info("Console proxy standby capacity : " + _standbyCapacity);
@ -2440,12 +1971,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_listener = new ConsoleProxyListener(this);
_agentMgr.registerForHostEvents(_listener, true, true, false);
Adapters<IpAddrAllocator> ipAllocators = locator.getAdapters(IpAddrAllocator.class);
if (ipAllocators != null && ipAllocators.isSet()) {
Enumeration<IpAddrAllocator> it = ipAllocators.enumeration();
_IpAllocator = it.nextElement();
}
HighAvailabilityManager haMgr = locator.getManager(HighAvailabilityManager.class);
if (haMgr != null) {
haMgr.registerHandler(VirtualMachine.Type.ConsoleProxy, this);
@ -2453,10 +1978,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_itMgr.registerGuru(VirtualMachine.Type.ConsoleProxy, this);
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
_networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
_multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
_serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual,
useLocalStorage, true, null, true);
_serviceOffering.setUniqueName("Cloud.com-ConsoleProxy");
@ -2559,10 +2080,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
}
if (controlNic == null) {
throw new CloudRuntimeException("Didn't start a control port");
}
profile.setParameter("control.nic", controlNic);
return true;

View File

@ -21,9 +21,6 @@ import java.util.List;
import java.util.Map;
import com.cloud.api.commands.UpgradeRouterCmd;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.VlanVO;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -36,14 +33,12 @@ import com.cloud.network.Network;
import com.cloud.network.RemoteAccessVpnVO;
import com.cloud.network.VpnUserVO;
import com.cloud.network.rules.FirewallRule;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Manager;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachineProfile;
/**
@ -53,28 +48,6 @@ import com.cloud.vm.VirtualMachineProfile;
public interface DomainRouterManager extends Manager {
public static final int DEFAULT_ROUTER_VM_RAMSIZE = 128; // 128M
public static final boolean USE_POD_VLAN = false;
/**
* create the router.
*
* @param accountId account Id the router belongs to.
* @param ipAddress public ip address the router should use to access the internet.
* @param dcId data center id the router should live in.
* @param domain domain name of this network.
* @param offering service offering associated with this request
* @return DomainRouterVO if created. null if not.
*/
DomainRouterVO createRouter(long accountId, String ipAddress, long dcId, String domain, ServiceOfferingVO offering, long startEventId) throws ConcurrentOperationException;
/**
* create a DHCP server/user data server for directly connected VMs
* @param userId the user id of the user creating the router.
* @param accountId the account id of the user creating the router.
* @param dcId data center id the router should live in.
* @param domain domain name of this network.
* @return DomainRouterVO if created. null if not.
*/
DomainRouterVO createDhcpServerForDirectlyAttachedGuests(long userId, long accountId, DataCenterVO dc, HostPodVO pod, Long candidateHost, VlanVO vlan) throws ConcurrentOperationException;
/**
/*
* Send ssh public/private key pair to specified host
@ -93,10 +66,6 @@ public interface DomainRouterManager extends Manager {
*/
boolean savePasswordToRouter(long routerId, String vmIpAddress, String password);
DomainRouterVO startRouter(long routerId, long eventId);
boolean releaseRouter(long routerId);
boolean destroyRouter(long routerId);
boolean stopRouter(long routerId, long eventId);
@ -117,34 +86,7 @@ public interface DomainRouterManager extends Manager {
*/
DomainRouterVO getRouter(long routerId);
/**
* Add a DHCP entry on the domr dhcp server
* @param routerHostId - the host id of the domr
* @param routerIp - the private ip address of the domr
* @param vmName - the name of the VM (e.g., i-10-TEST)
* @param vmMac - the mac address of the eth0 interface of the VM
* @param vmIp - the ip address to hand out.
* @return success or failure
*/
public boolean addDhcpEntry(long routerHostId, String routerIp, String vmName, String vmMac, String vmIp);
/**
* Adds a virtual machine into the guest network.
* 1. Starts the domR
* 2. Sets the dhcp Entry on the domR
* 3. Sets the domR
*
* @param vm user vm to add to the guest network
* @param password password for this vm. Can be null
* @return DomainRouterVO if everything is successful. null if not.
*
* @throws ConcurrentOperationException if multiple starts are being attempted.
*/
public DomainRouterVO addVirtualMachineToGuestNetwork(UserVmVO vm, String password, long startEventId) throws ConcurrentOperationException;
String createZoneVlan(DomainRouterVO router);
VirtualRouter upgradeRouter(UpgradeRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
VirtualRouter upgradeRouter(UpgradeRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
DomainRouterVO getRouter(long accountId, long zoneId);
DomainRouterVO getRouter(String publicIpAddress);

View File

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -40,17 +39,12 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckVirtualMachineAnswer;
import com.cloud.agent.api.CheckVirtualMachineCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.CreateZoneVlanAnswer;
import com.cloud.agent.api.CreateZoneVlanCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.ModifySshKeysCommand;
import com.cloud.agent.api.NetworkUsageAnswer;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootAnswer;
import com.cloud.agent.api.RebootRouterCommand;
import com.cloud.agent.api.StartRouterAnswer;
import com.cloud.agent.api.StartRouterCommand;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
@ -78,8 +72,6 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ResourceLimitDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.AccountVlanMapDao;
import com.cloud.dc.dao.DataCenterDao;
@ -87,7 +79,6 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.Event;
import com.cloud.event.EventTypes;
@ -142,7 +133,6 @@ import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
@ -155,7 +145,6 @@ import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountService;
import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.user.UserContext;
import com.cloud.user.UserStatisticsVO;
@ -294,323 +283,6 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
}
}
@Override
@DB
public DomainRouterVO createDhcpServerForDirectlyAttachedGuests(long userId, long accountId, DataCenterVO dc, HostPodVO pod, Long candidateHost, VlanVO guestVlan) throws ConcurrentOperationException{
final AccountVO account = _accountDao.findById(accountId);
boolean podVlan = guestVlan.getVlanType().equals(VlanType.DirectAttached) && guestVlan.getVlanId().equals(Vlan.UNTAGGED);
long accountIdForDHCPServer = podVlan ? Account.ACCOUNT_ID_SYSTEM : accountId;
long domainIdForDHCPServer = podVlan ? DomainVO.ROOT_DOMAIN : account.getDomainId();
String domainNameForDHCPServer = podVlan ? "root" : _domainDao.findById(account.getDomainId()).getName();
final VMTemplateVO rtrTemplate = _templateDao.findRoutingTemplate();
final Transaction txn = Transaction.currentTxn();
DomainRouterVO router = null;
Long podId = pod.getId();
pod = _podDao.acquireInLockTable(podId, 20*60);
if (pod == null) {
throw new ConcurrentOperationException("Unable to acquire lock on pod " + podId );
}
if(s_logger.isDebugEnabled()) {
s_logger.debug("Lock on pod " + podId + " is acquired");
}
final long id = _routerDao.getNextInSequence(Long.class, "id");
final String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(dc.getId());
final String mgmtMacAddress = macAddresses[0];
final String guestMacAddress = macAddresses[1];
final String name = VirtualMachineName.getRouterName(id, _instance).intern();
boolean routerLockAcquired = false;
try {
List<DomainRouterVO> rtrs = _routerDao.listByVlanDbId(guestVlan.getId());
assert rtrs.size() < 2 : "How did we get more than one router per vlan?";
if (rtrs.size() == 1) {
return rtrs.get(0);
}
String mgmtNetmask = NetUtils.getCidrNetmask(pod.getCidrSize());
final String guestIp = null;//_ipAddressDao.assignIpAddress(accountIdForDHCPServer, domainIdForDHCPServer, guestVlan.getId(), false).getAddress();
router =
new DomainRouterVO(id,
_offering.getId(),
name,
mgmtMacAddress,
null,
mgmtNetmask,
_routerTemplateId,
rtrTemplate.getGuestOSId(),
guestMacAddress,
guestIp,
guestVlan.getVlanNetmask(),
accountIdForDHCPServer,
domainIdForDHCPServer,
"FE:FF:FF:FF:FF:FF",
null,
"255.255.255.255",
guestVlan.getId(),
guestVlan.getVlanId(),
pod.getId(),
dc.getId(),
_routerRamSize,
guestVlan.getVlanGateway(),
domainNameForDHCPServer,
dc.getDns1(),
dc.getDns2());
router.setRole(Role.DHCP_USERDATA);
router.setVnet(guestVlan.getVlanId());
router.setLastHostId(candidateHost);
txn.start();
router = _routerDao.persist(router);
router = _routerDao.acquireInLockTable(router.getId());
if (router == null) {
s_logger.debug("Unable to acquire lock on router " + id);
throw new CloudRuntimeException("Unable to acquire lock on router " + id);
}
routerLockAcquired = true;
txn.commit();
List<VolumeVO> vols = _storageMgr.create(account, router, rtrTemplate, dc, pod, _offering, null,0);
if (vols == null){
_ipAddressDao.unassignIpAddress(guestIp);
_routerDao.expunge(router.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to create dhcp server in storage host or pool in pod " + pod.getName() + " (id:" + pod.getId() + ")");
}
}
final EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountIdForDHCPServer);
event.setType(EventTypes.EVENT_ROUTER_CREATE);
if (vols == null) {
event.setDescription("failed to create DHCP Server : " + router.getName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
throw new ExecutionException("Unable to create DHCP Server");
}
_itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, null);
s_logger.info("DHCP server created: id=" + router.getId() + "; name=" + router.getName() + "; vlan=" + guestVlan.getVlanId() + "; pod=" + pod.getName());
event.setDescription("successfully created DHCP Server : " + router.getName() + " with ip : " + router.getGuestIpAddress());
_eventDao.persist(event);
return router;
} catch (final Throwable th) {
if (th instanceof ExecutionException) {
s_logger.error("Error while starting router due to " + th.getMessage());
} else {
s_logger.error("Unable to create router", th);
}
txn.rollback();
if (router.getState() == State.Creating) {
_routerDao.expunge(router.getId());
}
return null;
} finally {
if (routerLockAcquired) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Releasing lock on router " + id);
}
_routerDao.releaseFromLockTable(id);
}
if (pod != null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Releasing lock on pod " + podId);
}
_podDao.releaseFromLockTable(pod.getId());
}
}
}
@Override
public boolean releaseRouter(final long routerId) {
return destroyRouter(routerId);
}
@Override @DB
public DomainRouterVO createRouter(final long accountId, final String publicIpAddress, final long dataCenterId,
String domain, final ServiceOfferingVO offering, long startEventId)
throws ConcurrentOperationException {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating a router for account=" + accountId + "; publicIpAddress=" + publicIpAddress + "; dc=" + dataCenterId + "domain=" + domain);
}
final AccountVO account = _accountDao.acquireInLockTable(accountId);
if (account == null) {
throw new ConcurrentOperationException("Unable to acquire account " + accountId);
}
if(s_logger.isDebugEnabled()) {
s_logger.debug("lock on account " + accountId + " for createRouter is acquired");
}
final Transaction txn = Transaction.currentTxn();
DomainRouterVO router = null;
boolean success = false;
try {
router = _routerDao.findBy(accountId, dataCenterId);
if (router != null && router.getState() != State.Creating) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.toString() + " found for account " + accountId + " in data center " + dataCenterId);
}
success = true;
return router;
}
EventVO event = new EventVO();
event.setUserId(1L);
event.setAccountId(accountId);
event.setType(EventTypes.EVENT_ROUTER_CREATE);
event.setState(Event.State.Started);
event.setStartId(startEventId);
event.setDescription("Creating Router for account with Id: "+accountId);
event = _eventDao.persist(event);
final DataCenterVO dc = _dcDao.findById(dataCenterId);
final VMTemplateVO template = _templateDao.findRoutingTemplate();
String[] macAddresses = getMacAddressPair(dataCenterId);
String privateMacAddress = macAddresses[0];
String publicMacAddress = macAddresses[1];
final long id = _routerDao.getNextInSequence(Long.class, "id");
if (domain == null) {
domain = "v" + Long.toHexString(accountId) + "." + _domain;
}
final String name = VirtualMachineName.getRouterName(id, _instance).intern();
long routerMacAddress = NetUtils.mac2Long(dc.getRouterMacAddress()) | ((dc.getId() & 0xff) << 32);
//set the guestNetworkCidr from the dc obj
String guestNetworkCidr = dc.getGuestNetworkCidr();
String[] cidrTuple = guestNetworkCidr.split("\\/");
String guestIpAddress = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
String guestNetmask = NetUtils.getCidrNetmask(Long.parseLong(cidrTuple[1]));
// String path = null;
// final int numVolumes = offering.isMirroredVolumes()?2:1;
// long routerId = 0;
// Find the VLAN ID, VLAN gateway, and VLAN netmask for publicIpAddress
IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddress);
VlanVO vlan = _vlanDao.findById(ipVO.getVlanId());
String vlanId = vlan.getVlanId();
String vlanGateway = vlan.getVlanGateway();
String vlanNetmask = vlan.getVlanNetmask();
Pair<HostPodVO, Long> pod = null;
Set<Long> avoids = new HashSet<Long>();
boolean found = false;
while ((pod = _agentMgr.findPod(template, offering, dc, accountId, avoids)) != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Attempting to create in pod " + pod.first().getName());
}
router = new DomainRouterVO(id,
_offering.getId(),
name,
privateMacAddress,
null,
null,
_routerTemplateId,
template.getGuestOSId(),
NetUtils.long2Mac(routerMacAddress),
guestIpAddress,
guestNetmask,
accountId,
account.getDomainId(),
publicMacAddress,
publicIpAddress,
vlanNetmask,
vlan.getId(),
vlanId,
pod.first().getId(),
dataCenterId,
_routerRamSize,
vlanGateway,
domain,
dc.getDns1(),
dc.getDns2());
router.setMirroredVols(offering.isMirrored());
router.setLastHostId(pod.second());
router = _routerDao.persist(router);
List<VolumeVO> vols = _storageMgr.create(account, router, template, dc, pod.first(), _offering, null,0);
if(vols != null) {
found = true;
break;
}
_routerDao.expunge(router.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find storage host or pool in pod " + pod.first().getName() + " (id:" + pod.first().getId() + "), checking other pods");
}
avoids.add(pod.first().getId());
}
if (!found) {
event.setDescription("failed to create Domain Router : " + name);
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
throw new ExecutionException("Unable to create DomainRouter");
}
_itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, null);
s_logger.debug("Router created: id=" + router.getId() + "; name=" + router.getName());
event = new EventVO();
event.setUserId(1L); // system user performed the action
event.setAccountId(accountId);
event.setType(EventTypes.EVENT_ROUTER_CREATE);
event.setStartId(startEventId);
event.setDescription("successfully created Domain Router : " + router.getName() + " with ip : " + publicIpAddress);
_eventDao.persist(event);
success = true;
return router;
} catch (final Throwable th) {
if (th instanceof ExecutionException) {
s_logger.error("Error while starting router due to " + th.getMessage());
} else {
s_logger.error("Unable to create router", th);
}
txn.rollback();
if (router != null && router.getState() == State.Creating) {
_routerDao.expunge(router.getId());
}
return null;
} finally {
if (account != null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Releasing lock on account " + account.getId() + " for createRouter");
}
_accountDao.releaseFromLockTable(account.getId());
}
if(!success){
EventVO event = new EventVO();
event.setUserId(1L); // system user performed the action
event.setAccountId(accountId);
event.setType(EventTypes.EVENT_ROUTER_CREATE);
event.setStartId(startEventId);
event.setLevel(EventVO.LEVEL_ERROR);
event.setDescription("Failed to create router for account " + accountId + " in data center " + dataCenterId);
_eventDao.persist(event);
}
}
}
@Override
public boolean destroyRouter(final long routerId) {
@ -764,386 +436,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
}
}
@Override
public DomainRouterVO startRouter(final long routerId, long eventId) {
try {
return start(routerId, eventId);
} catch (final StorageUnavailableException e) {
s_logger.debug(e.getMessage());
return null;
} catch (final ConcurrentOperationException e) {
s_logger.debug(e.getMessage());
return null;
}
}
@Override
public VirtualRouter startRouter(StartRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException{
if (_useNewNetworking) {
return startRouter(cmd.getId());
}
Long routerId = cmd.getId();
Account account = UserContext.current().getAccount();
//verify parameters
DomainRouterVO router = _routerDao.findById(routerId);
if (router == null) {
throw new InvalidParameterValueException ("Unable to find router with id " + routerId);
}
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), router.getDomainId())) {
throw new PermissionDeniedException ("Unable to start router with id " + routerId + ". Permission denied.");
}
long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_ROUTER_START, "starting Router with Id: "+routerId);
return startRouter(routerId, eventId);
return startRouter(cmd.getId());
}
@Override @DB
public DomainRouterVO start(long routerId, long startEventId) throws StorageUnavailableException, ConcurrentOperationException {
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
if (asyncExecutor != null) {
AsyncJobVO job = asyncExecutor.getJob();
if (s_logger.isInfoEnabled()) {
s_logger.info("Start router " + routerId + ", update async job-" + job.getId());
}
_asyncMgr.updateAsyncJobAttachment(job.getId(), "domain_router", routerId);
}
DomainRouterVO router = _routerDao.acquireInLockTable(routerId);
if (router == null) {
s_logger.debug("Unable to lock the router " + routerId);
return router;
}
if(s_logger.isDebugEnabled()) {
s_logger.debug("Lock on router " + routerId + " is acquired");
}
boolean started = false;
String vnet = null;
boolean vnetAllocated = false;
try {
final State state = router.getState();
if (state == State.Running) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router is already started: " + router.toString());
}
started = true;
return router;
}
EventVO event = new EventVO();
event.setUserId(1L);
event.setAccountId(router.getAccountId());
event.setType(EventTypes.EVENT_ROUTER_START);
event.setState(Event.State.Started);
event.setDescription("Starting Router with Id: "+routerId);
event.setStartId(startEventId);
event = _eventDao.persist(event);
if(startEventId == 0){
// When route start is not asynchronous, use id of the Started event instead of Scheduled event
startEventId = event.getId();
}
if (state == State.Destroyed || state == State.Expunging || router.getRemoved() != null) {
s_logger.debug("Starting a router that's can not be started: " + router.toString());
return null;
}
if (state.isTransitional()) {
throw new ConcurrentOperationException("Someone else is starting the router: " + router.toString());
}
final HostPodVO pod = _podDao.findById(router.getPodId());
final HashSet<Host> avoid = new HashSet<Host>();
final VMTemplateVO template = _templateDao.findById(router.getTemplateId());
final DataCenterVO dc = _dcDao.findById(router.getDataCenterId());
ServiceOfferingVO offering = _serviceOfferingDao.findById(router.getServiceOfferingId());
StoragePoolVO sp = _storageMgr.getStoragePoolForVm(router.getId());
HostVO routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, template, router, null, avoid);
if (routingHost == null) {
s_logger.error("Unable to find a host to start " + router.toString());
return null;
}
if (! _itMgr.stateTransitTo(router, VirtualMachine.Event.StartRequested, routingHost.getId())) {
s_logger.debug("Unable to start router " + router.toString() + " because it is not in a startable state");
throw new ConcurrentOperationException("Someone else is starting the router: " + router.toString());
}
final boolean mirroredVols = router.isMirroredVols();
try {
event = new EventVO();
event.setUserId(1L);
event.setAccountId(router.getAccountId());
event.setType(EventTypes.EVENT_ROUTER_START);
event.setStartId(startEventId);
final List<UserVmVO> vms = _vmDao.listBy(routerId, State.Starting, State.Running, State.Stopped, State.Stopping);
if (vms.size() != 0) { // Find it in the existing network.
for (final UserVmVO vm : vms) {
if (vm.getVnet() != null) {
vnet = vm.getVnet();
break;
}
}
}
if (vnet != null) {
s_logger.debug("Router: " + router.getName() + " discovered vnet: " + vnet + " from existing VMs.");
} else {
s_logger.debug("Router: " + router.getName() + " was unable to discover vnet from existing VMs. Acquiring new vnet.");
}
String routerMacAddress = null;
if (vnet == null && router.getRole() == Role.DHCP_FIREWALL_LB_PASSWD_USERDATA) { // If not found, then get another one.
if(USE_POD_VLAN){
vnet = _dcDao.allocatePodVlan(router.getPodId(), router.getAccountId());
} else {
vnet = _dcDao.allocateVnet(router.getDataCenterId(), router.getAccountId(), null);
}
vnetAllocated = true;
if(vnet != null){
routerMacAddress = getRouterMacForVnet(dc, vnet);
}
} else if (router.getRole() == Role.DHCP_USERDATA) {
if (!Vlan.UNTAGGED.equals(router.getVlanId())) {
vnet = router.getVlanId().trim();
} else {
vnet = Vlan.UNTAGGED;
}
routerMacAddress = router.getGuestMacAddress();
} else if (vnet != null && router.getRole() == Role.DHCP_FIREWALL_LB_PASSWD_USERDATA) {
routerMacAddress = getRouterMacForVnet(dc, vnet);
}
if (vnet == null) {
s_logger.error("Unable to get another vnet while starting router " + router.getName());
return null;
} else {
s_logger.debug("Router: " + router.getName() + " is using vnet: " + vnet);
}
Answer answer = null;
int retry = _retry;
do {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to start router on host " + routingHost.getName());
}
String privateIpAddress = null;
String privateNetMask = null;
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) {
privateIpAddress = _dcDao.allocateLinkLocalIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId(), null);
privateNetMask = NetUtils.getLinkLocalNetMask();
} else {
privateIpAddress = _dcDao.allocatePrivateIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId(), null).first();
privateNetMask = NetUtils.getCidrNetmask(pod.getCidrSize());
}
if (privateIpAddress == null) {
s_logger.error("Unable to allocate a private ip address while creating router for pod " + routingHost.getPodId());
avoid.add(routingHost);
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Private Ip Address allocated: " + privateIpAddress);
}
router.setPrivateIpAddress(privateIpAddress);
router.setPrivateNetmask(privateNetMask);
router.setGuestMacAddress(routerMacAddress);
router.setVnet(vnet);
/*Ram size can be changed by upgradeRouterCmd*/
router.setRamSize(offering.getRamSize());
final String name = VirtualMachineName.attachVnet(router.getName(), vnet);
router.setInstanceName(name);
long accountId = router.getAccountId();
// Use account level network domain if available
String networkDomain = _accountDao.findById(accountId).getNetworkDomain();
if(networkDomain == null){
// Use zone level network domain, if account level domain is not available
networkDomain = dc.getDomain();
if(networkDomain == null){
// Use system wide default network domain, if zone wide network domain is also not available
networkDomain = _networkDomain;
}
}
router.setDomain(networkDomain);
_itMgr.stateTransitTo(router, VirtualMachine.Event.OperationRetry, routingHost.getId());
List<VolumeVO> vols = _storageMgr.prepare(router, routingHost);
if (vols == null || vols.size() == 0) {
s_logger.debug("Couldn't get storage working for " + routingHost);
continue;
}
/*
if( !_storageMgr.share(router, vols, routingHost, true) ) {
s_logger.debug("Unable to share volumes to host " + routingHost.getId());
continue;
}
*/
try {
String[] storageIps = new String[2];
// Determine the VM's OS description
String guestOSDescription;
GuestOSVO guestOS = _guestOSDao.findById(router.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ router.getGuestOSId() + " for vm: " + router.getName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
guestOSDescription = guestOS.getDisplayName();
}
final StartRouterCommand cmdStartRouter = new StartRouterCommand(router, _networkRate,
_multicastRate, name, storageIps, vols, mirroredVols, guestOSDescription, _mgmt_host);
answer = _agentMgr.send(routingHost.getId(), cmdStartRouter);
if (answer != null && answer.getResult()) {
if (answer instanceof StartRouterAnswer){
StartRouterAnswer rAnswer = (StartRouterAnswer)answer;
if (rAnswer.getPrivateIpAddress() != null) {
router.setPrivateIpAddress(rAnswer.getPrivateIpAddress());
}
if (rAnswer.getPrivateMacAddress() != null) {
router.setPrivateMacAddress(rAnswer.getPrivateMacAddress());
}
}
if (resendRouterState(router)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.getName() + " started on " + routingHost.getName());
}
started = true;
break;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.getName() + " started on " + routingHost.getName() + " but failed to program rules");
}
sendStopCommand(router);
}
}
s_logger.debug("Unable to start " + router.toString() + " on host " + routingHost.toString() + " due to " + answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + router.getName() + " due to operation timed out and it is active so scheduling a restart.");
_haMgr.scheduleRestart(router, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + router.getName());
}
avoid.add(routingHost);
router.setPrivateIpAddress(null);
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) {
_dcDao.releaseLinkLocalIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
} else {
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
}
_storageMgr.unshare(router, vols, routingHost);
} while (--retry > 0 && (routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, template, router, null, avoid)) != null);
if (routingHost == null || retry <= 0) {
throw new ExecutionException("Couldn't find a routingHost");
}
_itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, routingHost.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.toString() + " is now started on " + routingHost.toString());
}
event.setDescription("successfully started Domain Router: " + router.getName());
_eventDao.persist(event);
return _routerDao.findById(routerId);
} catch (final Throwable th) {
if (th instanceof ExecutionException) {
s_logger.error("Error while starting router due to " + th.getMessage());
} else if (th instanceof ConcurrentOperationException) {
throw (ConcurrentOperationException)th;
} else if (th instanceof StorageUnavailableException) {
throw (StorageUnavailableException)th;
} else {
s_logger.error("Error while starting router", th);
}
return null;
}
} finally {
if (!started){
Transaction txn = Transaction.currentTxn();
txn.start();
if (vnetAllocated == true && vnet != null) {
_dcDao.releaseVnet(vnet, router.getDataCenterId(), router.getAccountId(), null);
}
router.setVnet(null);
String privateIpAddress = router.getPrivateIpAddress();
router.setPrivateIpAddress(null);
if (privateIpAddress != null) {
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
}
if ( _itMgr.stateTransitTo(router, VirtualMachine.Event.OperationFailed, null)) {
txn.commit();
}
EventVO event = new EventVO();
event.setUserId(1L);
event.setAccountId(router.getAccountId());
event.setType(EventTypes.EVENT_ROUTER_START);
event.setDescription("Failed to start Router with Id: "+routerId);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
_eventDao.persist(event);
}
if (router != null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Releasing lock on router " + routerId);
}
_routerDao.releaseFromLockTable(routerId);
}
}
}
private String getRouterMacForVnet(final DataCenterVO dc, final String vnet) {
final long vnetId = Long.parseLong(vnet);
//ToDo: There could be 2 DomR in 2 diff pods of the zone with same vnet. Add podId to the mix to make them unique
final long routerMac = (NetUtils.mac2Long(dc.getRouterMacAddress()) & (0x00ffff0000ffffl)) | ((vnetId & 0xffff) << 16);
return NetUtils.long2Mac(routerMac);
}
private String getRouterMacForZoneVlan(final DataCenterVO dc, final String vlan) {
final long vnetId = Long.parseLong(vlan);
final long routerMac = (NetUtils.mac2Long(dc.getRouterMacAddress()) & (0x00ffff0000ffffl)) | ((vnetId & 0xffff) << 16);
return NetUtils.long2Mac(routerMac);
}
private String[] getMacAddressPair(long dataCenterId) {
return _dcDao.getNextAvailableMacAddressPair(dataCenterId);
}
private boolean resendRouterState(final DomainRouterVO router) {
if (router.getRole() == Role.DHCP_FIREWALL_LB_PASSWD_USERDATA) {
//source NAT address is stored in /proc/cmdline of the domR and gets
@ -1420,25 +717,27 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
event.setAccountId(router.getAccountId());
event.setType(EventTypes.EVENT_ROUTER_REBOOT);
event.setStartId(startEventId);
return false;
if (router.getState() == State.Running && router.getHostId() != null) {
final RebootRouterCommand cmd = new RebootRouterCommand(router.getInstanceName(), router.getPrivateIpAddress());
final RebootAnswer answer = (RebootAnswer)_agentMgr.easySend(router.getHostId(), cmd);
if (answer != null && resendRouterState(router)) {
processStopOrRebootAnswer(router, answer);
event.setDescription("successfully rebooted Domain Router : " + router.getName());
_eventDao.persist(event);
return true;
} else {
event.setDescription("failed to reboot Domain Router : " + router.getName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
return false;
}
} else {
return startRouter(routerId, 0) != null;
}
//FIXME Alena if (router.getState() == State.Running && router.getHostId() != null) {
// final RebootRouterCommand cmd = new RebootRouterCommand(router.getInstanceName(), router.getPrivateIpAddress());
// final RebootAnswer answer = (RebootAnswer)_agentMgr.easySend(router.getHostId(), cmd);
//
// if (answer != null && resendRouterState(router)) {
// processStopOrRebootAnswer(router, answer);
// event.setDescription("successfully rebooted Domain Router : " + router.getName());
// _eventDao.persist(event);
// return true;
// } else {
// event.setDescription("failed to reboot Domain Router : " + router.getName());
// event.setLevel(EventVO.LEVEL_ERROR);
// _eventDao.persist(event);
// return false;
// }
// } else {
// return startRouter(routerId, 0) != null;
// }
}
@Override
@ -1890,89 +1189,6 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
}
}
@Override
public boolean addDhcpEntry(final long routerHostId, final String routerIp, String vmName, String vmMac, String vmIp) {
final DhcpEntryCommand dhcpEntry = new DhcpEntryCommand(vmMac, vmIp, routerIp, vmName);
final Answer answer = _agentMgr.easySend(routerHostId, dhcpEntry);
return (answer != null && answer.getResult());
}
@Override
public DomainRouterVO addVirtualMachineToGuestNetwork(UserVmVO vm, String password, long startEventId) throws ConcurrentOperationException {
try {
DomainRouterVO router = start(vm.getDomainRouterId(), 0);
if (router == null) {
s_logger.error("Can't find a domain router to start VM: " + vm.getName());
return null;
}
if (vm.getGuestMacAddress() == null){
String routerGuestMacAddress = null;
if(USE_POD_VLAN){
if((vm.getPodId() == router.getPodId())){
routerGuestMacAddress = router.getGuestMacAddress();
} else {
//Not in the same pod use guest zone mac address
routerGuestMacAddress = router.getGuestZoneMacAddress();
}
String vmMacAddress = NetUtils.long2Mac((NetUtils.mac2Long(routerGuestMacAddress) & 0xffffffff0000L) | (NetUtils.ip2Long(vm.getGuestIpAddress()) & 0xffff));
vm.setGuestMacAddress(vmMacAddress);
}
else {
String vmMacAddress = NetUtils.long2Mac((NetUtils.mac2Long(router.getGuestMacAddress()) & 0xffffffff0000L) | (NetUtils.ip2Long(vm.getGuestIpAddress()) & 0xffff));
vm.setGuestMacAddress(vmMacAddress);
}
}
String userData = vm.getUserData();
Commands cmds = new Commands(OnError.Stop);
int cmdIndex = 0;
int passwordIndex = -1;
int vmDataIndex = -1;
cmds.addCommand(new DhcpEntryCommand(vm.getGuestMacAddress(), vm.getGuestIpAddress(), router.getPrivateIpAddress(), vm.getName()));
if (password != null) {
final String encodedPassword = rot13(password);
cmds.addCommand(new SavePasswordCommand(encodedPassword, vm.getPrivateIpAddress(), router.getPrivateIpAddress(), vm.getName()));
passwordIndex = cmdIndex;
}
String serviceOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId()).getDisplayText();
String zoneName = _dcDao.findById(vm.getDataCenterId()).getName();
String routerPublicIpAddress = (router.getPublicIpAddress() != null) ? router.getPublicIpAddress() : vm.getGuestIpAddress();
cmds.addCommand(generateVmDataCommand(router.getPrivateIpAddress(), routerPublicIpAddress, vm.getPrivateIpAddress(), userData, serviceOffering, zoneName, vm.getGuestIpAddress(), vm.getName(), vm.getInstanceName(), vm.getId()));
vmDataIndex = cmdIndex;
Answer[] answers = _agentMgr.send(router.getHostId(), cmds);
if (!answers[0].getResult()) {
s_logger.error("Unable to set dhcp entry for " + vm.getId() + " - " + vm.getName() +" on domR: " + router.getName() + " due to " + answers[0].getDetails());
return null;
}
if (password != null && !answers[passwordIndex].getResult()) {
s_logger.error("Unable to set password for " + vm.getId() + " - " + vm.getName() + " due to " + answers[passwordIndex].getDetails());
return null;
}
if (vmDataIndex > 0 && !answers[vmDataIndex].getResult()) {
s_logger.error("Unable to set VM data for " + vm.getId() + " - " + vm.getName() + " due to " + answers[vmDataIndex].getDetails());
return null;
}
return router;
} catch (StorageUnavailableException e) {
s_logger.error("Unable to start router " + vm.getDomainRouterId() + " because storage is unavailable.");
return null;
} catch (AgentUnavailableException e) {
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getName() + " because agent is unavailable");
return null;
} catch (OperationTimedoutException e) {
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getName() + " because agent is too busy");
return null;
}
}
private VmDataCommand generateVmDataCommand(String routerPrivateIpAddress, String routerPublicIpAddress,
String vmPrivateIpAddress, String userData, String serviceOffering, String zoneName,
String guestIpAddress, String vmName, String vmInstanceName, long vmId) {
@ -1991,25 +1207,6 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
return cmd;
}
public void releaseVirtualMachineFromGuestNetwork(UserVmVO vm) {
}
@Override
public String createZoneVlan(DomainRouterVO router) {
String zoneVlan = _dcDao.allocateVnet(router.getDataCenterId(), router.getAccountId(), null);
final DataCenterVO dc = _dcDao.findById(router.getDataCenterId());
router.setZoneVlan(zoneVlan);
router.setGuestZoneMacAddress(getRouterMacForZoneVlan(dc, zoneVlan));
_routerDao.update(router.getId(), router);
final CreateZoneVlanCommand cmdCreateZoneVlan = new CreateZoneVlanCommand(router);
CreateZoneVlanAnswer answer = (CreateZoneVlanAnswer) _agentMgr.easySend(router.getHostId(), cmdCreateZoneVlan);
if(!answer.getResult()){
s_logger.error("Unable to create zone vlan for router: "+router.getName()+ " zoneVlan: "+zoneVlan);
return null;
}
return zoneVlan;
}
protected class NetworkUsageTask implements Runnable {
public NetworkUsageTask() {
@ -2784,4 +1981,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
//TODO - apply port forwarding rules here
return true;
}
@Override
public DomainRouterVO start(long vmId, long startEventId) throws InsufficientCapacityException, StorageUnavailableException,
ConcurrentOperationException, ExecutionException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -2376,14 +2376,14 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
{
//create a dummy event and restart the domr immediately
long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting domr with Id: "+vmInstance.getId());
if(_routerMgr.startRouter(vmInstance.getId(), eventId)==null)
{
String errorMsg = "There was an error starting the domain router id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance";
s_logger.warn(errorMsg);
primaryStorage.setStatus(Status.ErrorInMaintenance);
_storagePoolDao.persist(primaryStorage);
throw new CloudRuntimeException(errorMsg);
}
// FIXME if(_routerMgr.startRouter(vmInstance.getId(), eventId)==null)
// {
// String errorMsg = "There was an error starting the domain router id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance";
// s_logger.warn(errorMsg);
// primaryStorage.setStatus(Status.ErrorInMaintenance);
// _storagePoolDao.persist(primaryStorage);
// throw new CloudRuntimeException(errorMsg);
// }
}
}
}

View File

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -44,8 +43,6 @@ import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
import com.cloud.agent.api.SecStorageSetupCommand;
import com.cloud.agent.api.StartSecStorageVmAnswer;
import com.cloud.agent.api.StartSecStorageVmCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.StopCommand;
@ -56,7 +53,6 @@ import com.cloud.async.AsyncJobExecutor;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobVO;
import com.cloud.async.BaseAsyncJobExecutor;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
@ -64,7 +60,6 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.event.Event;
@ -78,7 +73,6 @@ import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.ha.dao.HighAvailabilityDao;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
@ -86,7 +80,6 @@ import com.cloud.info.RunningHostCountInfo;
import com.cloud.info.RunningHostInfoAgregator;
import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
import com.cloud.network.IpAddrAllocator;
import com.cloud.network.IpAddrAllocator.networkInfo;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.TrafficType;
@ -96,15 +89,12 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateHostDao;
@ -142,8 +132,6 @@ import com.cloud.vm.VirtualMachineName;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
//
// Possible secondary storage vm state transition cases
@ -167,7 +155,6 @@ import com.cloud.vm.dao.VMInstanceDao;
public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, VirtualMachineGuru<SecondaryStorageVmVO> {
private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class);
private static final int DEFAULT_FIND_HOST_RETRY_COUNT = 2;
private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds
private static final int EXECUTOR_SHUTDOWN_TIMEOUT = 1000; // 1 second
@ -175,52 +162,41 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC = 180; // 3 minutes
private static final int STARTUP_DELAY = 60000; // 60 seconds
private String _mgmt_host;
private int _mgmt_port = 8250;
private int _secStorageVmCmdPort = 3;
private String _name;
@Inject(adapter=SecondaryStorageVmAllocator.class)
private Adapters<SecondaryStorageVmAllocator> _ssVmAllocators;
private SecondaryStorageVmDao _secStorageVmDao;
private DataCenterDao _dcDao;
private VlanDao _vlanDao;
private VMTemplateDao _templateDao;
private IPAddressDao _ipAddressDao;
private VolumeDao _volsDao;
private HostPodDao _podDao;
private HostDao _hostDao;
private StoragePoolDao _storagePoolDao;
private StoragePoolHostDao _storagePoolHostDao;
private UserVmDao _userVmDao;
private VMInstanceDao _instanceDao;
private AccountDao _accountDao;
@Inject private SecondaryStorageVmDao _secStorageVmDao;
@Inject private DataCenterDao _dcDao;
@Inject private VMTemplateDao _templateDao;
@Inject private IPAddressDao _ipAddressDao;
@Inject private VolumeDao _volsDao;
@Inject private HostPodDao _podDao;
@Inject private HostDao _hostDao;
@Inject private StoragePoolHostDao _storagePoolHostDao;
@Inject private AccountDao _accountDao;
private VMTemplateHostDao _vmTemplateHostDao;
private CapacityDao _capacityDao;
private HighAvailabilityDao _haDao;
@Inject private VMTemplateHostDao _vmTemplateHostDao;
private AgentManager _agentMgr;
private NetworkManager _networkMgr;
private StorageManager _storageMgr;
private HighAvailabilityManager _haMgr;
@Inject private AgentManager _agentMgr;
@Inject private NetworkManager _networkMgr;
@Inject private StorageManager _storageMgr;
private ClusterManager _clusterMgr;
@Inject private ClusterManager _clusterMgr;
private SecondaryStorageListener _listener;
private ServiceOfferingVO _serviceOffering;
private int _networkRate;
private int _multicastRate;
private VMTemplateVO _template;
@Inject private ConfigurationDao _configDao;
@Inject private EventDao _eventDao;
@Inject private ServiceOfferingDao _offeringDao;
@Inject private AccountService _accountMgr;
@Inject GuestOSDao _guestOSDao = null;
@Inject private VirtualMachineManager _itMgr;
@Inject private NicDao _nicDao;
@Inject private NetworkDao _networkDao;
@ -237,7 +213,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private int _secStorageVmRamSize;
private int _find_host_retry = DEFAULT_FIND_HOST_RETRY_COUNT;
private String _domain;
private String _instance;
@ -246,20 +221,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
private String _secHostUuid;
private String _nfsShare;
private String _allowedInternalSites;
private boolean _useNewNetworking;
private final GlobalLock _capacityScanLock = GlobalLock.getInternLock(getCapacityScanLockName());
private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName());
@Override
public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId, long startEventId) {
try {
return start2(secStorageVmId, startEventId);
return start(secStorageVmId, startEventId);
} catch (StorageUnavailableException e) {
s_logger.warn("Exception while trying to start secondary storage vm", e);
return null;
@ -274,308 +243,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
}
public SecondaryStorageVmVO start2(long secStorageVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
if (!_useNewNetworking) {
return start(secStorageVmId, startEventId);
}
@Override
public SecondaryStorageVmVO start(long secStorageVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
Account systemAcct = _accountMgr.getSystemAccount();
User systemUser = _accountMgr.getSystemUser();
return _itMgr.start(secStorageVm, null, systemUser, systemAcct, null);
}
@Override @DB
public SecondaryStorageVmVO start(long secStorageVmId, long startEventId) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
long eventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Starting secondary storage Vm Id: "+secStorageVmId, startEventId);
if(startEventId == 0){
startEventId = eventId;
}
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
if (asyncExecutor != null) {
AsyncJobVO job = asyncExecutor.getJob();
if (s_logger.isInfoEnabled()) {
s_logger.info("Start secondary storage vm " + secStorageVmId + ", update async job-" + job.getId());
}
_asyncMgr.updateAsyncJobAttachment(job.getId(), "sec_storage_vm", secStorageVmId);
}
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
if (secStorageVm == null || secStorageVm.getRemoved() != null) {
s_logger.debug("secondary storage vm is not found: " + secStorageVmId);
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "secondary storage vm is not found", startEventId);
return null;
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("Starting secondary storage vm if it is not started, secondary storage vm vm id : " + secStorageVmId);
}
for (int i = 0; i < 2; i++) {
State state = secStorageVm.getState();
if (state == State.Starting /* || state == State.Migrating */) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Waiting secondary storage vm to be ready, secondary storage vm id : "
+ secStorageVmId
+ " secStorageVm VM state : "
+ state.toString());
}
if (secStorageVm.getPrivateIpAddress() == null || connect(secStorageVm.getPrivateIpAddress(), _secStorageVmCmdPort) != null) {
if (secStorageVm.getPrivateIpAddress() == null) {
s_logger.warn("Retruning a secondary storage vm that is being started but private IP has not been allocated yet, secondary storage vm id : "
+ secStorageVmId);
} else {
s_logger.warn("Waiting secondary storage vm to be ready timed out, secondary storage vm id : "
+ secStorageVmId);
}
// TODO, it is very tricky here, if the startup process
// takes too long and it timed out here,
// we may give back a secondary storage vm that is not fully ready for
// functioning
}
return secStorageVm;
}
if (state == State.Running) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Secondary storage vm is already started: "
+ secStorageVm.getName());
}
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Secondary storage vm is already started", startEventId);
return secStorageVm;
}
DataCenterVO dc = _dcDao.findById(secStorageVm.getDataCenterId());
HostPodVO pod = _podDao.findById(secStorageVm.getPodId());
StoragePoolVO sp = _storageMgr.getStoragePoolForVm(secStorageVm.getId());
HashSet<Host> avoid = new HashSet<Host>();
HostVO routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _serviceOffering, _template, secStorageVm, null, avoid);
if (routingHost == null) {
if (s_logger.isDebugEnabled()) {
String msg = "Unable to find a routing host for " + secStorageVm.toString() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
}
// to ensure atomic state transition to Starting state
if (! _itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.StartRequested, routingHost.getId())) {
if (s_logger.isDebugEnabled()) {
SecondaryStorageVmVO temp = _secStorageVmDao.findById(secStorageVmId);
s_logger.debug("Unable to start secondary storage vm "
+ secStorageVm.getName()
+ " because it is not in a startable state : "
+ ((temp != null) ? temp.getState().toString() : "null"));
}
continue;
}
try {
Answer answer = null;
int retry = _find_host_retry;
// Secondary storage vm VM will be running at routing hosts as routing
// hosts have public access to outside network
do {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to start secondary storage vm on host "
+ routingHost.getName());
}
String privateIpAddress = allocPrivateIpAddress(
secStorageVm.getDataCenterId(), routingHost.getPodId(),
secStorageVm.getId(), secStorageVm.getPrivateMacAddress());
if (privateIpAddress == null && (_IpAllocator != null && !_IpAllocator.exteralIpAddressAllocatorEnabled())) {
String msg = "Unable to allocate private ip addresses for " + secStorageVm.getName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
secStorageVm.setPrivateIpAddress(privateIpAddress);
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(secStorageVm.getDataCenterId(), routingHost.getPodId(), secStorageVm.getId(), null);
secStorageVm.setGuestIpAddress(guestIpAddress);
_itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.OperationRetry, routingHost.getId());
secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
List<VolumeVO> vols = _storageMgr.prepare(secStorageVm, routingHost);
if (vols == null || vols.size() == 0) {
String msg = "Unable to prepare storage for " + secStorageVm.getName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
VolumeVO vol = vols.get(0);
// Determine the VM's OS description
String guestOSDescription;
GuestOSVO guestOS = _guestOSDao.findById(secStorageVm.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ secStorageVm.getGuestOSId() + " for vm: " + secStorageVm.getName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
guestOSDescription = guestOS.getDisplayName();
}
// carry the secondary storage vm port info over so that we don't
// need to configure agent on this
StartSecStorageVmCommand cmdStart = new StartSecStorageVmCommand(_networkRate,
_multicastRate, _secStorageVmCmdPort, secStorageVm,
secStorageVm.getName(), "", vols, _mgmt_host, _mgmt_port, _useSSlCopy, guestOSDescription);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending start command for secondary storage vm "
+ secStorageVm.getName()
+ " to "
+ routingHost.getName());
}
try {
answer = _agentMgr.send(routingHost.getId(), cmdStart);
s_logger.debug("StartSecStorageVmCommand Answer: " + (answer != null ? answer : "null"));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Received answer on starting secondary storage vm "
+ secStorageVm.getName()
+ " on "
+ routingHost.getName());
}
if ( answer != null && answer.getResult() ) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary storage vm " + secStorageVm.getName()
+ " started on " + routingHost.getName());
}
if (answer instanceof StartSecStorageVmAnswer){
StartSecStorageVmAnswer rAnswer = (StartSecStorageVmAnswer)answer;
if (rAnswer.getPrivateIpAddress() != null) {
secStorageVm.setPrivateIpAddress(rAnswer.getPrivateIpAddress());
}
if (rAnswer.getPrivateMacAddress() != null) {
secStorageVm.setPrivateMacAddress(rAnswer.getPrivateMacAddress());
}
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Secondary Storage VM started - " + secStorageVm.getName());
_eventDao.persist(event);
}
break;
}
s_logger.debug("Unable to start " + secStorageVm.toString() + " on host " + routingHost.toString() + " due to " + answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + secStorageVm.getName() + " due to operation timed out and it is active so scheduling a restart.");
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Unable to start vm due to operation timed out", startEventId);
_haMgr.scheduleRestart(secStorageVm, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + secStorageVm.getName());
}
avoid.add(routingHost);
secStorageVm.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, secStorageVm
.getDataCenterId(), secStorageVm.getId());
secStorageVm.setGuestIpAddress(null);
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
_storageMgr.unshare(secStorageVm, vols, routingHost);
} while (--retry > 0 && (routingHost = (HostVO) _agentMgr.findHost(
Host.Type.Routing, dc, pod, sp, _serviceOffering, _template,
secStorageVm, null, avoid)) != null);
if (routingHost == null || retry <= 0) {
SubscriptionMgr.getInstance().notifySubscribers(
ALERT_SUBJECT, this,
new SecStorageVmAlertEventArgs(
SecStorageVmAlertEventArgs.SSVM_START_FAILURE,
secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, "Unable to find a routing host to run")
);
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting secondary storage vm failed due to unable to find a host - " + secStorageVm.getName());
_eventDao.persist(event);
throw new ExecutionException(
"Couldn't find a routingHost to run secondary storage vm");
}
_itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.OperationSucceeded, routingHost.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary storage vm is now started, vm id : " + secStorageVm.getId());
}
SubscriptionMgr.getInstance().notifySubscribers(
ALERT_SUBJECT, this,
new SecStorageVmAlertEventArgs(
SecStorageVmAlertEventArgs.SSVM_UP,
secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null)
);
return secStorageVm;
} catch (Throwable thr) {
s_logger.warn("Unexpected exception: ", thr);
SubscriptionMgr.getInstance().notifySubscribers(
ALERT_SUBJECT, this,
new SecStorageVmAlertEventArgs(
SecStorageVmAlertEventArgs.SSVM_START_FAILURE,
secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, "Unexpected exception: " + thr.getMessage())
);
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting secondary storage vm failed due to unhandled exception - " + secStorageVm.getName());
_eventDao.persist(event);
Transaction txn = Transaction.currentTxn();
try {
txn.start();
String privateIpAddress = secStorageVm.getPrivateIpAddress();
if (privateIpAddress != null) {
secStorageVm.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
}
_itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.OperationFailed, null);
txn.commit();
} catch (Exception e) {
s_logger.error("Caught exception during error recovery");
}
if (thr instanceof StorageUnavailableException) {
throw (StorageUnavailableException) thr;
} else if (thr instanceof ConcurrentOperationException) {
throw (ConcurrentOperationException) thr;
} else if (thr instanceof ExecutionException) {
s_logger.error("Error while starting secondary storage vm due to " + thr.getMessage());
} else {
s_logger.error("Error while starting secondary storage vm ", thr);
}
return null;
}
}
s_logger.warn("Starting secondary storage vm encounters non-startable situation");
return null;
}
@Override
public boolean generateFirewallConfiguration(Long hostId){
@ -694,7 +369,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
s_logger.debug("Assign secondary storage vm from a newly started instance for request from data center : " + dataCenterId);
}
Map<String, Object> context = _useNewNetworking ? createSecStorageVmInstance2(dataCenterId) : createSecStorageVmInstance(dataCenterId);
Map<String, Object> context = createSecStorageVmInstance(dataCenterId);
long secStorageVmId = (Long) context.get("secStorageVmId");
if (secStorageVmId == 0) {
@ -735,7 +410,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return null;
}
protected Map<String, Object> createSecStorageVmInstance2(long dataCenterId) {
protected Map<String, Object> createSecStorageVmInstance(long dataCenterId) {
long startEventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, "Creating secondary storage Vm in zone : "+dataCenterId, 0);
HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId);
if (secHost == null) {
@ -786,112 +461,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return context;
}
@DB
protected Map<String, Object> createSecStorageVmInstance(long dataCenterId) {
long startEventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, "Creating secondary storage Vm in zone : "+dataCenterId, 0);
Map<String, Object> context = new HashMap<String, Object>();
String publicIpAddress = null;
HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId);
if (secHost == null) {
String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
s_logger.warn(msg);
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, msg, startEventId);
throw new CloudRuntimeException(msg);
}
boolean success = false;
Transaction txn = Transaction.currentTxn();
try {
DataCenterVO dc = _dcDao.findById(dataCenterId);
assert (dc != null);
context.put("dc", dc);
// this will basically allocate the pod based on data center id as
// we use system user id here
Set<Long> avoidPods = new HashSet<Long>();
Pair<HostPodVO, Long> pod = null;
networkInfo publicIpAndVlan = null;
// About MAC address allocation
// MAC address used by User VM is inherited from DomR MAC address,
// with the least 16 bits overrided. to avoid
// potential conflicts, domP will mask bit 31
//
String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(
dataCenterId, (1L << 31));
String privateMacAddress = macAddresses[0];
String publicMacAddress = macAddresses[1];
macAddresses = _dcDao.getNextAvailableMacAddressPair(
dataCenterId, (1L << 31));
String guestMacAddress = macAddresses[0];
while ((pod = _agentMgr.findPod(_template, _serviceOffering, dc, Account.ACCOUNT_ID_SYSTEM, avoidPods)) != null){
publicIpAndVlan = allocPublicIpAddress(dataCenterId, pod.first().getId(), publicMacAddress);
if (publicIpAndVlan == null) {
s_logger.warn("Unable to allocate public IP address for secondary storage vm in data center : " + dataCenterId + ", pod="+ pod.first().getId());
avoidPods.add(pod.first().getId());
} else {
break;
}
}
if (pod == null || publicIpAndVlan == null) {
String msg = "Unable to allocate pod for secondary storage vm in data center : " + dataCenterId;
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
context.put("publicIpAddress", publicIpAndVlan._ipAddr);
context.put("pod", pod);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Pod allocated " + pod.first().getName());
}
String cidrNetmask = NetUtils.getCidrNetmask(pod.first().getCidrSize());
// Find the VLAN ID, VLAN gateway, and VLAN netmask for publicIpAddress
publicIpAddress = publicIpAndVlan._ipAddr;
String vlanGateway = publicIpAndVlan._gateWay;
String vlanNetmask = publicIpAndVlan._netMask;
Account systemAcct = _accountMgr.getSystemAccount();
txn.start();
SecondaryStorageVmVO secStorageVm;
String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(),
privateMacAddress, null, cidrNetmask, _template.getId(), _template.getGuestOSId(),
publicMacAddress, publicIpAddress, vlanNetmask, publicIpAndVlan._vlanDbId, publicIpAndVlan._vlanid,
pod.first().getId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), vlanGateway, null,
dc.getInternalDns1(), dc.getInternalDns2(), _domain, _secStorageVmRamSize, secHost.getGuid(), secHost.getStorageUrl());
secStorageVm.setLastHostId(pod.second());
secStorageVm = _secStorageVmDao.persist(secStorageVm);
long secStorageVmId = secStorageVm.getId();
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_CREATE);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("New Secondary Storage VM created - " + secStorageVm.getName());
_eventDao.persist(event);
txn.commit();
success = true;
context.put("secStorageVmId", secStorageVmId);
return context;
} catch (Throwable e) {
s_logger.error("Unexpected exception : ", e);
context.put("secStorageVmId", (long) 0);
return context;
} finally {
if(!success){
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, "Failed to create secondary storage Vm", startEventId);
}
}
}
protected SecondaryStorageVmVO allocSecStorageVmStorage(long dataCenterId, long secStorageVmId) {
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
assert (secStorageVm != null);
@ -920,31 +489,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
}
private networkInfo allocPublicIpAddress(long dcId, long podId, String macAddr) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
IpAddrAllocator.IpAddr ip = _IpAllocator.getPublicIpAddress(macAddr, dcId, podId);
networkInfo net = new networkInfo(ip.ipaddr, ip.netMask, ip.gateway, null, "untagged");
return net;
}
//FIXME am I even needed any more? Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN, VlanType.VirtualNetwork, true);
//
// if (ipAndVlan == null) {
// s_logger.debug("Unable to get public ip address (type=Virtual) for secondary storage vm for data center : " + dcId);
// ipAndVlan = _vlanDao.assignPodDirectAttachIpAddress(dcId, podId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN);
// if (ipAndVlan == null) {
// s_logger.debug("Unable to get public ip address (type=DirectAttach) for secondary storage vm for data center : " + dcId);
// }
//
// }
// if (ipAndVlan != null) {
// VlanVO vlan = ipAndVlan.second();
// networkInfo net = new networkInfo(ipAndVlan.first(), vlan.getVlanNetmask(), vlan.getVlanGateway(), vlan.getId(), vlan.getVlanId());
// return net;
// }
return null;
}
private void freePublicIpAddress(String ipAddress, long dcId, long podId) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
_IpAllocator.releasePublicIpAddress(ipAddress, dcId, podId);
@ -953,22 +497,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
}
private String allocPrivateIpAddress(Long dcId, Long podId, Long proxyId, String macAddr) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
} else {
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId, null).first();
}
}
private void freePrivateIpAddress(String ipAddress, Long dcId, Long podId) {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
_IpAllocator.releasePrivateIpAddress(ipAddress, dcId, podId);
} else {
_dcDao.releasePrivateIpAddress(ipAddress, dcId, podId);
}
}
private SecondaryStorageVmAllocator getCurrentAllocator() {
// for now, only one adapter is supported
@ -1008,7 +536,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
try {
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
readysecStorageVm = start2(readysecStorageVm.getId(), 0);
readysecStorageVm = start(readysecStorageVm.getId(), 0);
} finally {
secStorageVmLock.unlock();
}
@ -1360,10 +888,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
_allowedInternalSites = configDao.getValue("secstorage.allowed.internal.sites");
String value = configs.get("start.retry");
_find_host_retry = NumbersUtil.parseInt(value, DEFAULT_FIND_HOST_RETRY_COUNT);
value = configs.get("secstorage.vm.cmd.port");
String value = configs.get("secstorage.vm.cmd.port");
_secStorageVmCmdPort = NumbersUtil.parseInt(value, 3922);
@ -1390,145 +915,18 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
value = agentMgrConfigs.get("port");
_mgmt_port = NumbersUtil.parseInt(value, 8250);
_secStorageVmDao = locator.getDao(SecondaryStorageVmDao.class);
if (_secStorageVmDao == null) {
throw new ConfigurationException("Unable to get " + SecondaryStorageVmDao.class.getName());
}
_ssVmAllocators = locator.getAdapters(SecondaryStorageVmAllocator.class);
if (_ssVmAllocators == null || !_ssVmAllocators.isSet()) {
throw new ConfigurationException("Unable to get secStorageVm allocators");
}
_dcDao = locator.getDao(DataCenterDao.class);
if (_dcDao == null) {
throw new ConfigurationException("Unable to get " + DataCenterDao.class.getName());
}
_templateDao = locator.getDao(VMTemplateDao.class);
if (_templateDao == null) {
throw new ConfigurationException("Unable to get " + VMTemplateDao.class.getName());
}
_ipAddressDao = locator.getDao(IPAddressDao.class);
if (_ipAddressDao == null) {
throw new ConfigurationException("Unable to get " + IPAddressDao.class.getName());
}
_volsDao = locator.getDao(VolumeDao.class);
if (_volsDao == null) {
throw new ConfigurationException("Unable to get " + VolumeDao.class.getName());
}
_podDao = locator.getDao(HostPodDao.class);
if (_podDao == null) {
throw new ConfigurationException("Unable to get " + HostPodDao.class.getName());
}
_hostDao = locator.getDao(HostDao.class);
if (_hostDao == null) {
throw new ConfigurationException("Unable to get " + HostDao.class.getName());
}
_storagePoolDao = locator.getDao(StoragePoolDao.class);
if (_storagePoolDao == null) {
throw new ConfigurationException("Unable to find " + StoragePoolDao.class);
}
_storagePoolHostDao = locator.getDao(StoragePoolHostDao.class);
if (_storagePoolHostDao == null) {
throw new ConfigurationException("Unable to find " + StoragePoolHostDao.class);
}
_vmTemplateHostDao = locator.getDao(VMTemplateHostDao.class);
if (_vmTemplateHostDao == null) {
throw new ConfigurationException("Unable to get " + VMTemplateHostDao.class.getName());
}
_userVmDao = locator.getDao(UserVmDao.class);
if (_userVmDao == null) {
throw new ConfigurationException("Unable to get " + UserVmDao.class.getName());
}
_instanceDao = locator.getDao(VMInstanceDao.class);
if (_instanceDao == null) {
throw new ConfigurationException("Unable to get " + VMInstanceDao.class.getName());
}
_capacityDao = locator.getDao(CapacityDao.class);
if (_capacityDao == null) {
throw new ConfigurationException("Unable to get " + CapacityDao.class.getName());
}
_haDao = locator.getDao(HighAvailabilityDao.class);
if (_haDao == null) {
throw new ConfigurationException("Unable to get " + HighAvailabilityDao.class.getName());
}
_accountDao = locator.getDao(AccountDao.class);
if (_accountDao == null) {
throw new ConfigurationException("Unable to get " + AccountDao.class.getName());
}
_vlanDao = locator.getDao(VlanDao.class);
if (_vlanDao == null) {
throw new ConfigurationException("Unable to get " + VlanDao.class.getName());
}
_agentMgr = locator.getManager(AgentManager.class);
if (_agentMgr == null) {
throw new ConfigurationException("Unable to get " + AgentManager.class.getName());
}
_networkMgr = locator.getManager(NetworkManager.class);
if (_networkMgr == null) {
throw new ConfigurationException("Unable to get " + NetworkManager.class.getName());
}
_listener = new SecondaryStorageListener(this);
_agentMgr.registerForHostEvents(_listener, true, true, false);
_storageMgr = locator.getManager(StorageManager.class);
if (_storageMgr == null) {
throw new ConfigurationException("Unable to get " + StorageManager.class.getName());
}
_haMgr = locator.getManager(HighAvailabilityManager.class);
if (_haMgr == null) {
throw new ConfigurationException("Unable to get " + HighAvailabilityManager.class.getName());
}
_clusterMgr = locator.getManager(ClusterManager.class);
if (_clusterMgr == null) {
throw new ConfigurationException("Unable to get " + ClusterManager.class.getName());
}
_asyncMgr = locator.getManager(AsyncJobManager.class);
if (_asyncMgr == null) {
throw new ConfigurationException("Unable to get " + AsyncJobManager.class.getName());
}
HighAvailabilityManager haMgr = locator.getManager(HighAvailabilityManager.class);
if (haMgr != null) {
haMgr.registerHandler(VirtualMachine.Type.SecondaryStorageVm, this);
}
_itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);
_itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);
_useNewNetworking = Boolean.parseBoolean(configs.get("use.new.networking"));
Adapters<IpAddrAllocator> ipAllocators = locator.getAdapters(IpAddrAllocator.class);
if (ipAllocators != null && ipAllocators.isSet()) {
Enumeration<IpAddrAllocator> it = ipAllocators.enumeration();
_IpAllocator = it.nextElement();
}
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
_networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
_multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
_serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, useLocalStorage, true, null, true);
_serviceOffering.setUniqueName("Cloud.com-SecondaryStorage");
_serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
@ -1582,7 +980,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
String privateIpAddress = secStorageVm.getPrivateIpAddress();
if (privateIpAddress != null) {
secStorageVm.setPrivateIpAddress(null);
freePrivateIpAddress(privateIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
// FIXME: freePrivateIpAddress(privateIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
}
String guestIpAddress = secStorageVm.getGuestIpAddress();
if (guestIpAddress != null) {

View File

@ -21,23 +21,7 @@ import java.util.HashMap;
import java.util.List;
import com.cloud.agent.api.VmStatsEntry;
import com.cloud.async.executor.OperationResponse;
import com.cloud.async.executor.StartVMExecutor;
import com.cloud.async.executor.StopVMExecutor;
import com.cloud.async.executor.VMOperationParam;
import com.cloud.dc.DataCenterVO;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientStorageCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.network.security.NetworkGroupVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.AccountVO;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.VirtualMachine.Event;
/**
@ -60,24 +44,7 @@ public interface UserVmManager extends VirtualMachineGuru<UserVmVO>{
*/
UserVmVO getVirtualMachine(long vmId);
/**
* creates a virtual machine.
* @param userId the id of the user performing the action
* @param account account creating the virtual machine.
* @param dc data center to deploy it in.
* @param offering the service offering that comes with it.
* @param template template to base the virtual machine on. Can either represent an ISO, or a normal template.
* @param diskOffering the disk offering for the root disk (deploying from ISO) or the data disk (deploying from a normal template)
* @return UserVmVO if created; null if not.
*/
UserVmVO createVirtualMachine(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> avoids, long startEventId, long size) throws InsufficientStorageCapacityException, ResourceAllocationException;
UserVmVO createDirectlyAttachedVM(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> a, List<NetworkGroupVO> networkGroupVO, long startEventId, long size) throws ResourceAllocationException;
UserVmVO createDirectlyAttachedVMExternal(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> a, List<NetworkGroupVO> networkGroupVO, long startEventId, long size) throws ResourceAllocationException;
boolean destroyVirtualMachine(long userId, long vmId);
// OperationResponse executeDestroyVM(DestroyVMExecutor executor, VMOperationParam param);
/**
@ -89,30 +56,6 @@ public interface UserVmManager extends VirtualMachineGuru<UserVmVO>{
*/
boolean attachISOToVM(long vmId, long isoId, boolean attach);
/**
* Start the virtual machine.
* @param userId the id of the user performing the action
* @param vmId the id of the virtual machine.
* @param isoPath path of the ISO from which the VM should be booted (optional)
* @throws ExecutionException
* @throws StorageUnavailableException
* @throws ConcurrentOperationException
*/
UserVmVO startVirtualMachine(long userId, long vmId, String isoPath, long startEventId) throws ExecutionException, StorageUnavailableException, ConcurrentOperationException;
boolean executeStartVM(StartVMExecutor executor, VMOperationParam param);
/**
* Start the virtual machine.
* @param userId the id of the user performing the action
* @param vmId the id of the virtual machine.
* @param password the password that the user wants to use to access the virtual machine
* @param isoPath path of the ISO from which the VM should be booted (optional)
* @throws ExecutionException
* @throws StorageUnavailableException
* @throws ConcurrentOperationException
*/
UserVmVO startVirtualMachine(long userId, long vmId, String password, String isoPath, long startEventId) throws ExecutionException, StorageUnavailableException, ConcurrentOperationException;
/**
* Stops the virtual machine
* @param userId the id of the user performing the action
@ -153,8 +96,4 @@ public interface UserVmManager extends VirtualMachineGuru<UserVmVO>{
InstanceGroupVO getGroupForVm(long vmId);
void removeInstanceFromGroup(long vmId);
@Deprecated
OperationResponse executeStopVM(StopVMExecutor executor, VMOperationParam param);
}

File diff suppressed because it is too large Load Diff