diff --git a/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java b/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java new file mode 100644 index 00000000000..ce6ae1b8a81 --- /dev/null +++ b/agent/src/com/cloud/agent/resource/computing/KVMGuestOsMapper.java @@ -0,0 +1,115 @@ +package com.cloud.agent.resource.computing; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + +public class KVMGuestOsMapper { + private static final Logger s_logger = Logger.getLogger(KVMGuestOsMapper.class); + private static Map s_mapper = new HashMap(); + static { + s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5"); + s_mapper.put("CentOS 4.6 (32-bit)", "CentOS 4.6"); + s_mapper.put("CentOS 4.7 (32-bit)", "CentOS 4.7"); + s_mapper.put("CentOS 4.8 (32-bit)", "CentOS 4.8"); + s_mapper.put("CentOS 5.0 (32-bit)", "CentOS 5.0"); + s_mapper.put("CentOS 5.0 (64-bit)", "CentOS 5.0"); + s_mapper.put("CentOS 5.1 (32-bit)", "CentOS 5.1"); + s_mapper.put("CentOS 5.1 (64-bit)", "CentOS 5.1"); + s_mapper.put("CentOS 5.2 (32-bit)", "CentOS 5.2"); + s_mapper.put("CentOS 5.2 (64-bit)", "CentOS 5.2"); + s_mapper.put("CentOS 5.3 (32-bit)", "CentOS 5.3"); + s_mapper.put("CentOS 5.3 (64-bit)", "CentOS 5.3"); + s_mapper.put("CentOS 5.4 (32-bit)", "CentOS 5.4"); + s_mapper.put("CentOS 5.4 (64-bit)", "CentOS 5.4"); + s_mapper.put("CentOS 5.5 (32-bit)", "CentOS 5.5"); + s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5"); + s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2"); + s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)", "Red Hat Enterprise Linux 3"); + s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)", "Red Hat Enterprise Linux 3"); + s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", "Red Hat Enterprise Linux 4"); + s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", "Red Hat Enterprise Linux 4.5"); + s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", "Red Hat Enterprise Linux 4.6"); + s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)", "Red Hat Enterprise Linux 4.7"); + s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)", "Red Hat Enterprise Linux 4.8"); + s_mapper.put("Red Hat Enterprise Linux 5.0 (32-bit)", "Red Hat Enterprise Linux 5.0"); + s_mapper.put("Red Hat Enterprise Linux 5.0 (64-bit)", "Red Hat Enterprise Linux 5.0"); + s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)", "Red Hat Enterprise Linux 5.1"); + s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)", "Red Hat Enterprise Linux 5.1"); + s_mapper.put("Red Hat Enterprise Linux 5.2 (32-bit)", "Red Hat Enterprise Linux 5.2"); + s_mapper.put("Red Hat Enterprise Linux 5.2 (64-bit)", "Red Hat Enterprise Linux 5.2"); + s_mapper.put("Red Hat Enterprise Linux 5.3 (32-bit)", "Red Hat Enterprise Linux 5.3"); + s_mapper.put("Red Hat Enterprise Linux 5.3 (64-bit)", "Red Hat Enterprise Linux 5.3"); + s_mapper.put("Red Hat Enterprise Linux 5.4 (32-bit)", "Red Hat Enterprise Linux 5.4"); + s_mapper.put("Red Hat Enterprise Linux 5.4 (64-bit)", "Red Hat Enterprise Linux 5.4"); + s_mapper.put("Red Hat Enterprise Linux 5.5 (32-bit)", "Red Hat Enterprise Linux 5.5"); + s_mapper.put("Red Hat Enterprise Linux 5.5 (64-bit)", "Red Hat Enterprise Linux 5.5"); + s_mapper.put("Fedora 13", "Fedora 13"); + s_mapper.put("Fedora 12", "Fedora 12"); + s_mapper.put("Fedora 11", "Fedora 11"); + s_mapper.put("Fedora 10", "Fedora 10"); + s_mapper.put("Fedora 9", "Fedora 9"); + s_mapper.put("Fedora 8", "Fedora 8"); + s_mapper.put("Ubuntu 10.04 (32-bit)", "Ubuntu 10.04"); + s_mapper.put("Ubuntu 10.04 (64-bit)", "Ubuntu 10.04"); + s_mapper.put("Ubuntu 9.10 (32-bit)", "Ubuntu 9.10"); + s_mapper.put("Ubuntu 9.10 (64-bit)", "Ubuntu 9.10"); + s_mapper.put("Ubuntu 9.04 (32-bit)", "Ubuntu 9.04"); + s_mapper.put("Ubuntu 9.04 (64-bit)", "Ubuntu 9.04"); + s_mapper.put("Ubuntu 8.10 (32-bit)", "Ubuntu 8.10"); + s_mapper.put("Ubuntu 8.10 (64-bit)", "Ubuntu 8.10"); + s_mapper.put("Ubuntu 8.04 (32-bit)", "Ubuntu 8.04"); + s_mapper.put("Ubuntu 8.04 (64-bit)", "Ubuntu 8.04"); + s_mapper.put("Debian GNU/Linux 5.0 (32-bit)", "Debian GNU/Linux 5"); + s_mapper.put("Debian GNU/Linux 5.0 (64-bit)", "Debian GNU/Linux 5"); + s_mapper.put("Debian GNU/Linux 4.0 (32-bit)", "Debian GNU/Linux 4"); + s_mapper.put("Debian GNU/Linux 4.0 (64-bit)", "Debian GNU/Linux 4"); + s_mapper.put("Other 2.6x Linux (32-bit)", "Other 2.6x Linux"); + s_mapper.put("Other 2.6x Linux (64-bit)", "Other 2.6x Linux"); + s_mapper.put("Other Linux (32-bit)", "Other Linux"); + s_mapper.put("Other Linux (64-bit)", "Other Linux"); + s_mapper.put("Other Ubuntu (32-bit)", "Other Linux"); + s_mapper.put("Other Ubuntu (64-bit)", "Other Linux"); + s_mapper.put("Asianux 3(32-bit)", "Other Linux"); + s_mapper.put("Asianux 3(64-bit)", "Other Linux"); + s_mapper.put("Windows 7 (32-bit)", "Windows 7"); + s_mapper.put("Windows 7 (64-bit)", "Windows 7"); + s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 Standard Edition(32-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 Standard Edition(64-bit)", "Windows Server 2003"); + s_mapper.put("Windows Server 2003 Web Edition", "Windows Server 2003"); + s_mapper.put("Microsoft Small Bussiness Server 2003", "Windows Server 2003"); + s_mapper.put("Windows Server 2008 (32-bit)", "Windows Server 2008"); + s_mapper.put("Windows Server 2008 (64-bit)", "Windows Server 2008"); + s_mapper.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008"); + s_mapper.put("Windows 2000 Server SP4 (32-bit)", "Windows 2000"); + s_mapper.put("Windows 2000 Server", "Windows 2000"); + s_mapper.put("Windows 2000 Advanced Server", "Windows 2000"); + s_mapper.put("Windows 2000 Professional", "Windows 2000"); + s_mapper.put("Windows Vista (32-bit)", "Windows Vista"); + s_mapper.put("Windows Vista (64-bit)", "Windows Vista"); + s_mapper.put("Windows XP SP2 (32-bit)", "Windows XP"); + s_mapper.put("Windows XP SP3 (32-bit)", "Windows XP"); + s_mapper.put("Windows XP (32-bit)", "Windows XP"); + s_mapper.put("Windows XP (64-bit)", "Windows XP"); + s_mapper.put("Windows 98", "Windows 98"); + s_mapper.put("Windows 95", "Windows 95"); + s_mapper.put("Windows NT 4", "Windows NT"); + s_mapper.put("Windows 3.1", "Windows 3.1"); + } + + public static String getGuestOsName(String guestOsName) { + String guestOS = s_mapper.get(guestOsName); + if (guestOS == null) { + s_logger.debug("Can't find the mapping of guest os: " + guestOsName); + return "Other"; + } else { + return guestOS; + } + } +} + diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index 7f9d79c65bc..34c83416cf7 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -121,6 +121,8 @@ 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; @@ -137,7 +139,7 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateCommand; import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; -import com.cloud.agent.api.to.StoragePoolTO; +import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VolumeTO; import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.poolType; import com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat; @@ -156,12 +158,11 @@ import com.cloud.agent.resource.computing.LibvirtVMDef.interfaceDef.hostNicType; import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import com.cloud.exception.InternalErrorException; import com.cloud.host.Host.Type; -import com.cloud.hypervisor.Hypervisor; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy; import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResourceBase; import com.cloud.storage.Storage; -import com.cloud.storage.Storage.StorageResourceType; import com.cloud.storage.StorageLayer; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.Volume; @@ -185,6 +186,7 @@ import com.cloud.utils.script.Script; import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.DiskProfile; import com.cloud.vm.DomainRouter; +import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.State; import com.cloud.vm.VirtualMachineName; @@ -416,6 +418,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected String _hypervisorType; protected String _hypervisorURI; protected String _hypervisorPath; + protected String _sysvmISOPath; protected String _privNwName; protected String _privBridgeName; protected String _linkLocalBridgeName; @@ -425,6 +428,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected String _domrKernel; protected String _domrRamdisk; protected String _pool; + protected String _localGateway; private boolean _can_bridge_firewall; private Pair _pifs; private final Map _vmStats = new ConcurrentHashMap(); @@ -684,18 +688,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv _domrArch = "i686"; } else if (!"i686".equalsIgnoreCase(_domrArch) && !"x86_64".equalsIgnoreCase(_domrArch)) { throw new ConfigurationException("Invalid architecture (domr.arch) -- needs to be i686 or x86_64"); - } - - _domrKernel = (String)params.get("domr.kernel"); - if (_domrKernel == null ) { - _domrKernel = new File("/var/lib/libvirt/images/vmops-domr-kernel").getAbsolutePath(); - } - - _domrRamdisk = (String)params.get("domr.ramdisk"); - if (_domrRamdisk == null ) { - _domrRamdisk = new File("/var/lib/libvirt/images/vmops-domr-initramfs").getAbsolutePath(); - } - + } value = (String)params.get("host.reserved.mem.mb"); _dom0MinMem = NumbersUtil.parseInt(value, 0)*1024*1024; @@ -732,6 +725,20 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } catch (ClassNotFoundException e) { throw new ConfigurationException("Unable to find class " + "com.cloud.storage.JavaStorageLayer"); } + + _sysvmISOPath = (String)params.get("systemvm.iso.path"); + if (_sysvmISOPath == null) { + String[] isoPaths = {"/usr/lib64/cloud/agent/vms/systemvm.iso", "/usr/lib/cloud/agent/vms/systemvm.iso"}; + for (String isoPath : isoPaths) { + if (_storage.exists(isoPath)) { + _sysvmISOPath = isoPath; + break; + } + } + if (_sysvmISOPath == null) { + throw new ConfigurationException("Can't find system vm ISO"); + } + } //_can_bridge_firewall = can_bridge_firewall(); @@ -780,6 +787,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv throw new ConfigurationException("Failed to get public nic name"); } s_logger.debug("Found pif: " + _pifs.first() + " on " + _privBridgeName + ", pif: " + _pifs.second() + " on " + _publicBridgeName); + + _localGateway = Script.runSimpleBashScript("ip route |grep default|awk '{print $3}'"); + if (_localGateway == null) { + s_logger.debug("Failed to found the local gateway"); + } + return true; } @@ -837,7 +850,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String dataDiskPath = null; for (diskDef disk : disks) { - if (disk.getDiskLabel().equalsIgnoreCase("hdb")) { + if (disk.getDiskLabel().equalsIgnoreCase("vdb")) { dataDiskPath = disk.getDiskPath(); } } @@ -846,7 +859,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv 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(), "Fedora 12"); + String domXML = defineVMXML(cmd.getVmName(), uuid, router.getRamSize(), 1, _domrArch, nics, disks, router.getVncPassword(), cmd.getGuestOSDescription()); s_logger.debug(domXML); @@ -880,19 +893,24 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv ConsoleProxyVO console = cmd.getProxy(); List nics = null; try { - nics = createConsoleVMNetworks(cmd); + nics = createSysVMNetworks(console.getGuestMacAddress(), console.getPrivateMacAddress(), console.getPublicMacAddress(), console.getVlanId()); List disks = createSystemVMDisk(cmd.getVolumes()); String dataDiskPath = null; for (diskDef disk : disks) { - if (disk.getDiskLabel().equalsIgnoreCase("hdb")) { + 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(cmd.getBootArgs(), dataDiskPath, vmName); + 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"); @@ -910,12 +928,50 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return null; } + protected String startSecStorageVM(StartSecStorageVmCommand cmd) { + SecondaryStorageVmVO secVm = cmd.getSecondaryStorageVmVO(); + List nics = null; + try { + nics = createSysVMNetworks(secVm.getGuestMacAddress(), secVm.getPrivateMacAddress(), secVm.getPublicMacAddress(), secVm.getVlanId()); + + List 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 nics, List disks, String vncPaswd, String guestOSType) { LibvirtVMDef vm = new LibvirtVMDef(); vm.setHvsType(_hypervisorType); vm.setDomainName(vmName); vm.setDomUUID(uuid); - vm.setDomDescription(guestOSType); + vm.setDomDescription(KVMGuestOsMapper.getGuestOsName(guestOSType)); guestDef guest = new guestDef(); guest.setGuestType(guestDef.guestType.KVM); @@ -1101,6 +1157,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv 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) { @@ -1173,7 +1231,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } protected Answer execute(CreateCommand cmd) { - StoragePoolTO pool = cmd.getPool(); + StorageFilerTO pool = cmd.getPool(); DiskProfile dskch = cmd.getDiskCharacteristics(); StorageVol tmplVol = null; StoragePool primaryPool = null; @@ -1636,6 +1694,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv if (secondaryPool == null) { return new Answer(cmd, false, " Failed to create storage pool"); } + if (tmpltname == null) { + /*Hack: server just pass the directory of system vm template, need to scan the folder */ + secondaryPool.refresh(0); + String[] volumes = secondaryPool.listVolumes(); + if (volumes == null) { + return new Answer(cmd, false, "Failed to get volumes from pool: " + secondaryPool.getName()); + } + for (String volumeName : volumes) { + if (volumeName.endsWith("qcow2")) { + tmpltname = volumeName; + break; + } + } + if (tmpltname == null) { + return new Answer(cmd, false, "Failed to get template from pool: " + secondaryPool.getName()); + } + } tmplVol = getVolume(secondaryPool, getPathOfStoragePool(secondaryPool) + tmpltname); if (tmplVol == null) { return new Answer(cmd, false, " Can't find volume"); @@ -1838,18 +1913,52 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv _vms.put(cmd.getVmName(), State.Starting); } try { + result = startConsoleProxy(cmd); if (result != null) { throw new ExecutionException(result, null); } - result = _virtRouterResource.connect(router.getPrivateIpAddress(), cmd.getProxyCmdPort()); + result = _virtRouterResource.connect(router.getGuestIpAddress(), cmd.getProxyCmdPort()); if (result != null) { throw new ExecutionException(result, null); } state = State.Running; - return new StartConsoleProxyAnswer(cmd, router.getPrivateIpAddress(), router.getPrivateMacAddress()); + 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) { @@ -2557,7 +2666,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final List info = getHostInfo(); - final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), Hypervisor.Type.KVM, RouterPrivateIpStrategy.HostLocal, changes); + final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal, changes); fillNetworkInformation(cmd); cmd.getHostDetails().putAll(getVersionStrings()); cmd.setPool(_pool); @@ -3093,24 +3202,24 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private boolean isGuestPVEnabled(String guestOS) { if (guestOS == null) return false; - if (guestOS.startsWith("Ubuntu 10.04") || - guestOS.startsWith("Ubuntu 9") || - guestOS.startsWith("Ubuntu 8.10") || - guestOS.startsWith("Fedora 13") || - guestOS.startsWith("Fedora 12") || - guestOS.startsWith("Fedora 11") || - guestOS.startsWith("Fedora 10") || - guestOS.startsWith("Fedora 9") || - guestOS.startsWith("CentOS 5.3") || - guestOS.startsWith("CentOS 5.4") || - guestOS.startsWith("CentOS 5.5") || - guestOS.startsWith("Red Hat Enterprise Linux 5.3") || - guestOS.startsWith("Red Hat Enterprise Linux 5.4") || - guestOS.startsWith("Red Hat Enterprise Linux 5.5") || - guestOS.startsWith("Red Hat Enterprise Linux 6") || - guestOS.startsWith("Debain Lenney") || - guestOS.startsWith("Debain Squeeze") - ) + String guestOSName = KVMGuestOsMapper.getGuestOsName(guestOS); + if (guestOSName.startsWith("Ubuntu 10.04") || + guestOSName.startsWith("Ubuntu 9") || + guestOSName.startsWith("Ubuntu 8.10") || + guestOSName.startsWith("Fedora 13") || + guestOSName.startsWith("Fedora 12") || + guestOSName.startsWith("Fedora 11") || + guestOSName.startsWith("Fedora 10") || + guestOSName.startsWith("Fedora 9") || + guestOSName.startsWith("CentOS 5.3") || + guestOSName.startsWith("CentOS 5.4") || + guestOSName.startsWith("CentOS 5.5") || + guestOSName.startsWith("Red Hat Enterprise Linux 5.3") || + guestOSName.startsWith("Red Hat Enterprise Linux 5.4") || + 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; @@ -3231,25 +3340,34 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return nics; } - private List createConsoleVMNetworks(StartConsoleProxyCommand cmd) { + private List createSysVMNetworks(String guestMac, String privMac, String pubMac, String vlanId) throws InternalErrorException { List nics = new ArrayList(); - ConsoleProxyVO console = cmd.getProxy(); - String privateMac = console.getPrivateMacAddress(); - String pubMac = console.getPublicMacAddress(); + String brName; interfaceDef pubNic = new interfaceDef(); interfaceDef privNic = new interfaceDef(); interfaceDef vnetNic = new interfaceDef(); - - /*guest network is vnet: 0 is not used, 1 is link local, 2 is pub nic*/ - vnetNic.defPrivateNet("default", null, null, interfaceDef.nicModel.VIRTIO); - nics.add(vnetNic); - - privNic.defPrivateNet(_privNwName, null, privateMac, interfaceDef.nicModel.VIRTIO); - nics.add(privNic); - - pubNic.defBridgeNet(_publicBridgeName, null, pubMac, interfaceDef.nicModel.VIRTIO); - nics.add(pubNic); - + + /*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; } @@ -3277,13 +3395,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String datadiskPath = tmplVol.getKey(); diskDef hda = new diskDef(); - hda.defFileBasedDisk(rootkPath, "hda", diskDef.diskBus.IDE, diskDef.diskFmtType.QCOW2); + hda.defFileBasedDisk(rootkPath, "vda", diskDef.diskBus.VIRTIO, diskDef.diskFmtType.QCOW2); disks.add(hda); diskDef hdb = new diskDef(); - hdb.defFileBasedDisk(datadiskPath, "hdb", diskDef.diskBus.IDE, diskDef.diskFmtType.RAW); + hdb.defFileBasedDisk(datadiskPath, "vdb", diskDef.diskBus.VIRTIO, diskDef.diskFmtType.RAW); disks.add(hdb); + diskDef hdc = new diskDef(); + hdc.defFileBasedDisk(_sysvmISOPath, "hdc", diskDef.diskBus.IDE, diskDef.diskFmtType.RAW); + hdc.setDeviceType(diskDef.deviceType.CDROM); + disks.add(hdc); + return disks; } diff --git a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index 4696b98b426..94a99400667 100644 --- a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -82,6 +82,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe String _localgw; String _eth1ip; String _eth1mask; + String _pubIp; @Override public Answer executeRequest(final Command cmd) { @@ -158,6 +159,8 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe fillNetworkInformation(cmd); cmd.setProxyPort(_proxyPort); cmd.setProxyVmId(_proxyVmId); + if(_pubIp != null) + cmd.setPublicIpAddress(_pubIp); return new StartupCommand[] {cmd}; } @@ -222,6 +225,8 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe } } + _pubIp = (String)params.get("public.ip"); + if(s_logger.isInfoEnabled()) s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + _proxyVmId); @@ -309,8 +314,8 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe _consoleProxyMain.start(); } - public boolean authenticateConsoleAccess(String vmId, String sid) { - ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(vmId, sid); + public boolean authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket) { + ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket); try { AgentControlAnswer answer = getAgentControl().sendRequest(cmd, 10000); diff --git a/core/src/com/cloud/agent/api/Answer.java b/api/src/com/cloud/agent/api/Answer.java similarity index 100% rename from core/src/com/cloud/agent/api/Answer.java rename to api/src/com/cloud/agent/api/Answer.java diff --git a/core/src/com/cloud/agent/api/Command.java b/api/src/com/cloud/agent/api/Command.java similarity index 100% rename from core/src/com/cloud/agent/api/Command.java rename to api/src/com/cloud/agent/api/Command.java diff --git a/core/src/com/cloud/agent/api/UnsupportedAnswer.java b/api/src/com/cloud/agent/api/UnsupportedAnswer.java similarity index 100% rename from core/src/com/cloud/agent/api/UnsupportedAnswer.java rename to api/src/com/cloud/agent/api/UnsupportedAnswer.java diff --git a/core/src/com/cloud/agent/api/storage/CreateCommand.java b/api/src/com/cloud/agent/api/storage/CreateCommand.java similarity index 70% rename from core/src/com/cloud/agent/api/storage/CreateCommand.java rename to api/src/com/cloud/agent/api/storage/CreateCommand.java index d53e378aec7..46eae20a601 100644 --- a/core/src/com/cloud/agent/api/storage/CreateCommand.java +++ b/api/src/com/cloud/agent/api/storage/CreateCommand.java @@ -18,19 +18,16 @@ package com.cloud.agent.api.storage; import com.cloud.agent.api.Command; -import com.cloud.agent.api.to.StoragePoolTO; -import com.cloud.storage.StoragePoolVO; -import com.cloud.storage.VolumeVO; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.storage.StoragePool; import com.cloud.vm.DiskProfile; -import com.cloud.vm.VMInstanceVO; public class CreateCommand extends Command { private long volId; - private StoragePoolTO pool; + private StorageFilerTO pool; private DiskProfile diskCharacteristics; private String templateUrl; private long size; - private String instanceName; protected CreateCommand() { super(); @@ -45,8 +42,8 @@ public class CreateCommand extends Command { * @param templateUrl * @param pool */ - public CreateCommand(VolumeVO vol, VMInstanceVO vm, DiskProfile diskCharacteristics, String templateUrl, StoragePoolVO pool) { - this(vol, vm, diskCharacteristics, pool, 0); + public CreateCommand(DiskProfile diskCharacteristics, String templateUrl, StorageFilerTO pool) { + this(diskCharacteristics, pool, 0); this.templateUrl = templateUrl; } @@ -58,13 +55,20 @@ public class CreateCommand extends Command { * @param diskCharacteristics * @param pool */ - public CreateCommand(VolumeVO vol, VMInstanceVO vm, DiskProfile diskCharacteristics, StoragePoolVO pool, long size) { - this.volId = vol.getId(); + public CreateCommand(DiskProfile diskCharacteristics, StorageFilerTO pool, long size) { + this.volId = diskCharacteristics.getVolumeId(); this.diskCharacteristics = diskCharacteristics; - this.pool = new StoragePoolTO(pool); + this.pool = pool; this.templateUrl = null; this.size = size; - //this.instanceName = vm.getInstanceName(); + } + + public CreateCommand(DiskProfile diskCharacteristics, String templateUrl, StoragePool pool) { + this(diskCharacteristics, templateUrl, new StorageFilerTO(pool)); + } + + public CreateCommand(DiskProfile diskCharacteristics, StoragePool pool, long size) { + this(diskCharacteristics, new StorageFilerTO(pool), size); } @Override @@ -76,7 +80,7 @@ public class CreateCommand extends Command { return templateUrl; } - public StoragePoolTO getPool() { + public StorageFilerTO getPool() { return pool; } @@ -92,7 +96,8 @@ public class CreateCommand extends Command { return this.size; } + @Deprecated public String getInstanceName() { - return instanceName; + return null; } } diff --git a/core/src/com/cloud/agent/api/to/NetworkTO.java b/api/src/com/cloud/agent/api/to/NetworkTO.java similarity index 81% rename from core/src/com/cloud/agent/api/to/NetworkTO.java rename to api/src/com/cloud/agent/api/to/NetworkTO.java index d6e428831f3..009fc1df7b6 100644 --- a/core/src/com/cloud/agent/api/to/NetworkTO.java +++ b/api/src/com/cloud/agent/api/to/NetworkTO.java @@ -17,6 +17,8 @@ */ package com.cloud.agent.api.to; +import java.net.URI; + import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.TrafficType; @@ -24,16 +26,18 @@ import com.cloud.network.Network.TrafficType; * Transfer object to transfer network settings. */ public class NetworkTO { - private String uuid; - private String ip; - private String netmask; - private String gateway; - private String mac; - private String dns1; - private String dns2; - private Long vlan; - private BroadcastDomainType broadcastType; - private TrafficType type; + protected String uuid; + protected String ip; + protected String netmask; + protected String gateway; + protected String mac; + protected String dns1; + protected String dns2; + protected Long vlan; + protected BroadcastDomainType broadcastType; + protected TrafficType type; + protected URI broadcastUri; + protected URI isolationUri; public NetworkTO() { } @@ -150,4 +154,20 @@ public class NetworkTO { public TrafficType getType() { return type; } + + public URI getBroadcastUri() { + return broadcastUri; + } + + public void setBroadcastUri(URI broadcastUri) { + this.broadcastUri = broadcastUri; + } + + public URI getIsolationUri() { + return isolationUri; + } + + public void setIsolationuri(URI isolationUri) { + this.isolationUri = isolationUri; + } } diff --git a/api/src/com/cloud/agent/api/to/NicTO.java b/api/src/com/cloud/agent/api/to/NicTO.java new file mode 100644 index 00000000000..af1ed168e38 --- /dev/null +++ b/api/src/com/cloud/agent/api/to/NicTO.java @@ -0,0 +1,53 @@ +/** + * + */ +package com.cloud.agent.api.to; + +public class NicTO extends NetworkTO { + int deviceId; + Integer networkRateMbps; + Integer networkRateMulticastMbps; + String bootParams; + boolean defaultNic; + + public NicTO() { + super(); + } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + public int getDeviceId() { + return deviceId; + } + + public Integer getNetworkRateMbps() { + return networkRateMbps; + } + + public Integer getNetworkRateMulticastMbps() { + return networkRateMulticastMbps; + } + + public String getBootParams() { + return bootParams; + } + + public void setBootParams(String bootParams) { + this.bootParams = bootParams; + } + + public boolean isDefaultNic() { + return defaultNic; + } + + public void setDefaultNic(boolean defaultNic) { + this.defaultNic = defaultNic; + } + + @Override + public String toString() { + return new StringBuilder("[Nic:").append(type).append("-").append(ip).append("-").append(broadcastUri).append("]").toString(); + } +} diff --git a/core/src/com/cloud/agent/api/to/StoragePoolTO.java b/api/src/com/cloud/agent/api/to/StorageFilerTO.java similarity index 92% rename from core/src/com/cloud/agent/api/to/StoragePoolTO.java rename to api/src/com/cloud/agent/api/to/StorageFilerTO.java index 188dc1c8094..f59ca841aa4 100644 --- a/core/src/com/cloud/agent/api/to/StoragePoolTO.java +++ b/api/src/com/cloud/agent/api/to/StorageFilerTO.java @@ -17,11 +17,10 @@ */ package com.cloud.agent.api.to; -import com.cloud.storage.StoragePoolVO; import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.StoragePool; - -public class StoragePoolTO { +public class StorageFilerTO { long id; String uuid; String host; @@ -29,7 +28,7 @@ public class StoragePoolTO { int port; StoragePoolType type; - public StoragePoolTO(StoragePoolVO pool) { + public StorageFilerTO(StoragePool pool) { this.id = pool.getId(); this.host = pool.getHostAddress(); this.port = pool.getPort(); @@ -62,7 +61,7 @@ public class StoragePoolTO { return type; } - protected StoragePoolTO() { + protected StorageFilerTO() { } @Override diff --git a/core/src/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java similarity index 69% rename from core/src/com/cloud/agent/api/to/VirtualMachineTO.java rename to api/src/com/cloud/agent/api/to/VirtualMachineTO.java index b37c2fd2426..c6511dfbcde 100644 --- a/core/src/com/cloud/agent/api/to/VirtualMachineTO.java +++ b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java @@ -21,6 +21,7 @@ import java.util.Map; import com.cloud.template.VirtualMachineTemplate.BootloaderType; import com.cloud.vm.VirtualMachine.Type; +import com.cloud.vm.VirtualMachineProfile; public class VirtualMachineTO { private long id; @@ -28,8 +29,7 @@ public class VirtualMachineTO { private BootloaderType bootloader; Type type; int cpus; - Integer weight; - Integer utilization; + Integer speed; long minRam; long maxRam; String hostName; @@ -38,11 +38,24 @@ public class VirtualMachineTO { String bootArgs; String[] bootupScripts; boolean rebootOnCrash; + Monitor monitor; VolumeTO[] disks; NicTO[] nics; - public VirtualMachineTO() { + public VirtualMachineTO(VirtualMachineProfile profile, BootloaderType bootloader) { + this.id = profile.getId(); + this.type = profile.getType(); + this.cpus = profile.getCpus(); + this.minRam = profile.getRam(); + this.maxRam = profile.getRam(); + this.speed = profile.getSpeed(); + this.os = profile.getOs(); + this.name = profile.getName(); + this.bootloader = bootloader; + } + + protected VirtualMachineTO() { } public long getId() { @@ -56,6 +69,14 @@ public class VirtualMachineTO { public String getName() { return name; } + + public Monitor getMonitor() { + return monitor; + } + + public void setMonitor(Monitor monitor) { + this.monitor = monitor; + } public void setName(String name) { this.name = name; @@ -81,22 +102,10 @@ public class VirtualMachineTO { this.cpus = cpus; } - public Integer getWeight() { - return weight; + public Integer getSpeed() { + return speed; } - public void setWeight(Integer weight) { - this.weight = weight; - } - - public Integer getUtilization() { - return utilization; - } - - public void setUtiliziation(Integer utilization) { - this.utilization = utilization; - } - public long getMinRam() { return minRam; } @@ -133,11 +142,20 @@ public class VirtualMachineTO { public void setOs(String os) { this.os = os; } - + public String getBootArgs() { + StringBuilder buf = new StringBuilder(bootArgs != null ? bootArgs : ""); + buf.append(" "); + for (NicTO nic : nics) { + buf.append(""); + } return bootArgs; } + public void setBootArgs(String bootArgs) { + this.bootArgs = bootArgs; + } + public void setBootArgs(Map bootParams) { StringBuilder buf = new StringBuilder(); for (Map.Entry entry : bootParams.entrySet()) { @@ -162,12 +180,33 @@ public class VirtualMachineTO { this.disks = disks; } - public NicTO[] getNetworks() { + public NicTO[] getNics() { return nics; } public void setNics(NicTO[] nics) { this.nics = nics; } - + + public static interface Monitor { + + } + + public static class SshMonitor implements Monitor { + String ip; + int port; + + public String getIp() { + return ip; + } + + public int getPort() { + return port; + } + + public SshMonitor(String ip, int port) { + this.ip = ip; + this.port = port; + } + } } diff --git a/core/src/com/cloud/agent/api/to/VolumeTO.java b/api/src/com/cloud/agent/api/to/VolumeTO.java similarity index 83% rename from core/src/com/cloud/agent/api/to/VolumeTO.java rename to api/src/com/cloud/agent/api/to/VolumeTO.java index 15853b13098..60dfe9eaf2b 100644 --- a/core/src/com/cloud/agent/api/to/VolumeTO.java +++ b/api/src/com/cloud/agent/api/to/VolumeTO.java @@ -19,10 +19,8 @@ package com.cloud.agent.api.to; import com.cloud.storage.Storage; import com.cloud.storage.Storage.StoragePoolType; -import com.cloud.storage.StoragePoolVO; -import com.cloud.storage.VMTemplateStoragePoolVO; +import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; -import com.cloud.storage.VolumeVO; public class VolumeTO { @@ -51,7 +49,7 @@ public class VolumeTO { this.mountPoint = mountPoint; } - public VolumeTO(VolumeVO volume, StoragePoolVO pool) { + public VolumeTO(Volume volume, StoragePool pool) { this.id = volume.getId(); this.name = volume.getName(); this.path = volume.getPath(); @@ -62,15 +60,7 @@ public class VolumeTO { this.mountPoint = volume.getFolder(); } - public VolumeTO(VMTemplateStoragePoolVO templatePoolRef, StoragePoolVO pool) { - this.id = templatePoolRef.getId(); - this.path = templatePoolRef.getInstallPath(); - this.size = templatePoolRef.getTemplateSize(); - this.resourceType = Storage.StorageResourceType.STORAGE_POOL; - this.storagePoolType = pool.getPoolType(); - this.mountPoint = pool.getPath(); - } - + public int getDeviceId() { return deviceId; } diff --git a/api/src/com/cloud/dc/DataCenter.java b/api/src/com/cloud/dc/DataCenter.java index 83902e42e3f..de4cca038e5 100644 --- a/api/src/com/cloud/dc/DataCenter.java +++ b/api/src/com/cloud/dc/DataCenter.java @@ -10,4 +10,6 @@ import com.cloud.org.Grouping; */ public interface DataCenter extends Grouping { long getId(); + String getDns1(); + String getDns2(); } diff --git a/api/src/com/cloud/deploy/DeploymentPlan.java b/api/src/com/cloud/deploy/DeploymentPlan.java index a36d7b35154..f7e3f04d464 100644 --- a/api/src/com/cloud/deploy/DeploymentPlan.java +++ b/api/src/com/cloud/deploy/DeploymentPlan.java @@ -18,10 +18,13 @@ package com.cloud.deploy; /** - * Describes how a VM should be deployed. + * Describes how a VM should be deployed. * */ public interface DeploymentPlan { + // TODO: This interface is not fully developed. It really + // should be more complicated than this and allow a + // number of parameters to be specified. public long getDataCenterId(); public int getCount(); } diff --git a/api/src/com/cloud/exception/StorageUnavailableException.java b/api/src/com/cloud/exception/StorageUnavailableException.java index d6ed0265d88..1015e65835e 100644 --- a/api/src/com/cloud/exception/StorageUnavailableException.java +++ b/api/src/com/cloud/exception/StorageUnavailableException.java @@ -20,18 +20,39 @@ package com.cloud.exception; import com.cloud.utils.SerialVersionUID; /** - * This exception is thrown when the storage device can not be reached. - * + * This exception is thrown when storage for a VM is unavailable. + * If the cause is due to storage pool unavailable, calling + * getOffendingObject() will return the object that we have + * problem with. + * */ -public class StorageUnavailableException extends AgentUnavailableException { +public class StorageUnavailableException extends Exception { + Object _obj; private static final long serialVersionUID = SerialVersionUID.StorageUnavailableException; - public StorageUnavailableException(long hostId) { - super(hostId); - } - public StorageUnavailableException(String msg) { - super(msg, -1); + super(msg); + } + + public StorageUnavailableException(String msg, Throwable cause) { + super(msg, cause); + } + + public StorageUnavailableException(String msg, Object cause) { + super(msg); + _obj = cause; + } + + public StorageUnavailableException(String msg, Object obj, Throwable cause) { + super(msg, cause); + _obj = obj; + } + + /** + * @return object that caused this problem. It can either be a StoragePool or volume. + */ + public Object getOffendingObject() { + return _obj; } } diff --git a/api/src/com/cloud/host/Host.java b/api/src/com/cloud/host/Host.java index f90307ed6a6..0ece719bcc4 100755 --- a/api/src/com/cloud/host/Host.java +++ b/api/src/com/cloud/host/Host.java @@ -20,8 +20,7 @@ package com.cloud.host; import java.util.Date; import com.cloud.host.Status; -import com.cloud.hypervisor.Hypervisor; -import com.cloud.hypervisor.Hypervisor.Type; +import com.cloud.hypervisor.Hypervisor.HypervisorType;; /** @@ -135,7 +134,7 @@ public interface Host { /** * @return type of hypervisor */ - Hypervisor.Type getHypervisorType(); + HypervisorType getHypervisorType(); /** * @return disconnection date diff --git a/api/src/com/cloud/hypervisor/Hypervisor.java b/api/src/com/cloud/hypervisor/Hypervisor.java index c938bba26e4..cc063cd00dd 100644 --- a/api/src/com/cloud/hypervisor/Hypervisor.java +++ b/api/src/com/cloud/hypervisor/Hypervisor.java @@ -19,13 +19,38 @@ package com.cloud.hypervisor; public class Hypervisor { - public static enum Type { + public static enum HypervisorType { None, //for storage hosts Xen, XenServer, KVM, VmWare, VirtualBox, - Parralels; + Parralels, + Any; /*If you don't care about the hypervisor type*/ + + public static HypervisorType getType(String hypervisor) { + if (hypervisor == null) { + return HypervisorType.None; + } + + if (hypervisor.equalsIgnoreCase("Xen")) { + return HypervisorType.Xen; + } else if (hypervisor.equalsIgnoreCase("XenServer")) { + return HypervisorType.XenServer; + } else if (hypervisor.equalsIgnoreCase("KVM")) { + return HypervisorType.KVM; + } else if (hypervisor.equalsIgnoreCase("VmWare")) { + return HypervisorType.VmWare; + } else if (hypervisor.equalsIgnoreCase("VirtualBox")) { + return HypervisorType.VirtualBox; + } else if (hypervisor.equalsIgnoreCase("Parralels")) { + return HypervisorType.Parralels; + } else if (hypervisor.equalsIgnoreCase("Any")) { + return HypervisorType.Any; + } else { + return HypervisorType.None; + } + } } } diff --git a/api/src/com/cloud/hypervisor/HypervisorGuru.java b/api/src/com/cloud/hypervisor/HypervisorGuru.java new file mode 100644 index 00000000000..4768ee34ca8 --- /dev/null +++ b/api/src/com/cloud/hypervisor/HypervisorGuru.java @@ -0,0 +1,28 @@ +/** + * 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 . + * + */ +package com.cloud.hypervisor; + +import com.cloud.offering.ServiceOffering; +import com.cloud.utils.component.Adapter; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; + +public interface HypervisorGuru extends Adapter { + VirtualMachineProfile design(VirtualMachine vm, ServiceOffering offering); + boolean check(VirtualMachineProfile profile); +} diff --git a/api/src/com/cloud/network/NetworkConfiguration.java b/api/src/com/cloud/network/NetworkConfiguration.java index 9ccf426a389..760e7ce2e13 100644 --- a/api/src/com/cloud/network/NetworkConfiguration.java +++ b/api/src/com/cloud/network/NetworkConfiguration.java @@ -23,10 +23,10 @@ public interface NetworkConfiguration { } enum State implements FiniteState { - Allocated, // Indicates the network configuration is in allocated but not setup. - Setup, // Indicates the network configuration is setup. - Implemented, // Indicates the network configuration is in use. - Destroying; + Allocated("Indicates the network configuration is in allocated but not setup"), + Setup("Indicates the network configuration is setup"), + Implemented("Indicates the network configuration is in use"), + Destroying("Indicates the network configuration is being destroyed"); @Override public StateMachine getStateMachine() { @@ -48,7 +48,23 @@ public interface NetworkConfiguration { return s_fsm.getPossibleEvents(this); } + String _description; + + @Override + public String getDescription() { + return _description; + } + + private State(String description) { + _description = description; + } + private static StateMachine s_fsm = new StateMachine(); + static { + s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implemented); + s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying); + } + } diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 87ff831d32e..333b6f1bbcf 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -66,5 +66,4 @@ public interface ServiceOffering { * @return whether or not the service offering requires local storage */ boolean getUseLocalStorage(); - } diff --git a/api/src/com/cloud/resource/Resource.java b/api/src/com/cloud/resource/Resource.java index 310507061ae..3cc5135c648 100644 --- a/api/src/com/cloud/resource/Resource.java +++ b/api/src/com/cloud/resource/Resource.java @@ -26,12 +26,14 @@ public interface Resource { } enum State implements FiniteState { - Allocated, // Resource is allocated - Reserving, // Resource is being reserved right now. - Reserved, // Resource is reserved - Releasing, // Resource is being released. - Ready; // Resource is ready which means it does not need to go through reservation. + Allocated("Resource is allocated but not reserved"), + Reserving("Resource is being reserved right now"), + Reserved("Resource has been reserved."), + Releasing("Resource is being released"), + Ready("Resource is ready which means it doesn't need to go through resservation"); + String _description; + @Override public StateMachine getStateMachine() { @@ -54,12 +56,24 @@ public interface Resource { return s_fsm.getPossibleEvents(this); } + private State(String description) { + _description = description; + } + + @Override + public String getDescription() { + return _description; + } + final static private StateMachine s_fsm = new StateMachine(); static { s_fsm.addTransition(State.Allocated, Event.ReservationRequested, State.Reserving); s_fsm.addTransition(State.Reserving, Event.CancelRequested, State.Allocated); s_fsm.addTransition(State.Reserving, Event.OperationCompleted, State.Reserved); s_fsm.addTransition(State.Reserving, Event.OperationFailed, State.Allocated); + s_fsm.addTransition(State.Reserved, Event.ReleaseRequested, State.Releasing); + s_fsm.addTransition(State.Releasing, Event.OperationCompleted, State.Allocated); + s_fsm.addTransition(State.Releasing, Event.OperationFailed, State.Reserved); } } diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java index 81d94ad0331..6eb07ec51ed 100644 --- a/api/src/com/cloud/storage/Storage.java +++ b/api/src/com/cloud/storage/Storage.java @@ -23,7 +23,7 @@ public class Storage { RAW(false, false, false), VHD(true, true, true), ISO(false, false, false), - VMDK(true, true, true, "vmw.tar"); + OVA(true, true, true, "ova"); private final boolean thinProvisioned; private final boolean supportSparse; @@ -79,6 +79,11 @@ public class Storage { hfsp } + public static enum TemplateType { + SYSTEM, + BUILTIN + } + public static enum StoragePoolType { Filesystem(false), //local directory NetworkFilesystem(true), //NFS or CIFS diff --git a/api/src/com/cloud/storage/StorageGuru.java b/api/src/com/cloud/storage/StorageGuru.java new file mode 100644 index 00000000000..396013debf5 --- /dev/null +++ b/api/src/com/cloud/storage/StorageGuru.java @@ -0,0 +1,30 @@ +/** + * 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 . + * + */ +package com.cloud.storage; + +import com.cloud.utils.component.Adapter; + +/** + * StorageGuru understands about how to implement different + * types of storage pools. + */ +public interface StorageGuru extends Adapter { + void createVolume(); + void prepareVolume(); + void destroyVolume(); +} diff --git a/api/src/com/cloud/storage/StoragePool.java b/api/src/com/cloud/storage/StoragePool.java index 2c06aba7628..dbbb8c61492 100644 --- a/api/src/com/cloud/storage/StoragePool.java +++ b/api/src/com/cloud/storage/StoragePool.java @@ -101,4 +101,8 @@ public interface StoragePool { * @return the storage pool status */ Status getStatus(); + + int getPort(); + + Long getPodId(); } diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index 75421e1880b..bd663f142f6 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -18,10 +18,14 @@ package com.cloud.storage; import java.util.Date; +import java.util.List; +import java.util.Set; import com.cloud.domain.PartOf; import com.cloud.template.BasedOn; import com.cloud.user.OwnedBy; +import com.cloud.utils.fsm.FiniteState; +import com.cloud.utils.fsm.StateMachine; public interface Volume extends PartOf, OwnedBy, BasedOn { @@ -29,14 +33,69 @@ public interface Volume extends PartOf, OwnedBy, BasedOn { enum MirrorState {NOT_MIRRORED, ACTIVE, DEFUNCT}; - enum State { - Allocated, - Creating, - Created, - Corrupted, - ToBeDestroyed, - Expunging, - Destroyed + enum State implements FiniteState { + Allocated("The volume is allocated but has not been created yet."), + Creating("The volume is being created. getPoolId() should reflect the pool where it is being created."), + Ready("The volume is ready to be used."), + Destroy("The volume is set to be desctroyed but can be recovered."), + Expunging("The volume is being destroyed. There's no way to recover."), + Destroyed("The volume is destroyed. Should be removed."); + + String _description; + + private State(String description) { + _description = description; + } + + @Override + public StateMachine getStateMachine() { + return s_fsm; + } + + @Override + public State getNextState(Event event) { + return s_fsm.getNextState(this, event); + } + + @Override + public List getFromStates(Event event) { + return s_fsm.getFromStates(this, event); + } + + @Override + public Set getPossibleEvents() { + return s_fsm.getPossibleEvents(this); + } + + @Override + public String getDescription() { + return _description; + } + + private final static StateMachine s_fsm = new StateMachine(); + static { + s_fsm.addTransition(Allocated, Event.Create, Creating); + s_fsm.addTransition(Allocated, Event.Destroy, Destroyed); + s_fsm.addTransition(Creating, Event.OperationRetry, Creating); + s_fsm.addTransition(Creating, Event.OperationFailed, Allocated); + s_fsm.addTransition(Creating, Event.OperationSucceeded, Ready); + s_fsm.addTransition(Creating, Event.Destroy, Expunging); + s_fsm.addTransition(Ready, Event.Destroy, Destroy); + s_fsm.addTransition(Destroy, Event.Expunge, Expunging); + s_fsm.addTransition(Destroy, Event.Recover, Ready); + s_fsm.addTransition(Expunging, Event.OperationSucceeded, Destroyed); + s_fsm.addTransition(Expunging, Event.OperationFailed, Destroy); + } + } + + enum Event { + Create, + OperationFailed, + OperationSucceeded, + OperationRetry, + Destroy, + Recover, + Expunge; } enum SourceType { diff --git a/api/src/com/cloud/template/VirtualMachineTemplate.java b/api/src/com/cloud/template/VirtualMachineTemplate.java index 0cdffe856d8..1697c1f5a3b 100755 --- a/api/src/com/cloud/template/VirtualMachineTemplate.java +++ b/api/src/com/cloud/template/VirtualMachineTemplate.java @@ -37,10 +37,5 @@ public interface VirtualMachineTemplate { * @return name */ String getName(); - - /** - * @return the file system for this template. - */ - FileSystem getFileSystem(); } diff --git a/api/src/com/cloud/vm/DiskProfile.java b/api/src/com/cloud/vm/DiskProfile.java index cad858b9dad..7cfbedb1118 100644 --- a/api/src/com/cloud/vm/DiskProfile.java +++ b/api/src/com/cloud/vm/DiskProfile.java @@ -17,6 +17,7 @@ */ package com.cloud.vm; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.DiskOffering; import com.cloud.storage.Volume; @@ -38,6 +39,7 @@ public class DiskProfile { private long volumeId; private Volume vol; private DiskOffering offering; + private HypervisorType hyperType; protected DiskProfile() { } @@ -54,10 +56,11 @@ public class DiskProfile { this.volumeId = volumeId; } - public DiskProfile(Volume vol, DiskOffering offering) { + public DiskProfile(Volume vol, DiskOffering offering, HypervisorType hyperType) { this(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.getUseLocalStorage(), offering.getUseLocalStorage(), vol.getSize()); this.vol = vol; this.offering = offering; + this.hyperType = hyperType; } /** @@ -128,4 +131,12 @@ public class DiskProfile { public String toString() { return new StringBuilder("DskChr[").append(type).append("|").append(size).append("|").append("]").toString(); } + + public void setHyperType(HypervisorType hyperType) { + this.hyperType = hyperType; + } + + public HypervisorType getHypersorType() { + return this.hyperType; + } } diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index 621472723ea..ab89c55ac8e 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -29,6 +29,30 @@ public class NicProfile { URI broadcastUri; ReservationStrategy strategy; String reservationId; + boolean defaultNic; + Integer deviceId; + String dns1; + String dns2; + + public String getDns1() { + return dns1; + } + + public String getDns2() { + return dns2; + } + + public void setDns1(String dns1) { + this.dns1 = dns1; + } + + public void setDns2(String dns2) { + this.dns2 = dns2; + } + + public boolean isDefaultNic() { + return defaultNic; + } public String getNetmask() { return netmask; @@ -54,6 +78,10 @@ public class NicProfile { return isolationUri; } + public void setStrategy(ReservationStrategy strategy) { + this.strategy = strategy; + } + public BroadcastDomainType getType() { return broadcastType; } @@ -69,6 +97,18 @@ public class NicProfile { public void setVmId(long vmId) { this.vmId = vmId; } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + public void setDefaultNic(boolean defaultNic) { + this.defaultNic = defaultNic; + } + + public Integer getDeviceId() { + return deviceId; + } public void setGateway(String gateway) { this.gateway = gateway; @@ -142,7 +182,7 @@ public class NicProfile { this.ip4Address = ip4Address; } - public NicProfile(Nic nic, NetworkConfiguration network) { + public NicProfile(Nic nic, NetworkConfiguration network, URI broadcastUri, URI isolationUri) { this.id = nic.getId(); this.gateway = network.getGateway(); this.mode = network.getMode(); @@ -171,6 +211,9 @@ public class NicProfile { this.netmask = netmask; this.strategy = strategy; } + + public NicProfile() { + } public ReservationStrategy getReservationStrategy() { return strategy; diff --git a/api/src/com/cloud/vm/State.java b/api/src/com/cloud/vm/State.java index 53bd798818f..c024ff270b9 100644 --- a/api/src/com/cloud/vm/State.java +++ b/api/src/com/cloud/vm/State.java @@ -26,21 +26,28 @@ import com.cloud.utils.fsm.StateMachine; import com.cloud.vm.VirtualMachine.Event; public enum State implements FiniteState { - Creating(true), - Starting(true), - Running(false), - Stopping(true), - Stopped(false), - Destroyed(false), - Expunging(true), - Migrating(true), - Error(false), - Unknown(false); + Creating(true, "VM is being created"), + Starting(true, "VM is being started. At this state, you should find host id filled which means it's being started on that host."), + Running(false, "VM is running. host id has the host that it is running on."), + Stopping(true, "VM is being stopped. host id has the host that it is being stopped on."), + Stopped(false, "VM is stopped. host id should be null."), + Destroyed(false, "VM is marked for destroy."), + Expunging(true, "VM is being expunged."), + Migrating(true, "VM is being migrated. host id holds to from host"), + Error(false, "VM is in error"), + Unknown(false, "VM state is unknown."); private final boolean _transitional; + String _description; - private State(boolean transitional) { + private State(boolean transitional, String description) { _transitional = transitional; + _description = description; + } + + @Override + public String getDescription() { + return _description; } public boolean isTransitional() { @@ -67,6 +74,7 @@ public enum State implements FiniteState { return s_fsm; } + protected static final StateMachine s_fsm = new StateMachine(); static { s_fsm.addTransition(null, VirtualMachine.Event.CreateRequested, State.Creating); diff --git a/api/src/com/cloud/vm/VirtualMachineProfile.java b/api/src/com/cloud/vm/VirtualMachineProfile.java index 6d97f5d21c1..9bd820fb673 100644 --- a/api/src/com/cloud/vm/VirtualMachineProfile.java +++ b/api/src/com/cloud/vm/VirtualMachineProfile.java @@ -20,25 +20,34 @@ package com.cloud.vm; import java.util.List; import java.util.Map; -import com.cloud.hypervisor.Hypervisor; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; public class VirtualMachineProfile { VirtualMachine _vm; - int _cpus; - int _speed; // in mhz + Integer _cpus; + Integer _speed; // in mhz long _ram; // in bytes - Hypervisor.Type _hypervisorType; + HypervisorType _hypervisorType; VirtualMachine.Type _type; Map _params; Long _templateId; List _disks; List _nics; + String _os; public VirtualMachineProfile(VirtualMachine.Type type) { this._type = type; } + public String getName() { + return _vm.getInstanceName(); + } + + public String getOs() { + return _os; + } + public long getId() { return _vm.getId(); } @@ -51,11 +60,11 @@ public class VirtualMachineProfile { return _templateId; } - public int getCpus() { + public Integer getCpus() { return _cpus; } - public int getSpeed() { + public Integer getSpeed() { return _speed; } @@ -79,7 +88,7 @@ public class VirtualMachineProfile { return _disks; } - public Hypervisor.Type getHypervisorType() { + public HypervisorType getHypervisorType() { return _hypervisorType; } @@ -87,22 +96,15 @@ public class VirtualMachineProfile { return _vm; } - public VirtualMachineProfile(long id, int core, int speed, long ram, Long templateId, Hypervisor.Type type, Map params) { - this._cpus = core; - this._speed = speed; - this._ram = ram; - this._hypervisorType = type; - this._params = params; - this._templateId = templateId; - } - - public VirtualMachineProfile(VirtualMachine vm, ServiceOffering offering) { + public VirtualMachineProfile(VirtualMachine vm, ServiceOffering offering, String os, HypervisorType hypervisorType) { this._cpus = offering.getCpu(); this._speed = offering.getSpeed(); - this._ram = offering.getRamSize(); + this._ram = offering.getRamSize() * 1024l * 1024l; this._templateId = vm.getTemplateId(); this._type = vm.getType(); this._vm = vm; + this._os = os; + this._hypervisorType = hypervisorType; } protected VirtualMachineProfile() { @@ -112,4 +114,4 @@ public class VirtualMachineProfile { public String toString() { return "VM-" + _type + "-" + _vm.getId(); } -} \ No newline at end of file +} diff --git a/build/build-cloud.xml b/build/build-cloud.xml index 1f9764271e3..8e534232109 100755 --- a/build/build-cloud.xml +++ b/build/build-cloud.xml @@ -518,15 +518,15 @@ - + - - + + diff --git a/build/developer.xml b/build/developer.xml index 33d77a6c85a..ac0956a96c4 100755 --- a/build/developer.xml +++ b/build/developer.xml @@ -160,24 +160,8 @@ - - - - - - - - - - - - - - - - - - + + diff --git a/client/WEB-INF/classes/resources/resource.properties b/client/WEB-INF/classes/resources/resource.properties index 0310e1c3f06..e11b0388b7d 100644 --- a/client/WEB-INF/classes/resources/resource.properties +++ b/client/WEB-INF/classes/resources/resource.properties @@ -1 +1,95 @@ -Details = Details +actions = Actions +add = Add +help = Help +advanced = Advanced +version = Version + +dashboard = Dashboard +instance = Instance +router = Router +storage = Storage +volume = Volume +snapshot = Snapshot +ip.address = IP Address +template = Template +my.template = My Template +featured.template = Featured Template +community.template = Community Template +iso = ISO +my.iso = My ISO +featured.iso = Featured ISO +community.iso = Community ISO +account = Account +domain = Domain +event = Event +alert = Alert +system = System +global.settings = Global Settings +resources = Resources +service.offerings = Service Offerings +disk.offerings = Disk Offerings + +details = Details +network = Network +secondary.storage = Secondary Storage + +no.available.actions = No available actions + +ID = ID +name = Name +display.text = Display Text +os.type = OS Type +public = Public +instance.name = Instance Name +group.name = Group Name +service.offering = Service Offering +password.enabled = Password Enabled +instance.limit = Instance Limit +public.ip.limit = Public IP Limit +disk.volume.limit = Disk Volume Limit +snapshot.limit = Snapshot Limit +template.limit = Template Limit +URL = URL +zone = Zone +bootable = Bootable +group = Group +storage.type = Storage Type +CPU = CPU +memory = Memory +offer.HA = Offer HA +network.type = Network Type +created = Created +disk.size = Disk Size +value = Value +description = Description + +disk.offering = Disk Offering +copy.ISO.to = Copy ISO to +no.available.iso = No Available ISO +please.wait = Please wait + +your.session.has.expired = Your session has expired +internet.name.can.not.be.resolved = Internet name can not be resolved +management.server.is.not.accessible = Management server is not accessible +please.select.at.least.one.item.in.middle.menu = Please select at least one item in middle menu +please.confirm.you.want.to.detach.an.iso.from.the.virtual.machine = Please confirm you want to detach an ISO from the virtual machine +please.specify.the.iso.you.wish.to.attach.to.virtual.machine = Please specify the ISO you wish to attach to virtual instance +please.specify.the.new.name.you.want.to.change.for.the.virtual.machine = Please specify the new name you want to change for the virtual instance +please.specify.the.new.group.you.want.to.assign.the.virtual.machine.to = Please specify the new group you want to assign the virtual machine to +after.changing.service.offering.you.must.restart.the.virtual.machine.for.new.service.offering.to.take.effect = After changing service offering, you must restart the virtual machine for the new service offering to take effect. +creating.a.template.of.disk.volume.could.take.up.to.several.hours.depending.on.the.size.of.the.disk.volume = Creating a template of disk volume could take up to several hours depending on the size of the disk volume +please.confirm.you.want.to.change.the.root.password.for.the.virtual.machine = Please confirm you want to change the ROOT password for the virtual machine +please.confirm.you.want.to.enable.HA.for.your.virtual.machine.once.HA.is.enabled.your.virtual.machine.will.be.automatically.restarted.in.the.event.it.is.detected.to.have.failed = Please confirm you want to enable HA for your virtual machine. Once HA is enabled, your virtual machine will be automatically restarted in the event it is detected to have failed. +please.confirm.you.want.to.disable.HA.for.the.virtual.machine.once.HA.is.disabled.the.virtual.machine.will.no.longer.be.automatically.restarted.in.the.event.of.a.failure = Please confirm you want to disable HA for the virtual machine. Once HA is disabled, the virtual machine will no longer be be automatically restarted in the event of a failure. +the.ISO.is.used.by.all.zones.please.confirm.you.want.to.delete.it.from.all.zones = The ISO is used by all zones. Please confirm you want to delete it from all zones. +please.confirm.you.want.to.delete.the.ISO = Please confirm you want to delete the ISO +the.template.is.used.by.all.zones.please.confirm.you.want.to.delete.it.from.all.zones = The template is used by all zones. Please confirm you want to delete it from all zones. +please.confirm.you.want.to.delete.the.template = Please confirm you want to delete the template +please.specify.limits.to.the.various.resources.-1.means.the.resource.has.no.limits = Please specify limits to the various resources. -1 means the resource has no limits. +please.confirm.you.want.to.disable.account.that.will.prevent.account.access.to.the.cloud.and.shut.down.all.existing.virtual.machines = Please confirm you want to disable account that will prevent account access to the cloud and shut down all existing virtual machines. +please.confirm.you.want.to.lock.account.that.will.prevent.account.access.to.the.cloud = Please confirm you want to lock account that will prevent account access to the cloud. +please.confirm.you.want.to.enable.account = Please confirm you want to enable account. +please.select.an.available.zone.to.associate.your.new.ip.with..acquiring.additional.ip.may.cost.you.an.additional.dollars.per.month. = Please select an availability zone to associate your new IP with. Acquiring additional IP may cost you an additional dollars per month. +please.confirm.you.want.to.release.this.IP.address = Please confirm you want to release this IP address + + diff --git a/client/WEB-INF/classes/resources/resource_zh.properties b/client/WEB-INF/classes/resources/resource_zh.properties index 307334f028f..44c50ef43ca 100644 --- a/client/WEB-INF/classes/resources/resource_zh.properties +++ b/client/WEB-INF/classes/resources/resource_zh.properties @@ -1,3 +1,29 @@ +actions = 功能 +add = 增加 +help = 幫助 +advanced = 進階 +version = 版本 + +dashboard = 儀器板 +instance = 實例 +router = 路由器 +storage = 貯藏 +volume = 容積 +snapshot = 快照 +ip.address = 網路地址 +template = 模板 +my.template = 我的模板 +featured.template = 特色模板 +community.template = 共有模板 +iso = 空白模板 +my.iso = 我的空白模板 +featured.iso = 特色空白模板 +community.iso = 共有空白模板 +account = 帳戶 +domain = 領土 +event = 事件 +alert = 警報 + Details = 詳述 Volume = 容積 Statistics = 統計 @@ -7,7 +33,6 @@ Service = 服務 HA = 高的可用性 Created = 產生日期 Account = 帳戶 -Domain = 領土 Host = 主機 ISO = 空白模板 diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index c8ae73f15d1..e1989cbc6a3 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -129,6 +129,7 @@ listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstanc startRouter=com.cloud.api.commands.StartRouterCmd;3 rebootRouter=com.cloud.api.commands.RebootRouterCmd;3 stopRouter=com.cloud.api.commands.StopRouterCmd;3 +changeServiceForRouter=com.cloud.api.commands.UpgradeRouterCmd;3 listRouters=com.cloud.api.commands.ListRoutersCmd;7 #### system vm commands @@ -213,9 +214,14 @@ registerPreallocatedLun=com.cloud.server.api.commands.RegisterPreallocatedLunCmd deletePreallocatedLun=com.cloud.server.api.commands.DeletePreallocatedLunCmd;1 listPreallocatedLuns=com.cloud.api.commands.ListPreallocatedLunsCmd;1 - #### vm group commands createInstanceGroup=com.cloud.api.commands.CreateVMGroupCmd;15 deleteInstanceGroup=com.cloud.api.commands.DeleteVMGroupCmd;15 updateInstanceGroup=com.cloud.api.commands.UpdateVMGroupCmd;15 listInstanceGroups=com.cloud.api.commands.ListVMGroupsCmd;15 + +### Certificate commands +uploadCustomCertificate=com.cloud.api.commands.UploadCustomCertificateCmd;15 + +### other commands +listHypervisors=com.cloud.api.commands.ListHypervisorsCmd;15 \ No newline at end of file diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 9e8733eb886..66940f90c0a 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -89,6 +89,7 @@ + @@ -101,7 +102,6 @@ - diff --git a/cloud.spec b/cloud.spec index 3d03ea82383..cebe04292e0 100644 --- a/cloud.spec +++ b/cloud.spec @@ -522,6 +522,9 @@ fi %files python %defattr(0644,root,root,0755) %{_prefix}/lib*/python*/site-packages/%{name}* +%attr(0755,root,root) %{_bindir}/cloud-external-ipallocator.py +%attr(0755,root,root) %{_initrddir}/cloud-ipallocator +%dir %attr(770,root,root) %{_localstatedir}/log/%{name}/ipallocator %files setup %attr(0755,root,root) %{_bindir}/%{name}-setup-databases @@ -532,6 +535,7 @@ fi %{_datadir}/%{name}/setup/create-schema.sql %{_datadir}/%{name}/setup/server-setup.sql %{_datadir}/%{name}/setup/templates.*.sql +%{_datadir}/%{name}/setup/templates.sql %{_datadir}/%{name}/setup/deploy-db-dev.sh %{_datadir}/%{name}/setup/server-setup.xml %{_datadir}/%{name}/setup/data-20to21.sql @@ -602,6 +606,7 @@ fi %attr(0755,root,root) %{_bindir}/%{name}-setup-agent %dir %attr(770,root,root) %{_localstatedir}/log/%{name}/agent + %files console-proxy %defattr(0644,root,root,0755) %{_javadir}/%{name}-console*.jar diff --git a/console-proxy/conf.dom0/agent.properties.in b/console-proxy/conf.dom0/agent.properties.in index 100f6532af8..7eaf336e198 100644 --- a/console-proxy/conf.dom0/agent.properties.in +++ b/console-proxy/conf.dom0/agent.properties.in @@ -2,6 +2,7 @@ instance=ConsoleProxy consoleproxy.httpListenPort=8002 +public.ip=65.19.181.3 #resource= the java class, which agent load to execute resource=com.cloud.agent.resource.consoleproxy.ConsoleProxyResource diff --git a/console-proxy/scripts/_run.sh b/console-proxy/scripts/_run.sh index e90005d2ebb..4b4b00641b8 100755 --- a/console-proxy/scripts/_run.sh +++ b/console-proxy/scripts/_run.sh @@ -14,12 +14,9 @@ do CP=${CP}:$file done keyvalues= -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi + +CMDLINE=$(cat /var/cache/cloud/cmdline) + #CMDLINE="graphical utf8 eth0ip=0.0.0.0 eth0mask=255.255.255.0 eth1ip=192.168.140.40 eth1mask=255.255.255.0 eth2ip=172.24.0.50 eth2mask=255.255.0.0 gateway=172.24.0.1 dns1=72.52.126.11 template=domP dns2=72.52.126.12 host=192.168.1.142 port=8250 mgmtcidr=192.168.1.0/24 localgw=192.168.140.1 zone=5 pod=5" for i in $CMDLINE do diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java index a1a1b35e915..81af054c487 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java @@ -180,14 +180,14 @@ public class ConsoleProxy { } } - public static boolean authenticateConsoleAccess(String vmId, String sid) { + public static boolean authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket) { if(standaloneStart) return true; if(authMethod != null) { Object result; try { - result = authMethod.invoke(ConsoleProxy.context, vmId, sid); + result = authMethod.invoke(ConsoleProxy.context, host, port, vmId, sid, ticket); } catch (IllegalAccessException e) { s_logger.error("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + vmId, e); return false; @@ -252,7 +252,7 @@ public class ConsoleProxy { ConsoleProxy.context = context; try { Class contextClazz = Class.forName("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource"); - authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class); + authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class, String.class, String.class, String.class); reportMethod = contextClazz.getDeclaredMethod("reportLoadInfo", String.class); ensureRouteMethod = contextClazz.getDeclaredMethod("ensureRoute", String.class); } catch (SecurityException e) { @@ -419,8 +419,8 @@ public class ConsoleProxy { return viewer; } - static void initViewer(ConsoleProxyViewer viewer, String host, int port, String tag, String sid) throws AuthenticationException { - ConsoleProxyViewer.authenticationExternally(tag, sid); + static void initViewer(ConsoleProxyViewer viewer, String host, int port, String tag, String sid, String ticket) throws AuthenticationException { + ConsoleProxyViewer.authenticationExternally(host, String.valueOf(port), tag, sid, ticket); viewer.host = host; viewer.port = port; @@ -430,7 +430,7 @@ public class ConsoleProxy { viewer.init(); } - static ConsoleProxyViewer getVncViewer(String host, int port, String sid, String tag) throws Exception { + static ConsoleProxyViewer getVncViewer(String host, int port, String sid, String tag, String ticket) throws Exception { ConsoleProxyViewer viewer = null; boolean reportLoadChange = false; @@ -438,7 +438,7 @@ public class ConsoleProxy { viewer = connectionMap.get(host + ":" + port); if (viewer == null) { viewer = createViewer(); - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); connectionMap.put(host + ":" + port, viewer); s_logger.info("Added viewer object " + viewer); @@ -446,12 +446,12 @@ public class ConsoleProxy { } else if (!viewer.rfbThread.isAlive()) { s_logger.info("The rfb thread died, reinitializing the viewer " + viewer); - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); reportLoadChange = true; } else if (!sid.equals(viewer.passwordParam)) { s_logger.warn("Bad sid detected(VNC port may be reused). sid in session: " + viewer.passwordParam + ", sid in request: " + sid); - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); reportLoadChange = true; @@ -484,7 +484,7 @@ public class ConsoleProxy { return viewer; } - static ConsoleProxyViewer getAjaxVncViewer(String host, int port, String sid, String tag) throws Exception { + static ConsoleProxyViewer getAjaxVncViewer(String host, int port, String sid, String tag, String ticket, String ajaxSession) throws Exception { boolean reportLoadChange = false; synchronized (connectionMap) { ConsoleProxyViewer viewer = connectionMap.get(host + ":" + port); @@ -494,25 +494,29 @@ public class ConsoleProxy { viewer = createViewer(); viewer.ajaxViewer = true; - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); connectionMap.put(host + ":" + port, viewer); s_logger.info("Added viewer object " + viewer); reportLoadChange = true; } else if (!viewer.rfbThread.isAlive()) { s_logger.info("The rfb thread died, reinitializing the viewer " + viewer); - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); reportLoadChange = true; } else if (!sid.equals(viewer.passwordParam)) { s_logger.warn("Bad sid detected(VNC port may be reused). sid in session: " + viewer.passwordParam + ", sid in request: " + sid); - initViewer(viewer, host, port, tag, sid); + initViewer(viewer, host, port, tag, sid, ticket); reportLoadChange = true; /* throw new AuthenticationException ("Cannot use the existing viewer " + viewer + ": bad sid"); */ + } else { + if(ajaxSession == null || ajaxSession.isEmpty()) + ConsoleProxyViewer.authenticationExternally(host, String.valueOf(port), tag, sid, ticket); } + if (viewer.status == ConsoleProxyViewer.STATUS_NORMAL_OPERATION) { // Do not update lastUsedTime if the viewer is in the process of starting up // or if it failed to authenticate. diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java index 0324988c64b..22f8294fbec 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java @@ -72,7 +72,8 @@ public class ConsoleProxyAjaxHandler implements HttpHandler { String host = queryMap.get("host"); String portStr = queryMap.get("port"); String sid = queryMap.get("sid"); - String tag = queryMap.get("tag"); + String tag = queryMap.get("tag"); + String ticket = queryMap.get("ticket"); String ajaxSessionIdStr = queryMap.get("sess"); String eventStr = queryMap.get("event"); if(tag == null) @@ -113,7 +114,7 @@ public class ConsoleProxyAjaxHandler implements HttpHandler { ConsoleProxyViewer viewer = null; try { - viewer = ConsoleProxy.getAjaxVncViewer(host, port, sid, tag); + viewer = ConsoleProxy.getAjaxVncViewer(host, port, sid, tag, ticket, ajaxSessionIdStr); } catch(Exception e) { /* diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java index 66cba4129b4..66632f93cea 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java @@ -62,7 +62,8 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler { String host = queryMap.get("host"); String portStr = queryMap.get("port"); String sid = queryMap.get("sid"); - String tag = queryMap.get("tag"); + String tag = queryMap.get("tag"); + String ticket = queryMap.get("ticket"); String keyStr = queryMap.get("key"); int key = 0; @@ -87,7 +88,7 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler { throw new IllegalArgumentException(e); } - ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, tag); + ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, tag, ticket); byte[] img = viewer.getAjaxImageCache().getImage(key); if(img != null) { Headers hds = t.getResponseHeaders(); diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientHandler.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientHandler.java index 4c9be4cd02d..23543a706c4 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientHandler.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientHandler.java @@ -88,7 +88,7 @@ public class ConsoleProxyClientHandler extends Thread { String host = stk.nextToken(); int port = Integer.parseInt(stk.nextToken()); String sid = stk.nextToken(); - ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, ""); + ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, "", ""); ConsoleProxy.waitForViewerToStart(viewer); diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java index 140ede10581..0773c263d9c 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java @@ -135,7 +135,8 @@ public class ConsoleProxyThumbnailHandler implements HttpHandler { String host = queryMap.get("host"); String portStr = queryMap.get("port"); String sid = queryMap.get("sid"); - String tag = queryMap.get("tag"); + String tag = queryMap.get("tag"); + String ticket = queryMap.get("ticket"); if(tag == null) tag = ""; @@ -150,7 +151,7 @@ public class ConsoleProxyThumbnailHandler implements HttpHandler { throw new IllegalArgumentException(e); } - ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, tag); + ConsoleProxyViewer viewer = ConsoleProxy.getVncViewer(host, port, sid, tag, ticket); if (viewer.status != ConsoleProxyViewer.STATUS_NORMAL_OPERATION) { // use generated image instead of static diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyViewer.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyViewer.java index 754d8f6727e..98453acf134 100644 --- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyViewer.java +++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyViewer.java @@ -315,7 +315,7 @@ public class ConsoleProxyViewer implements java.lang.Runnable, RfbViewer, RfbPro } } - static void authenticationExternally(String tag, String sid) throws AuthenticationException { + static void authenticationExternally(String host, String port, String tag, String sid, String ticket) throws AuthenticationException { /* if(ConsoleProxy.management_host != null) { try { @@ -352,7 +352,7 @@ public class ConsoleProxyViewer implements java.lang.Runnable, RfbViewer, RfbPro s_logger.warn("No external authentication source being setup."); } */ - if(!ConsoleProxy.authenticateConsoleAccess(tag, sid)) { + if(!ConsoleProxy.authenticateConsoleAccess(host, port, tag, sid, ticket)) { s_logger.warn("External authenticator failed authencation request for vm " + tag + " with sid " + sid); throw new AuthenticationException("External authenticator failed request for vm " + tag + " with sid " + sid); diff --git a/core/src/com/cloud/agent/api/AttachIsoCommand.java b/core/src/com/cloud/agent/api/AttachIsoCommand.java index 6073ab553f7..f4e3fcc46bc 100644 --- a/core/src/com/cloud/agent/api/AttachIsoCommand.java +++ b/core/src/com/cloud/agent/api/AttachIsoCommand.java @@ -21,6 +21,7 @@ package com.cloud.agent.api; public class AttachIsoCommand extends Command { private String vmName; + private String storeUrl; private String isoPath; private boolean attach; @@ -49,4 +50,12 @@ public class AttachIsoCommand extends Command { public boolean isAttach() { return attach; } + + public String getStoreUrl() { + return storeUrl; + } + + public void setStoreUrl(String url) { + storeUrl = url; + } } diff --git a/core/src/com/cloud/agent/api/AttachVolumeCommand.java b/core/src/com/cloud/agent/api/AttachVolumeCommand.java index ca07733a91e..0ac47dd7e2e 100644 --- a/core/src/com/cloud/agent/api/AttachVolumeCommand.java +++ b/core/src/com/cloud/agent/api/AttachVolumeCommand.java @@ -25,6 +25,7 @@ public class AttachVolumeCommand extends Command { boolean attach; String vmName; StoragePoolType pooltype; + String poolUuid; String volumeFolder; String volumePath; String volumeName; @@ -83,5 +84,12 @@ public class AttachVolumeCommand extends Command { public void setDeviceId(Long deviceId) { this.deviceId = deviceId; } - + + public String getPoolUuid() { + return poolUuid; + } + + public void setPoolUuid(String poolUuid) { + this.poolUuid = poolUuid; + } } diff --git a/core/src/com/cloud/agent/api/BackupSnapshotCommand.java b/core/src/com/cloud/agent/api/BackupSnapshotCommand.java index ccf45d71115..08b4b7b5a5c 100644 --- a/core/src/com/cloud/agent/api/BackupSnapshotCommand.java +++ b/core/src/com/cloud/agent/api/BackupSnapshotCommand.java @@ -27,7 +27,6 @@ package com.cloud.agent.api; public class BackupSnapshotCommand extends SnapshotCommand { private String prevSnapshotUuid; private String prevBackupUuid; - private boolean isFirstSnapshotOfRootVolume; private boolean isVolumeInactive; private String firstBackupUuid; private String vmName; @@ -56,7 +55,6 @@ public class BackupSnapshotCommand extends SnapshotCommand { String prevSnapshotUuid, String prevBackupUuid, String firstBackupUuid, - boolean isFirstSnapshotOfRootVolume, boolean isVolumeInactive, String vmName) { @@ -64,7 +62,6 @@ public class BackupSnapshotCommand extends SnapshotCommand { this.prevSnapshotUuid = prevSnapshotUuid; this.prevBackupUuid = prevBackupUuid; this.firstBackupUuid = firstBackupUuid; - this.isFirstSnapshotOfRootVolume = isFirstSnapshotOfRootVolume; this.isVolumeInactive = isVolumeInactive; this.vmName = vmName; } @@ -81,10 +78,6 @@ public class BackupSnapshotCommand extends SnapshotCommand { return firstBackupUuid; } - public boolean isFirstSnapshotOfRootVolume() { - return isFirstSnapshotOfRootVolume; - } - public boolean isVolumeInactive() { return isVolumeInactive; } diff --git a/core/src/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java b/core/src/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java index f1c25c5bd2f..2db7dec8073 100644 --- a/core/src/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java +++ b/core/src/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java @@ -19,17 +19,31 @@ package com.cloud.agent.api; public class ConsoleAccessAuthenticationCommand extends AgentControlCommand { - + + private String _host; + private String _port; private String _vmId; - private String _sid; + private String _sid; + private String _ticket; public ConsoleAccessAuthenticationCommand() { } - public ConsoleAccessAuthenticationCommand(String vmId, String sid) { + public ConsoleAccessAuthenticationCommand(String host, String port, String vmId, String sid, String ticket) { + _host = host; + _port = port; _vmId = vmId; - _sid = sid; + _sid = sid; + _ticket = ticket; } + + public String getHost() { + return _host; + } + + public String getPort() { + return _port; + } public String getVmId() { return _vmId; @@ -37,5 +51,9 @@ public class ConsoleAccessAuthenticationCommand extends AgentControlCommand { public String getSid() { return _sid; + } + + public String getTicket() { + return _ticket; } } diff --git a/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java new file mode 100644 index 00000000000..957e84fcb73 --- /dev/null +++ b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java @@ -0,0 +1,79 @@ +/** + * 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 . + * + */ + +package com.cloud.agent.api; + +public class CreatePrivateTemplateFromVolumeCommand extends SnapshotCommand { + private String _volumePath; + private String _userSpecifiedName; + private String _uniqueName; + private long _templateId; + private long _accountId; + // For XenServer + private String _secondaryStorageURL; + + + public CreatePrivateTemplateFromVolumeCommand() {} + + public CreatePrivateTemplateFromVolumeCommand(String secondaryStorageURL, long templateId, long accountId, String userSpecifiedName, String uniqueName, String volumePath) { + _secondaryStorageURL = secondaryStorageURL; + _templateId = templateId; + _accountId = accountId; + _userSpecifiedName = userSpecifiedName; + _uniqueName = uniqueName; + _volumePath = volumePath; + + } + + @Override + public boolean executeInSequence() { + return false; + } + + public String getSecondaryStorageURL() { + return _secondaryStorageURL; + } + + public String getTemplateName() { + return _userSpecifiedName; + } + + public String getUniqueName() { + return _uniqueName; + } + + public long getTemplateId() { + return _templateId; + } + + public void setVolumePath(String _volumePath) { + this._volumePath = _volumePath; + } + + public String getVolumePath() { + return _volumePath; + } + + public Long getAccountId() { + return _accountId; + } + + public void setTemplateId(long templateId) { + _templateId = templateId; + } +} diff --git a/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java b/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java index 2894c76d2c9..b6a2197d8d1 100644 --- a/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java +++ b/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java @@ -22,7 +22,6 @@ package com.cloud.agent.api; * This currently assumes that both primary and secondary storage are mounted on the XenServer. */ public class CreateVolumeFromSnapshotCommand extends SnapshotCommand { - private String templatePath; protected CreateVolumeFromSnapshotCommand() { @@ -51,18 +50,9 @@ public class CreateVolumeFromSnapshotCommand extends SnapshotCommand { Long accountId, Long volumeId, String backedUpSnapshotUuid, - String backedUpSnapshotName, - String templatePath) + String backedUpSnapshotName) { super(primaryStoragePoolNameLabel, secondaryStoragePoolURL, backedUpSnapshotUuid, backedUpSnapshotName, dcId, accountId, volumeId); - this.templatePath = templatePath; } - /** - * @return the templatePath - */ - public String getTemplatePath() { - return templatePath; - } - } \ No newline at end of file diff --git a/core/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java b/core/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java index 600477bd7ec..4a5ba5974f8 100644 --- a/core/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java +++ b/core/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java @@ -22,8 +22,7 @@ package com.cloud.agent.api; * This currently assumes that the secondary storage are mounted on the XenServer. */ public class DeleteSnapshotBackupCommand extends SnapshotCommand { - private String childUUID; - + protected DeleteSnapshotBackupCommand() { } @@ -59,18 +58,8 @@ public class DeleteSnapshotBackupCommand extends SnapshotCommand { Long accountId, Long volumeId, String backupUUID, - String backupName, - String childUUID) + String backupName) { super(primaryStoragePoolNameLabel, secondaryStoragePoolURL, backupUUID, backupName, dcId, accountId, volumeId); - this.childUUID = childUUID; } - - /** - * @return the childUUID - */ - public String getChildUUID() { - return childUUID; - } - } \ No newline at end of file diff --git a/core/src/com/cloud/agent/api/ManageSnapshotCommand.java b/core/src/com/cloud/agent/api/ManageSnapshotCommand.java index 57497bc478b..efcb37d2ab2 100644 --- a/core/src/com/cloud/agent/api/ManageSnapshotCommand.java +++ b/core/src/com/cloud/agent/api/ManageSnapshotCommand.java @@ -38,19 +38,21 @@ public class ManageSnapshotCommand extends Command { public ManageSnapshotCommand() {} - public ManageSnapshotCommand(String commandSwitch, long snapshotId, String path, String snapshotName, String vmName) { - _commandSwitch = commandSwitch; - if (commandSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) { - _volumePath = path; - } - else if (commandSwitch.equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) { - _snapshotPath = path; - } + public ManageSnapshotCommand(long snapshotId, String volumePath, String preSnapshotPath ,String snapshotName, String vmName) { + _commandSwitch = ManageSnapshotCommand.CREATE_SNAPSHOT; + _volumePath = volumePath; + _snapshotPath = preSnapshotPath; _snapshotName = snapshotName; _snapshotId = snapshotId; _vmName = vmName; } - + + public ManageSnapshotCommand(long snapshotId, String snapshotPath) { + _commandSwitch = ManageSnapshotCommand.DESTROY_SNAPSHOT; + _snapshotPath = snapshotPath; + } + + @Override public boolean executeInSequence() { return false; diff --git a/core/src/com/cloud/agent/api/NetworkUsageCommand.java b/core/src/com/cloud/agent/api/NetworkUsageCommand.java index c9c88279f6d..5ecf9741959 100644 --- a/core/src/com/cloud/agent/api/NetworkUsageCommand.java +++ b/core/src/com/cloud/agent/api/NetworkUsageCommand.java @@ -20,20 +20,26 @@ package com.cloud.agent.api; public class NetworkUsageCommand extends Command { private String privateIP; + private String domRName; protected NetworkUsageCommand() { } - public NetworkUsageCommand(String privateIP) + public NetworkUsageCommand(String privateIP, String domRName) { this.privateIP = privateIP; + this.domRName = domRName; } public String getPrivateIP() { return privateIP; } + public String getDomRName() { + return domRName; + } + /** * {@inheritDoc} */ diff --git a/core/src/com/cloud/agent/api/Start2Command.java b/core/src/com/cloud/agent/api/Start2Command.java index 4414b888d44..c670aef8e64 100644 --- a/core/src/com/cloud/agent/api/Start2Command.java +++ b/core/src/com/cloud/agent/api/Start2Command.java @@ -12,51 +12,15 @@ public class Start2Command extends Command { return vm; } - /* - 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; - - ---->console proxy - private ConsoleProxyVO proxy; - private int proxyCmdPort; - private String vncPort; - private String urlPort; - private String mgmt_host; - private int mgmt_port; - private boolean sslEnabled; - - ----->abstract - protected String vmName; - protected String storageHosts[] = new String[2]; - protected List volumes; - protected boolean mirroredVols = false; - protected BootloaderType bootloader = BootloaderType.PyGrub; - - */ - @Override public boolean executeInSequence() { return true; } - public Start2Command() { + protected Start2Command() { + } + + public Start2Command(VirtualMachineTO vm) { + this.vm = vm; } } diff --git a/core/src/com/cloud/agent/api/StartConsoleProxyCommand.java b/core/src/com/cloud/agent/api/StartConsoleProxyCommand.java index c1a0c31bb6e..08661de1d5b 100644 --- a/core/src/com/cloud/agent/api/StartConsoleProxyCommand.java +++ b/core/src/com/cloud/agent/api/StartConsoleProxyCommand.java @@ -33,14 +33,16 @@ public class StartConsoleProxyCommand extends AbstractStartCommand { private String urlPort; private String mgmt_host; private int mgmt_port; - private boolean sslEnabled; + private boolean sslEnabled; + private String guestOSDescription; protected StartConsoleProxyCommand() { } public StartConsoleProxyCommand(int networkRateMbps, int networkRateMulticastMbps, int proxyCmdPort, ConsoleProxyVO proxy, String vmName, String storageHost, - List vols, String vncPort, String urlPort, String mgmtHost, int mgmtPort, boolean sslEnabled) { + List vols, String vncPort, String urlPort, String mgmtHost, int mgmtPort, + boolean sslEnabled, String guestOSDescription) { super(vmName, storageHost, vols); this.networkRateMbps = networkRateMbps; this.networkRateMulticastMbps = networkRateMulticastMbps; @@ -50,7 +52,8 @@ public class StartConsoleProxyCommand extends AbstractStartCommand { this.urlPort = urlPort; this.mgmt_host = mgmtHost; this.mgmt_port = mgmtPort; - this.sslEnabled = sslEnabled; + this.sslEnabled = sslEnabled; + this.guestOSDescription = guestOSDescription; } @Override @@ -66,6 +69,10 @@ public class StartConsoleProxyCommand extends AbstractStartCommand { return networkRateMbps; } + public String getGuestOSDescription() { + return guestOSDescription; + } + public int getNetworkRateMulticastMbps() { return networkRateMulticastMbps; } diff --git a/core/src/com/cloud/agent/api/StartRouterCommand.java b/core/src/com/cloud/agent/api/StartRouterCommand.java index 913745273ca..5654c570de9 100755 --- a/core/src/com/cloud/agent/api/StartRouterCommand.java +++ b/core/src/com/cloud/agent/api/StartRouterCommand.java @@ -30,6 +30,7 @@ public class StartRouterCommand extends AbstractStartCommand { DomainRouterVO router; int networkRateMbps; int networkRateMulticastMbps; + private String guestOSDescription; protected StartRouterCommand() { super(); @@ -41,11 +42,13 @@ public class StartRouterCommand extends AbstractStartCommand { } public StartRouterCommand(DomainRouterVO router, int networkRateMbps, int networkRateMulticastMbps, - String routerName, String[] storageIps, List vols, boolean mirroredVols) { + String routerName, String[] storageIps, List vols, boolean mirroredVols, + String guestOSDescription ) { super(routerName, storageIps, vols, mirroredVols); this.router = router; this.networkRateMbps = networkRateMbps; this.networkRateMulticastMbps = networkRateMulticastMbps; + this.guestOSDescription = guestOSDescription; } public DomainRouter getRouter() { @@ -56,6 +59,10 @@ public class StartRouterCommand extends AbstractStartCommand { return networkRateMbps; } + public String getGuestOSDescription() { + return guestOSDescription; + } + public int getNetworkRateMulticastMbps() { return networkRateMulticastMbps; } diff --git a/core/src/com/cloud/agent/api/StartSecStorageVmCommand.java b/core/src/com/cloud/agent/api/StartSecStorageVmCommand.java index 19c0f30882e..74bd7f3b5bb 100644 --- a/core/src/com/cloud/agent/api/StartSecStorageVmCommand.java +++ b/core/src/com/cloud/agent/api/StartSecStorageVmCommand.java @@ -33,14 +33,15 @@ public class StartSecStorageVmCommand extends AbstractStartCommand { private int proxyCmdPort; private String mgmt_host; private int mgmt_port; - private boolean sslCopy; + private boolean sslCopy; + private String guestOSDescription; protected StartSecStorageVmCommand() { } public StartSecStorageVmCommand(int networkRateMbps, int networkRateMulticastMbps, int proxyCmdPort, SecondaryStorageVmVO secStorageVm, String vmName, String storageHost, - List vols, String mgmtHost, int mgmtPort, boolean sslCopy) { + List vols, String mgmtHost, int mgmtPort, boolean sslCopy, String guestOSDescription) { super(vmName, storageHost, vols); this.networkRateMbps = networkRateMbps; this.networkRateMulticastMbps = networkRateMulticastMbps; @@ -49,7 +50,8 @@ public class StartSecStorageVmCommand extends AbstractStartCommand { this.mgmt_host = mgmtHost; this.mgmt_port = mgmtPort; - this.sslCopy = sslCopy; + this.sslCopy = sslCopy; + this.guestOSDescription = guestOSDescription; } @Override @@ -65,6 +67,10 @@ public class StartSecStorageVmCommand extends AbstractStartCommand { return networkRateMbps; } + public String getGuestOSDescription() { + return guestOSDescription; + } + public int getNetworkRateMulticastMbps() { return networkRateMulticastMbps; } diff --git a/core/src/com/cloud/agent/api/StartupRoutingCommand.java b/core/src/com/cloud/agent/api/StartupRoutingCommand.java index deb2a5aba24..9126ef0eb55 100755 --- a/core/src/com/cloud/agent/api/StartupRoutingCommand.java +++ b/core/src/com/cloud/agent/api/StartupRoutingCommand.java @@ -20,7 +20,7 @@ import java.util.HashMap; import java.util.Map; import com.cloud.hypervisor.Hypervisor; -import com.cloud.hypervisor.Hypervisor.Type; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy; import com.cloud.vm.State; @@ -32,7 +32,7 @@ public class StartupRoutingCommand extends StartupCommand { Map vms; String caps; String pool; - Hypervisor.Type hypervisorType; + HypervisorType hypervisorType; Map hostDetails; //stuff like host os, cpu capabilities public StartupRoutingCommand() { @@ -47,7 +47,7 @@ public class StartupRoutingCommand extends StartupCommand { long memory, long dom0MinMemory, String caps, - Hypervisor.Type hypervisorType, + HypervisorType hypervisorType, RouterPrivateIpStrategy privIpStrategy, Map vms) { this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms); @@ -59,7 +59,7 @@ public class StartupRoutingCommand extends StartupCommand { long memory, long dom0MinMemory, final String caps, - final Hypervisor.Type hypervisorType, + final HypervisorType hypervisorType, final Map hostDetails, Map vms) { @@ -75,7 +75,7 @@ public class StartupRoutingCommand extends StartupCommand { } public StartupRoutingCommand(int cpus2, long speed2, long memory2, - long dom0MinMemory2, String caps2, Hypervisor.Type hypervisorType2, + long dom0MinMemory2, String caps2, HypervisorType hypervisorType2, Map vms2) { this(cpus2, speed2, memory2, dom0MinMemory2, caps2, hypervisorType2, new HashMap(), vms2); } @@ -136,11 +136,11 @@ public class StartupRoutingCommand extends StartupCommand { this.pool = pool; } - public Hypervisor.Type getHypervisorType() { + public HypervisorType getHypervisorType() { return hypervisorType; } - public void setHypervisorType(Hypervisor.Type hypervisorType) { + public void setHypervisorType(HypervisorType hypervisorType) { this.hypervisorType = hypervisorType; } diff --git a/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java b/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java index e9a038f7cd6..135dc80a33d 100644 --- a/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java +++ b/core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java @@ -30,6 +30,9 @@ public abstract class AbstractDownloadCommand extends StorageCommand { } protected AbstractDownloadCommand(String name, String url, ImageFormat format, long accountId) { + assert(url != null); + url = url.replace('\\', '/'); + this.url = url; this.format = format; this.accountId = accountId; @@ -62,6 +65,8 @@ public abstract class AbstractDownloadCommand extends StorageCommand { } public void setUrl(String url) { + assert(url != null); + url = url.replace('\\', '/'); this.url = url; } diff --git a/core/src/com/cloud/agent/api/storage/CreatePrivateTemplateAnswer.java b/core/src/com/cloud/agent/api/storage/CreatePrivateTemplateAnswer.java index 352c3e1f1d1..c42f10799f8 100644 --- a/core/src/com/cloud/agent/api/storage/CreatePrivateTemplateAnswer.java +++ b/core/src/com/cloud/agent/api/storage/CreatePrivateTemplateAnswer.java @@ -37,7 +37,11 @@ public class CreatePrivateTemplateAnswer extends Answer { _uniqueName = uniqueName; _format = format; } - + + public CreatePrivateTemplateAnswer(Command cmd, boolean success, String result) { + super(cmd, success, result); + } + public String getPath() { return _path; } diff --git a/core/src/com/cloud/agent/api/storage/DestroyCommand.java b/core/src/com/cloud/agent/api/storage/DestroyCommand.java index fe8f9eeebfc..8e0dbf497fe 100755 --- a/core/src/com/cloud/agent/api/storage/DestroyCommand.java +++ b/core/src/com/cloud/agent/api/storage/DestroyCommand.java @@ -18,6 +18,7 @@ package com.cloud.agent.api.storage; import com.cloud.agent.api.to.VolumeTO; +import com.cloud.storage.Storage; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.VMTemplateStoragePoolVO; import com.cloud.storage.VolumeVO; @@ -33,7 +34,7 @@ public class DestroyCommand extends StorageCommand { } public DestroyCommand(StoragePoolVO pool, VMTemplateStoragePoolVO templatePoolRef) { - this.volume = new VolumeTO(templatePoolRef, pool); + volume = new VolumeTO(templatePoolRef.getId(), null, Storage.StorageResourceType.STORAGE_POOL, pool.getPoolType(), null, pool.getPath(), templatePoolRef.getInstallPath(), templatePoolRef.getTemplateSize()); } public VolumeTO getVolume() { diff --git a/core/src/com/cloud/agent/api/to/NicTO.java b/core/src/com/cloud/agent/api/to/NicTO.java deleted file mode 100644 index 42e4f66bd94..00000000000 --- a/core/src/com/cloud/agent/api/to/NicTO.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - */ -package com.cloud.agent.api.to; - -public class NicTO extends NetworkTO { - int deviceId; - Integer controlPort; - Integer networkRateMbps; - Integer networkRateMulticastMbps; - - public NicTO() { - super(); - controlPort = null; - } - - public void setDeviceId(int deviceId) { - this.deviceId = deviceId; - } - - public int getDeviceId() { - return deviceId; - } - - public Integer getControlPort() { - return controlPort; - } - - public Integer getNetworkRateMbps() { - return networkRateMbps; - } - - public Integer getNetworkRateMulticastMbps() { - return networkRateMulticastMbps; - } -} diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 0e9090f432d..d7895b714c5 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -491,7 +491,7 @@ public class VirtualRoutingResource implements Manager { _startTimeout = NumbersUtil.parseInt(value, 360) * 1000; value = (String)params.get("ssh.sleep"); - _sleep = NumbersUtil.parseInt(value, 5) * 1000; + _sleep = NumbersUtil.parseInt(value, 10) * 1000; value = (String)params.get("ssh.retry"); _retry = NumbersUtil.parseInt(value, 24); diff --git a/core/src/com/cloud/storage/SnapshotPolicyRefVO.java b/core/src/com/cloud/certificate/CertificateVO.java similarity index 56% rename from core/src/com/cloud/storage/SnapshotPolicyRefVO.java rename to core/src/com/cloud/certificate/CertificateVO.java index ab06e6796f9..5e989e7ff68 100644 --- a/core/src/com/cloud/storage/SnapshotPolicyRefVO.java +++ b/core/src/com/cloud/certificate/CertificateVO.java @@ -15,43 +15,42 @@ * along with this program. If not, see . * */ +package com.cloud.certificate; -package com.cloud.storage; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -@Entity -@Table(name="snapshot_policy_ref") -public class SnapshotPolicyRefVO { - - @Column(name="snap_id") - long snapshotId; - - @Column(name="volume_id") - long volumeId; - - @Column(name="policy_id") - long policyId; - - public SnapshotPolicyRefVO() { } - - public SnapshotPolicyRefVO(long snapshotId, long volumeId, long policyId) { - this.snapshotId = snapshotId; - this.volumeId = volumeId; - this.policyId = policyId; - } - - public long getSnapshotId() { - return snapshotId; - } - - public long getVolumeId() { - return snapshotId; - } - - public long getPolicyId() { - return policyId; - } -} +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="certificate") +public class CertificateVO { + + public CertificateVO(String cert) + { + this.certificate = cert; + } + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + private Long id = null; + + @Column(name="certificate",length=65535) + private String certificate; + + public CertificateVO() {} + + public Long getId() { + return id; + } + + public String getCertificate() { + return certificate; + } + public void setCertificate(String certificate) { + this.certificate = certificate; + } +} diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java b/core/src/com/cloud/certificate/dao/CertificateDao.java similarity index 63% rename from core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java rename to core/src/com/cloud/certificate/dao/CertificateDao.java index c2ed3056df8..9da10b49fef 100644 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDao.java +++ b/core/src/com/cloud/certificate/dao/CertificateDao.java @@ -16,20 +16,11 @@ * */ -package com.cloud.storage.dao; - -import java.util.List; - -import com.cloud.storage.SnapshotPolicyRefVO; +package com.cloud.certificate.dao; + +import com.cloud.certificate.CertificateVO; import com.cloud.utils.db.GenericDao; - -public interface SnapshotPolicyRefDao extends GenericDao { - - SnapshotPolicyRefVO findBySnapPolicy(long snapshotId, long policyId); - - int removeSnapPolicy(long snapshotId, long policyId); - - List listByPolicyId(long policyId, long volumeId); - - List listBySnapshotId(long snapshotId); -} + +public interface CertificateDao extends GenericDao { + public boolean persistCustomCertToDb(String certPath); +} diff --git a/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java b/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java new file mode 100644 index 00000000000..209c30591a6 --- /dev/null +++ b/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java @@ -0,0 +1,51 @@ +package com.cloud.certificate.dao; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.certificate.CertificateVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; + +@Local(value={CertificateDao.class}) @DB(txn=false) +public class CertificateDaoImpl extends GenericDaoBase implements CertificateDao { + + private static final Logger s_logger = Logger.getLogger(CertificateDaoImpl.class); + + @Override + public boolean persistCustomCertToDb(String certPath){ + + String certStr = null; + byte[] buffer = new byte[(int) new File(certPath).length()]; + BufferedInputStream f = null; + try + { + f = new BufferedInputStream(new FileInputStream(certPath)); + f.read(buffer); + } catch (FileNotFoundException e) { + s_logger.warn("Unable to read the certificate: "+e); + return false; + } catch (IOException e) { + s_logger.warn("Unable to read the certificate: "+e); + return false; + } + finally + { + if (f != null) + try { f.close(); } catch (IOException ignored) { } + } + certStr = new String(buffer); + + CertificateVO certRec = new CertificateVO(certStr); + this.persist(certRec); + + return true; + } +} diff --git a/core/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java b/core/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java index 84f95d76d73..b66abfeeebe 100644 --- a/core/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java +++ b/core/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java @@ -133,12 +133,8 @@ public class ConfigurationDaoImpl extends GenericDaoBase { void persist(long hostId, Map details); DetailVO findDetail(long hostId, String name); + + void deleteDetails(long hostId); } diff --git a/core/src/com/cloud/host/dao/DetailsDaoImpl.java b/core/src/com/cloud/host/dao/DetailsDaoImpl.java index f4c95e82d11..d1cfe247d66 100644 --- a/core/src/com/cloud/host/dao/DetailsDaoImpl.java +++ b/core/src/com/cloud/host/dao/DetailsDaoImpl.java @@ -66,6 +66,17 @@ public class DetailsDaoImpl extends GenericDaoBase implements De } return details; } + + @Override + public void deleteDetails(long hostId) { + SearchCriteria sc = HostSearch.create(); + sc.setParameters("hostId", hostId); + + List results = search(sc, null); + for (DetailVO result : results) { + remove(result.getId()); + } + } @Override public void persist(long hostId, Map details) { diff --git a/core/src/com/cloud/host/dao/HostDao.java b/core/src/com/cloud/host/dao/HostDao.java index 6bccaa4a4ea..78eeea89bfb 100644 --- a/core/src/com/cloud/host/dao/HostDao.java +++ b/core/src/com/cloud/host/dao/HostDao.java @@ -35,7 +35,7 @@ import com.cloud.utils.db.GenericDao; public interface HostDao extends GenericDao { List listBy(Host.Type type, Long clusterId, Long podId, long dcId); - long countBy(long podId, Status... statuses); + long countBy(long clusterId, Status... statuses); List listByDataCenter(long dcId); List listByHostPod(long podId); diff --git a/core/src/com/cloud/host/dao/HostDaoImpl.java b/core/src/com/cloud/host/dao/HostDaoImpl.java index 01e5c1e173d..47d3134e0b6 100644 --- a/core/src/com/cloud/host/dao/HostDaoImpl.java +++ b/core/src/com/cloud/host/dao/HostDaoImpl.java @@ -77,7 +77,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao protected final SearchBuilder SequenceSearch; protected final SearchBuilder DirectlyConnectedSearch; protected final SearchBuilder UnmanagedDirectConnectSearch; - protected final GenericSearchBuilder MaintenanceCountSearch; + protected final SearchBuilder MaintenanceCountSearch; protected final SearchBuilder ClusterSearch; protected final Attribute _statusAttr; @@ -88,9 +88,8 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao public HostDaoImpl() { - MaintenanceCountSearch = createSearchBuilder(Long.class); - MaintenanceCountSearch.and("pod", MaintenanceCountSearch.entity().getPodId(), SearchCriteria.Op.EQ); - MaintenanceCountSearch.select(null, Func.COUNT, null); + MaintenanceCountSearch = createSearchBuilder(); + MaintenanceCountSearch.and("cluster", MaintenanceCountSearch.entity().getClusterId(), SearchCriteria.Op.EQ); MaintenanceCountSearch.and("status", MaintenanceCountSearch.entity().getStatus(), SearchCriteria.Op.IN); MaintenanceCountSearch.done(); @@ -200,18 +199,14 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } @Override - public long countBy(long podId, Status... statuses) { - SearchCriteria sc = MaintenanceCountSearch.create(); + public long countBy(long clusterId, Status... statuses) { + SearchCriteria sc = MaintenanceCountSearch.create(); sc.setParameters("status", (Object[])statuses); - sc.setParameters("pod", podId); - - List rs = searchIncludingRemoved(sc, null); - if (rs.size() == 0) { - return 0; - } - - return rs.get(0); + sc.setParameters("cluster", clusterId); + + List hosts = listBy(sc); + return hosts.size(); } @Override diff --git a/core/src/com/cloud/hypervisor/kvm/resource/KvmDummyResourceBase.java b/core/src/com/cloud/hypervisor/kvm/resource/KvmDummyResourceBase.java index fce1ce38c8d..a753c532e02 100644 --- a/core/src/com/cloud/hypervisor/kvm/resource/KvmDummyResourceBase.java +++ b/core/src/com/cloud/hypervisor/kvm/resource/KvmDummyResourceBase.java @@ -31,7 +31,7 @@ public class KvmDummyResourceBase extends ServerResourceBase implements ServerRe @Override public StartupCommand[] initialize() { - StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.Type.KVM, new HashMap(), new HashMap()); + StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap(), new HashMap()); cmd.setDataCenter(_zoneId); cmd.setPod(_podId); cmd.setCluster(_clusterId); diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixHelper.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixHelper.java index 23de8d0a0af..b6032e04e94 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixHelper.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixHelper.java @@ -21,143 +21,157 @@ package com.cloud.hypervisor.xen.resource; import java.util.ArrayList; import java.util.HashMap; +import org.apache.log4j.Logger; + /** * Reduce bloat inside CitrixResourceBase * */ public class CitrixHelper { - private static final HashMap _guestOsMap = new HashMap(70); - private static final ArrayList _guestOsList = new ArrayList(70); + private static final Logger s_logger = Logger.getLogger(CitrixHelper.class); + private static final HashMap _xcpGuestOsMap = new HashMap(70); + private static final HashMap _xenServerGuestOsMap = new HashMap(70); + private static final ArrayList _guestOsList = new ArrayList(70); static { - _guestOsMap.put("CentOS 4.5 (32-bit)", "CentOS 4.5"); - _guestOsMap.put("CentOS 4.6 (32-bit)", "CentOS 4.6"); - _guestOsMap.put("CentOS 4.7 (32-bit)", "CentOS 4.7"); - _guestOsMap.put("CentOS 4.8 (32-bit)", "CentOS 4.8"); - _guestOsMap.put("CentOS 5.0 (32-bit)", "CentOS 5.0"); - _guestOsMap.put("CentOS 5.0 (64-bit)", "CentOS 5.0 x64"); - _guestOsMap.put("CentOS 5.1 (32-bit)", "CentOS 5.1"); - _guestOsMap.put("CentOS 5.1 (64-bit)", "CentOS 5.1 x64"); - _guestOsMap.put("CentOS 5.2 (32-bit)", "CentOS 5.2"); - _guestOsMap.put("CentOS 5.2 (64-bit)", "CentOS 5.2 x64"); - _guestOsMap.put("CentOS 5.3 (32-bit)", "CentOS 5.3"); - _guestOsMap.put("CentOS 5.3 (64-bit)", "CentOS 5.3 x64"); - _guestOsMap.put("CentOS 5.4 (32-bit)", "CentOS 5.4"); - _guestOsMap.put("CentOS 5.4 (64-bit)", "CentOS 5.4 x64"); - _guestOsMap.put("Debian Lenny 5.0 (32-bit)", "Debian Lenny 5.0 (32-bit)"); - _guestOsMap.put("Oracle Enterprise Linux 5.0 (32-bit)", "Oracle Enterprise Linux 5.0"); - _guestOsMap.put("Oracle Enterprise Linux 5.0 (64-bit)", "Oracle Enterprise Linux 5.0 x64"); - _guestOsMap.put("Oracle Enterprise Linux 5.1 (32-bit)", "Oracle Enterprise Linux 5.1"); - _guestOsMap.put("Oracle Enterprise Linux 5.1 (64-bit)", "Oracle Enterprise Linux 5.1 x64"); - _guestOsMap.put("Oracle Enterprise Linux 5.2 (32-bit)", "Oracle Enterprise Linux 5.2"); - _guestOsMap.put("Oracle Enterprise Linux 5.2 (64-bit)", "Oracle Enterprise Linux 5.2 x64"); - _guestOsMap.put("Oracle Enterprise Linux 5.3 (32-bit)", "Oracle Enterprise Linux 5.3"); - _guestOsMap.put("Oracle Enterprise Linux 5.3 (64-bit)", "Oracle Enterprise Linux 5.3 x64"); - _guestOsMap.put("Oracle Enterprise Linux 5.4 (32-bit)", "Oracle Enterprise Linux 5.4"); - _guestOsMap.put("Oracle Enterprise Linux 5.4 (64-bit)", "Oracle Enterprise Linux 5.4 x64"); - _guestOsMap.put("Red Hat Enterprise Linux 4.5 (32-bit)", "Red Hat Enterprise Linux 4.5"); - _guestOsMap.put("Red Hat Enterprise Linux 4.6 (32-bit)", "Red Hat Enterprise Linux 4.6"); - _guestOsMap.put("Red Hat Enterprise Linux 4.7 (32-bit)", "Red Hat Enterprise Linux 4.7"); - _guestOsMap.put("Red Hat Enterprise Linux 4.8 (32-bit)", "Red Hat Enterprise Linux 4.8"); - _guestOsMap.put("Red Hat Enterprise Linux 5.0 (32-bit)", "Red Hat Enterprise Linux 5.0"); - _guestOsMap.put("Red Hat Enterprise Linux 5.0 (64-bit)", "Red Hat Enterprise Linux 5.0 x64"); - _guestOsMap.put("Red Hat Enterprise Linux 5.1 (32-bit)", "Red Hat Enterprise Linux 5.1"); - _guestOsMap.put("Red Hat Enterprise Linux 5.1 (64-bit)", "Red Hat Enterprise Linux 5.1 x64"); - _guestOsMap.put("Red Hat Enterprise Linux 5.2 (32-bit)", "Red Hat Enterprise Linux 5.2"); - _guestOsMap.put("Red Hat Enterprise Linux 5.2 (64-bit)", "Red Hat Enterprise Linux 5.2 x64"); - _guestOsMap.put("Red Hat Enterprise Linux 5.3 (32-bit)", "Red Hat Enterprise Linux 5.3"); - _guestOsMap.put("Red Hat Enterprise Linux 5.3 (64-bit)", "Red Hat Enterprise Linux 5.3 x64"); - _guestOsMap.put("Red Hat Enterprise Linux 5.4 (32-bit)", "Red Hat Enterprise Linux 5.4"); - _guestOsMap.put("Red Hat Enterprise Linux 5.4 (64-bit)", "Red Hat Enterprise Linux 5.4 x64"); - _guestOsMap.put("SUSE Linux Enterprise Server 9 SP4 (32-bit)", "SUSE Linux Enterprise Server 9 SP4"); - _guestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (32-bit)", "SUSE Linux Enterprise Server 10 SP1"); - _guestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (64-bit)", "SUSE Linux Enterprise Server 10 SP1 x64"); - _guestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (32-bit)", "SUSE Linux Enterprise Server 10 SP2"); - _guestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (64-bit)", "SUSE Linux Enterprise Server 10 SP2 x64"); - _guestOsMap.put("SUSE Linux Enterprise Server 10 SP3 (64-bit)", "Other install media"); - _guestOsMap.put("SUSE Linux Enterprise Server 11 (32-bit)", "SUSE Linux Enterprise Server 11"); - _guestOsMap.put("SUSE Linux Enterprise Server 11 (64-bit)", "SUSE Linux Enterprise Server 11 x64"); - _guestOsMap.put("Windows 7 (32-bit)", "Windows 7"); - _guestOsMap.put("Windows 7 (64-bit)", "Windows 7 x64"); - _guestOsMap.put("Windows Server 2003 (32-bit)", "Windows Server 2003"); - _guestOsMap.put("Windows Server 2003 (64-bit)", "Windows Server 2003 x64"); - _guestOsMap.put("Windows Server 2008 (32-bit)", "Windows Server 2008"); - _guestOsMap.put("Windows Server 2008 (64-bit)", "Windows Server 2008 x64"); - _guestOsMap.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008 R2 x64"); - _guestOsMap.put("Windows 2000 SP4 (32-bit)", "Windows 2000 SP4"); - _guestOsMap.put("Windows Vista (32-bit)", "Windows Vista"); - _guestOsMap.put("Windows XP SP2 (32-bit)", "Windows XP SP2"); - _guestOsMap.put("Windows XP SP3 (32-bit)", "Windows XP SP3"); - _guestOsMap.put("Other install media", "Other install media"); - - //access by index - _guestOsList.add("CentOS 4.5"); - _guestOsList.add("CentOS 4.6"); - _guestOsList.add("CentOS 4.7"); - _guestOsList.add("CentOS 4.8"); - _guestOsList.add("CentOS 5.0"); - _guestOsList.add("CentOS 5.0 x64"); - _guestOsList.add("CentOS 5.1"); - _guestOsList.add("CentOS 5.1 x64"); - _guestOsList.add("CentOS 5.2"); - _guestOsList.add("CentOS 5.2 x64"); - _guestOsList.add("CentOS 5.3"); - _guestOsList.add("CentOS 5.3 x64"); - _guestOsList.add("CentOS 5.4"); - _guestOsList.add("CentOS 5.4 x64"); - _guestOsList.add("Debian Lenny 5.0 (32-bit)"); - _guestOsList.add("Oracle Enterprise Linux 5.0"); - _guestOsList.add("Oracle Enterprise Linux 5.0 x64"); - _guestOsList.add("Oracle Enterprise Linux 5.1"); - _guestOsList.add("Oracle Enterprise Linux 5.1 x64"); - _guestOsList.add("Oracle Enterprise Linux 5.2"); - _guestOsList.add("Oracle Enterprise Linux 5.2 x64"); - _guestOsList.add("Oracle Enterprise Linux 5.3"); - _guestOsList.add("Oracle Enterprise Linux 5.3 x64"); - _guestOsList.add("Oracle Enterprise Linux 5.4"); - _guestOsList.add("Oracle Enterprise Linux 5.4 x64"); - _guestOsList.add("Red Hat Enterprise Linux 4.5"); - _guestOsList.add("Red Hat Enterprise Linux 4.6"); - _guestOsList.add("Red Hat Enterprise Linux 4.7"); - _guestOsList.add("Red Hat Enterprise Linux 4.8"); - _guestOsList.add("Red Hat Enterprise Linux 5.0"); - _guestOsList.add("Red Hat Enterprise Linux 5.0 x64"); - _guestOsList.add("Red Hat Enterprise Linux 5.1"); - _guestOsList.add("Red Hat Enterprise Linux 5.1 x64"); - _guestOsList.add("Red Hat Enterprise Linux 5.2"); - _guestOsList.add("Red Hat Enterprise Linux 5.2 x64"); - _guestOsList.add("Red Hat Enterprise Linux 5.3"); - _guestOsList.add("Red Hat Enterprise Linux 5.3 x64"); - _guestOsList.add("Red Hat Enterprise Linux 5.4"); - _guestOsList.add("Red Hat Enterprise Linux 5.4 x64"); - _guestOsList.add("SUSE Linux Enterprise Server 9 SP4"); - _guestOsList.add("SUSE Linux Enterprise Server 10 SP1"); - _guestOsList.add("SUSE Linux Enterprise Server 10 SP1 x64"); - _guestOsList.add("SUSE Linux Enterprise Server 10 SP2"); - _guestOsList.add("SUSE Linux Enterprise Server 10 SP2 x64"); - _guestOsList.add("Other install media"); - _guestOsList.add("SUSE Linux Enterprise Server 11"); - _guestOsList.add("SUSE Linux Enterprise Server 11 x64"); - _guestOsList.add("Windows 7"); - _guestOsList.add("Windows 7 x64"); - _guestOsList.add("Windows Server 2003"); - _guestOsList.add("Windows Server 2003 x64"); - _guestOsList.add("Windows Server 2008"); - _guestOsList.add("Windows Server 2008 x64"); - _guestOsList.add("Windows Server 2008 R2 x64"); - _guestOsList.add("Windows 2000 SP4"); - _guestOsList.add("Windows Vista"); - _guestOsList.add("Windows XP SP2"); - _guestOsList.add("Windows XP SP3"); - _guestOsList.add("Other install media"); + _xcpGuestOsMap.put("CentOS 4.5 (32-bit)", "CentOS 4.5"); + _xcpGuestOsMap.put("CentOS 4.6 (32-bit)", "CentOS 4.6"); + _xcpGuestOsMap.put("CentOS 4.7 (32-bit)", "CentOS 4.7"); + _xcpGuestOsMap.put("CentOS 4.8 (32-bit)", "CentOS 4.8"); + _xcpGuestOsMap.put("CentOS 5.0 (32-bit)", "CentOS 5.0"); + _xcpGuestOsMap.put("CentOS 5.0 (64-bit)", "CentOS 5.0 x64"); + _xcpGuestOsMap.put("CentOS 5.1 (32-bit)", "CentOS 5.1"); + _xcpGuestOsMap.put("CentOS 5.1 (64-bit)", "CentOS 5.1 x64"); + _xcpGuestOsMap.put("CentOS 5.2 (32-bit)", "CentOS 5.2"); + _xcpGuestOsMap.put("CentOS 5.2 (64-bit)", "CentOS 5.2 x64"); + _xcpGuestOsMap.put("CentOS 5.3 (32-bit)", "CentOS 5.3"); + _xcpGuestOsMap.put("CentOS 5.3 (64-bit)", "CentOS 5.3 x64"); + _xcpGuestOsMap.put("CentOS 5.4 (32-bit)", "CentOS 5.4"); + _xcpGuestOsMap.put("CentOS 5.4 (64-bit)", "CentOS 5.4 x64"); + _xcpGuestOsMap.put("Debian GNU/Linux 5.0 (32-bit)", "Debian Lenny 5.0 (32-bit)"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.0 (32-bit)", "Oracle Enterprise Linux 5.0"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.0 (64-bit)", "Oracle Enterprise Linux 5.0 x64"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.1 (32-bit)", "Oracle Enterprise Linux 5.1"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.1 (64-bit)", "Oracle Enterprise Linux 5.1 x64"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.2 (32-bit)", "Oracle Enterprise Linux 5.2"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.2 (64-bit)", "Oracle Enterprise Linux 5.2 x64"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.3 (32-bit)", "Oracle Enterprise Linux 5.3"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.3 (64-bit)", "Oracle Enterprise Linux 5.3 x64"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.4 (32-bit)", "Oracle Enterprise Linux 5.4"); + _xcpGuestOsMap.put("Oracle Enterprise Linux 5.4 (64-bit)", "Oracle Enterprise Linux 5.4 x64"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 4.5 (32-bit)", "Red Hat Enterprise Linux 4.5"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 4.6 (32-bit)", "Red Hat Enterprise Linux 4.6"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 4.7 (32-bit)", "Red Hat Enterprise Linux 4.7"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 4.8 (32-bit)", "Red Hat Enterprise Linux 4.8"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.0 (32-bit)", "Red Hat Enterprise Linux 5.0"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.0 (64-bit)", "Red Hat Enterprise Linux 5.0 x64"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.1 (32-bit)", "Red Hat Enterprise Linux 5.1"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.1 (64-bit)", "Red Hat Enterprise Linux 5.1 x64"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.2 (32-bit)", "Red Hat Enterprise Linux 5.2"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.2 (64-bit)", "Red Hat Enterprise Linux 5.2 x64"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.3 (32-bit)", "Red Hat Enterprise Linux 5.3"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.3 (64-bit)", "Red Hat Enterprise Linux 5.3 x64"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.4 (32-bit)", "Red Hat Enterprise Linux 5.4"); + _xcpGuestOsMap.put("Red Hat Enterprise Linux 5.4 (64-bit)", "Red Hat Enterprise Linux 5.4 x64"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 9 SP4 (32-bit)", "SUSE Linux Enterprise Server 9 SP4"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (32-bit)", "SUSE Linux Enterprise Server 10 SP1"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (64-bit)", "SUSE Linux Enterprise Server 10 SP1 x64"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (32-bit)", "SUSE Linux Enterprise Server 10 SP2"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (64-bit)", "SUSE Linux Enterprise Server 10 SP2 x64"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 10 SP3 (64-bit)", "Other install media"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 11 (32-bit)", "SUSE Linux Enterprise Server 11"); + _xcpGuestOsMap.put("SUSE Linux Enterprise Server 11 (64-bit)", "SUSE Linux Enterprise Server 11 x64"); + _xcpGuestOsMap.put("Windows 7 (32-bit)", "Windows 7"); + _xcpGuestOsMap.put("Windows 7 (64-bit)", "Windows 7 x64"); + _xcpGuestOsMap.put("Windows Server 2003 (32-bit)", "Windows Server 2003"); + _xcpGuestOsMap.put("Windows Server 2003 (64-bit)", "Windows Server 2003 x64"); + _xcpGuestOsMap.put("Windows Server 2008 (32-bit)", "Windows Server 2008"); + _xcpGuestOsMap.put("Windows Server 2008 (64-bit)", "Windows Server 2008 x64"); + _xcpGuestOsMap.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008 R2 x64"); + _xcpGuestOsMap.put("Windows 2000 SP4 (32-bit)", "Windows 2000 SP4"); + _xcpGuestOsMap.put("Windows Vista (32-bit)", "Windows Vista"); + _xcpGuestOsMap.put("Windows XP SP2 (32-bit)", "Windows XP SP2"); + _xcpGuestOsMap.put("Windows XP SP3 (32-bit)", "Windows XP SP3"); + _xcpGuestOsMap.put("Other install media", "Other install media"); } - public static String getGuestOsType(String stdType) { - return _guestOsMap.get(stdType); + static { + _xenServerGuestOsMap.put("CentOS 4.5 (32-bit)", "CentOS 4.5 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 4.6 (32-bit)", "CentOS 4.6 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 4.7 (32-bit)", "CentOS 4.7 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 4.8 (32-bit)", "CentOS 4.8 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.0 (32-bit)", "CentOS 5.0 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.0 (64-bit)", "CentOS 5.0 (64-bit)"); + _xenServerGuestOsMap.put("CentOS 5.1 (32-bit)", "CentOS 5.1 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.1 (64-bit)", "CentOS 5.1 (64-bit)"); + _xenServerGuestOsMap.put("CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.2 (64-bit)", "CentOS 5.2 (64-bit)"); + _xenServerGuestOsMap.put("CentOS 5.3 (32-bit)", "CentOS 5.3 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.3 (64-bit)", "CentOS 5.3 (64-bit)"); + _xenServerGuestOsMap.put("CentOS 5.4 (32-bit)", "CentOS 5.4 (32-bit)"); + _xenServerGuestOsMap.put("CentOS 5.4 (64-bit)", "CentOS 5.4 (64-bit)"); + _xenServerGuestOsMap.put("Debian GNU/Linux 5.0 (32-bit)", "Debian Lenny 5.0 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.0 (32-bit)", "Oracle Enterprise Linux 5.0 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.0 (64-bit)", "Oracle Enterprise Linux 5.0 (64-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.1 (32-bit)", "Oracle Enterprise Linux 5.1 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.1 (64-bit)", "Oracle Enterprise Linux 5.1 (64-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.2 (32-bit)", "Oracle Enterprise Linux 5.2 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.2 (64-bit)", "Oracle Enterprise Linux 5.2 (64-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.3 (32-bit)", "Oracle Enterprise Linux 5.3 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.3 (64-bit)", "Oracle Enterprise Linux 5.3 (64-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.4 (32-bit)", "Oracle Enterprise Linux 5.4 (32-bit)"); + _xenServerGuestOsMap.put("Oracle Enterprise Linux 5.4 (64-bit)", "Oracle Enterprise Linux 5.4 (64-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 4.5 (32-bit)", "Red Hat Enterprise Linux 4.5 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 4.6 (32-bit)", "Red Hat Enterprise Linux 4.6 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 4.7 (32-bit)", "Red Hat Enterprise Linux 4.7 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 4.8 (32-bit)", "Red Hat Enterprise Linux 4.8 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.0 (32-bit)", "Red Hat Enterprise Linux 5.0 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.0 (64-bit)", "Red Hat Enterprise Linux 5.0 (64-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.1 (32-bit)", "Red Hat Enterprise Linux 5.1 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.1 (64-bit)", "Red Hat Enterprise Linux 5.1 (64-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.2 (32-bit)", "Red Hat Enterprise Linux 5.2 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.2 (64-bit)", "Red Hat Enterprise Linux 5.2 (64-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.3 (32-bit)", "Red Hat Enterprise Linux 5.3 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.3 (64-bit)", "Red Hat Enterprise Linux 5.3 (64-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.4 (32-bit)", "Red Hat Enterprise Linux 5.4 (32-bit)"); + _xenServerGuestOsMap.put("Red Hat Enterprise Linux 5.4 (64-bit)", "Red Hat Enterprise Linux 5.4 (64-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 9 SP4 (32-bit)", "SUSE Linux Enterprise Server 9 SP4 (32-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (32-bit)", "SUSE Linux Enterprise Server 10 SP1 (32-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 10 SP1 (64-bit)", "SUSE Linux Enterprise Server 10 SP1 (64-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (32-bit)", "SUSE Linux Enterprise Server 10 SP2 (32-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 10 SP2 (64-bit)", "SUSE Linux Enterprise Server 10 SP2 (64-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 10 SP3 (64-bit)", "SUSE Linux Enterprise Server 10 SP3 (64-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 11 (32-bit)", "SUSE Linux Enterprise Server 11 (32-bit)"); + _xenServerGuestOsMap.put("SUSE Linux Enterprise Server 11 (64-bit)", "SUSE Linux Enterprise Server 11 (64-bit)"); + _xenServerGuestOsMap.put("Windows 7 (32-bit)", "Windows 7 (32-bit)"); + _xenServerGuestOsMap.put("Windows 7 (64-bit)", "Windows 7 (64-bit)"); + _xenServerGuestOsMap.put("Windows Server 2003 (32-bit)", "Windows Server 2003 (32-bit)"); + _xenServerGuestOsMap.put("Windows Server 2003 (64-bit)", "Windows Server 2003 (64-bit)"); + _xenServerGuestOsMap.put("Windows Server 2008 (32-bit)", "Windows Server 2008 (32-bit)"); + _xenServerGuestOsMap.put("Windows Server 2008 (64-bit)", "Windows Server 2008 (64-bit)"); + _xenServerGuestOsMap.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008 R2 (64-bit)"); + _xenServerGuestOsMap.put("Windows 2000 SP4 (32-bit)", "Windows 2000 SP4 (32-bit)"); + _xenServerGuestOsMap.put("Windows Vista (32-bit)", "Windows Vista (32-bit)"); + _xenServerGuestOsMap.put("Windows XP SP2 (32-bit)", "Windows XP SP2 (32-bit)"); + _xenServerGuestOsMap.put("Windows XP SP3 (32-bit)", "Windows XP SP3 (32-bit)"); } - - public static String getGuestOsType(long guestOsId) { - return _guestOsList.get((int) (guestOsId-1)); + + public static String getXcpGuestOsType(String stdType) { + String guestOS = _xcpGuestOsMap.get(stdType); + if (guestOS == null) { + s_logger.debug("Can't find the guest os: " + stdType + " mapping into xenserver's guestOS type, start it as HVM guest"); + guestOS = "Other install media"; + } + return guestOS; + } + + public static String getXenServerGuestOsType(String stdType) { + String guestOS = _xenServerGuestOsMap.get(stdType); + if (guestOS == null) { + s_logger.debug("Can't find the guest os: " + stdType + " mapping into xenserver's guestOS type, start it as HVM guest"); + guestOS = "Other install media"; + } + return guestOS; } } diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index b30a0996e92..df27f72a41e 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -67,6 +67,7 @@ import com.cloud.agent.api.CheckVirtualMachineAnswer; import com.cloud.agent.api.CheckVirtualMachineCommand; import com.cloud.agent.api.Command; import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand; +import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand; import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer; import com.cloud.agent.api.CreateVolumeFromSnapshotCommand; import com.cloud.agent.api.DeleteSnapshotBackupAnswer; @@ -121,8 +122,6 @@ import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.StoragePoolInfo; -import com.cloud.agent.api.ValidateSnapshotAnswer; -import com.cloud.agent.api.ValidateSnapshotCommand; import com.cloud.agent.api.VmStatsEntry; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; @@ -138,19 +137,20 @@ import com.cloud.agent.api.storage.CopyVolumeCommand; 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.DownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; import com.cloud.agent.api.storage.ShareAnswer; import com.cloud.agent.api.storage.ShareCommand; import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.StoragePoolTO; +import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VirtualMachineTO; +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.exception.InternalErrorException; import com.cloud.host.Host.Type; -import com.cloud.hypervisor.Hypervisor; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.TrafficType; import com.cloud.resource.ServerResource; @@ -234,6 +234,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected IAgentControl _agentControl; protected boolean _isRemoteAgent = false; + int _userVMCap = 0; + final int _maxWeight = 256; protected final XenServerHost _host = new XenServerHost(); @@ -607,8 +609,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return execute((AttachVolumeCommand) cmd); } else if (cmd instanceof AttachIsoCommand) { return execute((AttachIsoCommand) cmd); - } else if (cmd instanceof ValidateSnapshotCommand) { - return execute((ValidateSnapshotCommand) cmd); } else if (cmd instanceof ManageSnapshotCommand) { return execute((ManageSnapshotCommand) cmd); } else if (cmd instanceof BackupSnapshotCommand) { @@ -619,8 +619,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return execute((CreateVolumeFromSnapshotCommand) cmd); } else if (cmd instanceof DeleteSnapshotsDirCommand) { return execute((DeleteSnapshotsDirCommand) cmd); - } else if (cmd instanceof CreatePrivateTemplateCommand) { - return execute((CreatePrivateTemplateCommand) cmd); + } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) { + return execute((CreatePrivateTemplateFromVolumeCommand) cmd); } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) { return execute((CreatePrivateTemplateFromSnapshotCommand) cmd); } else if (cmd instanceof GetStorageStatsCommand) { @@ -656,6 +656,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (type == TrafficType.Guest) { return new Pair(Network.getByUuid(conn, _host.guestNetwork), _host.guestPif); } else if (type == TrafficType.Control) { + setupLinkLocalNetwork(); return new Pair(Network.getByUuid(conn, _host.linkLocalNetwork), null); } else if (type == TrafficType.Management) { return new Pair(Network.getByUuid(conn, _host.privateNetwork), _host.privatePif); @@ -671,6 +672,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } protected VIF createVif(Connection conn, String vmName, VM vm, NicTO nic) throws XmlRpcException, XenAPIException { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Creating VIF for " + vmName + " on nic " + nic); + } + VIF.Record vifr = new VIF.Record(); vifr.VM = vm; vifr.device = Integer.toString(nic.getDeviceId()); @@ -678,10 +683,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR Pair network = getNetworkForTraffic(conn, nic.getType()); if (nic.getBroadcastType() == BroadcastDomainType.Vlan) { - vifr.network = enableVlanNetwork(conn, nic.getVlan(), network.first(), network.second()); - } else { + URI broadcastUri = nic.getBroadcastUri(); + assert broadcastUri.getScheme().equals(BroadcastDomainType.Vlan.scheme()); + long vlan = Long.parseLong(broadcastUri.getHost()); + vifr.network = enableVlanNetwork(conn, vlan, network.first(), network.second()); + } else if (nic.getBroadcastType() == BroadcastDomainType.Native || nic.getBroadcastType() == BroadcastDomainType.LinkLocal) { vifr.network = network.first(); - } + } if (nic.getNetworkRateMbps() != null) { vifr.qosAlgorithmType = "ratelimit"; @@ -726,17 +734,11 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected VBD createVbd(Connection conn, String vmName, VM vm, VolumeTO volume, boolean patch) throws XmlRpcException, XenAPIException { + protected VBD createVbd(Connection conn, VolumeTO volume, String vmName, VM vm) throws XmlRpcException, XenAPIException { VolumeType type = volume.getType(); VDI vdi = mount(conn, vmName, volume); - if (patch) { - if (!patchSystemVm(vdi, vmName)) { - throw new CloudRuntimeException("Unable to patch system vm"); - } - } - VBD.Record vbdr = new VBD.Record(); vbdr.VM = vm; vbdr.VDI = vdi; @@ -762,7 +764,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return vbd; } - protected Pair createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { + protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { String guestOsTypeName = getGuestOsType(vmSpec.getOs()); Set templates = VM.getByNameLabel(conn, guestOsTypeName); assert templates.size() == 1 : "Should only have 1 template but found " + templates.size(); @@ -786,16 +788,27 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR setMemory(conn, vm, vmSpec.getMinRam()); vm.setVCPUsAtStartup(conn, (long)vmSpec.getCpus()); vm.setVCPUsMax(conn, (long)vmSpec.getCpus()); - vm.setVCPUsNumberLive(conn, (long)vmSpec.getCpus()); Map vcpuParams = new HashMap(); - if (vmSpec.getWeight() != null) { - vcpuParams.put("weight", Integer.toString(vmSpec.getWeight())); - } - if (vmSpec.getUtilization() != null) { - vcpuParams.put("cap", Integer.toString(vmSpec.getUtilization())); + Integer speed = vmSpec.getSpeed(); + if (speed != null) { + int utilization = _userVMCap; //cpu_cap + //Configuration cpu.uservm.cap is not available in default installation. Using this parameter is not encouraged + + int cpuWeight = _maxWeight; //cpu_weight + + // weight based allocation + cpuWeight = (int)((speed*0.99) / _host.speed * _maxWeight); + if (cpuWeight > _maxWeight) { + cpuWeight = _maxWeight; + } + + vcpuParams.put("weight", Integer.toString(cpuWeight)); + vcpuParams.put("cap", Integer.toString(utilization)); + } + if (vcpuParams.size() > 0) { vm.setVCPUsParams(conn, vcpuParams); } @@ -825,7 +838,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - return new Pair(vm, vmr.uuid); + return vm; } protected String handleVmStartFailure(String vmName, VM vm, String message, Throwable th) { @@ -876,6 +889,20 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return msg; } + protected VBD createPatchVbd(Connection conn, String vmName, VM vm) throws XmlRpcException, XenAPIException { + VBD.Record cdromVBDR = new VBD.Record(); + cdromVBDR.VM = vm; + cdromVBDR.empty = true; + cdromVBDR.bootable = false; + cdromVBDR.userdevice = "3"; + cdromVBDR.mode = Types.VbdMode.RO; + cdromVBDR.type = Types.VbdType.CD; + VBD cdromVBD = VBD.create(conn, cdromVBDR); + cdromVBD.insert(conn, VDI.getByUuid(conn, _host.systemvmisouuid)); + + return cdromVBD; + } + protected Start2Answer execute(Start2Command cmd) { VirtualMachineTO vmSpec = cmd.getVirtualMachine(); String vmName = vmSpec.getName(); @@ -889,80 +916,20 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR _vms.put(vmName, State.Starting); } - Pair v = createVmFromTemplate(conn, vmSpec, host); - vm = v.first(); - String vmUuid = v.second(); + vm = createVmFromTemplate(conn, vmSpec, host); for (VolumeTO disk : vmSpec.getDisks()) { - createVbd(conn, vmName, vm, disk, disk.getType() == VolumeType.ROOT && vmSpec.getType() != VirtualMachine.Type.User); + createVbd(conn, disk, vmName, vm); } - NicTO controlNic = null; - for (NicTO nic : vmSpec.getNetworks()) { - if (nic.getControlPort() != null) { - controlNic = nic; - } + if (vmSpec.getType() != VirtualMachine.Type.User) { + createPatchVbd(conn, vmName, vm); + } + + for (NicTO nic : vmSpec.getNics()) { createVif(conn, vmName, vm, nic); } - /* - * - VBD.Record vbdr = new VBD.Record(); - Ternary 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); - - 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); - - } - - 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); - - String isopath = cmd.getISOPath(); - if (isopath != null) { - int index = isopath.lastIndexOf("/"); - - String mountpoint = isopath.substring(0, index); - URI uri = new URI(mountpoint); - isosr = createIsoSRbyURI(uri, cmd.getVmName(), false); - - String isoname = isopath.substring(index + 1); - - VDI isovdi = getVDIbyLocationandSR(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); - } - - } - */ - vm.startOn(conn, host, false, true); if (_canBridgeFirewall) { @@ -979,9 +946,11 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - if (controlNic != null) { - String privateIp = controlNic.getIp(); - int cmdPort = controlNic.getControlPort(); + Monitor monitor = vmSpec.getMonitor(); + if (monitor != null && monitor instanceof SshMonitor) { + SshMonitor sshMon = (SshMonitor)monitor; + String privateIp = sshMon.getIp(); + int cmdPort = sshMon.getPort(); if (s_logger.isDebugEnabled()) { s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); @@ -999,12 +968,15 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR state = State.Running; return new Start2Answer(cmd); } catch (XmlRpcException e) { + s_logger.warn("Exception ", e); String msg = handleVmStartFailure(vmName, vm, "", e); return new Start2Answer(cmd, msg); } catch (XenAPIException e) { + s_logger.warn("Exception ", e); String msg = handleVmStartFailure(vmName, vm, "", e); return new Start2Answer(cmd, msg); } catch (Exception e) { + s_logger.warn("Exception ", e); String msg = handleVmStartFailure(vmName, vm, "", e); return new Start2Answer(cmd, msg); } finally { @@ -1120,7 +1092,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR bootArgs += " pod=" + _pod; bootArgs += " localgw=" + _localGateway; String result = startSystemVM(vmName, storage.getVlanId(), network, cmd.getVolumes(), bootArgs, storage.getGuestMacAddress(), storage.getGuestIpAddress(), storage - .getPrivateMacAddress(), storage.getPublicMacAddress(), cmd.getProxyCmdPort(), storage.getRamSize(), storage.getGuestOSId(), cmd.getNetworkRateMbps()); + .getPrivateMacAddress(), storage.getPublicMacAddress(), cmd.getProxyCmdPort(), storage.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps()); if (result == null) { return new StartSecStorageVmAnswer(cmd); } @@ -1624,9 +1596,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR vmStatsAnswer.setNumCPUs(vmStatsAnswer.getNumCPUs() + 1); vmStatsAnswer.setCPUUtilization((vmStatsAnswer.getCPUUtilization() + getDataAverage(dataNode, col, numRows))*100); } else if (param.equals("vif_0_rx")) { - vmStatsAnswer.setNetworkReadKBs(getDataAverage(dataNode, col, numRows)); + vmStatsAnswer.setNetworkReadKBs(getDataAverage(dataNode, col, numRows)/(8*2)); } else if (param.equals("vif_0_tx")) { - vmStatsAnswer.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows)); + vmStatsAnswer.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows)/(8*2)); } } @@ -2543,30 +2515,35 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR public boolean joinPool(String masterIp, String username, String password) { - Connection slaveConn = null; + Connection hostConn = null; Connection poolConn = null; - Session slaveSession = null; - URL slaveUrl = null; + Session hostSession = null; + URL hostUrl = null; try { // Connect and find out about the new connection to the new pool. poolConn = _connPool.masterConnect(masterIp, username, password); + Set pools = Pool.getAll(poolConn); + Pool pool = pools.iterator().next(); + String poolUUID = pool.getUuid(poolConn); + //check if this host is already in pool Set hosts = Host.getAll(poolConn); for( Host host : hosts ) { if(host.getAddress(poolConn).equals(_host.ip)) { + _host.pool = poolUUID; return true; } } - slaveUrl = new URL("http://" + _host.ip); - slaveConn = new Connection(slaveUrl, 100); - slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password); + hostUrl = new URL("http://" + _host.ip); + hostConn = new Connection(hostUrl, 100); + hostSession = Session.loginWithPassword(hostConn, _username, _password, APIVersion.latest().toString()); // Now join it. - Pool.join(slaveConn, masterIp, username, password); + Pool.join(hostConn, masterIp, username, password); if (s_logger.isDebugEnabled()) { s_logger.debug("Joined the pool at " + masterIp); } @@ -2578,12 +2555,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } // check if the master of this host is set correctly. - Connection c = new Connection(slaveUrl, 100); - for (int i = 0; i < 15; i++) { + Connection c = new Connection(hostUrl, 100); + int i; + for (i = 0 ; i < 15; i++) { try { Session.loginWithPassword(c, _username, _password, APIVersion.latest().toString()); - s_logger.debug("Still waiting for the conversion to the master"); + s_logger.debug(_host.ip + " is still master, waiting for the conversion to the slave"); Session.logout(c); c.dispose(); } catch (Types.HostIsSlave e) { @@ -2606,7 +2584,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } catch (InterruptedException e) { } } - + if( i >= 15 ) { + throw new CloudRuntimeException(_host.ip + " didn't change to slave after waiting 30 secondary"); + } + _host.pool = poolUUID; return true; } catch (MalformedURLException e) { throw new CloudRuntimeException("Problem with url " + _host.ip); @@ -2628,9 +2609,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } poolConn.dispose(); } - if(slaveSession != null) { + if(hostSession != null) { try { - Session.localLogout(slaveConn); + Session.logout(hostConn); } catch (Exception e) { } } @@ -3105,7 +3086,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR String bootArgs = cmd.getBootArgs(); String result = startSystemVM(vmName, router.getVlanId(), network, cmd.getVolumes(), bootArgs, router.getGuestMacAddress(), router.getPrivateIpAddress(), router - .getPrivateMacAddress(), router.getPublicMacAddress(), 3922, router.getRamSize(), router.getGuestOSId(), cmd.getNetworkRateMbps()); + .getPrivateMacAddress(), router.getPublicMacAddress(), 3922, router.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps()); if (result == null) { networkUsage(router.getPrivateIpAddress(), "create", null); return new StartRouterAnswer(cmd); @@ -3120,7 +3101,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } protected String startSystemVM(String vmName, String vlanId, Network nw0, List vols, String bootArgs, String guestMacAddr, String privateIp, String privateMacAddr, - String publicMacAddr, int cmdPort, long ramSize, long guestOsId, int networkRateMbps) { + String publicMacAddr, int cmdPort, long ramSize, String getGuestOSDescription, int networkRateMbps) { setupLinkLocalNetwork(); VM vm = null; @@ -3138,9 +3119,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR Ternary mount = mounts.get(0); - Set templates = VM.getByNameLabel(conn, CitrixHelper.getGuestOsType(guestOsId)); + Set templates = VM.getByNameLabel(conn, getGuestOsType(getGuestOSDescription)); if (templates.size() == 0) { - String msg = " can not find systemvm template " + CitrixHelper.getGuestOsType(guestOsId) ; + String msg = " can not find systemvm template " + getGuestOsType(getGuestOSDescription) ; s_logger.warn(msg); return msg; @@ -3295,7 +3276,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR bootArgs += " localgw=" + _localGateway; String result = startSystemVM(vmName, proxy.getVlanId(), network, cmd.getVolumes(), bootArgs, proxy.getGuestMacAddress(), proxy.getGuestIpAddress(), proxy - .getPrivateMacAddress(), proxy.getPublicMacAddress(), cmd.getProxyCmdPort(), proxy.getRamSize(), proxy.getGuestOSId(), cmd.getNetworkRateMbps()); + .getPrivateMacAddress(), proxy.getPublicMacAddress(), cmd.getProxyCmdPort(), proxy.getRamSize(), cmd.getGuestOSDescription(), cmd.getNetworkRateMbps()); if (result == null) { return new StartConsoleProxyAnswer(cmd); } @@ -3307,19 +3288,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return new StartConsoleProxyAnswer(cmd, msg); } } - - protected boolean patchSystemVm(VDI vdi, String vmName) { - if (vmName.startsWith("r-")) { - return patchSpecialVM(vdi, vmName, "router"); - } else if (vmName.startsWith("v-")) { - return patchSpecialVM(vdi, vmName, "consoleproxy"); - } else if (vmName.startsWith("s-")) { - return patchSpecialVM(vdi, vmName, "secstorage"); - } else { - throw new CloudRuntimeException("Tried to patch unknown type of system vm"); - } - } - + protected boolean isDeviceUsed(VM vm, Long deviceId) { // Figure out the disk number to attach the VM to @@ -3360,79 +3329,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR throw new CloudRuntimeException("Could not find an available slot in VM with name to attach a new disk."); } - protected boolean patchSpecialVM(VDI vdi, String vmname, String vmtype) { - // patch special vm here, domr, domp - VBD vbd = null; - Connection conn = getConnection(); - try { - Host host = Host.getByUuid(conn, _host.uuid); - - Set vms = host.getResidentVMs(conn); - - for (VM vm : vms) { - VM.Record vmrec = null; - try { - vmrec = vm.getRecord(conn); - } catch (Exception e) { - String msg = "VM.getRecord failed due to " + e.toString() + " " + e.getMessage(); - s_logger.warn(msg); - continue; - } - if (vmrec.isControlDomain) { - - /* create VBD */ - VBD.Record vbdr = new VBD.Record(); - vbdr.VM = vm; - vbdr.VDI = vdi; - vbdr.bootable = false; - vbdr.userdevice = getUnusedDeviceNum(vm); - vbdr.unpluggable = true; - vbdr.mode = Types.VbdMode.RW; - vbdr.type = Types.VbdType.DISK; - - vbd = VBD.create(conn, vbdr); - - vbd.plug(conn); - - String device = vbd.getDevice(conn); - - return patchspecialvm(vmname, device, vmtype); - } - } - - } catch (XenAPIException e) { - String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.toString(); - s_logger.warn(msg, e); - } catch (Exception e) { - String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.getMessage(); - s_logger.warn(msg, e); - } finally { - if (vbd != null) { - try { - if (vbd.getCurrentlyAttached(conn)) { - vbd.unplug(conn); - } - vbd.destroy(conn); - } catch (XmlRpcException e) { - String msg = "Catch XmlRpcException due to " + e.getMessage(); - s_logger.warn(msg, e); - } catch (XenAPIException e) { - String msg = "Catch XenAPIException due to " + e.toString(); - s_logger.warn(msg, e); - } - - } - } - return false; - } - - protected boolean patchspecialvm(String vmname, String device, String vmtype) { - String result = callHostPlugin("vmops", "patchdomr", "vmname", vmname, "vmtype", vmtype, "device", "/dev/" + device); - if (result == null || result.isEmpty()) - return false; - return true; - } - protected String callHostPlugin(String plugin, String cmd, String... params) { //default time out is 300 s return callHostPluginWithTimeOut(plugin, cmd, 300, params); @@ -3451,10 +3347,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (s_logger.isTraceEnabled()) { s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } - if( _host.host == null ) { - _host.host = Host.getByUuid(conn, _host.uuid); - } - String result = _host.host.callPlugin(conn, plugin, cmd, args); + Host host = Host.getByUuid(conn, _host.uuid); + String result = host.callPlugin(conn, plugin, cmd, args); if (s_logger.isTraceEnabled()) { s_logger.trace("callHostPlugin Result: " + result); } @@ -3746,7 +3640,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR for (PIF pif : vlanNetworkr.PIFs) { PIF.Record pifr = pif.getRecord(conn); if (pifr.device.equals(nPifr.device) && pifr.host.equals(nPifr.host)) { - pif.plug(conn); return vlanNetwork; } } @@ -3761,11 +3654,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR s_logger.debug("VLAN is created for " + tag + ". The uuid is " + vlanr.uuid); } - PIF untaggedPif = vlanr.untaggedPIF; - if (!untaggedPif.getCurrentlyAttached(conn)) { - untaggedPif.plug(conn); - } - return vlanNetwork; } @@ -3943,7 +3831,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR try { Host myself = Host.getByUuid(conn, _host.uuid); - boolean findsystemvmiso = false; + Set hcs = myself.getHostCPUs(conn); + _host.cpus = hcs.size(); + for (final HostCpu hc : hcs) { + _host.speed = hc.getSpeed(conn).intValue(); + break; + } + Set srs = SR.getByNameLabel(conn, "XenServer Tools"); if( srs.size() != 1 ) { throw new CloudRuntimeException("There are " + srs.size() + " SRs with name XenServer Tools"); @@ -4001,7 +3895,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR s_logger.warn("Unable to get private network " + name); return false; } - } + } else { + _privateNetworkName = name; + } + _host.privatePif = privateNic.pr.uuid; _host.privateNetwork = privateNic.nr.uuid; @@ -4193,7 +4090,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR changes = sync(); } - cmd.setHypervisorType(Hypervisor.Type.XenServer); + cmd.setHypervisorType(HypervisorType.XenServer); cmd.setChanges(changes); cmd.setCluster(_cluster); @@ -4449,7 +4346,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected Answer execute(ModifyStoragePoolCommand cmd) { StoragePoolVO pool = cmd.getPool(); - StoragePoolTO poolTO = new StoragePoolTO(pool); + StorageFilerTO poolTO = new StorageFilerTO(pool); try { Connection conn = getConnection(); @@ -4478,7 +4375,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected Answer execute(DeleteStoragePoolCommand cmd) { StoragePoolVO pool = cmd.getPool(); - StoragePoolTO poolTO = new StoragePoolTO(pool); + StorageFilerTO poolTO = new StorageFilerTO(pool); try { Connection conn = getConnection(); SR sr = getStorageRepository(conn, poolTO); @@ -4545,13 +4442,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } cmd.setCaps(caps.toString()); - Set hcs = host.getHostCPUs(conn); - cpus = hcs.size(); - for (final HostCpu hc : hcs) { - speed = hc.getSpeed(conn); - } - cmd.setSpeed(speed); - cmd.setCpus(cpus); + cmd.setSpeed(_host.speed); + cmd.setCpus(_host.cpus); long free = 0; @@ -4632,7 +4524,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } catch (NumberFormatException e) { throw new ConfigurationException("Unable to get the zone " + params.get("zone")); } - _host.host = null; _name = _host.uuid; _host.ip = (String) params.get("url"); _host.pool = (String) params.get("pool"); @@ -4719,7 +4610,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR @Override public CreateAnswer execute(CreateCommand cmd) { - StoragePoolTO pool = cmd.getPool(); + StorageFilerTO pool = cmd.getPool(); DiskProfile dskch = cmd.getDiskCharacteristics(); VDI vdi = null; @@ -4812,7 +4703,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR throw new Exception("no attached PBD"); } if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn))); + s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig)); } sr.scan(conn); return sr; @@ -4893,7 +4784,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected SR getIscsiSR(StoragePoolTO pool) { + protected SR getIscsiSR(StorageFilerTO pool) { Connection conn = getConnection(); synchronized (pool.getUuid().intern()) { Map deviceConfig = new HashMap(); @@ -5003,7 +4894,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected SR getNfsSR(StoragePoolTO pool) { + protected SR getNfsSR(StorageFilerTO pool) { Connection conn = getConnection(); Map deviceConfig = new HashMap(); @@ -5124,7 +5015,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR public CopyVolumeAnswer execute(final CopyVolumeCommand cmd) { String volumeUUID = cmd.getVolumePath(); StoragePoolVO pool = cmd.getPool(); - StoragePoolTO poolTO = new StoragePoolTO(pool); + StorageFilerTO poolTO = new StorageFilerTO(pool); String secondaryStorageURL = cmd.getSecondaryStorageURL(); URI uri = null; @@ -5412,84 +5303,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected ValidateSnapshotAnswer execute(final ValidateSnapshotCommand cmd) { - String primaryStoragePoolNameLabel = cmd.getPrimaryStoragePoolNameLabel(); - String volumeUuid = cmd.getVolumeUuid(); // Precondition: not null - String firstBackupUuid = cmd.getFirstBackupUuid(); - String previousSnapshotUuid = cmd.getPreviousSnapshotUuid(); - String templateUuid = cmd.getTemplateUuid(); - - // By default assume failure - String details = "Could not validate previous snapshot backup UUID " + "because the primary Storage SR could not be created from the name label: " - + primaryStoragePoolNameLabel; - boolean success = false; - String expectedSnapshotBackupUuid = null; - String actualSnapshotBackupUuid = null; - String actualSnapshotUuid = null; - - Boolean isISCSI = false; - String primaryStorageSRUuid = null; - Connection conn = getConnection(); - try { - SR primaryStorageSR = getSRByNameLabelandHost(primaryStoragePoolNameLabel); - - if (primaryStorageSR != null) { - primaryStorageSRUuid = primaryStorageSR.getUuid(conn); - isISCSI = SRType.LVMOISCSI.equals(primaryStorageSR.getType(conn)); - } - } catch (BadServerResponse e) { - details += ", reason: " + e.getMessage(); - s_logger.error(details, e); - } catch (XenAPIException e) { - details += ", reason: " + e.getMessage(); - s_logger.error(details, e); - } catch (XmlRpcException e) { - details += ", reason: " + e.getMessage(); - s_logger.error(details, e); - } - - if (primaryStorageSRUuid != null) { - if (templateUuid == null) { - templateUuid = ""; - } - if (firstBackupUuid == null) { - firstBackupUuid = ""; - } - if (previousSnapshotUuid == null) { - previousSnapshotUuid = ""; - } - String result = callHostPlugin("vmopsSnapshot", "validateSnapshot", "primaryStorageSRUuid", primaryStorageSRUuid, "volumeUuid", volumeUuid, "firstBackupUuid", firstBackupUuid, - "previousSnapshotUuid", previousSnapshotUuid, "templateUuid", templateUuid, "isISCSI", isISCSI.toString()); - if (result == null || result.isEmpty()) { - details = "Validating snapshot backup for volume with UUID: " + volumeUuid + " failed because there was an exception in the plugin"; - // callHostPlugin exception which has been logged already - } else { - String[] uuids = result.split("#", -1); - if (uuids.length >= 3) { - expectedSnapshotBackupUuid = uuids[1]; - actualSnapshotBackupUuid = uuids[2]; - } - if (uuids.length >= 4) { - actualSnapshotUuid = uuids[3]; - } else { - actualSnapshotUuid = ""; - } - if (uuids[0].equals("1")) { - success = true; - details = null; - } else { - details = "Previous snapshot backup on the primary storage is invalid. " + "Expected: " + expectedSnapshotBackupUuid + " Actual: " + actualSnapshotBackupUuid; - // success is still false - } - s_logger.debug("ValidatePreviousSnapshotBackup returned " + " success: " + success + " details: " + details + " expectedSnapshotBackupUuid: " - + expectedSnapshotBackupUuid + " actualSnapshotBackupUuid: " + actualSnapshotBackupUuid + " actualSnapshotUuid: " + actualSnapshotUuid); - } - } - - return new ValidateSnapshotAnswer(cmd, success, details, expectedSnapshotBackupUuid, actualSnapshotBackupUuid, actualSnapshotUuid); - } - protected ManageSnapshotAnswer execute(final ManageSnapshotCommand cmd) { + long snapshotId = cmd.getSnapshotId(); String snapshotName = cmd.getSnapshotName(); @@ -5510,20 +5325,35 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (cmdSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) { // Look up the volume String volumeUUID = cmd.getVolumePath(); - - VDI volume = getVDIbyUuid(volumeUUID); + VDI volume = VDI.getByUuid(conn, volumeUUID); // Create a snapshot VDI snapshot = volume.snapshot(conn, new HashMap()); - + if (snapshotName != null) { snapshot.setNameLabel(conn, snapshotName); } - // Determine the UUID of the snapshot - VDI.Record vdir = snapshot.getRecord(conn); - snapshotUUID = vdir.uuid; + snapshotUUID = snapshot.getUuid(conn); + String preSnapshotUUID = cmd.getSnapshotPath(); + //check if it is a empty snapshot + if( preSnapshotUUID != null) { + SR sr = volume.getSR(conn); + String srUUID = sr.getUuid(conn); + String type = sr.getType(conn); + Boolean isISCSI = SRType.LVMOISCSI.equals(type); + String snapshotParentUUID = getVhdParent(srUUID, snapshotUUID, isISCSI); + + String preSnapshotParentUUID = getVhdParent(srUUID, preSnapshotUUID, isISCSI); + if( snapshotParentUUID != null && snapshotParentUUID.equals(preSnapshotParentUUID)) { + // this is empty snapshot, remove it + snapshot.destroy(conn); + snapshotUUID = preSnapshotUUID; + } + + } + success = true; details = null; } else if (cmd.getCommandSwitch().equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) { @@ -5547,74 +5377,63 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return new ManageSnapshotAnswer(cmd, snapshotId, snapshotUUID, success, details); } - protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateCommand cmd) { - String secondaryStorageURL = cmd.getSecondaryStorageURL(); - String snapshotUUID = cmd.getSnapshotPath(); + protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateFromVolumeCommand cmd) { + String secondaryStoragePoolURL = cmd.getSecondaryStorageURL(); + String volumeUUID = cmd.getVolumePath(); + Long accountId = cmd.getAccountId(); String userSpecifiedName = cmd.getTemplateName(); + Long templateId = cmd.getTemplateId(); - SR secondaryStorage = null; - VDI privateTemplate = null; - Connection conn = getConnection(); + String details = null; + SR tmpltSR = null; + boolean result = false; try { - URI uri = new URI(secondaryStorageURL); - String remoteTemplateMountPath = uri.getHost() + ":" + uri.getPath() + "/template/"; - String templateFolder = cmd.getAccountId() + "/" + cmd.getTemplateId() + "/"; - String templateDownloadFolder = createTemplateDownloadFolder(remoteTemplateMountPath, templateFolder); - String templateInstallFolder = "tmpl/" + templateFolder; - - // Create a SR for the secondary storage download folder - secondaryStorage = createNfsSRbyURI(new URI(secondaryStorageURL + "/template/" + templateDownloadFolder), false); - - // Look up the snapshot and copy it to secondary storage - VDI snapshot = getVDIbyUuid(snapshotUUID); - privateTemplate = cloudVDIcopy(snapshot, secondaryStorage); + + URI uri = new URI(secondaryStoragePoolURL); + String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath(); + String installPath = "template/tmpl/" + accountId + "/" + templateId; + if( !createSecondaryStorageFolder(secondaryStorageMountPath, installPath)) { + details = " Filed to create folder " + installPath + " in secondary storage"; + s_logger.warn(details); + return new CreatePrivateTemplateAnswer(cmd, false, details); + } + Connection conn = getConnection(); + VDI volume = getVDIbyUuid(volumeUUID); + // create template SR + URI tmpltURI = new URI(secondaryStoragePoolURL + "/" + installPath); + tmpltSR = createNfsSRbyURI(tmpltURI, false); + // copy volume to template SR + VDI tmpltVDI = cloudVDIcopy(volume, tmpltSR); + if (userSpecifiedName != null) { - privateTemplate.setNameLabel(conn, userSpecifiedName); + tmpltVDI.setNameLabel(conn, userSpecifiedName); } - // Determine the template file name and install path - VDI.Record vdir = privateTemplate.getRecord(conn); - String templateName = vdir.uuid; - String templateFilename = templateName + ".vhd"; - String installPath = "template/" + templateInstallFolder + templateFilename; - - // Determine the template's virtual size and then forget the VDI - long virtualSize = privateTemplate.getVirtualSize(conn); - // Create the template.properties file in the download folder, move - // the template and the template.properties file - // to the install folder, and then delete the download folder - if (!postCreatePrivateTemplate(remoteTemplateMountPath, templateDownloadFolder, templateInstallFolder, templateFilename, templateName, userSpecifiedName, null, - virtualSize, cmd.getTemplateId())) { - throw new InternalErrorException("Failed to create the template.properties file."); + String tmpltSrUUID = tmpltSR.getUuid(conn); + String tmpltUUID = tmpltVDI.getUuid(conn); + String tmpltFilename = tmpltUUID + ".vhd"; + long virtualSize = tmpltVDI.getVirtualSize(conn); + long size = tmpltVDI.getPhysicalUtilisation(conn); + // create the template.properties file + result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, size, virtualSize, templateId); + if (!result) { + throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI); } - - return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, templateName, ImageFormat.VHD); + return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, tmpltUUID, ImageFormat.VHD); } catch (XenAPIException e) { - if (privateTemplate != null) { - destroyVDI(privateTemplate); - } - - s_logger.warn("CreatePrivateTemplate Failed due to " + e.toString(), e); - return new CreatePrivateTemplateAnswer(cmd, false, e.toString(), null, 0, null, null); + details = "Creating template from volume " + volumeUUID + " failed due to " + e.getMessage(); + s_logger.error(details, e); } catch (Exception e) { - s_logger.warn("CreatePrivateTemplate Failed due to " + e.getMessage(), e); - return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null); + details = "Creating template from volume " + volumeUUID + " failed due to " + e.getMessage(); + s_logger.error(details, e); } finally { // Remove the secondary storage SR - removeSR(secondaryStorage); + removeSR(tmpltSR); } + return new CreatePrivateTemplateAnswer(cmd, result, details); } - private String createTemplateDownloadFolder(String remoteTemplateMountPath, String templateFolder) throws InternalErrorException, URISyntaxException { - String templateDownloadFolder = "download/" + _host.uuid + "/" + templateFolder; - - // Create the download folder - if (!createSecondaryStorageFolder(remoteTemplateMountPath, templateDownloadFolder)) { - throw new InternalErrorException("Failed to create the template download folder."); - } - return templateDownloadFolder; - } protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateFromSnapshotCommand cmd) { String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); @@ -5623,59 +5442,61 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR Long volumeId = cmd.getVolumeId(); String secondaryStoragePoolURL = cmd.getSecondaryStoragePoolURL(); String backedUpSnapshotUuid = cmd.getSnapshotUuid(); - String origTemplateInstallPath = cmd.getOrigTemplateInstallPath(); Long newTemplateId = cmd.getNewTemplateId(); String userSpecifiedName = cmd.getTemplateName(); // By default, assume failure - String details = "Failed to create private template " + newTemplateId + " from snapshot for volume: " + volumeId + " with backupUuid: " + backedUpSnapshotUuid; - String newTemplatePath = null; - String templateName = null; + String details = null; + SR snapshotSR = null; + SR tmpltSR = null; boolean result = false; - long virtualSize = 0; try { URI uri = new URI(secondaryStoragePoolURL); - String remoteTemplateMountPath = uri.getHost() + ":" + uri.getPath() + "/template/"; - String templateFolder = cmd.getAccountId() + "/" + newTemplateId + "/"; - String templateDownloadFolder = createTemplateDownloadFolder(remoteTemplateMountPath, templateFolder); - String templateInstallFolder = "tmpl/" + templateFolder; - // Yes, create a template vhd - Pair vhdDetails = createVHDFromSnapshot(primaryStorageNameLabel, dcId, accountId, volumeId, secondaryStoragePoolURL, backedUpSnapshotUuid, - origTemplateInstallPath, templateDownloadFolder); - - VHDInfo vhdInfo = vhdDetails.first(); - String failureDetails = vhdDetails.second(); - if (vhdInfo == null) { - if (failureDetails != null) { - details += failureDetails; - } - } else { - templateName = vhdInfo.getUuid(); - String templateFilename = templateName + ".vhd"; - String templateInstallPath = templateInstallFolder + "/" + templateFilename; - - newTemplatePath = "template" + "/" + templateInstallPath; - - virtualSize = vhdInfo.getVirtualSize(); - // create the template.properties file - result = postCreatePrivateTemplate(remoteTemplateMountPath, templateDownloadFolder, templateInstallFolder, templateFilename, templateName, userSpecifiedName, null, - virtualSize, newTemplateId); - if (!result) { - details += ", reason: Could not create the template.properties file on secondary storage dir: " + templateInstallFolder; - } else { - // Aaah, success. - details = null; - } - + String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath(); + String installPath = "template/tmpl/" + accountId + "/" + newTemplateId; + if( !createSecondaryStorageFolder(secondaryStorageMountPath, installPath)) { + details = " Filed to create folder " + installPath + " in secondary storage"; + s_logger.warn(details); + return new CreatePrivateTemplateAnswer(cmd, false, details); } + Connection conn = getConnection(); + // create snapshot SR + URI snapshotURI = new URI(secondaryStoragePoolURL + "/snapshots/" + accountId + "/" + volumeId ); + snapshotSR = createNfsSRbyURI(snapshotURI, false); + snapshotSR.scan(conn); + VDI snapshotVDI = getVDIbyUuid(backedUpSnapshotUuid); + + // create template SR + URI tmpltURI = new URI(secondaryStoragePoolURL + "/" + installPath); + tmpltSR = createNfsSRbyURI(tmpltURI, false); + // copy snapshotVDI to template SR + VDI tmpltVDI = cloudVDIcopy(snapshotVDI, tmpltSR); + + String tmpltSrUUID = tmpltSR.getUuid(conn); + String tmpltUUID = tmpltVDI.getUuid(conn); + String tmpltFilename = tmpltUUID + ".vhd"; + long virtualSize = tmpltVDI.getVirtualSize(conn); + long size = tmpltVDI.getPhysicalUtilisation(conn); + + // create the template.properties file + result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, size, virtualSize, newTemplateId); + if (!result) { + throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI); + } + + return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, tmpltUUID, ImageFormat.VHD); } catch (XenAPIException e) { - details += ", reason: " + e.getMessage(); + details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.getMessage(); s_logger.error(details, e); } catch (Exception e) { - details += ", reason: " + e.getMessage(); + details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.getMessage(); s_logger.error(details, e); + } finally { + // Remove the secondary storage SR + removeSR(snapshotSR); + removeSR(tmpltSR); } - return new CreatePrivateTemplateAnswer(cmd, result, details, newTemplatePath, virtualSize, templateName, ImageFormat.VHD); + return new CreatePrivateTemplateAnswer(cmd, result, details); } protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) { @@ -5687,7 +5508,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR String snapshotUuid = cmd.getSnapshotUuid(); // not null: Precondition. String prevSnapshotUuid = cmd.getPrevSnapshotUuid(); String prevBackupUuid = cmd.getPrevBackupUuid(); - boolean isFirstSnapshotOfRootVolume = cmd.isFirstSnapshotOfRootVolume(); // By default assume failure String details = null; boolean success = false; @@ -5703,28 +5523,46 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR URI uri = new URI(secondaryStoragePoolURL); String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath(); + - if (secondaryStorageMountPath == null) { - details = "Couldn't backup snapshot because the URL passed: " + secondaryStoragePoolURL + " is invalid."; - } else { - boolean gcHappened = true; - if (gcHappened) { - snapshotBackupUuid = backupSnapshot(primaryStorageSRUuid, dcId, accountId, volumeId, secondaryStorageMountPath, snapshotUuid, prevSnapshotUuid, prevBackupUuid, - isFirstSnapshotOfRootVolume, isISCSI); - success = (snapshotBackupUuid != null); - } else { - s_logger.warn("GC hasn't happened yet for previousSnapshotUuid: " + prevSnapshotUuid + ". Will retry again after 1 min"); + if (prevBackupUuid == null) { + // the first snapshot is always a full snapshot + String folder = "snapshots/" + accountId + "/" + volumeId; + if( !createSecondaryStorageFolder(secondaryStorageMountPath, folder)) { + details = " Filed to create folder " + folder + " in secondary storage"; + s_logger.warn(details); + return new BackupSnapshotAnswer(cmd, success, details, snapshotBackupUuid); } + + String snapshotMountpoint = secondaryStoragePoolURL + "/" + folder; + SR snapshotSr = null; + try { + snapshotSr = createNfsSRbyURI(new URI(snapshotMountpoint), false); + VDI snapshotVdi = getVDIbyUuid(snapshotUuid); + VDI backedVdi = snapshotVdi.copy(conn, snapshotSr); + snapshotBackupUuid = backedVdi.getUuid(conn); + success = true; + } finally { + if( snapshotSr != null) { + removeSR(snapshotSr); + } + } + } else { + snapshotBackupUuid = backupSnapshot(primaryStorageSRUuid, dcId, accountId, volumeId, secondaryStorageMountPath, + snapshotUuid, prevSnapshotUuid, prevBackupUuid, isISCSI); + success = (snapshotBackupUuid != null); } - if (!success) { + if (success) { + details = "Successfully backedUp the snapshotUuid: " + snapshotUuid + " to secondary storage."; + // Mark the snapshot as removed in the database. // When the next snapshot is taken, it will be // 1) deleted from the DB 2) The snapshotUuid will be deleted from the primary // 3) the snapshotBackupUuid will be copied to secondary // 4) if possible it will be coalesced with the next snapshot. - } else if (prevSnapshotUuid != null && !isFirstSnapshotOfRootVolume) { + if (prevSnapshotUuid != null) { // Destroy the previous snapshot, if it exists. // We destroy the previous snapshot only if the current snapshot // backup succeeds. @@ -5732,8 +5570,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR // so that it doesn't get merged with the // new one // and muddle the vhd chain on the secondary storage. - details = "Successfully backedUp the snapshotUuid: " + snapshotUuid + " to secondary storage."; - destroySnapshotOnPrimaryStorage(prevSnapshotUuid); + + destroySnapshotOnPrimaryStorage(prevSnapshotUuid); + } } } catch (XenAPIException e) { @@ -5749,93 +5588,44 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected CreateVolumeFromSnapshotAnswer execute(final CreateVolumeFromSnapshotCommand cmd) { String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); - Long dcId = cmd.getDataCenterId(); Long accountId = cmd.getAccountId(); Long volumeId = cmd.getVolumeId(); String secondaryStoragePoolURL = cmd.getSecondaryStoragePoolURL(); String backedUpSnapshotUuid = cmd.getSnapshotUuid(); - String templatePath = cmd.getTemplatePath(); // By default, assume the command has failed and set the params to be // passed to CreateVolumeFromSnapshotAnswer appropriately boolean result = false; // Generic error message. - String details = "Failed to create volume from snapshot for volume: " + volumeId + " with backupUuid: " + backedUpSnapshotUuid; - String vhdUUID = null; - SR temporarySROnSecondaryStorage = null; - String mountPointOfTemporaryDirOnSecondaryStorage = null; + String details = null; + String volumeUUID = null; + SR snapshotSR = null; + + if (secondaryStoragePoolURL == null) { + details += " because the URL passed: " + secondaryStoragePoolURL + " is invalid."; + return new CreateVolumeFromSnapshotAnswer(cmd, result, details, volumeUUID); + } try { - VDI vdi = null; Connection conn = getConnection(); SR primaryStorageSR = getSRByNameLabelandHost(primaryStorageNameLabel); if (primaryStorageSR == null) { throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: " + primaryStorageNameLabel); } + // Get the absolute path of the snapshot on the secondary storage. + URI snapshotURI = new URI(secondaryStoragePoolURL + "/snapshots/" + accountId + "/" + volumeId ); + + snapshotSR = createNfsSRbyURI(snapshotURI, false); + snapshotSR.scan(conn); + VDI snapshotVDI = getVDIbyUuid(backedUpSnapshotUuid); - Boolean isISCSI = SRType.LVMOISCSI.equals(primaryStorageSR.getType(conn)); + VDI volumeVDI = cloudVDIcopy(snapshotVDI, primaryStorageSR); + + volumeUUID = volumeVDI.getUuid(conn); + + + result = true; - // Get the absolute path of the template on the secondary storage. - URI uri = new URI(secondaryStoragePoolURL); - String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath(); - - if (secondaryStorageMountPath == null) { - details += " because the URL passed: " + secondaryStoragePoolURL + " is invalid."; - return new CreateVolumeFromSnapshotAnswer(cmd, result, details, vhdUUID); - } - - // Create a volume and not a template - String templateDownloadFolder = ""; - - VHDInfo vhdInfo = createVHDFromSnapshot(dcId, accountId, volumeId, secondaryStorageMountPath, backedUpSnapshotUuid, templatePath, templateDownloadFolder, isISCSI); - if (vhdInfo == null) { - details += " because the vmops plugin on XenServer failed at some point"; - } else { - vhdUUID = vhdInfo.getUuid(); - String tempDirRelativePath = "snapshots" + File.separator + accountId + File.separator + volumeId + "_temp"; - mountPointOfTemporaryDirOnSecondaryStorage = secondaryStorageMountPath + File.separator + tempDirRelativePath; - - uri = new URI("nfs://" + mountPointOfTemporaryDirOnSecondaryStorage); - // No need to check if the SR already exists. It's a temporary - // SR destroyed when this method exits. - // And two createVolumeFromSnapshot operations cannot proceed at - // the same time. - temporarySROnSecondaryStorage = createNfsSRbyURI(uri, false); - if (temporarySROnSecondaryStorage == null) { - details += "because SR couldn't be created on " + mountPointOfTemporaryDirOnSecondaryStorage; - } else { - s_logger.debug("Successfully created temporary SR on secondary storage " + temporarySROnSecondaryStorage.getNameLabel(conn) + "with uuid " - + temporarySROnSecondaryStorage.getUuid(conn) + " and scanned it"); - // createNFSSRbyURI also scans the SR and introduces the VDI - - vdi = getVDIbyUuid(vhdUUID); - - if (vdi != null) { - s_logger.debug("Successfully created VDI on secondary storage SR " + temporarySROnSecondaryStorage.getNameLabel(conn) + " with uuid " + vhdUUID); - s_logger.debug("Copying VDI: " + vdi.getLocation(conn) + " from secondary to primary"); - VDI vdiOnPrimaryStorage = cloudVDIcopy(vdi, primaryStorageSR); - // vdi.copy introduces the vdi into the database. Don't - // need to do a scan on the primary - // storage. - - if (vdiOnPrimaryStorage != null) { - vhdUUID = vdiOnPrimaryStorage.getUuid(conn); - s_logger.debug("Successfully copied and introduced VDI on primary storage with path " + vdiOnPrimaryStorage.getLocation(conn) + " and uuid " + vhdUUID); - result = true; - details = null; - - } else { - details += ". Could not copy the vdi " + vhdUUID + " to primary storage"; - } - - // The VHD on temporary was scanned and introduced as a VDI - // destroy it as we don't need it anymore. - vdi.destroy(conn); - } else { - details += ". Could not scan and introduce vdi with uuid: " + vhdUUID; - } - } - } } catch (XenAPIException e) { details += " due to " + e.toString(); s_logger.warn(details, e); @@ -5844,13 +5634,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR s_logger.warn(details, e); } finally { // In all cases, if the temporary SR was created, forget it. - if (temporarySROnSecondaryStorage != null) { - removeSR(temporarySROnSecondaryStorage); - // Delete the temporary directory created. - File folderPath = new File(mountPointOfTemporaryDirOnSecondaryStorage); - String remoteMountPath = folderPath.getParent(); - String folder = folderPath.getName(); - deleteSecondaryStorageFolder(remoteMountPath, folder); + if (snapshotSR != null) { + removeSR(snapshotSR); } } if (!result) { @@ -5859,7 +5644,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } // In all cases return something. - return new CreateVolumeFromSnapshotAnswer(cmd, result, details, vhdUUID); + return new CreateVolumeFromSnapshotAnswer(cmd, result, details, volumeUUID); } protected DeleteSnapshotBackupAnswer execute(final DeleteSnapshotBackupCommand cmd) { @@ -5868,31 +5653,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR Long volumeId = cmd.getVolumeId(); String secondaryStoragePoolURL = cmd.getSecondaryStoragePoolURL(); String backupUUID = cmd.getSnapshotUuid(); - String childUUID = cmd.getChildUUID(); - String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); - String details = null; boolean success = false; - SR primaryStorageSR = null; - Boolean isISCSI = false; - try { - Connection conn = getConnection(); - primaryStorageSR = getSRByNameLabelandHost(primaryStorageNameLabel); - if (primaryStorageSR == null) { - details = "Primary Storage SR could not be created from the name label: " + primaryStorageNameLabel; - throw new InternalErrorException(details); - } - isISCSI = SRType.LVMOISCSI.equals(primaryStorageSR.getType(conn)); - } catch (XenAPIException e) { - details = "Couldn't determine primary SR type " + e.getMessage(); - s_logger.error(details, e); - } catch (Exception e) { - details = "Couldn't determine primary SR type " + e.getMessage(); - s_logger.error(details, e); - } - if (primaryStorageSR != null) { URI uri = null; try { uri = new URI(secondaryStoragePoolURL); @@ -5906,14 +5670,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR if (secondaryStorageMountPath == null) { details = "Couldn't delete snapshot because the URL passed: " + secondaryStoragePoolURL + " is invalid."; } else { - details = deleteSnapshotBackup(dcId, accountId, volumeId, secondaryStorageMountPath, backupUUID, childUUID, isISCSI); + details = deleteSnapshotBackup(dcId, accountId, volumeId, secondaryStorageMountPath, backupUUID); success = (details != null && details.equals("1")); if (success) { s_logger.debug("Successfully deleted snapshot backup " + backupUUID); } } } - } return new DeleteSnapshotBackupAnswer(cmd, success, details); } @@ -6041,7 +5804,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected SR getStorageRepository(Connection conn, StoragePoolTO pool) { + protected SR getStorageRepository(Connection conn, StorageFilerTO pool) { Set srs; try { srs = SR.getByNameLabel(conn, pool.getUuid()); @@ -6134,8 +5897,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return (result != null); } - protected boolean postCreatePrivateTemplate(String remoteTemplateMountPath, String templateDownloadFolder, String templateInstallFolder, String templateFilename, - String templateName, String templateDescription, String checksum, long virtualSize, long templateId) { + protected boolean postCreatePrivateTemplate(String tmpltSrUUID,String tmpltFilename, String templateName, String templateDescription, String checksum, long size, long virtualSize, long templateId) { if (templateDescription == null) { templateDescription = ""; @@ -6145,23 +5907,18 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR checksum = ""; } - String result = callHostPluginWithTimeOut("vmopsSnapshot", "post_create_private_template", 110*60, "remoteTemplateMountPath", remoteTemplateMountPath, "templateDownloadFolder", templateDownloadFolder, - "templateInstallFolder", templateInstallFolder, "templateFilename", templateFilename, "templateName", templateName, "templateDescription", templateDescription, - "checksum", checksum, "virtualSize", String.valueOf(virtualSize), "templateId", String.valueOf(templateId)); + String result = callHostPluginWithTimeOut("vmopsSnapshot", "post_create_private_template", 110*60, "tmpltSrUUID", tmpltSrUUID, "templateFilename", tmpltFilename, "templateName", templateName, "templateDescription", templateDescription, + "checksum", checksum, "size", String.valueOf(size), "virtualSize", String.valueOf(virtualSize), "templateId", String.valueOf(templateId)); boolean success = false; if (result != null && !result.isEmpty()) { // Else, command threw an exception which has already been logged. - String[] tmp = result.split("#"); - String status = tmp[0]; - - if (status != null && status.equalsIgnoreCase("1")) { - s_logger.debug("Successfully created template.properties file on secondary storage dir: " + templateInstallFolder); + if (result.equalsIgnoreCase("1")) { + s_logger.debug("Successfully created template.properties file on secondary storage for " + tmpltFilename); success = true; } else { - s_logger.warn("Could not create template.properties file on secondary storage dir: " + templateInstallFolder + " for templateId: " + templateId - + ". Failed with status " + status); + s_logger.warn("Could not create template.properties file on secondary storage for " + tmpltFilename + " for templateId: " + templateId); } } @@ -6170,8 +5927,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR // Each argument is put in a separate line for readability. // Using more lines does not harm the environment. - protected String backupSnapshot(String primaryStorageSRUuid, Long dcId, Long accountId, Long volumeId, String secondaryStorageMountPath, String snapshotUuid, - String prevSnapshotUuid, String prevBackupUuid, Boolean isFirstSnapshotOfRootVolume, Boolean isISCSI) { + protected String backupSnapshot(String primaryStorageSRUuid, Long dcId, Long accountId, Long volumeId, String secondaryStorageMountPath, + String snapshotUuid, String prevSnapshotUuid, String prevBackupUuid, Boolean isISCSI) { String backupSnapshotUuid = null; if (prevSnapshotUuid == null) { @@ -6185,7 +5942,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR // Using more lines does not harm the environment. String results = callHostPluginWithTimeOut("vmopsSnapshot", "backupSnapshot", 110*60, "primaryStorageSRUuid", primaryStorageSRUuid, "dcId", dcId.toString(), "accountId", accountId.toString(), "volumeId", volumeId.toString(), "secondaryStorageMountPath", secondaryStorageMountPath, "snapshotUuid", snapshotUuid, "prevSnapshotUuid", prevSnapshotUuid, "prevBackupUuid", - prevBackupUuid, "isFirstSnapshotOfRootVolume", isFirstSnapshotOfRootVolume.toString(), "isISCSI", isISCSI.toString()); + prevBackupUuid, "isISCSI", isISCSI.toString()); if (results == null || results.isEmpty()) { // errString is already logged. @@ -6205,10 +5962,24 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId + " to secondary storage"); } else { s_logger.debug(failureString + ". Failed with status: " + status); + return null; } return backupSnapshotUuid; } + + + protected String getVhdParent(String primaryStorageSRUuid, String snapshotUuid, Boolean isISCSI) { + String parentUuid = callHostPlugin("vmopsSnapshot", "getVhdParent", "primaryStorageSRUuid", primaryStorageSRUuid, + "snapshotUuid", snapshotUuid, "isISCSI", isISCSI.toString()); + + if (parentUuid == null || parentUuid.isEmpty()) { + s_logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); + // errString is already logged. + return null; + } + return parentUuid; + } protected boolean destroySnapshotOnPrimaryStorage(String snapshotUuid) { // Precondition snapshotUuid != null @@ -6232,11 +6003,11 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return false; } - protected String deleteSnapshotBackup(Long dcId, Long accountId, Long volumeId, String secondaryStorageMountPath, String backupUUID, String childUUID, Boolean isISCSI) { + protected String deleteSnapshotBackup(Long dcId, Long accountId, Long volumeId, String secondaryStorageMountPath, String backupUUID) { // If anybody modifies the formatting below again, I'll skin them - String result = callHostPlugin("vmopsSnapshot", "deleteSnapshotBackup", "backupUUID", backupUUID, "childUUID", childUUID, "dcId", dcId.toString(), "accountId", accountId.toString(), - "volumeId", volumeId.toString(), "secondaryStorageMountPath", secondaryStorageMountPath, "isISCSI", isISCSI.toString()); + String result = callHostPlugin("vmopsSnapshot", "deleteSnapshotBackup", "backupUUID", backupUUID, "dcId", dcId.toString(), "accountId", accountId.toString(), + "volumeId", volumeId.toString(), "secondaryStorageMountPath", secondaryStorageMountPath); return result; } @@ -6249,70 +6020,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return result; } - // If anybody messes up with the formatting, I'll skin them - protected Pair createVHDFromSnapshot(String primaryStorageNameLabel, Long dcId, Long accountId, Long volumeId, String secondaryStoragePoolURL, - String backedUpSnapshotUuid, String templatePath, String templateDownloadFolder) throws XenAPIException, IOException, XmlRpcException, InternalErrorException, - URISyntaxException { - // Return values - String details = null; - Connection conn = getConnection(); - SR primaryStorageSR = getSRByNameLabelandHost(primaryStorageNameLabel); - if (primaryStorageSR == null) { - throw new InternalErrorException("Could not create volume from snapshot " + "because the primary Storage SR could not be created from the name label: " - + primaryStorageNameLabel); - } - - Boolean isISCSI = SRType.LVMOISCSI.equals(primaryStorageSR.getType(conn)); - - // Get the absolute path of the template on the secondary storage. - URI uri = new URI(secondaryStoragePoolURL); - String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath(); - VHDInfo vhdInfo = null; - if (secondaryStorageMountPath == null) { - details = " because the URL passed: " + secondaryStoragePoolURL + " is invalid."; - } else { - vhdInfo = createVHDFromSnapshot(dcId, accountId, volumeId, secondaryStorageMountPath, backedUpSnapshotUuid, templatePath, templateDownloadFolder, isISCSI); - if (vhdInfo == null) { - details = " because the vmops plugin on XenServer failed at some point"; - } - } - - return new Pair(vhdInfo, details); - } - - protected VHDInfo createVHDFromSnapshot(Long dcId, Long accountId, Long volumeId, String secondaryStorageMountPath, String backedUpSnapshotUuid, String templatePath, - String templateDownloadFolder, Boolean isISCSI) { - String vdiUUID = null; - - String failureString = "Could not create volume from " + backedUpSnapshotUuid; - templatePath = (templatePath == null) ? "" : templatePath; - String results = callHostPluginWithTimeOut("vmopsSnapshot","createVolumeFromSnapshot", 110*60, "dcId", dcId.toString(), "accountId", accountId.toString(), "volumeId", volumeId.toString(), - "secondaryStorageMountPath", secondaryStorageMountPath, "backedUpSnapshotUuid", backedUpSnapshotUuid, "templatePath", templatePath, "templateDownloadFolder", - templateDownloadFolder, "isISCSI", isISCSI.toString()); - - if (results == null || results.isEmpty()) { - // Command threw an exception which has already been logged. - return null; - } - String[] tmp = results.split("#"); - String status = tmp[0]; - vdiUUID = tmp[1]; - Long virtualSizeInMB = 0L; - if (tmp.length == 3) { - virtualSizeInMB = Long.valueOf(tmp[2]); - } - // status == "1" if and only if vdiUUID != null - // So we don't rely on status value but return vdiUUID as an indicator - // of success. - - if (status != null && status.equalsIgnoreCase("1") && vdiUUID != null) { - s_logger.debug("Successfully created vhd file with all data on secondary storage : " + vdiUUID); - } else { - s_logger.debug(failureString + ". Failed with status " + status + " with vdiUuid " + vdiUUID); - } - return new VHDInfo(vdiUUID, virtualSizeInMB * MB); - - } @Override public boolean start() { @@ -6354,7 +6061,19 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected Answer execute(PoolEjectCommand cmd) { Connection conn = getConnection(); String hostuuid = cmd.getHostuuid(); + try { + Map hostrs = Host.getAllRecords(conn); + boolean found = false; + for( Host.Record hr : hostrs.values() ) { + if( hr.uuid.equals(hostuuid)) { + found = true; + } + } + if( ! found) { + s_logger.debug("host " + hostuuid + " has already been ejected from pool " + _host.pool); + return new Answer(cmd); + } Host host = Host.getByUuid(conn, hostuuid); // remove all tags cloud stack add before eject Host.Record hr = host.getRecord(conn); @@ -6366,19 +6085,23 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } // eject from pool - Pool.eject(conn, host); + try { + Pool.eject(conn, host); + } catch (XenAPIException e) { + String msg = "Unable to eject host " + _host.uuid + " due to " + e.toString(); + s_logger.warn(msg); + host.destroy(conn); + } return new Answer(cmd); } catch (XenAPIException e) { - String msg = "Unable to eject host " + _host.uuid + " due to " + e.toString(); + String msg = "XenAPIException Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.toString(); s_logger.warn(msg, e); return new Answer(cmd, false, msg); } catch (Exception e) { - s_logger.warn("Unable to eject host " + _host.uuid, e); - String msg = "Unable to eject host " + _host.uuid + " due to " + e.getMessage(); + String msg = "Exception Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.getMessage(); s_logger.warn(msg, e); return new Answer(cmd, false, msg); - } - + } } protected class Nic { @@ -6402,7 +6125,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR public String systemvmisouuid; public String uuid; public String ip; - public Host host; public String publicNetwork; public String privateNetwork; public String linkLocalNetwork; @@ -6415,33 +6137,111 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR public String storagePif1; public String storagePif2; public String pool; + public int speed; + public int cpus; } - private class VHDInfo { - private final String uuid; - private final Long virtualSize; - - public VHDInfo(String uuid, Long virtualSize) { - this.uuid = uuid; - this.virtualSize = virtualSize; - } - - /** - * @return the uuid - */ - public String getUuid() { - return uuid; - } - - /** - * @return the virtualSize - */ - public Long getVirtualSize() { - return virtualSize; - } - } - + /*Override by subclass*/ protected String getGuestOsType(String stdType) { - return CitrixHelper.getGuestOsType(stdType); + return stdType; } + +/* + protected boolean patchSystemVm(VDI vdi, String vmName, VirtualMachine.Type type) { + if (type == VirtualMachine.Type.DomainRouter) { + return patchSpecialVM(vdi, vmName, "router"); + } else if (type == VirtualMachine.Type.ConsoleProxy) { + return patchSpecialVM(vdi, vmName, "consoleproxy"); + } else if (type == VirtualMachine.Type.SecondaryStorageVm) { + return patchSpecialVM(vdi, vmName, "secstorage"); + } else { + throw new CloudRuntimeException("Tried to patch unknown type of system vm"); + } + } + + protected boolean patchSystemVm(VDI vdi, String vmName) { + if (vmName.startsWith("r-")) { + return patchSpecialVM(vdi, vmName, "router"); + } else if (vmName.startsWith("v-")) { + return patchSpecialVM(vdi, vmName, "consoleproxy"); + } else if (vmName.startsWith("s-")) { + return patchSpecialVM(vdi, vmName, "secstorage"); + } else { + throw new CloudRuntimeException("Tried to patch unknown type of system vm"); + } + } + + protected boolean patchSpecialVM(VDI vdi, String vmname, String vmtype) { + // patch special vm here, domr, domp + VBD vbd = null; + Connection conn = getConnection(); + try { + Host host = Host.getByUuid(conn, _host.uuid); + + Set vms = host.getResidentVMs(conn); + + for (VM vm : vms) { + VM.Record vmrec = null; + try { + vmrec = vm.getRecord(conn); + } catch (Exception e) { + String msg = "VM.getRecord failed due to " + e.toString() + " " + e.getMessage(); + s_logger.warn(msg); + continue; + } + if (vmrec.isControlDomain) { + + VBD.Record vbdr = new VBD.Record(); + vbdr.VM = vm; + vbdr.VDI = vdi; + vbdr.bootable = false; + vbdr.userdevice = getUnusedDeviceNum(vm); + vbdr.unpluggable = true; + vbdr.mode = Types.VbdMode.RW; + vbdr.type = Types.VbdType.DISK; + + vbd = VBD.create(conn, vbdr); + + vbd.plug(conn); + + String device = vbd.getDevice(conn); + + return patchspecialvm(vmname, device, vmtype); + } + } + + } catch (XenAPIException e) { + String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.toString(); + s_logger.warn(msg, e); + } catch (Exception e) { + String msg = "patchSpecialVM faile on " + _host.uuid + " due to " + e.getMessage(); + s_logger.warn(msg, e); + } finally { + if (vbd != null) { + try { + if (vbd.getCurrentlyAttached(conn)) { + vbd.unplug(conn); + } + vbd.destroy(conn); + } catch (XmlRpcException e) { + String msg = "Catch XmlRpcException due to " + e.getMessage(); + s_logger.warn(msg, e); + } catch (XenAPIException e) { + String msg = "Catch XenAPIException due to " + e.toString(); + s_logger.warn(msg, e); + } + + } + } + return false; + } + + protected boolean patchspecialvm(String vmname, String device, String vmtype) { + String result = callHostPlugin("vmops", "patchdomr", "vmname", vmname, "vmtype", vmtype, "device", "/dev/" + device); + if (result == null || result.isEmpty()) + return false; + return true; + } +*/ + } diff --git a/core/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java b/core/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java index 090ad36fc78..2d4da33ee23 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java +++ b/core/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java @@ -26,4 +26,9 @@ public class XcpServerResource extends CitrixResourceBase { public XcpServerResource() { super(); } + + @Override + protected String getGuestOsType(String stdType) { + return CitrixHelper.getXcpGuestOsType(stdType); + } } diff --git a/core/src/com/cloud/hypervisor/xen/resource/XenServerResource.java b/core/src/com/cloud/hypervisor/xen/resource/XenServerResource.java index 713b3e6c3ae..a0668f1a00c 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/XenServerResource.java +++ b/core/src/com/cloud/hypervisor/xen/resource/XenServerResource.java @@ -39,7 +39,7 @@ public class XenServerResource extends CitrixResourceBase { @Override protected String getGuestOsType(String stdType) { - return stdType; + return CitrixHelper.getXenServerGuestOsType(stdType); } @Override diff --git a/core/src/com/cloud/info/ConsoleProxyInfo.java b/core/src/com/cloud/info/ConsoleProxyInfo.java index 1e310ac9764..f83f9eae4b8 100644 --- a/core/src/com/cloud/info/ConsoleProxyInfo.java +++ b/core/src/com/cloud/info/ConsoleProxyInfo.java @@ -30,15 +30,22 @@ public class ConsoleProxyInfo { this.proxyUrlPort = proxyUrlPort; } - public ConsoleProxyInfo(boolean sslEnabled, String proxyIpAddress, int port, int proxyUrlPort) { + public ConsoleProxyInfo(boolean sslEnabled, String proxyIpAddress, int port, int proxyUrlPort, String consoleProxyUrlDomain) { this.sslEnabled = sslEnabled; if(sslEnabled) { StringBuffer sb = new StringBuffer(proxyIpAddress); for(int i = 0; i < sb.length(); i++) if(sb.charAt(i) == '.') - sb.setCharAt(i, '-'); - sb.append(".realhostip.com"); + sb.setCharAt(i, '-'); + if(consoleProxyUrlDomain!=null && consoleProxyUrlDomain.length()>0) + { + sb.append("."); + sb.append(consoleProxyUrlDomain); + } + else + sb.append(".realhostip.com"); + proxyAddress = sb.toString(); proxyPort = port; this.proxyUrlPort = proxyUrlPort; diff --git a/core/src/com/cloud/storage/Snapshot.java b/core/src/com/cloud/storage/Snapshot.java index 87ae90509f0..62ca195ce69 100644 --- a/core/src/com/cloud/storage/Snapshot.java +++ b/core/src/com/cloud/storage/Snapshot.java @@ -39,7 +39,8 @@ public interface Snapshot { Creating, CreatedOnPrimary, BackingUp, - BackedUp; + BackedUp, + EmptySnapshot; public String toString() { return this.name(); diff --git a/core/src/com/cloud/storage/SnapshotPolicyVO.java b/core/src/com/cloud/storage/SnapshotPolicyVO.java index 27bb2ed04b9..d58a898de9d 100644 --- a/core/src/com/cloud/storage/SnapshotPolicyVO.java +++ b/core/src/com/cloud/storage/SnapshotPolicyVO.java @@ -79,6 +79,10 @@ public class SnapshotPolicyVO { return schedule; } + public void setInterval(short interval) { + this.interval = interval; + } + public void setTimezone(String timezone) { this.timezone = timezone; } diff --git a/core/src/com/cloud/storage/SnapshotScheduleVO.java b/core/src/com/cloud/storage/SnapshotScheduleVO.java index b112cd19fa9..62d77e2617a 100644 --- a/core/src/com/cloud/storage/SnapshotScheduleVO.java +++ b/core/src/com/cloud/storage/SnapshotScheduleVO.java @@ -77,14 +77,22 @@ public class SnapshotScheduleVO { return policyId; } - /** + public void setPolicyId(long policyId) { + this.policyId = policyId; + } + + /** * @return the scheduledTimestamp */ public Date getScheduledTimestamp() { return scheduledTimestamp; } - public Long getAsyncJobId() { + public void setScheduledTimestamp(Date scheduledTimestamp) { + this.scheduledTimestamp = scheduledTimestamp; + } + + public Long getAsyncJobId() { return asyncJobId; } diff --git a/core/src/com/cloud/storage/SnapshotVO.java b/core/src/com/cloud/storage/SnapshotVO.java index bce1e8f699b..3fb643590de 100644 --- a/core/src/com/cloud/storage/SnapshotVO.java +++ b/core/src/com/cloud/storage/SnapshotVO.java @@ -54,8 +54,8 @@ public class SnapshotVO implements Snapshot { @Expose @Column(name="name") - String name; - + String name; + @Expose @Column(name="status", updatable = true, nullable=false) @Enumerated(value=EnumType.STRING) @@ -71,7 +71,7 @@ public class SnapshotVO implements Snapshot { Date created; @Column(name=GenericDao.REMOVED_COLUMN) - Date removed; + Date removed; @Column(name="backup_snap_id") String backupSnapshotId; @@ -88,7 +88,7 @@ public class SnapshotVO implements Snapshot { this.name = name; this.snapshotType = snapshotType; this.typeDescription = typeDescription; - this.status = Status.Creating; + this.status = Status.Creating; this.prevSnapshotId = 0; } @@ -157,7 +157,7 @@ public class SnapshotVO implements Snapshot { return backupSnapshotId; } - public long getPrevSnapshotId(){ + public long getPrevSnapshotId(){ return prevSnapshotId; } @@ -169,13 +169,12 @@ public class SnapshotVO implements Snapshot { this.prevSnapshotId = prevSnapshotId; } - public static SnapshotType getSnapshotType(List policyIds) { - assert policyIds != null && !policyIds.isEmpty(); - SnapshotType snapshotType = SnapshotType.RECURRING; - if (policyIds.contains(MANUAL_POLICY_ID)) { - snapshotType = SnapshotType.MANUAL; + public static SnapshotType getSnapshotType(Long policyId) { + if (policyId.equals(MANUAL_POLICY_ID)) { + return SnapshotType.MANUAL; + } else { + return SnapshotType.RECURRING; } - return snapshotType; } public static SnapshotType getSnapshotType(String snapshotType) { diff --git a/core/src/com/cloud/storage/StoragePoolVO.java b/core/src/com/cloud/storage/StoragePoolVO.java index f3a3460157c..f15be056f97 100644 --- a/core/src/com/cloud/storage/StoragePoolVO.java +++ b/core/src/com/cloud/storage/StoragePoolVO.java @@ -49,7 +49,7 @@ public class StoragePoolVO implements StoragePool { @Column(name="name", updatable=false, nullable=false, length=255) private String name = null; - @Column(name="uuid", updatable=false, nullable=false, length=255) + @Column(name="uuid", length=255) private String uuid = null; @Column(name="pool_type", updatable=false, nullable=false, length=32) @@ -82,7 +82,8 @@ public class StoragePoolVO implements StoragePool { @Enumerated(value=EnumType.STRING) private Status status; - public long getId() { + @Override + public long getId() { return id; } @@ -95,19 +96,23 @@ public class StoragePoolVO implements StoragePool { // TODO Auto-generated constructor stub } - public String getName() { + @Override + public String getName() { return name; } - public String getUuid() { + @Override + public String getUuid() { return uuid; } - public StoragePoolType getPoolType() { + @Override + public StoragePoolType getPoolType() { return poolType; } - public Date getCreated() { + @Override + public Date getCreated() { return created; } @@ -115,19 +120,23 @@ public class StoragePoolVO implements StoragePool { return removed; } - public Date getUpdateTime() { + @Override + public Date getUpdateTime() { return updateTime; } - public long getDataCenterId() { + @Override + public long getDataCenterId() { return dataCenterId; } - public long getAvailableBytes() { + @Override + public long getAvailableBytes() { return availableBytes; } - public long getCapacityBytes() { + @Override + public long getCapacityBytes() { return capacityBytes; } @@ -160,10 +169,12 @@ public class StoragePoolVO implements StoragePool { this.clusterId = clusterId; } + @Override public String getHostAddress() { return hostAddress; } + @Override public String getPath() { return path; } @@ -217,10 +228,12 @@ public class StoragePoolVO implements StoragePool { return port; } + @Override public boolean isShared() { return poolType.isShared(); } + @Override public boolean isLocal() { return !poolType.isShared(); } @@ -252,6 +265,10 @@ public class StoragePoolVO implements StoragePool { this.name = name; } + public boolean isInMaintenance() { + return status == Status.PrepareForMaintenance || status == Status.Maintenance || status == Status.ErrorInMaintenance || removed != null; + } + @Override public boolean equals(Object obj) { if (!(obj instanceof StoragePoolVO) || obj == null) { diff --git a/core/src/com/cloud/storage/VMTemplateVO.java b/core/src/com/cloud/storage/VMTemplateVO.java index e46a3bcc66e..f21e28a1b85 100644 --- a/core/src/com/cloud/storage/VMTemplateVO.java +++ b/core/src/com/cloud/storage/VMTemplateVO.java @@ -32,8 +32,10 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import com.cloud.async.AsyncInstanceCreateStatus; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Storage.FileSystem; import com.cloud.storage.Storage.ImageFormat; +import com.cloud.storage.Storage.TemplateType; import com.cloud.utils.db.GenericDao; import com.google.gson.annotations.Expose; import com.cloud.storage.Storage; @@ -63,7 +65,7 @@ public class VMTemplateVO implements VirtualMachineTemplate { private boolean featured; @Column(name="type") - private FileSystem fileSystem = null; + private Storage.TemplateType templateType; @Column(name="url") private String url = null; @@ -104,7 +106,11 @@ public class VMTemplateVO implements VirtualMachineTemplate { private boolean prepopulate = false; @Column(name="cross_zones") - private boolean crossZones = false; + private boolean crossZones = false; + + @Column(name="hypervisor_type") + private String hypervisorType; + public String getUniqueName() { return uniqueName; @@ -120,16 +126,16 @@ public class VMTemplateVO implements VirtualMachineTemplate { /** * Proper constructor for a new vm template. */ - public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, FileSystem fs, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable) { - this(id, generateUniqueName(id, accountId, name), name, format, isPublic, featured, fs, url, null, requiresHvm, bits, accountId, cksum, displayText, enablePassword, guestOSId, bootable); + public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType) { + this(id, generateUniqueName(id, accountId, name), name, format, isPublic, featured, type, url, null, requiresHvm, bits, accountId, cksum, displayText, enablePassword, guestOSId, bootable, hyperType); } - public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, FileSystem fs, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable) { + public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType) { this.id = id; this.name = name; this.publicTemplate = isPublic; this.featured = featured; - this.fileSystem = fs; + this.templateType = type; this.url = url; this.requiresHvm = requiresHvm; this.bits = bits; @@ -141,7 +147,8 @@ public class VMTemplateVO implements VirtualMachineTemplate { this.format = format; this.created = created; this.guestOSId = guestOSId; - this.bootable = bootable; + this.bootable = bootable; + this.hypervisorType = hyperType.toString(); } public boolean getEnablePassword() { @@ -175,13 +182,12 @@ public class VMTemplateVO implements VirtualMachineTemplate { return id; } - @Override - public FileSystem getFileSystem() { - return fileSystem; + public TemplateType getTemplateType() { + return templateType; } - public void setFileSystem(FileSystem fs) { - this.fileSystem = fs; + public void setTemplateType(TemplateType type) { + this.templateType = type; } public boolean requiresHvm() { @@ -289,6 +295,14 @@ public class VMTemplateVO implements VirtualMachineTemplate { public boolean isCrossZones() { return crossZones; } + + public HypervisorType getHypervisorType() { + return HypervisorType.getType(hypervisorType); + } + + public void setHypervisorType(HypervisorType hyperType) { + hypervisorType = hyperType.toString(); + } @Override public boolean equals(Object that) { @@ -299,8 +313,7 @@ public class VMTemplateVO implements VirtualMachineTemplate { } VMTemplateVO other = (VMTemplateVO)that; - return (this.getUniqueName().equals(other.getUniqueName())); - + return ((this.getUniqueName().equals(other.getUniqueName()))); } @Override diff --git a/core/src/com/cloud/storage/VolumeVO.java b/core/src/com/cloud/storage/VolumeVO.java index d5d23dea53d..b755376c3cd 100755 --- a/core/src/com/cloud/storage/VolumeVO.java +++ b/core/src/com/cloud/storage/VolumeVO.java @@ -236,6 +236,8 @@ public class VolumeVO implements Volume { this.status = AsyncInstanceCreateStatus.Created; this.recreatable = false; } + + public boolean isRecreatable() { return recreatable; @@ -245,7 +247,8 @@ public class VolumeVO implements Volume { return iscsiName; } - public long getId() { + @Override + public long getId() { return id; } @@ -466,6 +469,10 @@ public class VolumeVO implements Volume { public State getState() { return state; } + + public void setState(State state) { + this.state = state; + } public void setUpdated(Date updated) { this.updated = updated; diff --git a/core/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java b/core/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java index 990523bb6da..d2a2aba925c 100644 --- a/core/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java +++ b/core/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java @@ -30,7 +30,7 @@ import org.apache.log4j.Logger; import com.cloud.storage.LaunchPermissionVO; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.Storage.FileSystem; +import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.Storage.ImageFormat; import com.cloud.utils.DateUtil; import com.cloud.utils.db.GenericDaoBase; @@ -120,7 +120,7 @@ public class LaunchPermissionDaoImpl extends GenericDaoBase { List listByVolumeId(Filter filter, long volumeId); SnapshotVO findNextSnapshot(long parentSnapId); long getLastSnapshot(long volumeId, long snapId); + List listByVolumeIdType(long volumeId, String type); } diff --git a/core/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/core/src/com/cloud/storage/dao/SnapshotDaoImpl.java index 67c59e2ed85..19f5b64fde8 100644 --- a/core/src/com/cloud/storage/dao/SnapshotDaoImpl.java +++ b/core/src/com/cloud/storage/dao/SnapshotDaoImpl.java @@ -22,6 +22,7 @@ import java.util.List; import javax.ejb.Local; +import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; @@ -33,6 +34,7 @@ import com.cloud.utils.db.SearchCriteria; public class SnapshotDaoImpl extends GenericDaoBase implements SnapshotDao { private final SearchBuilder VolumeIdSearch; + private final SearchBuilder VolumeIdTypeSearch; private final SearchBuilder ParentIdSearch; private final GenericSearchBuilder lastSnapSearch; @@ -42,6 +44,12 @@ public class SnapshotDaoImpl extends GenericDaoBase implements sc.setParameters("prevSnapshotId", snapshotId); return findOneIncludingRemovedBy(sc); } + + @Override + public List listByVolumeIdType(long volumeId, String type ) { + return listByVolumeIdType(null, volumeId, type); + } + @Override public List listByVolumeId(long volumeId) { @@ -54,12 +62,25 @@ public class SnapshotDaoImpl extends GenericDaoBase implements sc.setParameters("volumeId", volumeId); return listBy(sc, filter); } + + + public List listByVolumeIdType(Filter filter, long volumeId, String type ) { + SearchCriteria sc = VolumeIdTypeSearch.create(); + sc.setParameters("volumeId", volumeId); + sc.setParameters("type", type); + return listBy(sc, filter); + } protected SnapshotDaoImpl() { VolumeIdSearch = createSearchBuilder(); VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdSearch.done(); + VolumeIdTypeSearch = createSearchBuilder(); + VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); + VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getTypeDescription(), SearchCriteria.Op.EQ); + VolumeIdTypeSearch.done(); + ParentIdSearch = createSearchBuilder(); ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); ParentIdSearch.done(); diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyDao.java b/core/src/com/cloud/storage/dao/SnapshotPolicyDao.java index c780e4d86cb..3b7a32d8c35 100644 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyDao.java +++ b/core/src/com/cloud/storage/dao/SnapshotPolicyDao.java @@ -31,5 +31,6 @@ public interface SnapshotPolicyDao extends GenericDao { List listByVolumeId(long volumeId); List listByVolumeId(long volumeId, Filter filter); SnapshotPolicyVO findOneByVolumeInterval(long volumeId, short interval); - List listActivePolicies(); + List listActivePolicies(); + SnapshotPolicyVO findOneByVolume(long volumeId); } diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java b/core/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java index 56d839ddbd4..a4dbb5fd7af 100644 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java +++ b/core/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java @@ -41,7 +41,15 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase sc = VolumeIdSearch.create(); + sc.setParameters("volumeId", volumeId); + sc.setParameters("active", true); + return findOneBy(sc); + } @Override public List listByVolumeId(long volumeId) { diff --git a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java b/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java deleted file mode 100644 index 73479ad727e..00000000000 --- a/core/src/com/cloud/storage/dao/SnapshotPolicyRefDaoImpl.java +++ /dev/null @@ -1,83 +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 . - * - */ - -package com.cloud.storage.dao; - - -import java.util.List; - -import javax.ejb.Local; - -import com.cloud.storage.SnapshotPolicyRefVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Local (value={SnapshotPolicyRefDao.class}) -public class SnapshotPolicyRefDaoImpl extends GenericDaoBase implements SnapshotPolicyRefDao { - protected final SearchBuilder snapPolicy; - protected final SearchBuilder snapSearch; - protected final SearchBuilder policySearch; - - protected SnapshotPolicyRefDaoImpl() { - snapPolicy = createSearchBuilder(); - snapPolicy.and("snapshotId", snapPolicy.entity().getSnapshotId(), SearchCriteria.Op.EQ); - snapPolicy.and("policyId", snapPolicy.entity().getPolicyId(), SearchCriteria.Op.EQ); - snapPolicy.done(); - - snapSearch = createSearchBuilder(); - snapSearch.and("snapshotId", snapSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); - snapSearch.done(); - - policySearch = createSearchBuilder(); - policySearch.and("policyId", policySearch.entity().getPolicyId(), SearchCriteria.Op.EQ); - policySearch.and("volumeId", policySearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - policySearch.done(); - } - - @Override - public SnapshotPolicyRefVO findBySnapPolicy(long snapshotId, long policyId) { - SearchCriteria sc = snapPolicy.create(); - sc.setParameters("snapshotId", snapshotId); - sc.setParameters("policyId", policyId); - return findOneIncludingRemovedBy(sc); - } - - @Override - public int removeSnapPolicy(long snapshotId, long policyId) { - SearchCriteria sc = snapPolicy.create(); - sc.setParameters("snapshotId", snapshotId); - sc.setParameters("policyId", policyId); - return expunge(sc); - } - - @Override - public List listBySnapshotId(long snapshotId) { - SearchCriteria sc = snapSearch.create(); - sc.setParameters("snapshotId", snapshotId); - return listIncludingRemovedBy(sc); - } - - @Override - public List listByPolicyId(long policyId, long volumeId) { - SearchCriteria sc = policySearch.create(); - sc.setParameters("policyId", policyId); - sc.setParameters("volumeId", volumeId); - return listIncludingRemovedBy(sc); - } -} \ No newline at end of file diff --git a/core/src/com/cloud/storage/dao/SnapshotScheduleDao.java b/core/src/com/cloud/storage/dao/SnapshotScheduleDao.java index 30af98d93a4..85d82dfa45d 100644 --- a/core/src/com/cloud/storage/dao/SnapshotScheduleDao.java +++ b/core/src/com/cloud/storage/dao/SnapshotScheduleDao.java @@ -22,6 +22,7 @@ package com.cloud.storage.dao; import java.util.Date; import java.util.List; +import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotScheduleVO; import com.cloud.utils.db.GenericDao; @@ -36,4 +37,6 @@ public interface SnapshotScheduleDao extends GenericDao implements SnapshotScheduleDao { protected final SearchBuilder executableSchedulesSearch; protected final SearchBuilder coincidingSchedulesSearch; + private final SearchBuilder VolumeIdSearch; // DB constraint: For a given volume and policyId, there will only be one entry in this table. @@ -52,6 +53,10 @@ public class SnapshotScheduleDaoImpl extends GenericDaoBase sc = VolumeIdSearch.create(); + sc.setParameters("volumeId", volumeId); + return findOneBy(sc); + } /** * {@inheritDoc} */ diff --git a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java index 0c68217f3e8..f303614fff2 100644 --- a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java +++ b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java @@ -60,7 +60,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp protected final StoragePoolDetailsDao _detailsDao; - private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; + private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?"; private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?"; @@ -346,8 +346,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp while (rs.next()) { tags.add(rs.getString("name")); - } - + } return tags; } catch (SQLException e) { throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); diff --git a/core/src/com/cloud/storage/dao/VMTemplateDao.java b/core/src/com/cloud/storage/dao/VMTemplateDao.java index b28818dee9c..d78ae8d4864 100644 --- a/core/src/com/cloud/storage/dao/VMTemplateDao.java +++ b/core/src/com/cloud/storage/dao/VMTemplateDao.java @@ -21,6 +21,7 @@ package com.cloud.storage.dao; import java.util.List; import com.cloud.domain.DomainVO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.VMTemplateVO; import com.cloud.user.Account; import com.cloud.utils.db.GenericDao; @@ -55,16 +56,19 @@ public interface VMTemplateDao extends GenericDao { public VMTemplateVO findByTemplateNameAccountId(String templateName, Long accountId); //public void update(VMTemplateVO template); - public VMTemplateVO findRoutingTemplate(); + public VMTemplateVO findRoutingTemplate(); + public List listAllRoutingTemplates(); public VMTemplateVO findConsoleProxyTemplate(); - public VMTemplateVO findDefaultBuiltinTemplate(); + public List listDefaultBuiltinTemplates(); public String getRoutingTemplateUniqueName(); public List findIsosByIdAndPath(Long domainId, Long accountId, String path); public List listReadyTemplates(); public List listByAccountId(long accountId); - public List searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Integer pageSize, Long startIndex, Long zoneId); + public List searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Integer pageSize, Long startIndex, Long zoneId, HypervisorType hyperType); public long addTemplateToZone(VMTemplateVO tmplt, long zoneId); public List listAllInZone(long dataCenterId); + + public List listByHypervisorType(HypervisorType hyperType); } diff --git a/core/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/core/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index ea3d24ea32c..7aa4fc04e24 100644 --- a/core/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/core/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -31,37 +31,41 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.domain.DomainVO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Storage; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateZoneVO; -import com.cloud.storage.template.TemplateConstants; import com.cloud.user.Account; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; @Local(value={VMTemplateDao.class}) public class VMTemplateDaoImpl extends GenericDaoBase implements VMTemplateDao { private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class); + private HypervisorType _defaultHyperType; @Inject - VMTemplateZoneDao _templateZoneDao; + VMTemplateZoneDao _templateZoneDao; + @Inject + ConfigurationDao _configDao; - private final String SELECT_ALL = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + - "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones FROM vm_template t"; - - private static final String SELECT_ALL_IN_ZONE = - "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.removed, t.account_id, " + - "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones FROM vm_template t, template_zone_ref tz where t.removed is null and tz.removed is null and t.id = tz.template_id and tz.zone_id=? "; + private final String SELECT_ALL = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t"; - private SearchBuilder UniqueNameSearch; - private SearchBuilder AccountIdSearch; - private SearchBuilder NameSearch; + protected SearchBuilder TemplateNameSearch; + protected SearchBuilder UniqueNameSearch; + protected SearchBuilder tmpltTypeSearch; + protected SearchBuilder tmpltTypeHyperSearch; + protected SearchBuilder AccountIdSearch; + protected SearchBuilder NameSearch; + protected SearchBuilder TmpltsInZoneSearch; private SearchBuilder PublicSearch; private SearchBuilder NameAccountIdSearch; @@ -90,7 +94,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem sc.setParameters("name", templateName); return findOneIncludingRemovedBy(sc); } - + @Override public VMTemplateVO findByTemplateNameAccountId(String templateName, Long accountId) { SearchCriteria sc = NameAccountIdSearch.create(); @@ -99,18 +103,21 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem return findOneBy(sc); } + @Override + public List listAllRoutingTemplates() { + SearchCriteria sc = tmpltTypeSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + return listBy(sc); + } + @Override public VMTemplateVO findRoutingTemplate() { - SearchCriteria sc = UniqueNameSearch.create(); - sc.setParameters("uniqueName", routerTmpltName); - return findOneIncludingRemovedBy(sc); + return findSystemVMTemplate(); } @Override public VMTemplateVO findConsoleProxyTemplate() { - SearchCriteria sc = UniqueNameSearch.create(); - sc.setParameters("uniqueName", consoleProxyTmpltName); - return findOneIncludingRemovedBy(sc); + return findSystemVMTemplate(); } @Override @@ -139,6 +146,13 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem SearchCriteria sc = AccountIdSearch.create(); sc.setParameters("accountId", accountId); return listBy(sc); + } + + @Override + public List listByHypervisorType(HypervisorType hyperType) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("hypervisor_type", SearchCriteria.Op.EQ, hyperType.toString()); + return listBy(sc); } @Override @@ -170,11 +184,30 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ); NameAccountIdSearch.and("accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + + tmpltTypeHyperSearch = createSearchBuilder(); + tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + tmpltTypeHyperSearch.and("hypervisor_type", tmpltTypeHyperSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); + + tmpltTypeSearch = createSearchBuilder(); + tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + AccountIdSearch = createSearchBuilder(); AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); - AccountIdSearch.done(); - + AccountIdSearch.done(); + + SearchBuilder tmpltZoneSearch = _templateZoneDao.createSearchBuilder(); + tmpltZoneSearch.and("removed", tmpltZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ); + + TmpltsInZoneSearch = createSearchBuilder(); + TmpltsInZoneSearch.and("removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + TmpltsInZoneSearch.join("tmpltzone", tmpltZoneSearch, tmpltZoneSearch.entity().getTemplateId(), TmpltsInZoneSearch.entity().getId(), JoinBuilder.JoinType.INNER); + tmpltZoneSearch.done(); + TmpltsInZoneSearch.done(); + + _defaultHyperType = HypervisorType.getType(_configDao.getValue("hypervisor.type")); return result; } @@ -184,7 +217,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem } @Override - public List searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Integer pageSize, Long startIndex, Long zoneId) { + public List searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Integer pageSize, Long startIndex, Long zoneId, HypervisorType hyperType) { Transaction txn = Transaction.currentTxn(); txn.start(); List templates = new ArrayList(); @@ -200,7 +233,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem accountType = Account.ACCOUNT_TYPE_ADMIN; } - String sql = SELECT_ALL; + String guestOSJoin = ""; + if (isIso) { + guestOSJoin = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) "; + } + + String sql = SELECT_ALL + guestOSJoin; String whereClause = ""; if (templateFilter == TemplateFilter.featured) { @@ -235,7 +273,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem whereClause += " AND "; } - sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable) + getOrderByLimit(pageSize, startIndex); + sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType) + getOrderByLimit(pageSize, startIndex); pstmt = txn.prepareStatement(sql); rs = pstmt.executeQuery(); @@ -269,7 +307,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem return templates; } - private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable) { + private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType) { String sql = ""; if (keyword != null) { sql += " t.name LIKE \"%" + keyword + "%\" AND"; @@ -278,14 +316,22 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem } if (isIso) { - sql += " t.format = 'ISO'"; + sql += " t.format = 'ISO'"; + if (!hyperType.equals(HypervisorType.None)) { + sql += " AND goh.hypervisor_type = '" + hyperType.toString() + "'"; + } } else { - sql += " t.format <> 'ISO'"; + sql += " t.format <> 'ISO'"; + if (!hyperType.equals(HypervisorType.None)) { + sql += " AND t.hypervisor_type = '" + hyperType.toString() + "'"; + } } if (bootable != null) { sql += " AND t.bootable = " + bootable; - } + } + + sql += " AND t.removed IS NULL"; @@ -319,29 +365,41 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem @Override @DB public List listAllInZone(long dataCenterId) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - PreparedStatement pstmt = null; - List result = new ArrayList(); - try { - String sql = SELECT_ALL_IN_ZONE; - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, dataCenterId); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - result.add(toEntityBean(rs, false)); - } - txn.commit(); - } catch (SQLException sqle) { - s_logger.warn("Exception: ",sqle); - throw new CloudRuntimeException("Unable to list templates in zone", sqle); - } - - return result; + SearchCriteria sc = TmpltsInZoneSearch.create(); + sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId); + return listBy(sc); } @Override - public VMTemplateVO findDefaultBuiltinTemplate() { - return findById(TemplateConstants.DEFAULT_BUILTIN_VM_DB_ID); + public List listDefaultBuiltinTemplates() { + SearchCriteria sc = tmpltTypeSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.BUILTIN); + return listBy(sc); + } + + private VMTemplateVO findSystemVMTemplate() { + SearchCriteria sc = tmpltTypeHyperSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setParameters("hypervisor_type", _defaultHyperType.toString()); + VMTemplateVO tmplt = findOneBy(sc); + + if (tmplt == null) { + /*Can't find it? We'd like to prefer xenserver */ + if (_defaultHyperType != HypervisorType.XenServer) { + sc = tmpltTypeHyperSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setParameters("hypervisor_type", HypervisorType.XenServer); + tmplt = findOneBy(sc); + + /*Still can't find it? return a random one*/ + if (tmplt == null) { + sc = tmpltTypeSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + tmplt = findOneBy(sc); + } + } + } + + return tmplt; } } diff --git a/core/src/com/cloud/storage/dao/VolumeDao.java b/core/src/com/cloud/storage/dao/VolumeDao.java index 3bd43faf9bc..cfd3c9ada0c 100755 --- a/core/src/com/cloud/storage/dao/VolumeDao.java +++ b/core/src/com/cloud/storage/dao/VolumeDao.java @@ -19,6 +19,8 @@ package com.cloud.storage.dao; import java.util.List; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; import com.cloud.utils.Pair; @@ -47,4 +49,14 @@ public interface VolumeDao extends GenericDao { List findCreatedByInstance(long id); List findByPoolId(long poolId); List findByInstanceAndDeviceId(long instanceId, long deviceId); + List findUsableVolumesForInstance(long instanceId); + + /** + * Updates the volume only if the state in memory matches the state in the database. + * @param vol Volume to be updated. + * @param event event that causes the database change. + * @return true if update happened, false if not. + */ + boolean update(VolumeVO vol, Volume.Event event) throws ConcurrentOperationException; + HypervisorType getHypervisorType(long volumeId); } diff --git a/core/src/com/cloud/storage/dao/VolumeDaoImpl.java b/core/src/com/cloud/storage/dao/VolumeDaoImpl.java index dc82102a1a5..76155bed84e 100755 --- a/core/src/com/cloud/storage/dao/VolumeDaoImpl.java +++ b/core/src/com/cloud/storage/dao/VolumeDaoImpl.java @@ -29,11 +29,14 @@ import javax.ejb.Local; import org.apache.log4j.Logger; import com.cloud.async.AsyncInstanceCreateStatus; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Volume; import com.cloud.storage.Volume.MirrorState; import com.cloud.storage.Volume.VolumeType; import com.cloud.storage.VolumeVO; import com.cloud.utils.Pair; +import com.cloud.utils.db.Attribute; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; @@ -42,6 +45,7 @@ import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; @Local(value=VolumeDao.class) @DB(txn=false) @@ -62,9 +66,14 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol protected final SearchBuilder RemovedButNotDestroyedSearch; protected final SearchBuilder PoolIdSearch; protected final SearchBuilder InstanceAndDeviceIdSearch; + protected final SearchBuilder InstanceStatesSearch; + protected final SearchBuilder IdStateSearch; + + protected final Attribute _stateAttr; protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?"; protected static final String SELECT_VM_ID_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ?"; + protected static final String SELECT_HYPERTYPE_FROM_VOLUME = "SELECT c.hypervisor_type from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and v.id = ?"; @Override public List listRemovedButNotDestroyed() { @@ -143,6 +152,15 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol return listBy(sc); } + @Override + public List findUsableVolumesForInstance(long instanceId) { + SearchCriteria sc = InstanceStatesSearch.create(); + sc.setParameters("instance", instanceId); + sc.setParameters("states", Volume.State.Creating, Volume.State.Ready, Volume.State.Allocated); + + return listBy(sc); + } + @Override public List findByInstanceAndType(long id, VolumeType vType) { SearchCriteria sc = InstanceAndTypeSearch.create(); @@ -271,6 +289,48 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol update(volumeId, volume); } + @Override + public boolean update(VolumeVO vol, Volume.Event event) throws ConcurrentOperationException { + Volume.State oldState = vol.getState(); + Volume.State newState = oldState.getNextState(event); + + assert newState != null : "Event "+ event + " cannot happen from " + oldState; + + UpdateBuilder builder = getUpdateBuilder(vol); + builder.set(vol, _stateAttr, newState); + + SearchCriteria sc = IdStateSearch.create(); + sc.setParameters("id", vol.getId()); + sc.setParameters("state", oldState); + + int rows = update(builder, sc, null); + if (rows != 1) { + VolumeVO dbVol = findById(vol.getId()); + throw new ConcurrentOperationException("Unable to update " + vol + ": Old State=" + oldState + "; New State = " + newState + "; DB State=" + dbVol.getState()); + } + return rows == 1; + } + @DB + public HypervisorType getHypervisorType(long volumeId) { + /*lookup from cluster of pool*/ + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + + try { + String sql = SELECT_HYPERTYPE_FROM_VOLUME; + pstmt = txn.prepareAutoCloseStatement(sql); + pstmt.setLong(1, volumeId); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + return HypervisorType.getType(rs.getString(1)); + return HypervisorType.None; + } catch (SQLException e) { + throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME, e); + } catch (Throwable e) { + throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e); + } + } + protected VolumeDaoImpl() { AccountIdSearch = createSearchBuilder(); AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); @@ -353,6 +413,19 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol RemovedButNotDestroyedSearch.and("destroyed", RemovedButNotDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); RemovedButNotDestroyedSearch.and("removed", RemovedButNotDestroyedSearch.entity().getRemoved(), SearchCriteria.Op.NNULL); RemovedButNotDestroyedSearch.done(); + + InstanceStatesSearch = createSearchBuilder(); + InstanceStatesSearch.and("instance", InstanceStatesSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); + InstanceStatesSearch.and("states", InstanceStatesSearch.entity().getState(), SearchCriteria.Op.IN); + InstanceStatesSearch.done(); + + IdStateSearch = createSearchBuilder(); + IdStateSearch.and("id", IdStateSearch.entity().getId(), SearchCriteria.Op.EQ); + IdStateSearch.and("state", IdStateSearch.entity().getState(), SearchCriteria.Op.EQ); + IdStateSearch.done(); + + _stateAttr = _allAttributes.get("state"); + assert _stateAttr != null : "Couldn't get the state attribute"; } @Override @DB(txn=false) diff --git a/core/src/com/cloud/storage/resource/DummySecondaryStorageResource.java b/core/src/com/cloud/storage/resource/DummySecondaryStorageResource.java index 611dc1c5450..dbcd37c9fa1 100644 --- a/core/src/com/cloud/storage/resource/DummySecondaryStorageResource.java +++ b/core/src/com/cloud/storage/resource/DummySecondaryStorageResource.java @@ -18,7 +18,9 @@ package com.cloud.storage.resource; +import java.io.File; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.naming.ConfigurationException; @@ -38,13 +40,20 @@ import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.storage.DownloadCommand; import com.cloud.agent.api.storage.DownloadProgressCommand; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.host.Host; import com.cloud.host.Host.Type; import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResourceBase; +import com.cloud.server.ManagementServer; import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.template.TemplateConstants; import com.cloud.storage.template.TemplateInfo; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.Inject; public class DummySecondaryStorageResource extends ServerResourceBase implements ServerResource { private static final Logger s_logger = Logger.getLogger(DummySecondaryStorageResource.class); @@ -53,8 +62,9 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements String _pod; String _guid; String _dummyPath; - - private boolean _useServiceVm; + VMTemplateDao _tmpltDao; + private boolean _useServiceVm; + public DummySecondaryStorageResource(boolean useServiceVM) { setUseServiceVm(useServiceVM); @@ -114,9 +124,7 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements cmd.setName(_guid); cmd.setVersion(DummySecondaryStorageResource.class.getPackage().getImplementationVersion()); /* gather TemplateInfo in second storage */ - final Map tInfo = new HashMap(); - tInfo.put("routing", TemplateInfo.getDefaultSystemVmTemplateInfo()); - cmd.setTemplateInfo(tInfo); + cmd.setTemplateInfo(getDefaultSystemVmTemplateInfo()); cmd.getHostDetails().put("mount.parent", "dummy"); cmd.getHostDetails().put("mount.path", "dummy"); cmd.getHostDetails().put("orig.url", _guid); @@ -149,7 +157,13 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements _dummyPath = (String)params.get("mount.path"); if (_dummyPath == null) { throw new ConfigurationException("Unable to find mount.path"); - } + } + + ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); + _tmpltDao = locator.getDao(VMTemplateDao.class); + if (_tmpltDao == null) { + throw new ConfigurationException("Unable to find VMTemplate dao"); + } return true; } @@ -159,5 +173,17 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements public boolean useServiceVm() { return _useServiceVm; - } + } + + public Map getDefaultSystemVmTemplateInfo() { + List tmplts = _tmpltDao.listAllRoutingTemplates(); + Map tmpltInfo = new HashMap(); + if (tmplts != null) { + for (VMTemplateVO tmplt : tmplts) { + TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false); + tmpltInfo.put(tmplt.getUniqueName(), routingInfo); + } + } + return tmpltInfo; + } } diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java index b99d867978f..a1f4f03bdb0 100755 --- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java +++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java @@ -431,7 +431,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S private void startAdditionalServices() { Script command = new Script("/bin/bash", s_logger); command.add("-c"); - command.add("service sshd restart "); + command.add("if [ -f /etc/init.d/ssh ]; then service ssh restart; else service sshd restart; fi "); String result = command.execute(); if (result != null) { s_logger.warn("Error in starting sshd service err=" + result ); @@ -556,6 +556,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S // Change permissions for the mountpoint script = new Script(!_inSystemVM, "chmod", _timeout, s_logger); script.add("777", mountPoint); + script.add("-R"); result = script.execute(); if (result != null) { s_logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java index 2d37f630fe3..86d74c892b9 100644 --- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java +++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java @@ -769,7 +769,7 @@ public class DownloadManagerImpl implements DownloadManager { s_logger.info("createtmplt.sh found in " + createTmpltScr); List processors = new ArrayList(); - _processors = new Adapters("processors", processors); + Processor processor = new VhdProcessor(); processor.configure("VHD Processor", params); @@ -787,6 +787,7 @@ public class DownloadManagerImpl implements DownloadManager { processor.configure("VMDK Processor", params); processors.add(processor); + _processors = new Adapters("processors", processors); // Add more processors here. threadPool = Executors.newFixedThreadPool(numInstallThreads); return true; @@ -853,7 +854,7 @@ public class DownloadManagerImpl implements DownloadManager { Script command = new Script("/bin/bash", s_logger); command.add("-c"); - command.add("service httpd stop "); + command.add("if [ -d /etc/apache2 ] ; then service apache2 stop; else service httpd stop; fi "); String result = command.execute(); if (result != null) { s_logger.warn("Error in stopping httpd service err=" + result ); @@ -883,7 +884,7 @@ public class DownloadManagerImpl implements DownloadManager { command = new Script("/bin/bash", s_logger); command.add("-c"); - command.add("service httpd start "); + command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi "); result = command.execute(); if (result != null) { s_logger.warn("Error in starting httpd service err=" + result ); diff --git a/core/src/com/cloud/storage/template/TemplateConstants.java b/core/src/com/cloud/storage/template/TemplateConstants.java index 172a4e55d8e..32008e843be 100644 --- a/core/src/com/cloud/storage/template/TemplateConstants.java +++ b/core/src/com/cloud/storage/template/TemplateConstants.java @@ -25,7 +25,7 @@ public final class TemplateConstants { public static final String DEFAULT_TMPLT_ROOT_DIR = "template/"; public static final String DEFAULT_TMPLT_FIRST_LEVEL_DIR = "tmpl/"; - public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/1/"; + public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/"; public static final long DEFAULT_SYSTEM_VM_DB_ID = 1L; public static final long DEFAULT_BUILTIN_VM_DB_ID = 2L; diff --git a/core/src/com/cloud/storage/template/TemplateInfo.java b/core/src/com/cloud/storage/template/TemplateInfo.java index 800417c7fa9..bf32e07c4ba 100644 --- a/core/src/com/cloud/storage/template/TemplateInfo.java +++ b/core/src/com/cloud/storage/template/TemplateInfo.java @@ -22,14 +22,8 @@ public class TemplateInfo { String installPath; long size; long id; - boolean isPublic; - - public static TemplateInfo getDefaultSystemVmTemplateInfo() { - TemplateInfo routingInfo = new TemplateInfo(TemplateConstants.DEFAULT_SYSTEM_VM_TMPLT_NAME, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH, false); - return routingInfo; - } - + protected TemplateInfo() { } diff --git a/core/src/com/cloud/storage/template/VmdkProcessor.java b/core/src/com/cloud/storage/template/VmdkProcessor.java index d1e522196b1..ff748b919d9 100644 --- a/core/src/com/cloud/storage/template/VmdkProcessor.java +++ b/core/src/com/cloud/storage/template/VmdkProcessor.java @@ -10,6 +10,7 @@ import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.storage.StorageLayer; import com.cloud.storage.Storage.ImageFormat; +import com.cloud.utils.script.Script; public class VmdkProcessor implements Processor { private static final Logger s_logger = Logger.getLogger(VmdkProcessor.class); @@ -26,18 +27,34 @@ public class VmdkProcessor implements Processor { } s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); - String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.VMDK.getFileExtension(); + String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.OVA.getFileExtension(); if (!_storage.exists(templateFilePath)) { if(s_logger.isInfoEnabled()) s_logger.info("Unable to find the vmware template file: " + templateFilePath); return null; } + s_logger.info("Template processing - untar OVA package. templatePath: " + templatePath + ", templateName: " + templateName); + String templateFileFullPath = templatePath + templateName + "." + ImageFormat.OVA.getFileExtension(); + File templateFile = new File(templateFileFullPath); + + Script command = new Script("tar", 0, s_logger); + command.add("-xf", templateFileFullPath); + command.setWorkDir(templateFile.getParent()); + String result = command.execute(); + if (result != null) { + s_logger.info("failed to untar OVA package due to " + result + ". templatePath: " + templatePath + ", templateName: " + templateName); + return null; + } + FormatInfo info = new FormatInfo(); - info.format = ImageFormat.VMDK; - info.filename = templateName + "." + ImageFormat.VMDK.getFileExtension(); + info.format = ImageFormat.OVA; + info.filename = templateName + "." + ImageFormat.OVA.getFileExtension(); info.size = _storage.getSize(templateFilePath); info.virtualSize = info.size; + + // delete original OVA file + // templateFile.delete(); return info; } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 12f4cafb1cb..d03ecea83ff 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -320,4 +320,8 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { public String getGuestZoneMacAddress() { return guestZoneMacAddress; } + + public void setServiceOfferingId(long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } } diff --git a/core/src/com/cloud/vm/InstanceGroupVMMapVO.java b/core/src/com/cloud/vm/InstanceGroupVMMapVO.java index f51092c5dc7..96d389ff3fd 100644 --- a/core/src/com/cloud/vm/InstanceGroupVMMapVO.java +++ b/core/src/com/cloud/vm/InstanceGroupVMMapVO.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm; import javax.persistence.Column; diff --git a/core/src/com/cloud/vm/InstanceGroupVO.java b/core/src/com/cloud/vm/InstanceGroupVO.java index a16d784c3fb..1f7dde80430 100644 --- a/core/src/com/cloud/vm/InstanceGroupVO.java +++ b/core/src/com/cloud/vm/InstanceGroupVO.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm; import java.util.Date; diff --git a/core/src/com/cloud/vm/dao/InstanceGroupDao.java b/core/src/com/cloud/vm/dao/InstanceGroupDao.java index 6cfadce311b..b4d61b6ec21 100644 --- a/core/src/com/cloud/vm/dao/InstanceGroupDao.java +++ b/core/src/com/cloud/vm/dao/InstanceGroupDao.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm.dao; import java.util.List; diff --git a/core/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java b/core/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java index ad38184c6e8..a86d5fcf539 100644 --- a/core/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java +++ b/core/src/com/cloud/vm/dao/InstanceGroupDaoImpl.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm.dao; import java.util.List; diff --git a/core/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java b/core/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java index 14d05cb4f7a..76cad6af1b7 100644 --- a/core/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java +++ b/core/src/com/cloud/vm/dao/InstanceGroupVMMapDao.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm.dao; import java.util.List; diff --git a/core/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java b/core/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java index 7e61dad390a..e0d8f2f0eea 100644 --- a/core/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java +++ b/core/src/com/cloud/vm/dao/InstanceGroupVMMapDaoImpl.java @@ -1,3 +1,21 @@ +/** + * 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 . + * + */ + package com.cloud.vm.dao; import java.util.List; diff --git a/core/test/com/cloud/vmware/TestVMWare.java b/core/test/com/cloud/vmware/TestVMWare.java index 6ec9c9f3d3e..76ecc489d7a 100644 --- a/core/test/com/cloud/vmware/TestVMWare.java +++ b/core/test/com/cloud/vmware/TestVMWare.java @@ -1,12 +1,23 @@ package com.cloud.vmware; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; + import org.apache.log4j.xml.DOMConfigurator; import com.cloud.utils.PropertiesUtil; @@ -15,6 +26,13 @@ import com.vmware.vim25.HostIpConfig; import com.vmware.vim25.HostVirtualNicSpec; import com.vmware.vim25.HostConfigManager; import com.vmware.vim25.HostPortGroupSpec; +import com.vmware.vim25.HttpNfcLeaseDeviceUrl; +import com.vmware.vim25.HttpNfcLeaseInfo; +import com.vmware.vim25.HttpNfcLeaseState; +import com.vmware.vim25.OvfCreateImportSpecParams; +import com.vmware.vim25.OvfCreateImportSpecResult; +import com.vmware.vim25.OvfFileItem; +import com.vmware.vim25.OvfNetworkMapping; import com.vmware.vim25.VirtualMachineConfigSpec; import com.vmware.vim25.VirtualDeviceConfigSpecOperation; import com.vmware.vim25.VirtualEthernetCard; @@ -40,6 +58,18 @@ import com.vmware.vim25.TraversalSpec; public class TestVMWare { private static ExtendedAppUtil cb; + static { + try { + javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; + javax.net.ssl.TrustManager tm = new TrustAllManager(); + trustAllCerts[0] = tm; + javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, null); + javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } catch (Exception e) { + } + } + private static void setupLog4j() { File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); @@ -624,7 +654,7 @@ public class TestVMWare { private void powerOnVm() throws Exception { ManagedObjectReference morVm = new ManagedObjectReference(); morVm.setType("VirtualMachine"); - morVm.set_value("vm-66"); + morVm.set_value("vm-480"); cb.getServiceConnection3().getService().powerOnVM_Task(morVm, null); } @@ -822,6 +852,212 @@ public class TestVMWare { this.printContent(ocs); } + private void testFT() throws Exception { + + ManagedObjectReference morVm = new ManagedObjectReference(); + morVm.setType("VirtualMachine"); + morVm.set_value("vm-480"); + + ManagedObjectReference morHost = new ManagedObjectReference(); + morHost.setType("HostSystem"); + morHost.set_value("host-470"); + + System.out.println("Create secondary VM"); + ManagedObjectReference morTask = cb.getServiceConnection3().getService().createSecondaryVM_Task(morVm, morHost); + String result = cb.getServiceUtil3().waitForTask(morTask); + + System.out.println("Create secondary VM resutl : " + result); + } + + private void testFTEnable() throws Exception { + ManagedObjectReference morVm = new ManagedObjectReference(); + morVm.setType("VirtualMachine"); + morVm.set_value("vm-480"); + + ManagedObjectReference morHost = new ManagedObjectReference(); + morHost.setType("HostSystem"); + morHost.set_value("host-470"); + + ManagedObjectReference morSecondaryVm = new ManagedObjectReference(); + morSecondaryVm.setType("VirtualMachine"); + morSecondaryVm.set_value("vm-485"); + + System.out.println("Enable FT"); + ManagedObjectReference morTask = cb.getServiceConnection3().getService().enableSecondaryVM_Task(morVm, + morSecondaryVm, morHost); + String result = cb.getServiceUtil3().waitForTask(morTask); + + System.out.println("Enable FT resutl : " + result); + } + + private void importOVF() throws Exception { + ManagedObjectReference morHost = new ManagedObjectReference(); + morHost.setType("HostSystem"); + morHost.set_value("host-223"); + + ManagedObjectReference morRp = new ManagedObjectReference(); + morRp.setType("ResourcePool"); + morRp.set_value("resgroup-222"); + + ManagedObjectReference morDs = new ManagedObjectReference(); + morDs.setType("Datastore"); + morDs.set_value("datastore-30"); + + ManagedObjectReference morVmFolder = new ManagedObjectReference(); + morVmFolder.setType("Folder"); + morVmFolder.set_value("group-v3"); + + ManagedObjectReference morNetwork = new ManagedObjectReference(); + morNetwork.setType("Network"); + morNetwork.set_value("network-32"); + + ManagedObjectReference morOvf = cb.getServiceConnection3().getServiceContent().getOvfManager(); + + OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams(); + importSpecParams.setHostSystem(morHost); + importSpecParams.setLocale("US"); + importSpecParams.setEntityName("winxpsp3-ovf-deployed"); + importSpecParams.setDeploymentOption(""); + importSpecParams.setDiskProvisioning("thin"); + +/* + OvfNetworkMapping networkMapping = new OvfNetworkMapping(); + networkMapping.setName("VM Network"); + networkMapping.setNetwork(morNetwork); // network); + importSpecParams.setNetworkMapping(new OvfNetworkMapping[] { networkMapping }); +*/ + importSpecParams.setPropertyMapping(null); + + String ovfDescriptor = readOvfContent("C:\\research\\vmware\\winxpsp3-ovf\\winxpsp3-ovf.ovf"); + OvfCreateImportSpecResult ovfImportResult = cb.getServiceConnection3().getService().createImportSpec( + morOvf, ovfDescriptor, morRp, morDs, importSpecParams); + + if(ovfImportResult != null) { + long totalBytes = addTotalBytes(ovfImportResult); + + ManagedObjectReference morLease = cb.getServiceConnection3().getService().importVApp(morRp, + ovfImportResult.getImportSpec(), morVmFolder, morHost); + + HttpNfcLeaseState state; + for(;;) { + state = (HttpNfcLeaseState)cb.getServiceUtil3().getDynamicProperty(morLease, "state"); + if(state == HttpNfcLeaseState.ready || state == HttpNfcLeaseState.error) + break; + } + + if(state == HttpNfcLeaseState.ready) { + HttpNfcLeaseInfo httpNfcLeaseInfo = (HttpNfcLeaseInfo)cb.getServiceUtil3().getDynamicProperty(morLease, "info"); + HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl(); + long bytesAlreadyWritten = 0; + for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls) { + + String deviceKey = deviceUrl.getImportKey(); + for (OvfFileItem ovfFileItem : ovfImportResult.getFileItem()) { + if (deviceKey.equals(ovfFileItem.getDeviceId())) { + System.out.println("Import key==OvfFileItem device id: " + deviceKey); + System.out.println("device URL: " + deviceUrl.getUrl()); + + String absoluteFile = "C:\\research\\vmware\\winxpsp3-ovf\\" + ovfFileItem.getPath(); + String urlToPost = deviceUrl.getUrl().replace("*", "esxhost-1.lab.vmops.com"); + + uploadVmdkFile(ovfFileItem.isCreate(), absoluteFile, urlToPost, bytesAlreadyWritten, totalBytes); + bytesAlreadyWritten += ovfFileItem.getSize(); + System.out.println("Completed uploading the VMDK file:" + absoluteFile); + } + } + } + cb.getServiceConnection3().getService().httpNfcLeaseProgress(morLease, 100); + cb.getServiceConnection3().getService().httpNfcLeaseComplete(morLease); + } + } + } + + private static void uploadVmdkFile(boolean put, String diskFilePath, String urlStr, long bytesAlreadyWritten, long totalBytes) throws IOException { + HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { + public boolean verify(String urlHostName, SSLSession session) { + return true; + } + }); + + HttpsURLConnection conn = (HttpsURLConnection) new URL(urlStr).openConnection(); + + conn.setDoOutput(true); + conn.setUseCaches(false); + + int CHUCK_LEN = 64*1024; + conn.setChunkedStreamingMode(CHUCK_LEN); + conn.setRequestMethod(put? "PUT" : "POST"); // Use a post method to write the file. + conn.setRequestProperty("Connection", "Keep-Alive"); + conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk"); + conn.setRequestProperty("Content-Length", Long.toString(new File(diskFilePath).length())); + BufferedOutputStream bos = new BufferedOutputStream(conn.getOutputStream()); + BufferedInputStream diskis = new BufferedInputStream(new FileInputStream(diskFilePath)); + int bytesAvailable = diskis.available(); + int bufferSize = Math.min(bytesAvailable, CHUCK_LEN); + byte[] buffer = new byte[bufferSize]; + long totalBytesWritten = 0; + while (true) { + int bytesRead = diskis.read(buffer, 0, bufferSize); + if (bytesRead == -1) + { + System.out.println("Total bytes written: " + totalBytesWritten); + break; + } + totalBytesWritten += bytesRead; + bos.write(buffer, 0, bufferSize); + bos.flush(); + System.out.println("Total bytes written: " + totalBytesWritten); + +/* + int progressPercent = (int) (((bytesAlreadyWritten + totalBytesWritten) * 100) / totalBytes); + leaseUpdater.setPercent(progressPercent); +*/ + } + diskis.close(); + bos.flush(); + bos.close(); + conn.disconnect(); + } + + public static long addTotalBytes(OvfCreateImportSpecResult ovfImportResult) { + OvfFileItem[] fileItemArr = ovfImportResult.getFileItem(); + long totalBytes = 0; + if (fileItemArr != null) { + for (OvfFileItem fi : fileItemArr) { + printOvfFileItem(fi); + totalBytes += fi.getSize(); + } + } + return totalBytes; + } + + private static void printOvfFileItem(OvfFileItem fi) { + System.out.println("================ OvfFileItem ================"); + System.out.println("chunkSize: " + fi.getChunkSize()); + System.out.println("create: " + fi.isCreate()); + System.out.println("deviceId: " + fi.getDeviceId()); + System.out.println("path: " + fi.getPath()); + System.out.println("size: " + fi.getSize()); + System.out.println("=============================================="); + } + + public static String readOvfContent(String ovfFilePath) throws IOException { + StringBuffer strContent = new StringBuffer(); + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(ovfFilePath))); + String lineStr; + while ((lineStr = in.readLine()) != null) { + strContent.append(lineStr); + } + + in.close(); + return strContent.toString(); + } + + public static String escapeSpecialChars(String str) { + str = str.replaceAll("<", "<"); + return str.replaceAll(">", ">"); // do not escape "&" -> "&", "\"" -> """ + } + public static void main(String[] args) throws Exception { setupLog4j(); TestVMWare client = new TestVMWare(); @@ -849,11 +1085,40 @@ public class TestVMWare { // client.createDatacenter(); // client.getPropertyWithPath(); - client.getHostVMs(); + // client.getHostVMs(); + // client.testFT(); + // client.testFTEnable(); + + client.importOVF(); cb.disConnect(); } catch (Exception e) { e.printStackTrace(); } } + + public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager { + + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) { + return true; + } + + public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) { + return true; + } + + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) + throws java.security.cert.CertificateException { + return; + } + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) + throws java.security.cert.CertificateException { + return; + } + } } + diff --git a/tools/systemvm/debian/README b/patches/systemvm/debian/README similarity index 100% rename from tools/systemvm/debian/README rename to patches/systemvm/debian/README diff --git a/tools/systemvm/debian/buildsystemvm.sh b/patches/systemvm/debian/buildsystemvm.sh similarity index 100% rename from tools/systemvm/debian/buildsystemvm.sh rename to patches/systemvm/debian/buildsystemvm.sh diff --git a/tools/systemvm/debian/config.dat b/patches/systemvm/debian/config.dat similarity index 100% rename from tools/systemvm/debian/config.dat rename to patches/systemvm/debian/config.dat diff --git a/tools/systemvm/debian/config/etc/apache2/httpd.conf b/patches/systemvm/debian/config/etc/apache2/httpd.conf similarity index 100% rename from tools/systemvm/debian/config/etc/apache2/httpd.conf rename to patches/systemvm/debian/config/etc/apache2/httpd.conf diff --git a/tools/systemvm/debian/config/etc/apache2/ports.conf b/patches/systemvm/debian/config/etc/apache2/ports.conf similarity index 100% rename from tools/systemvm/debian/config/etc/apache2/ports.conf rename to patches/systemvm/debian/config/etc/apache2/ports.conf diff --git a/tools/systemvm/debian/config/etc/apache2/sites-available/default b/patches/systemvm/debian/config/etc/apache2/sites-available/default similarity index 100% rename from tools/systemvm/debian/config/etc/apache2/sites-available/default rename to patches/systemvm/debian/config/etc/apache2/sites-available/default diff --git a/tools/systemvm/debian/config/etc/apache2/sites-available/default-ssl b/patches/systemvm/debian/config/etc/apache2/sites-available/default-ssl similarity index 100% rename from tools/systemvm/debian/config/etc/apache2/sites-available/default-ssl rename to patches/systemvm/debian/config/etc/apache2/sites-available/default-ssl diff --git a/tools/systemvm/debian/config/etc/default/cloud b/patches/systemvm/debian/config/etc/default/cloud similarity index 100% rename from tools/systemvm/debian/config/etc/default/cloud rename to patches/systemvm/debian/config/etc/default/cloud diff --git a/tools/systemvm/debian/config/etc/default/cloud-passwd-srvr b/patches/systemvm/debian/config/etc/default/cloud-passwd-srvr similarity index 100% rename from tools/systemvm/debian/config/etc/default/cloud-passwd-srvr rename to patches/systemvm/debian/config/etc/default/cloud-passwd-srvr diff --git a/tools/systemvm/debian/config/etc/dnsmasq.conf b/patches/systemvm/debian/config/etc/dnsmasq.conf similarity index 100% rename from tools/systemvm/debian/config/etc/dnsmasq.conf rename to patches/systemvm/debian/config/etc/dnsmasq.conf diff --git a/tools/systemvm/debian/config/etc/haproxy/haproxy.cfg b/patches/systemvm/debian/config/etc/haproxy/haproxy.cfg similarity index 100% rename from tools/systemvm/debian/config/etc/haproxy/haproxy.cfg rename to patches/systemvm/debian/config/etc/haproxy/haproxy.cfg diff --git a/tools/systemvm/debian/config/etc/httpd/conf/httpd.conf b/patches/systemvm/debian/config/etc/httpd/conf/httpd.conf similarity index 100% rename from tools/systemvm/debian/config/etc/httpd/conf/httpd.conf rename to patches/systemvm/debian/config/etc/httpd/conf/httpd.conf diff --git a/tools/systemvm/debian/config/etc/init.d/cloud b/patches/systemvm/debian/config/etc/init.d/cloud similarity index 95% rename from tools/systemvm/debian/config/etc/init.d/cloud rename to patches/systemvm/debian/config/etc/init.d/cloud index c437f77350f..8abeb6b1bd5 100755 --- a/tools/systemvm/debian/config/etc/init.d/cloud +++ b/patches/systemvm/debian/config/etc/init.d/cloud @@ -15,12 +15,7 @@ ENABLED=0 [ -e /etc/default/cloud ] && . /etc/default/cloud -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi +CMDLINE=$(cat /var/cache/cloud/cmdline) TYPE="router" for i in $CMDLINE diff --git a/tools/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config similarity index 89% rename from tools/systemvm/debian/config/etc/init.d/cloud-early-config rename to patches/systemvm/debian/config/etc/init.d/cloud-early-config index 11efc5c1afc..bd86756fdaa 100755 --- a/tools/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -26,13 +26,35 @@ EOF patch() { local PATCH_MOUNT=/media/cdrom + local EXTRA_MOUNT=/media/extra local patchfile=$PATCH_MOUNT/cloud-scripts.tgz local md5file=/var/cache/cloud/cloud-scripts-signature local privkey=$PATCH_MOUNT/authorized_keys local shouldpatch=false + local cdrom_dev= mkdir -p $PATCH_MOUNT + + if [ -e /dev/vdb ]; then + # KVM needs to mount another disk, to get cmdline + mkdir -p $EXTRA_MOUNT + mount /dev/vdb $EXTRA_MOUNT + cp -f $EXTRA_MOUNT/cmdline /var/cache/cloud/cmdline + cp -f $EXTRA_MOUNT/authorized_keys /var/cache/cloud/authorized_keys + privkey=/var/cache/cloud/authorized_keys + umount $EXTRA_MOUNT + else + cat /proc/cmdline > /var/cache/cloud/cmdline + fi + if [ -e /dev/xvdd ]; then - mount -o ro /dev/xvdd $PATCH_MOUNT + cdrom_dev=/dev/xvdd + elif [ -e /dev/cdrom ]; then + # For KVM + cdrom_dev=/dev/cdrom + fi + + if [ -n "$cdrom_dev" ]; then + mount -o ro $cdrom_dev $PATCH_MOUNT [ -f $privkey ] && cp -f $privkey /root/.ssh/ && chmod go-rwx /root/.ssh/authorized_keys local oldmd5= [ -f ${md5file} ] && oldmd5=$(cat ${md5file}) @@ -43,10 +65,9 @@ patch() { then shouldpatch=true logger -t cloud "Patching scripts" - tar xzf $patchfile -C ${path} + tar xzf $patchfile -C / echo ${newmd5} > ${md5file} fi - cat /proc/cmdline > /var/cache/cloud/cmdline logger -t cloud "Patching cloud service" /opt/cloud/bin/patchsystemvm.sh $PATCH_MOUNT umount $PATCH_MOUNT @@ -57,9 +78,6 @@ patch() { reboot fi fi - if [ -f /mnt/cmdline ]; then - cat /mnt/cmdline > /var/cache/cloud/cmdline - fi return 0 } @@ -141,7 +159,7 @@ setup_common() { fi ip route delete default - ip route add default via $GW + ip route add default via $GW dev eth2 } setup_dnsmasq() { @@ -197,6 +215,12 @@ setup_dhcpsrvr() { setup_dnsmasq setup_apache2 + sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf + #for now set up ourself as the dns server as well + sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=6,$NS1,$NS2" >> /etc/dnsmasq.conf + sed -i /gateway/d /etc/hosts echo "$ETH0_IP $NAME" >> /etc/hosts @@ -256,6 +280,7 @@ EOF start() { patch + parse_cmd_line case $TYPE in router) [ "$NAME" == "" ] && NAME=router @@ -282,14 +307,9 @@ start() { } disable_hvc -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi - +parse_cmd_line() { +CMDLINE=$(cat /var/cache/cloud/cmdline) TYPE="unknown" BOOTPROTO="static" @@ -352,6 +372,7 @@ for i in $CMDLINE ;; esac done +} case "$1" in diff --git a/tools/systemvm/debian/config/etc/init.d/cloud-passwd-srvr b/patches/systemvm/debian/config/etc/init.d/cloud-passwd-srvr similarity index 100% rename from tools/systemvm/debian/config/etc/init.d/cloud-passwd-srvr rename to patches/systemvm/debian/config/etc/init.d/cloud-passwd-srvr diff --git a/tools/systemvm/debian/config/etc/init.d/postinit b/patches/systemvm/debian/config/etc/init.d/postinit similarity index 100% rename from tools/systemvm/debian/config/etc/init.d/postinit rename to patches/systemvm/debian/config/etc/init.d/postinit diff --git a/patches/systemvm/etc/sysconfig/iptables-consoleproxy b/patches/systemvm/debian/config/etc/iptables/iptables-consoleproxy similarity index 100% rename from patches/systemvm/etc/sysconfig/iptables-consoleproxy rename to patches/systemvm/debian/config/etc/iptables/iptables-consoleproxy diff --git a/tools/systemvm/debian/config/etc/iptables/iptables-router b/patches/systemvm/debian/config/etc/iptables/iptables-router similarity index 100% rename from tools/systemvm/debian/config/etc/iptables/iptables-router rename to patches/systemvm/debian/config/etc/iptables/iptables-router diff --git a/patches/systemvm/etc/sysconfig/iptables-secstorage b/patches/systemvm/debian/config/etc/iptables/iptables-secstorage similarity index 100% rename from patches/systemvm/etc/sysconfig/iptables-secstorage rename to patches/systemvm/debian/config/etc/iptables/iptables-secstorage diff --git a/tools/systemvm/debian/config/etc/iptables/rules b/patches/systemvm/debian/config/etc/iptables/rules similarity index 100% rename from tools/systemvm/debian/config/etc/iptables/rules rename to patches/systemvm/debian/config/etc/iptables/rules diff --git a/tools/systemvm/debian/config/etc/rc.local b/patches/systemvm/debian/config/etc/rc.local similarity index 100% rename from tools/systemvm/debian/config/etc/rc.local rename to patches/systemvm/debian/config/etc/rc.local diff --git a/tools/systemvm/debian/config/etc/ssh/sshd_config b/patches/systemvm/debian/config/etc/ssh/sshd_config similarity index 100% rename from tools/systemvm/debian/config/etc/ssh/sshd_config rename to patches/systemvm/debian/config/etc/ssh/sshd_config diff --git a/tools/systemvm/debian/config/etc/sysctl.conf b/patches/systemvm/debian/config/etc/sysctl.conf similarity index 100% rename from tools/systemvm/debian/config/etc/sysctl.conf rename to patches/systemvm/debian/config/etc/sysctl.conf diff --git a/tools/systemvm/debian/config/opt/cloud/bin/passwd_server b/patches/systemvm/debian/config/opt/cloud/bin/passwd_server similarity index 100% rename from tools/systemvm/debian/config/opt/cloud/bin/passwd_server rename to patches/systemvm/debian/config/opt/cloud/bin/passwd_server diff --git a/tools/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh similarity index 98% rename from tools/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh rename to patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh index 51f0bf1fbe6..c1df35c275e 100755 --- a/tools/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh @@ -36,6 +36,8 @@ secstorage_svcs() { chkconfig cloud-passwd-srvr off chkconfig haproxy off ; chkconfig dnsmasq off + chkconfig portmap on + chkconfig nfs-common on chkconfig ssh on chkconfig apache2 off echo "cloud postinit ssh nfs-common portmap" > /var/cache/cloud/enabled_svcs diff --git a/tools/systemvm/debian/config/opt/cloud/bin/serve_password.sh b/patches/systemvm/debian/config/opt/cloud/bin/serve_password.sh similarity index 100% rename from tools/systemvm/debian/config/opt/cloud/bin/serve_password.sh rename to patches/systemvm/debian/config/opt/cloud/bin/serve_password.sh diff --git a/tools/systemvm/debian/config/root/.ssh/authorized_keys b/patches/systemvm/debian/config/root/.ssh/authorized_keys similarity index 100% rename from tools/systemvm/debian/config/root/.ssh/authorized_keys rename to patches/systemvm/debian/config/root/.ssh/authorized_keys diff --git a/patches/systemvm/root/clearUsageRules.sh b/patches/systemvm/debian/config/root/clearUsageRules.sh similarity index 100% rename from patches/systemvm/root/clearUsageRules.sh rename to patches/systemvm/debian/config/root/clearUsageRules.sh diff --git a/tools/systemvm/debian/config/root/edithosts.sh b/patches/systemvm/debian/config/root/edithosts.sh similarity index 100% rename from tools/systemvm/debian/config/root/edithosts.sh rename to patches/systemvm/debian/config/root/edithosts.sh diff --git a/patches/systemvm/root/firewall.sh b/patches/systemvm/debian/config/root/firewall.sh similarity index 100% rename from patches/systemvm/root/firewall.sh rename to patches/systemvm/debian/config/root/firewall.sh diff --git a/patches/systemvm/root/loadbalancer.sh b/patches/systemvm/debian/config/root/loadbalancer.sh similarity index 100% rename from patches/systemvm/root/loadbalancer.sh rename to patches/systemvm/debian/config/root/loadbalancer.sh diff --git a/tools/systemvm/debian/config/root/reconfigLB.sh b/patches/systemvm/debian/config/root/reconfigLB.sh similarity index 100% rename from tools/systemvm/debian/config/root/reconfigLB.sh rename to patches/systemvm/debian/config/root/reconfigLB.sh diff --git a/tools/systemvm/debian/config/var/lib/misc/dnsmasq.leases b/patches/systemvm/debian/config/var/lib/misc/dnsmasq.leases similarity index 100% rename from tools/systemvm/debian/config/var/lib/misc/dnsmasq.leases rename to patches/systemvm/debian/config/var/lib/misc/dnsmasq.leases diff --git a/tools/systemvm/debian/config/var/www/html/latest/.htaccess b/patches/systemvm/debian/config/var/www/html/latest/.htaccess similarity index 100% rename from tools/systemvm/debian/config/var/www/html/latest/.htaccess rename to patches/systemvm/debian/config/var/www/html/latest/.htaccess diff --git a/patches/systemvm/var/www/html/metadata/.htaccess b/patches/systemvm/debian/config/var/www/html/userdata/.htaccess similarity index 100% rename from patches/systemvm/var/www/html/metadata/.htaccess rename to patches/systemvm/debian/config/var/www/html/userdata/.htaccess diff --git a/tools/systemvm/debian/systemvm.xml b/patches/systemvm/debian/systemvm.xml similarity index 100% rename from tools/systemvm/debian/systemvm.xml rename to patches/systemvm/debian/systemvm.xml diff --git a/patches/systemvm/etc/dnsmasq.conf b/patches/systemvm/etc/dnsmasq.conf deleted file mode 100755 index 234bcdaed5d..00000000000 --- a/patches/systemvm/etc/dnsmasq.conf +++ /dev/null @@ -1,463 +0,0 @@ -# Configuration file for dnsmasq. -# -# Format is one option per line, legal options are the same -# as the long options legal on the command line. See -# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details. -# @VERSION@ - -# The following two options make you a better netizen, since they -# tell dnsmasq to filter out queries which the public DNS cannot -# answer, and which load the servers (especially the root servers) -# uneccessarily. If you have a dial-on-demand link they also stop -# these requests from bringing up the link uneccessarily. - -# Never forward plain names (without a dot or domain part) -domain-needed -# Never forward addresses in the non-routed address spaces. -bogus-priv - - -# Uncomment this to filter useless windows-originated DNS requests -# which can trigger dial-on-demand links needlessly. -# Note that (amongst other things) this blocks all SRV requests, -# so don't use it if you use eg Kerberos. -# This option only affects forwarding, SRV records originating for -# dnsmasq (via srv-host= lines) are not suppressed by it. -#filterwin2k - -# Change this line if you want dns to get its upstream servers from -# somewhere other that /etc/resolv.conf -resolv-file=/etc/dnsmasq-resolv.conf - -# By default, dnsmasq will send queries to any of the upstream -# servers it knows about and tries to favour servers to are known -# to be up. Uncommenting this forces dnsmasq to try each query -# with each server strictly in the order they appear in -# /etc/resolv.conf -#strict-order - -# If you don't want dnsmasq to read /etc/resolv.conf or any other -# file, getting its servers from this file instead (see below), then -# uncomment this. -#no-resolv - -# If you don't want dnsmasq to poll /etc/resolv.conf or other resolv -# files for changes and re-read them then uncomment this. -#no-poll - -# Add other name servers here, with domain specs if they are for -# non-public domains. -#server=/localnet/192.168.0.1 - -# Example of routing PTR queries to nameservers: this will send all -# address->name queries for 192.168.3/24 to nameserver 10.1.2.3 -#server=/3.168.192.in-addr.arpa/10.1.2.3 - -# Add local-only domains here, queries in these domains are answered -# from /etc/hosts or DHCP only. -#local=/localnet/ - -# Add domains which you want to force to an IP address here. -# The example below send any host in doubleclick.net to a local -# webserver. -#address=/doubleclick.net/127.0.0.1 - -# If you want dnsmasq to change uid and gid to something other -# than the default, edit the following lines. -#user= -#group= - -# If you want dnsmasq to listen for DHCP and DNS requests only on -# specified interfaces (and the loopback) give the name of the -# interface (eg eth0) here. -# Repeat the line for more than one interface. -interface=eth0 -# Or you can specify which interface _not_ to listen on -except-interface=eth1 -except-interface=eth2 -# Or which to listen on by address (remember to include 127.0.0.1 if -# you use this.) -#listen-address= -# If you want dnsmasq to provide only DNS service on an interface, -# configure it as shown above, and then use the following line to -# disable DHCP on it. -no-dhcp-interface=eth1 -no-dhcp-interface=eth2 - -# On systems which support it, dnsmasq binds the wildcard address, -# even when it is listening on only some interfaces. It then discards -# requests that it shouldn't reply to. This has the advantage of -# working even when interfaces come and go and change address. If you -# want dnsmasq to really bind only the interfaces it is listening on, -# uncomment this option. About the only time you may need this is when -# running another nameserver on the same machine. -bind-interfaces - -# If you don't want dnsmasq to read /etc/hosts, uncomment the -# following line. -#no-hosts -# or if you want it to read another file, as well as /etc/hosts, use -# this. -#addn-hosts=/etc/banner_add_hosts - -# Set this (and domain: see below) if you want to have a domain -# automatically added to simple names in a hosts-file. -expand-hosts - -# Set the domain for dnsmasq. this is optional, but if it is set, it -# does the following things. -# 1) Allows DHCP hosts to have fully qualified domain names, as long -# as the domain part matches this setting. -# 2) Sets the "domain" DHCP option thereby potentially setting the -# domain of all systems configured by DHCP -# 3) Provides the domain part for "expand-hosts" -#domain=foo.com - -# Uncomment this to enable the integrated DHCP server, you need -# to supply the range of addresses available for lease and optionally -# a lease time. If you have more than one network, you will need to -# repeat this for each network on which you want to supply DHCP -# service. -dhcp-range=10.0.0.1,static -#dhcp-range=10.0.0.1,10.255.255.255 -dhcp-hostsfile=/etc/dhcphosts.txt - -# This is an example of a DHCP range where the netmask is given. This -# is needed for networks we reach the dnsmasq DHCP server via a relay -# agent. If you don't know what a DHCP relay agent is, you probably -# don't need to worry about this. -#dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h - -# This is an example of a DHCP range with a network-id, so that -# some DHCP options may be set only for this network. -#dhcp-range=red,192.168.0.50,192.168.0.150 - -# Supply parameters for specified hosts using DHCP. There are lots -# of valid alternatives, so we will give examples of each. Note that -# IP addresses DO NOT have to be in the range given above, they just -# need to be on the same network. The order of the parameters in these -# do not matter, it's permissble to give name,adddress and MAC in any order - -# Always allocate the host with ethernet address 11:22:33:44:55:66 -# The IP address 192.168.0.60 -#dhcp-host=11:22:33:44:55:66,192.168.0.60 - -# Always set the name of the host with hardware address -# 11:22:33:44:55:66 to be "fred" -#dhcp-host=11:22:33:44:55:66,fred - -# Always give the host with ethernet address 11:22:33:44:55:66 -# the name fred and IP address 192.168.0.60 and lease time 45 minutes -#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m - -# Give the machine which says it's name is "bert" IP address -# 192.168.0.70 and an infinite lease -#dhcp-host=bert,192.168.0.70,infinite - -# Always give the host with client identifier 01:02:02:04 -# the IP address 192.168.0.60 -#dhcp-host=id:01:02:02:04,192.168.0.60 - -# Always give the host with client identifier "marjorie" -# the IP address 192.168.0.60 -#dhcp-host=id:marjorie,192.168.0.60 - -# Enable the address given for "judge" in /etc/hosts -# to be given to a machine presenting the name "judge" when -# it asks for a DHCP lease. -#dhcp-host=judge - -# Never offer DHCP service to a machine whose ethernet -# address is 11:22:33:44:55:66 -#dhcp-host=11:22:33:44:55:66,ignore - -# Ignore any client-id presented by the machine with ethernet -# address 11:22:33:44:55:66. This is useful to prevent a machine -# being treated differently when running under different OS's or -# between PXE boot and OS boot. -#dhcp-host=11:22:33:44:55:66,id:* - -# Send extra options which are tagged as "red" to -# the machine with ethernet address 11:22:33:44:55:66 -#dhcp-host=11:22:33:44:55:66,net:red - -# Send extra options which are tagged as "red" to -# any machine with ethernet address starting 11:22:33: -#dhcp-host=11:22:33:*:*:*,net:red - -# Ignore any clients which are specified in dhcp-host lines -# or /etc/ethers. Equivalent to ISC "deny unkown-clients". -# This relies on the special "known" tag which is set when -# a host is matched. -#dhcp-ignore=#known - -# Send extra options which are tagged as "red" to any machine whose -# DHCP vendorclass string includes the substring "Linux" -#dhcp-vendorclass=red,Linux - -# Send extra options which are tagged as "red" to any machine one -# of whose DHCP userclass strings includes the substring "accounts" -#dhcp-userclass=red,accounts - -# Send extra options which are tagged as "red" to any machine whose -# MAC address matches the pattern. -#dhcp-mac=red,00:60:8C:*:*:* - -# If this line is uncommented, dnsmasq will read /etc/ethers and act -# on the ethernet-address/IP pairs found there just as if they had -# been given as --dhcp-host options. Useful if you keep -# MAC-address/host mappings there for other purposes. -#read-ethers - -# Send options to hosts which ask for a DHCP lease. -# See RFC 2132 for details of available options. -# Common options can be given to dnsmasq by name: -# run "dnsmasq --help dhcp" to get a list. -# Note that all the common settings, such as netmask and -# broadcast address, DNS server and default route, are given -# sane defaults by dnsmasq. You very likely will not need -# any dhcp-options. If you use Windows clients and Samba, there -# are some options which are recommended, they are detailed at the -# end of this section. - -# Override the default route supplied by dnsmasq, which assumes the -# router is the same machine as the one running dnsmasq. -#dhcp-option=3,1.2.3.4 - -# Do the same thing, but using the option name -#dhcp-option=option:router,1.2.3.4 - -# Override the default route supplied by dnsmasq and send no default -# route at all. Note that this only works for the options sent by -# default (1, 3, 6, 12, 28) the same line will send a zero-length option -# for all other option numbers. -#dhcp-option=3 - -# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5 -#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5 - -# Set the NTP time server address to be the same machine as -# is running dnsmasq -#dhcp-option=42,0.0.0.0 - -# Set the NIS domain name to "welly" -#dhcp-option=40,welly - -# Set the default time-to-live to 50 -#dhcp-option=23,50 - -# Set the "all subnets are local" flag -#dhcp-option=27,1 - -# Set the domain -#dhcp-option=15,"foo.com" - -# Send the etherboot magic flag and then etherboot options (a string). -#dhcp-option=128,e4:45:74:68:00:00 -#dhcp-option=129,NIC=eepro100 - -# Specify an option which will only be sent to the "red" network -# (see dhcp-range for the declaration of the "red" network) -# Note that the net: part must precede the option: part. -#dhcp-option = net:red, option:ntp-server, 192.168.1.1 - -# The following DHCP options set up dnsmasq in the same way as is specified -# for the ISC dhcpcd in -# http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt -# adapted for a typical dnsmasq installation where the host running -# dnsmasq is also the host running samba. -# you may want to uncomment them if you use Windows clients and Samba. -#dhcp-option=19,0 # option ip-forwarding off -#dhcp-option=44,0.0.0.0 # set netbios-over-TCP/IP nameserver(s) aka WINS server(s) -#dhcp-option=45,0.0.0.0 # netbios datagram distribution server -#dhcp-option=46,8 # netbios node type -#dhcp-option=47 # empty netbios scope. - -# Send RFC-3397 DNS domain search DHCP option. WARNING: Your DHCP client -# probably doesn't support this...... -#dhcp-option=option:domain-search,eng.apple.com,marketing.apple.com - -# Send RFC-3442 classless static routes (note the netmask encoding) -#dhcp-option=121,192.168.1.0/24,1.2.3.4,10.0.0.0/8,5.6.7.8 - -# Send vendor-class specific options encapsulated in DHCP option 43. -# The meaning of the options is defined by the vendor-class so -# options are sent only when the client supplied vendor class -# matches the class given here. (A substring match is OK, so "MSFT" -# matches "MSFT" and "MSFT 5.0"). This example sets the -# mtftp address to 0.0.0.0 for PXEClients. -#dhcp-option=vendor:PXEClient,1,0.0.0.0 - -# Send microsoft-specific option to tell windows to release the DHCP lease -# when it shuts down. Note the "i" flag, to tell dnsmasq to send the -# value as a four-byte integer - that's what microsoft wants. See -# http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true -dhcp-option=vendor:MSFT,2,1i - -# Send the Encapsulated-vendor-class ID needed by some configurations of -# Etherboot to allow is to recognise the DHCP server. -#dhcp-option=vendor:Etherboot,60,"Etherboot" - -# Send options to PXELinux. Note that we need to send the options even -# though they don't appear in the parameter request list, so we need -# to use dhcp-option-force here. -# See http://syslinux.zytor.com/pxe.php#special for details. -# Magic number - needed before anything else is recognised -#dhcp-option-force=208,f1:00:74:7e -# Configuration file name -#dhcp-option-force=209,configs/common -# Path prefix -#dhcp-option-force=210,/tftpboot/pxelinux/files/ -# Reboot time. (Note 'i' to send 32-bit value) -#dhcp-option-force=211,30i - -# Set the boot filename for BOOTP. You will only need -# this is you want to boot machines over the network and you will need -# a TFTP server; either dnsmasq's built in TFTP server or an -# external one. (See below for how to enable the TFTP server.) -#dhcp-boot=pxelinux.0 - -# Enable dnsmasq's built-in TFTP server -#enable-tftp - -# Set the root directory for files availble via FTP. -#tftp-root=/var/ftpd - -# Make the TFTP server more secure: with this set, only files owned by -# the user dnsmasq is running as will be send over the net. -#tftp-secure - -# Set the boot file name only when the "red" tag is set. -#dhcp-boot=net:red,pxelinux.red-net - -# An example of dhcp-boot with an external server: the name and IP -# address of the server are given after the filename. -#dhcp-boot=/var/ftpd/pxelinux.0,boothost,192.168.0.3 - -# Set the limit on DHCP leases, the default is 150 -#dhcp-lease-max=150 - -# The DHCP server needs somewhere on disk to keep its lease database. -# This defaults to a sane location, but if you want to change it, use -# the line below. -#dhcp-leasefile=/var/lib/misc/dnsmasq.leases -leasefile-ro - -# Set the DHCP server to authoritative mode. In this mode it will barge in -# and take over the lease for any client which broadcasts on the network, -# whether it has a record of the lease or not. This avoids long timeouts -# when a machine wakes up on a new network. DO NOT enable this if there's -# the slighest chance that you might end up accidentally configuring a DHCP -# server for your campus/company accidentally. The ISC server uses -# the same option, and this URL provides more information: -# http://www.isc.org/index.pl?/sw/dhcp/authoritative.php -#dhcp-authoritative - -# Run an executable when a DHCP lease is created or destroyed. -# The arguments sent to the script are "add" or "del", -# then the MAC address, the IP address and finally the hostname -# if there is one. -#dhcp-script=/bin/echo - -# Set the cachesize here. -#cache-size=150 - -# If you want to disable negative caching, uncomment this. -#no-negcache - -# Normally responses which come form /etc/hosts and the DHCP lease -# file have Time-To-Live set as zero, which conventionally means -# do not cache further. If you are happy to trade lower load on the -# server for potentially stale date, you can set a time-to-live (in -# seconds) here. -#local-ttl= - -# If you want dnsmasq to detect attempts by Verisign to send queries -# to unregistered .com and .net hosts to its sitefinder service and -# have dnsmasq instead return the correct NXDOMAIN response, uncomment -# this line. You can add similar lines to do the same for other -# registries which have implemented wildcard A records. -#bogus-nxdomain=64.94.110.11 - -# If you want to fix up DNS results from upstream servers, use the -# alias option. This only works for IPv4. -# This alias makes a result of 1.2.3.4 appear as 5.6.7.8 -#alias=1.2.3.4,5.6.7.8 -# and this maps 1.2.3.x to 5.6.7.x -#alias=1.2.3.0,5.6.7.0,255.255.255.0 - - -# Change these lines if you want dnsmasq to serve MX records. - -# Return an MX record named "maildomain.com" with target -# servermachine.com and preference 50 -#mx-host=maildomain.com,servermachine.com,50 - -# Set the default target for MX records created using the localmx option. -#mx-target=servermachine.com - -# Return an MX record pointing to the mx-target for all local -# machines. -#localmx - -# Return an MX record pointing to itself for all local machines. -#selfmx - -# Change the following lines if you want dnsmasq to serve SRV -# records. These are useful if you want to serve ldap requests for -# Active Directory and other windows-originated DNS requests. -# See RFC 2782. -# You may add multiple srv-host lines. -# The fields are ,,,, -# If the domain part if missing from the name (so that is just has the -# service and protocol sections) then the domain given by the domain= -# config option is used. (Note that expand-hosts does not need to be -# set for this to work.) - -# A SRV record sending LDAP for the example.com domain to -# ldapserver.example.com port 289 -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389 - -# A SRV record sending LDAP for the example.com domain to -# ldapserver.example.com port 289 (using domain=) -###domain=example.com -#srv-host=_ldap._tcp,ldapserver.example.com,389 - -# Two SRV records for LDAP, each with different priorities -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1 -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2 - -# A SRV record indicating that there is no LDAP server for the domain -# example.com -#srv-host=_ldap._tcp.example.com - -# The following line shows how to make dnsmasq serve an arbitrary PTR -# record. This is useful for DNS-SD. (Note that the -# domain-name expansion done for SRV records _does_not -# occur for PTR records.) -#ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services" - -# Change the following lines to enable dnsmasq to serve TXT records. -# These are used for things like SPF and zeroconf. (Note that the -# domain-name expansion done for SRV records _does_not -# occur for TXT records.) - -#Example SPF. -#txt-record=example.com,"v=spf1 a -all" - -#Example zeroconf -#txt-record=_http._tcp.example.com,name=value,paper=A4 - - -# For debugging purposes, log each DNS query as it passes through -# dnsmasq. -log-queries - -# Log lots of extra information about DHCP transactions. -log-dhcp - -log-facility=/var/log/dnsmasq.log - -# Include a another lot of configuration options. -#conf-file=/etc/dnsmasq.more.conf -conf-dir=/etc/dnsmasq.d diff --git a/patches/systemvm/etc/haproxy/haproxy.cfg b/patches/systemvm/etc/haproxy/haproxy.cfg deleted file mode 100755 index 1a34373de68..00000000000 --- a/patches/systemvm/etc/haproxy/haproxy.cfg +++ /dev/null @@ -1,26 +0,0 @@ -global - log 127.0.0.1:3914 local0 info - chroot /var/lib/haproxy - user haproxy - group haproxy - daemon - -defaults - log global - mode tcp - option dontlognull - retries 3 - option redispatch - option forwardfor - stats enable - stats uri /admin?stats - stats realm Haproxy\ Statistics - stats auth admin1:AdMiN123 - option forceclose - timeout connect 5000 - timeout client 50000 - timeout server 50000 - - -listen 0.0.0.0:9 - option transparent diff --git a/patches/systemvm/etc/hosts b/patches/systemvm/etc/hosts deleted file mode 100755 index 28486e43ca8..00000000000 --- a/patches/systemvm/etc/hosts +++ /dev/null @@ -1,2 +0,0 @@ -# @VERSION@ -10.1.1.1 gateway diff --git a/patches/systemvm/etc/init.d/domr_webserver b/patches/systemvm/etc/init.d/domr_webserver deleted file mode 100755 index fef8ee25321..00000000000 --- a/patches/systemvm/etc/init.d/domr_webserver +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# chkconfig: 345 98 02 -# description: Web server that sends passwords to User VMs -# This file exists in /etc/init.d/ in the routing domain -# @VERSION@ - -bash /root/run_domr_webserver& diff --git a/patches/systemvm/etc/init.d/postinit b/patches/systemvm/etc/init.d/postinit deleted file mode 100755 index 681d5264fd9..00000000000 --- a/patches/systemvm/etc/init.d/postinit +++ /dev/null @@ -1,117 +0,0 @@ -#! /bin/bash -# chkconfig: 35 11 90 -# description: pre-boot configuration using boot line parameters -# This file exists in /etc/init.d/ - -replace_in_file() { - local filename=$1 - local keyname=$2 - local value=$3 - sed -i /$keyname=/d $filename - echo "$keyname=$value" >> $filename - return $? -} - -setup_secstorage() { - public_ip=$ETH2_IP - sed -i /$NAME/d /etc/hosts - echo "$public_ip $NAME" >> /etc/hosts - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*:80$/Listen $public_ip:80/" /etc/httpd/conf/httpd.conf - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*:443$/Listen $public_ip:443/" /etc/httpd/conf/httpd.conf -} - -setup_console_proxy() { - public_ip=$ETH2_IP - sed -i /$NAME/d /etc/hosts - echo "$public_ip $NAME" >> /etc/hosts -} - - -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi - -TYPE="router" -BOOTPROTO="static" - -for i in $CMDLINE - do - # search for foo=bar pattern and cut out foo - KEY=$(echo $i | cut -d= -f1) - VALUE=$(echo $i | cut -d= -f2) - case $KEY in - eth0ip) - ETH0_IP=$VALUE - ;; - eth1ip) - ETH1_IP=$VALUE - ;; - eth2ip) - ETH2_IP=$VALUE - ;; - gateway) - GW=$VALUE - ;; - eth0mask) - ETH0_MASK=$VALUE - ;; - eth1mask) - ETH1_MASK=$VALUE - ;; - eth2mask) - ETH2_MASK=$VALUE - ;; - dns1) - NS1=$VALUE - ;; - dns2) - NS2=$VALUE - ;; - domain) - DOMAIN=$VALUE - ;; - mgmtcidr) - MGMTNET=$VALUE - ;; - localgw) - LOCAL_GW=$VALUE - ;; - template) - TEMPLATE=$VALUE - ;; - name) - NAME=$VALUE - ;; - dhcprange) - DHCP_RANGE=$(echo $VALUE | tr ':' ',') - ;; - bootproto) - BOOTPROTO=$VALUE - ;; - type) - TYPE=$VALUE - ;; - esac -done - -if [ "$BOOTPROTO" == "static" ] -then - exit 0 -fi - -ETH1_IP=$(ifconfig eth1|grep 'inet addr:'|cut -d : -f 2|cut -d \ -f 1) -ETH2_IP=$(ifconfig eth2|grep 'inet addr:'|cut -d : -f 2|cut -d \ -f 1) - -case $TYPE in - secstorage) - [ "$NAME" == "" ] && NAME=secstorage - setup_secstorage; - ;; - consoleproxy) - [ "$NAME" == "" ] && NAME=consoleproxy - setup_console_proxy; - ;; -esac diff --git a/patches/systemvm/etc/init.d/seteth1 b/patches/systemvm/etc/init.d/seteth1 deleted file mode 100755 index 32a0ad704f4..00000000000 --- a/patches/systemvm/etc/init.d/seteth1 +++ /dev/null @@ -1,246 +0,0 @@ -#! /bin/bash -# chkconfig: 35 09 90 -# description: pre-boot configuration using boot line parameters -# This file exists in /etc/init.d/ - -replace_in_file() { - local filename=$1 - local keyname=$2 - local value=$3 - sed -i /$keyname=/d $filename - echo "$keyname=$value" >> $filename - return $? -} - -setup_interface() { - local intfnum=$1 - local ip=$2 - local mask=$3 - - cfg=/etc/sysconfig/network-scripts/ifcfg-eth${intfnum} - - if [ "$BOOTPROTO" == "dhcp" ] - then - if [ "$intfnum" != "0" ] - then - replace_in_file ${cfg} BOOTPROTO dhcp - replace_in_file ${cfg} ONBOOT Yes - sed -i /IPADDR/d ${cfg} - sed -i /NETMASK/d ${cfg} - return - fi - fi - - replace_in_file ${cfg} IPADDR ${ip} - replace_in_file ${cfg} NETMASK ${mask} - if [ "$ip" == "0.0.0.0" ] - then - replace_in_file ${cfg} ONBOOT No - else - replace_in_file ${cfg} ONBOOT Yes - fi - -} - -setup_common() { - setup_interface "0" $ETH0_IP $ETH0_MASK - setup_interface "1" $ETH1_IP $ETH1_MASK - setup_interface "2" $ETH2_IP $ETH2_MASK - - if [ "$BOOTPROTO" == "static" ] - then - replace_in_file /etc/sysconfig/network GATEWAY $GW - if [ -n "$ETH2_IP" -a "$ETH2_IP" != "0.0.0.0" ] - then - replace_in_file /etc/sysconfig/network GATEWAYDEV "eth2" - else - sed -i /GATEWAYDEV/d /etc/sysconfig/network - fi - else - sed -i /GATEWAY/d /etc/sysconfig/network - fi - replace_in_file /etc/sysconfig/network HOSTNAME $NAME - replace_in_file /etc/sysconfig/network NOZEROCONF yes - hostname $NAME - - #Nameserver - if [ -n "$NS1" ] - then - echo "nameserver $NS1" > /etc/dnsmasq-resolv.conf - echo "nameserver $NS1" > /etc/resolv.conf - fi - - if [ -n "$NS2" ] - then - echo "nameserver $NS2" >> /etc/dnsmasq-resolv.conf - echo "nameserver $NS2" >> /etc/resolv.conf - fi - if [[ -n "$MGMTNET" && -n "$LOCAL_GW" ]] - then - echo "$MGMTNET via $LOCAL_GW dev eth1" > /etc/sysconfig/network-scripts/route-eth1 - fi -} - -setup_router() { - setup_common - [ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP - if [ -n "$DOMAIN" ] - then - #send domain name to dhcp clients - sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\"$DOMAIN\"/ /etc/dnsmasq.conf - #DNS server will append $DOMAIN to local queries - sed -r -i s/^[#]?domain=.*$/domain=$DOMAIN/ /etc/dnsmasq.conf - #answer all local domain queries - sed -i -e "s/^[#]*local=.*$/local=\/$DOMAIN\//" /etc/dnsmasq.conf - fi - sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf - sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf - sed -i /gateway/d /etc/hosts - echo "$ETH0_IP $NAME" >> /etc/hosts - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*$/Listen $ETH0_IP:80/" /etc/httpd/conf/httpd.conf - [ -f /etc/httpd/conf.d/ssl.conf ] && mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak - [ -f /etc/ssh/sshd_config ] && sed -i -e "s/^[#]*ListenAddress.*$/ListenAddress $ETH1_IP/" /etc/ssh/sshd_config -} - -setup_dhcpsrvr() { - setup_common - [ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP - [ -z $DOMAIN ] && DOMAIN="cloudnine.internal" - if [ -n "$DOMAIN" ] - then - #send domain name to dhcp clients - sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\"$DOMAIN\"/ /etc/dnsmasq.conf - #DNS server will append $DOMAIN to local queries - sed -r -i s/^[#]?domain=.*$/domain=$DOMAIN/ /etc/dnsmasq.conf - #answer all local domain queries - sed -i -e "s/^[#]*local=.*$/local=\/$DOMAIN\//" /etc/dnsmasq.conf - fi - sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf - sed -i -e "s/^[#]*dhcp-option=option:router.*$/dhcp-option=option:router,$GW/" /etc/dnsmasq.conf - #for now set up ourself as the dns server as well - sed -i s/[#]*dhcp-option=6.*$/dhcp-option=6,\"$NS1\",\"$NS2\"/ /etc/dnsmasq.conf - sed -i /gateway/d /etc/hosts - echo "$ETH0_IP $NAME" >> /etc/hosts - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*$/Listen $ETH0_IP:80/" /etc/httpd/conf/httpd.conf - [ -f /etc/httpd/conf.d/ssl.conf ] && mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak - [ -f /etc/ssh/sshd_config ] && sed -i -e "s/^[#]*ListenAddress.*$/ListenAddress $ETH1_IP/" /etc/ssh/sshd_config -} - -setup_secstorage() { - setup_common - sed -i /gateway/d /etc/hosts - public_ip=$ETH2_IP - [ "$ETH2_IP" == "0.0.0.0" ] && public_ip=$ETH1_IP - echo "$public_ip $NAME" >> /etc/hosts - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*:80$/Listen $public_ip:80/" /etc/httpd/conf/httpd.conf - [ -f /etc/httpd/conf/httpd.conf ] && sed -i -e "s/^Listen.*:443$/Listen $public_ip:443/" /etc/httpd/conf/httpd.conf -} - -setup_console_proxy() { - setup_common - public_ip=$ETH2_IP - [ "$ETH2_IP" == "0.0.0.0" ] && public_ip=$ETH1_IP - sed -i /gateway/d /etc/hosts - echo "$public_ip $NAME" >> /etc/hosts -} - -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi - - -if [ ! -d /root/.ssh ] -then - mkdir /root/.ssh - chmod 700 /root/.ssh -fi -if [ -f /mnt/id_rsa.pub ] -then - cat /mnt/id_rsa.pub > /root/.ssh/authorized_keys - chmod 600 /root/.ssh/authorized_keys -fi - -TYPE="router" -BOOTPROTO="static" - -for i in $CMDLINE - do - # search for foo=bar pattern and cut out foo - KEY=$(echo $i | cut -d= -f1) - VALUE=$(echo $i | cut -d= -f2) - case $KEY in - eth0ip) - ETH0_IP=$VALUE - ;; - eth1ip) - ETH1_IP=$VALUE - ;; - eth2ip) - ETH2_IP=$VALUE - ;; - gateway) - GW=$VALUE - ;; - eth0mask) - ETH0_MASK=$VALUE - ;; - eth1mask) - ETH1_MASK=$VALUE - ;; - eth2mask) - ETH2_MASK=$VALUE - ;; - dns1) - NS1=$VALUE - ;; - dns2) - NS2=$VALUE - ;; - domain) - DOMAIN=$VALUE - ;; - mgmtcidr) - MGMTNET=$VALUE - ;; - localgw) - LOCAL_GW=$VALUE - ;; - template) - TEMPLATE=$VALUE - ;; - name) - NAME=$VALUE - ;; - dhcprange) - DHCP_RANGE=$(echo $VALUE | tr ':' ',') - ;; - bootproto) - BOOTPROTO=$VALUE - ;; - type) - TYPE=$VALUE - ;; - esac -done - -case $TYPE in - router) - [ "$NAME" == "" ] && NAME=router - setup_router - ;; - dhcpsrvr) - [ "$NAME" == "" ] && NAME=dhcpsrvr - setup_dhcpsrvr - ;; - secstorage) - [ "$NAME" == "" ] && NAME=secstorage - setup_secstorage; - ;; - consoleproxy) - [ "$NAME" == "" ] && NAME=consoleproxy - setup_console_proxy; - ;; -esac diff --git a/patches/systemvm/etc/init.d/vmops b/patches/systemvm/etc/init.d/vmops deleted file mode 100755 index f0c4b3e2c0f..00000000000 --- a/patches/systemvm/etc/init.d/vmops +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash -# -# vmops Script to start and stop VMOps console proxy in domR/domP. -# -# Author: Chiradeep Vittal -# chkconfig: 2345 99 01 -# description: Start up the VMOps agent -# -# This file exists in /etc/init.d/ in the domR/DomP -# with a software link /etc/rc.d/rc3.d/S99vmops pointed to it -# -# @VERSION@ - -if [ -f /mnt/cmdline ] -then - CMDLINE=$(cat /mnt/cmdline) -else - CMDLINE=$(cat /proc/cmdline) -fi -TEMPLATE="domR" -for i in $CMDLINE - do - # search for foo=bar pattern and cut out foo - FIRSTPATTERN=$(echo $i | cut -d= -f1) - case $FIRSTPATTERN in - template) - TEMPLATE=$(echo $i | cut -d= -f2) - ;; - esac -done - -# Source function library. -if [ -f /etc/init.d/functions ] -then - . /etc/init.d/functions -fi - -_success() { - if [ -f /etc/init.d/functions ] - then - success - else - echo "Success" - fi -} - -_failure() { - if [ -f /etc/init.d/functions ] - then - failure - else - echo "Failed" - fi -} -RETVAL=$? -VMOPS_HOME="/usr/local/vmops" - -# mkdir -p /var/log/vmops - -get_pids() { - local i - for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}'); - do - echo $(pwdx $i) | grep "$VMOPS_HOME" | grep -i console | awk -F: '{print $1}'; - done -} - -start() { - if [ "$TEMPLATE" == "domP" ]; - then - local pid=$(get_pids) - echo -n "Starting VMOps Console Proxy: " - if [ -f $VMOPS_HOME/consoleproxy/run.sh ]; - then - if [ "$pid" == "" ] - then - if [ ! -d /var/log/vmops ] - then - mkdir -p /var/log/vmops - fi - if [ ! -f /var/log/vmops/vmops.out ] - then - touch /var/log/vmops/vmops.out - fi - (cd $VMOPS_HOME/consoleproxy; nohup ./run.sh > /var/log/vmops/vmops.out 2>&1 & ) - pid=$(get_pids) - echo $pid > /var/run/vmops.pid - fi - _success - else - _failure - fi - echo - fi -} - -stop() { - if [ "$TEMPLATE" == "domP" ]; - then - local pid - echo -n "Stopping VMOps agent: " - for pid in $(get_pids) - do - kill $pid - done - _success - echo - fi -} - -status() { - if [ "$TEMPLATE" == "domP" ]; - then - local pids=$(get_pids) - if [ "$pids" == "" ] - then - echo "VMOps agent is not running" - return 1 - fi - echo "VMOps agent is running: process id: $pids" - fi - return 0 -} - -case "$1" in - start) start - ;; - stop) stop - ;; - status) status - ;; - restart) stop - start - ;; - *) echo $"Usage: $0 {start|stop|status|restart}" - exit 1 - ;; -esac - -exit $RETVAL diff --git a/patches/systemvm/etc/rc.local b/patches/systemvm/etc/rc.local deleted file mode 100755 index 6a6c84a2117..00000000000 --- a/patches/systemvm/etc/rc.local +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# -# This script will be executed *after* all the other init scripts. -# You can put your own initialization stuff in here if you don't -# want to do the full Sys V style init stuff. -# @VERSION@ - -touch /var/lock/subsys/local -ethtool -K eth0 tx off -ethtool -K eth1 tx off diff --git a/patches/systemvm/etc/ssh/sshd_config b/patches/systemvm/etc/ssh/sshd_config deleted file mode 100755 index 9ce6bccbb10..00000000000 --- a/patches/systemvm/etc/ssh/sshd_config +++ /dev/null @@ -1,128 +0,0 @@ -# $OpenBSD: sshd_config,v 1.75 2007/03/19 01:01:29 djm Exp $ - -# This is the sshd server system-wide configuration file. See -# sshd_config(5) for more information. - -# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin - -# The strategy used for options in the default sshd_config shipped with -# OpenSSH is to specify options with their default value where -# possible, but leave them commented. Uncommented options change a -# default value. - -Port 3922 -#AddressFamily any -#ListenAddress 0.0.0.0 -#ListenAddress :: - -# Disable legacy (protocol version 1) support in the server for new -# installations. In future the default will change to require explicit -# activation of protocol 1 -Protocol 2 - -# HostKey for protocol version 1 -#HostKey /etc/ssh/ssh_host_key -# HostKeys for protocol version 2 -#HostKey /etc/ssh/ssh_host_rsa_key -#HostKey /etc/ssh/ssh_host_dsa_key - -# Lifetime and size of ephemeral version 1 server key -#KeyRegenerationInterval 1h -#ServerKeyBits 768 - -# Logging -# obsoletes QuietMode and FascistLogging -#SyslogFacility AUTH -SyslogFacility AUTHPRIV -#LogLevel INFO - -# Authentication: - -#LoginGraceTime 2m -PermitRootLogin yes -#StrictModes yes -#MaxAuthTries 6 - -#RSAAuthentication yes -#PubkeyAuthentication yes -#AuthorizedKeysFile .ssh/authorized_keys - -# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts -#RhostsRSAAuthentication no -# similar for protocol version 2 -#HostbasedAuthentication no -# Change to yes if you don't trust ~/.ssh/known_hosts for -# RhostsRSAAuthentication and HostbasedAuthentication -#IgnoreUserKnownHosts no -# Don't read the user's ~/.rhosts and ~/.shosts files -#IgnoreRhosts yes - -# To disable tunneled clear text passwords, change to no here! -#PasswordAuthentication yes -#PermitEmptyPasswords no -PasswordAuthentication no - -# Change to no to disable s/key passwords -#ChallengeResponseAuthentication yes -ChallengeResponseAuthentication no - -# Kerberos options -#KerberosAuthentication no -#KerberosOrLocalPasswd yes -#KerberosTicketCleanup yes -#KerberosGetAFSToken no - -# GSSAPI options -#GSSAPIAuthentication no -GSSAPIAuthentication yes -#GSSAPICleanupCredentials yes -GSSAPICleanupCredentials yes - -# Set this to 'yes' to enable PAM authentication, account processing, -# and session processing. If this is enabled, PAM authentication will -# be allowed through the ChallengeResponseAuthentication and -# PasswordAuthentication. Depending on your PAM configuration, -# PAM authentication via ChallengeResponseAuthentication may bypass -# the setting of "PermitRootLogin without-password". -# If you just want the PAM account and session checks to run without -# PAM authentication, then enable this but set PasswordAuthentication -# and ChallengeResponseAuthentication to 'no'. -#UsePAM no -UsePAM yes - -# Accept locale-related environment variables -AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES -AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT -AcceptEnv LC_IDENTIFICATION LC_ALL -#AllowTcpForwarding yes -#GatewayPorts no -#X11Forwarding no -X11Forwarding yes -#X11DisplayOffset 10 -#X11UseLocalhost yes -#PrintMotd yes -#PrintLastLog yes -#TCPKeepAlive yes -#UseLogin no -#UsePrivilegeSeparation yes -#PermitUserEnvironment no -#Compression delayed -#ClientAliveInterval 0 -#ClientAliveCountMax 3 -#ShowPatchLevel no -UseDNS no -#PidFile /var/run/sshd.pid -#MaxStartups 10 -#PermitTunnel no - -# no default banner path -#Banner /some/path - -# override default of no subsystems -Subsystem sftp /usr/libexec/openssh/sftp-server - -# Example of overriding settings on a per-user basis -#Match User anoncvs -# X11Forwarding no -# AllowTcpForwarding no -# ForceCommand cvs server diff --git a/patches/systemvm/etc/sysconfig/iptables-domr b/patches/systemvm/etc/sysconfig/iptables-domr deleted file mode 100644 index 3bc7b50f74a..00000000000 --- a/patches/systemvm/etc/sysconfig/iptables-domr +++ /dev/null @@ -1,24 +0,0 @@ -*nat -:PREROUTING ACCEPT [0:0] -:POSTROUTING ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] -COMMIT -*filter -:INPUT DROP [0:0] -:FORWARD DROP [0:0] -:OUTPUT ACCEPT [0:0] --A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -p icmp -j ACCEPT --A INPUT -i lo -j ACCEPT --A INPUT -i eth0 -p udp -m udp --dport 67 -j ACCEPT --A INPUT -i eth0 -p udp -m udp --dport 53 -j ACCEPT --A INPUT -i eth1 -p tcp -m state --state NEW --dport 3922 -j ACCEPT --A INPUT -i eth0 -p tcp -m state --state NEW --dport 8080 -j ACCEPT --A INPUT -i eth0 -p tcp -m state --state NEW --dport 80 -j ACCEPT --A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT --A FORWARD -i eth0 -o eth2 -j ACCEPT --A FORWARD -i eth2 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT -COMMIT - diff --git a/patches/systemvm/etc/sysctl.conf b/patches/systemvm/etc/sysctl.conf deleted file mode 100644 index ba5cbe6137d..00000000000 --- a/patches/systemvm/etc/sysctl.conf +++ /dev/null @@ -1,33 +0,0 @@ -# Kernel sysctl configuration file for Red Hat Linux -# -# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and -# sysctl.conf(5) for more details. -# @VERSION@ - -# Controls IP packet forwarding -net.ipv4.ip_forward = 1 - -# Controls source route verification -net.ipv4.conf.default.rp_filter = 1 - -# Do not accept source routing -net.ipv4.conf.default.accept_source_route = 0 - -# Respect local interface in ARP interactions -net.ipv4.conf.default.arp_announce = 2 -net.ipv4.conf.default.arp_ignore = 2 -net.ipv4.conf.all.arp_announce = 2 -net.ipv4.conf.all.arp_ignore = 2 - - -# Controls the System Request debugging functionality of the kernel -kernel.sysrq = 0 - -# Controls whether core dumps will append the PID to the core filename. -# Useful for debugging multi-threaded applications. -kernel.core_uses_pid = 1 - -# Controls the use of TCP syncookies -net.ipv4.tcp_syncookies = 1 - -net.netfilter.nf_conntrack_max=65536 diff --git a/patches/systemvm/root/.ssh/authorized_keys b/patches/systemvm/root/.ssh/authorized_keys deleted file mode 100644 index 2cb275c2582..00000000000 --- a/patches/systemvm/root/.ssh/authorized_keys +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3VD1tGRDn3stlJvPNXmQZdQCNjqcfY+xlitd5q0n3KYqJ5OBrty3/00XBUdLt31TbQ4dv+GR7uEr+ex7rm0jjmTFKV4rHYPi882CuC5+bkBp5R4k+mpcyKbxb+IoNS9ItbiExQxMiiRQpHvNem0GGnNFO3lElRPwUFs8evTvZu5HcTj4k4RJLJ66jeIGJ3sMAJ03SICGwfEZjrsyeOMwJk7cH8WNeuNzxzoZd9v02eI0lHdK9O5z7FwrxvRBbzsmJ0EwuhbH8pR7WR6kGLTNP9KEwtrnzV1LYWd+rFoSeh6ImExG7fma3Ldydg8CPTQsjvCEQUxiuV1/x5am5VJlUw== root@r-6-TEST diff --git a/patches/systemvm/root/edithosts.sh b/patches/systemvm/root/edithosts.sh deleted file mode 100755 index 5193376b8b5..00000000000 --- a/patches/systemvm/root/edithosts.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -# edithosts.sh -- edit the dhcphosts file on the routing domain -# $1 : the mac address -# $2 : the associated ip address -# $3 : the hostname - -wait_for_dnsmasq () { - local _pid=$(/sbin/pidof dnsmasq) - for i in 0 1 2 3 4 5 6 7 8 9 10 - do - sleep 1 - _pid=$(/sbin/pidof dnsmasq) - [ "$_pid" != "" ] && break; - done - [ "$_pid" != "" ] && return 0; - echo "edithosts: timed out waiting for dnsmasq to start" - return 1 -} - -#delete any previous entries from the dhcp hosts file -sed -i /$1/d /etc/dhcphosts.txt -sed -i /$2,/d /etc/dhcphosts.txt -sed -i /$3,/d /etc/dhcphosts.txt - -#put in the new entry -echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt - -#delete leases to supplied mac and ip addresses -sed -i /$1/d /var/lib/misc/dnsmasq.leases -sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases -sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases - -#put in the new entry -echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases - -#edit hosts file as well -sed -i /"$2 "/d /etc/hosts -sed -i /"$3"/d /etc/hosts -echo "$2 $3" >> /etc/hosts - -# make dnsmasq re-read files -pid=$(/sbin/pidof dnsmasq) -if [ "$pid" != "" ] -then - service dnsmasq restart -else - wait_for_dnsmasq -fi - -exit $? diff --git a/patches/systemvm/root/patchsystemvm.sh b/patches/systemvm/root/patchsystemvm.sh deleted file mode 100755 index 8a25ebf894c..00000000000 --- a/patches/systemvm/root/patchsystemvm.sh +++ /dev/null @@ -1,116 +0,0 @@ -#/bin/bash -# $Id: patchsystemvm.sh 10800 2010-07-16 13:48:39Z edison $ $HeadURL: svn://svn.lab.vmops.com/repos/branches/2.1.x/java/scripts/vm/hypervisor/xenserver/prepsystemvm.sh $ - -#set -x -logfile="/var/log/patchsystemvm.log" -# -# To use existing console proxy .zip-based package file -# -patch_console_proxy() { - local patchfile=$1 - rm /usr/local/cloud/systemvm -rf - mkdir -p /usr/local/cloud/systemvm - echo "All" | unzip $patchfile -d /usr/local/cloud/systemvm >$logfile 2>&1 - find /usr/local/cloud/systemvm/ -name \*.sh | xargs chmod 555 - return 0 -} - -consoleproxy_svcs() { - chkconfig cloud on - chkconfig postinit on - chkconfig domr_webserver off - chkconfig haproxy off ; - chkconfig dnsmasq off - chkconfig sshd on - chkconfig httpd off - chkconfig nfs off - chkconfig nfslock off - chkconfig rpcbind off - chkconfig rpcidmap off - cp /etc/sysconfig/iptables-consoleproxy /etc/sysconfig/iptables - mkdir -p /var/log/cloud -} - -secstorage_svcs() { - chkconfig cloud on - chkconfig postinit on - chkconfig domr_webserver off - chkconfig haproxy off ; - chkconfig dnsmasq off - chkconfig sshd on - chkconfig httpd off - cp /etc/sysconfig/iptables-secstorage /etc/sysconfig/iptables - scp 169.254.0.1:/usr/sbin/vhd-util /usr/sbin - mkdir -p /var/log/cloud -} - -routing_svcs() { - chkconfig cloud off - chkconfig domr_webserver on ; - chkconfig haproxy on ; - chkconfig dnsmasq on - chkconfig sshd on - chkconfig nfs off - chkconfig nfslock off - chkconfig rpcbind off - chkconfig rpcidmap off - cp /etc/sysconfig/iptables-domr /etc/sysconfig/iptables -} - -CMDLINE=$(cat /proc/cmdline) -TYPE="router" - -for i in $CMDLINE - do - # search for foo=bar pattern and cut out foo - KEY=$(echo $i | cut -d= -f1) - VALUE=$(echo $i | cut -d= -f2) - case $KEY in - type) - TYPE=$VALUE - ;; - *) - ;; - esac -done - -if [ "$TYPE" = "consoleproxy" ] || [ "$TYPE" = "secstorage" ] && [ -f /media/cdrom/systemvm.zip ] -then - patch_console_proxy /media/cdrom/systemvm.zip - if [ $? -gt 0 ] - then - printf "Failed to apply patch systemvm\n" >$logfile - exit 5 - fi -fi - - -#empty known hosts -echo "" > /root/.ssh/known_hosts - -if [ "$TYPE" = "consoleproxy" ] -then - consoleproxy_svcs - if [ $? -gt 0 ] - then - printf "Failed to execute consoleproxy_svcs\n" >$logfile - exit 6 - fi -elif [ "$TYPE" = "secstorage" ] -then - secstorage_svcs - if [ $? -gt 0 ] - then - printf "Failed to execute secstorage_svcs\n" >$logfile - exit 7 - fi -else - routing_svcs - if [ $? -gt 0 ] - then - printf "Failed to execute routing_svcs\n" >$logfile - exit 8 - fi -fi - -exit $? diff --git a/patches/systemvm/root/reconfigLB.sh b/patches/systemvm/root/reconfigLB.sh deleted file mode 100755 index 3b1155ebfde..00000000000 --- a/patches/systemvm/root/reconfigLB.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# $Id: reconfigLB.sh 9947 2010-06-25 19:34:24Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/patches/kvm/root/reconfigLB.sh $ -# @VERSION@ - -# save previous state - mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.old - mv /var/run/haproxy.pid /var/run/haproxy.pid.old - - mv /etc/haproxy/haproxy.cfg.new /etc/haproxy/haproxy.cfg - kill -TTOU $(cat /var/run/haproxy.pid.old) - sleep 2 - if haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy/haproxy.cfg; then - echo "New haproxy instance successfully loaded, stopping previous one." - kill -KILL $(cat /var/run/haproxy.pid.old) - rm -f /var/run/haproxy.pid.old - exit 0 - else - echo "New instance failed to start, resuming previous one." - kill -TTIN $(cat /var/run/haproxy.pid.old) - rm -f /var/run/haproxy.pid - mv /var/run/haproxy.pid.old /var/run/haproxy.pid - mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.new - mv /etc/haproxy/haproxy.cfg.old /etc/haproxy/haproxy.cfg - exit 1 - fi diff --git a/patches/systemvm/root/run_domr_webserver b/patches/systemvm/root/run_domr_webserver deleted file mode 100755 index 39ee48417e2..00000000000 --- a/patches/systemvm/root/run_domr_webserver +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# @VERSION@ - -guestIp=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') - -while true -do - /usr/bin/socat TCP4-LISTEN:8080,reuseaddr,crnl,bind=$guestIp SYSTEM:"/root/send_password_to_domu.sh \"\$SOCAT_PEERADDR\"" - - rc=$? - if [ $rc -ne 0 ] - then - logger "Socat failed with error code $rc. Restarting socat..." - sleep 3 - fi - -done diff --git a/patches/systemvm/root/send_password_to_domu.sh b/patches/systemvm/root/send_password_to_domu.sh deleted file mode 100755 index d785fa41e55..00000000000 --- a/patches/systemvm/root/send_password_to_domu.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# $Id: send_password_to_domu.sh 9947 2010-06-25 19:34:24Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/patches/kvm/root/send_password_to_domu.sh $ -# @VERSION@ - -# set -x - -#replace a line in a file of the form key=value -# $1 filename -# $2 keyname -# $3 value -replace_in_file() { - local filename=$1 - local keyname=$2 - local value=$3 - sed -i /$keyname=/d $filename - echo "$keyname=$value" >> $filename - return $? -} - -#get a value from a file in the form key=value -# $1 filename -# $2 keyname -get_value() { - local filename=$1 - local keyname=$2 - grep -i $keyname= $filename | cut -d= -f2 -} - -ip=$1 - -logger "send_password_to_domu called to service a request for $ip." - -while read input -do - if [ "$input" == "" ] - then - break - fi - - request=$(echo $input | grep "DomU_Request:" | cut -d: -f2 | sed 's/^[ \t]*//') - - if [ "$request" != "" ] - then - break - fi -done - -# echo -e \"\\\"HTTP/1.0 200 OK\\\nDocumentType: text/plain\\\n\\\n\\\"\"; - -if [ "$request" == "send_my_password" ] -then - password=$(get_value /root/passwords $ip) - if [ "$password" == "" ] - then - logger "send_password_to_domu sent bad_request to $ip." - echo "bad_request" - else - logger "send_password_to_domu sent a password to $ip." - echo $password - fi -else - if [ "$request" == "saved_password" ] - then - replace_in_file /root/passwords $ip "saved_password" - logger "send_password_to_domu sent saved_password to $ip." - echo "saved_password" - else - logger "send_password_to_domu sent bad_request to $ip." - echo "bad_request" - fi -fi - -# echo -e \"\\\"\\\n\\\"\" - -exit 0 diff --git a/patches/systemvm/var/www/html/latest/.htaccess b/patches/systemvm/var/www/html/latest/.htaccess deleted file mode 100644 index c62613d1fda..00000000000 --- a/patches/systemvm/var/www/html/latest/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ -Options +FollowSymLinks -Options -Indexes -RewriteEngine On - diff --git a/patches/systemvm/var/www/html/userdata/.htaccess b/patches/systemvm/var/www/html/userdata/.htaccess deleted file mode 100644 index 5a928f6da25..00000000000 --- a/patches/systemvm/var/www/html/userdata/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Options -Indexes diff --git a/patches/wscript_build b/patches/wscript_build index a28272fb8e4..5abef720b8a 100644 --- a/patches/wscript_build +++ b/patches/wscript_build @@ -4,15 +4,12 @@ bld.substitute("*/**",name="patchsubst") for virttech in Utils.to_list(bld.path.ant_glob("*",dir=True)): if virttech in ["shared","wscript_build"]: continue - patchfiles = bld.path.ant_glob('shared/** %s/**'%virttech,src=False,bld=True,dir=False,flat=True) + patchfiles = bld.path.ant_glob('shared/** %s/debian/config/**'%virttech,src=False,bld=True,dir=False,flat=True) tgen = bld( features = 'tar',#Utils.tar_up, source = patchfiles, - target = '%s-patch.tgz'%virttech, - name = '%s-patch_tgz'%virttech, - root = os.path.join("patches",virttech), + target = 'cloud-scripts.tgz', + name = 'cloud-scripts_tgz', + root = os.path.join("patches", virttech + "/debian/config"), rename = lambda x: re.sub(".subst$","",x), ) - if virttech != "xenserver": - # xenserver uses the patch.tgz file later to make an ISO, so we do not need to install it - bld.install_as("${AGENTLIBDIR}/scripts/vm/hypervisor/%s/patch.tgz"%virttech, "%s-patch.tgz"%virttech) diff --git a/python/incubation/cloud-web-ipallocator b/python/bindir/cloud-external-ipallocator.py similarity index 99% rename from python/incubation/cloud-web-ipallocator rename to python/bindir/cloud-external-ipallocator.py index 3a278d29e56..533acfc4eab 100755 --- a/python/incubation/cloud-web-ipallocator +++ b/python/bindir/cloud-external-ipallocator.py @@ -101,6 +101,8 @@ class dhcp: save"""%(path) augtool < script + self.availIP.remove(ip) + #reset dnsmasq service("dnsmasq", "restart", stdout=None, stderr=None) diff --git a/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in b/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in new file mode 100755 index 00000000000..dca8f000904 --- /dev/null +++ b/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in @@ -0,0 +1,82 @@ +#!/bin/bash + +# chkconfig: 35 99 10 +# description: Cloud Agent + +# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well + +. /etc/rc.d/init.d/functions + +whatami=cloud-external-ipallocator + +# set environment variables + +SHORTNAME="$whatami" +PIDFILE=@PIDDIR@/"$whatami".pid +LOCKFILE=@LOCKDIR@/"$SHORTNAME" +LOGFILE=@IPALOCATORLOG@ +PROGNAME="External IPAllocator" + +unset OPTIONS +[ -r @SYSCONFDIR@/sysconfig/"$SHORTNAME" ] && source @SYSCONFDIR@/sysconfig/"$SHORTNAME" +DAEMONIZE=@BINDIR@/@PACKAGE@-daemonize +PROG=@BINDIR@/@PACKAGE@-external-ipallocator.py +OPTIONS=8083 + +start() { + echo -n $"Starting $PROGNAME: " + if hostname --fqdn >/dev/null 2>&1 ; then + daemon --check=$SHORTNAME --pidfile=${PIDFILE} "$DAEMONIZE" \ + -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS + RETVAL=$? + echo + else + failure + echo + echo The host name does not resolve properly to an IP address. Cannot start "$PROGNAME". > /dev/stderr + RETVAL=9 + fi + [ $RETVAL = 0 ] && touch ${LOCKFILE} + return $RETVAL +} + +stop() { + echo -n $"Stopping $PROGNAME: " + killproc -p ${PIDFILE} $SHORTNAME # -d 10 $SHORTNAME + RETVAL=$? + echo + [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE} +} + + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status -p ${PIDFILE} $SHORTNAME + RETVAL=$? + ;; + restart) + stop + sleep 3 + start + ;; + condrestart) + if status -p ${PIDFILE} $SHORTNAME >&/dev/null; then + stop + sleep 3 + start + fi + ;; + *) + echo $"Usage: $whatami {start|stop|restart|condrestart|status|help}" + RETVAL=3 +esac + +exit $RETVAL + diff --git a/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in b/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in new file mode 100755 index 00000000000..e0b6b613253 --- /dev/null +++ b/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in @@ -0,0 +1,82 @@ +#!/bin/bash + +# chkconfig: 35 99 10 +# description: Cloud Agent + +# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well + +. /etc/rc.d/init.d/functions + +whatami=cloud-external-ipallocator + +# set environment variables + +SHORTNAME="$whatami" +PIDFILE=@PIDDIR@/"$whatami".pid +LOCKFILE=@LOCKDIR@/"$SHORTNAME" +LOGFILE=@AGENTLOG@ +PROGNAME="Cloud Agent" + +unset OPTIONS +[ -r @SYSCONFDIR@/sysconfig/"$SHORTNAME" ] && source @SYSCONFDIR@/sysconfig/"$SHORTNAME" +DAEMONIZE=@BINDIR@/@PACKAGE@-daemonize +PROG=@BINDIR@/@PACKAGE@-external-ipallocator.py +OPTIONS=8083 + +start() { + echo -n $"Starting $PROGNAME: " + if hostname --fqdn >/dev/null 2>&1 ; then + daemon --check=$SHORTNAME --pidfile=${PIDFILE} "$DAEMONIZE" \ + -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS + RETVAL=$? + echo + else + failure + echo + echo The host name does not resolve properly to an IP address. Cannot start "$PROGNAME". > /dev/stderr + RETVAL=9 + fi + [ $RETVAL = 0 ] && touch ${LOCKFILE} + return $RETVAL +} + +stop() { + echo -n $"Stopping $PROGNAME: " + killproc -p ${PIDFILE} $SHORTNAME # -d 10 $SHORTNAME + RETVAL=$? + echo + [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE} +} + + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status -p ${PIDFILE} $SHORTNAME + RETVAL=$? + ;; + restart) + stop + sleep 3 + start + ;; + condrestart) + if status -p ${PIDFILE} $SHORTNAME >&/dev/null; then + stop + sleep 3 + start + fi + ;; + *) + echo $"Usage: $whatami {start|stop|restart|condrestart|status|help}" + RETVAL=3 +esac + +exit $RETVAL + diff --git a/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in b/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in new file mode 100755 index 00000000000..0407f91943e --- /dev/null +++ b/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in @@ -0,0 +1,96 @@ +#!/bin/bash + +# chkconfig: 35 99 10 +# description: Cloud Agent + +# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well + +. /lib/lsb/init-functions +. /etc/default/rcS + +whatami=cloud-external-ipallocator + +# set environment variables + +SHORTNAME="$whatami" +PIDFILE=@PIDDIR@/"$whatami".pid +LOCKFILE=@LOCKDIR@/"$SHORTNAME" +LOGFILE=@AGENTLOG@ +PROGNAME="Cloud Agent" + +unset OPTIONS +[ -r @SYSCONFDIR@/default/"$SHORTNAME" ] && source @SYSCONFDIR@/default/"$SHORTNAME" +DAEMONIZE=@BINDIR@/@PACKAGE@-daemonize +PROG=@BINDIR@/@PACKAGE@-external-ipallocator.py +OPTIONS=8083 + +start() { + log_daemon_msg $"Starting $PROGNAME" "$SHORTNAME" + if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then + log_progress_msg "apparently already running" + log_end_msg 0 + exit 0 + fi + if hostname --fqdn >/dev/null 2>&1 ; then + true + else + log_failure_msg "The host name does not resolve properly to an IP address. Cannot start $PROGNAME" + log_end_msg 1 + exit 1 + fi + + if start-stop-daemon --start --quiet \ + --pidfile "$PIDFILE" \ + --exec "$DAEMONIZE" -- -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS + RETVAL=$? + then + rc=0 + sleep 1 + if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then + log_failure_msg "$PROG failed to start" + rc=1 + fi + else + rc=1 + fi + + if [ $rc -eq 0 ]; then + log_end_msg 0 + else + log_end_msg 1 + rm -f "$PIDFILE" + fi +} + +stop() { + echo -n $"Stopping $PROGNAME" "$SHORTNAME" + start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE" + log_end_msg $? + rm -f "$PIDFILE" +} + + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status_of_proc -p "$PIDFILE" "$PROG" "$SHORTNAME" + RETVAL=$? + ;; + restart) + stop + sleep 3 + start + ;; + *) + echo $"Usage: $whatami {start|stop|restart|status|help}" + RETVAL=3 +esac + +exit $RETVAL + diff --git a/python/incubation/cloud-web-ipallocator.py b/python/incubation/cloud-web-ipallocator.py new file mode 100755 index 00000000000..533acfc4eab --- /dev/null +++ b/python/incubation/cloud-web-ipallocator.py @@ -0,0 +1,138 @@ +#! /usr/bin/python +import web +import socket, struct +import cloud_utils +from cloud_utils import Command +urls = ("/ipallocator", "ipallocator") +app = web.application(urls, globals()) + +augtool = Command("augtool") +service = Command("service") +class dhcp: + _instance = None + def __init__(self): + self.availIP=[] + self.router=None + self.netmask=None + self.initialized=False + + options = augtool.match("/files/etc/dnsmasq.conf/dhcp-option").stdout.strip() + for option in options.splitlines(): + if option.find("option:router") != -1: + self.router = option.split("=")[1].strip().split(",")[1] + print self.router + + dhcp_range = augtool.get("/files/etc/dnsmasq.conf/dhcp-range").stdout.strip() + dhcp_start = dhcp_range.split("=")[1].strip().split(",")[0] + dhcp_end = dhcp_range.split("=")[1].strip().split(",")[1] + self.netmask = dhcp_range.split("=")[1].strip().split(",")[2] + print dhcp_start, dhcp_end, self.netmask + + start_ip_num = self.ipToNum(dhcp_start); + end_ip_num = self.ipToNum(dhcp_end) + print start_ip_num, end_ip_num + + for ip in range(start_ip_num, end_ip_num + 1): + self.availIP.append(ip) + print self.availIP[0], self.availIP[len(self.availIP) - 1] + + #load the ip already allocated + self.reloadAllocatedIP() + + def ipToNum(self, ip): + return struct.unpack("!I", socket.inet_aton(ip))[0] + + def numToIp(self, num): + return socket.inet_ntoa(struct.pack('!I', num)) + + def getFreeIP(self): + if len(self.availIP) > 0: + ip = self.numToIp(self.availIP[0]) + self.availIP.remove(self.availIP[0]) + return ip + else: + return None + + def getNetmask(self): + return self.netmask + + def getRouter(self): + return self.router + + def getInstance(): + if not dhcp._instance: + dhcp._instance = dhcp() + return dhcp._instance + getInstance = staticmethod(getInstance) + + def reloadAllocatedIP(self): + dhcp_hosts = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip().splitlines() + + for host in dhcp_hosts: + if host.find("dhcp-host") != -1: + allocatedIP = self.ipToNum(host.split("=")[1].strip().split(",")[1]) + if allocatedIP in self.availIP: + self.availIP.remove(allocatedIP) + + def allocateIP(self, mac): + newIP = self.getFreeIP() + dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip() + cnt = len(dhcp_host.splitlines()) + 1 + script = """set %s %s + save"""%("/files/etc/dnsmasq.conf/dhcp-host[" + str(cnt) + "]", str(mac) + "," + newIP) + augtool < script + #reset dnsmasq + service("dnsmasq", "restart", stdout=None, stderr=None) + return newIP + + def releaseIP(self, ip): + dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip() + path = None + for host in dhcp_host.splitlines(): + if host.find(ip) != -1: + path = host.split("=")[0].strip() + + if path == None: + print "Can't find " + str(ip) + " in conf file" + return None + + print path + script = """rm %s + save"""%(path) + augtool < script + + self.availIP.remove(ip) + + #reset dnsmasq + service("dnsmasq", "restart", stdout=None, stderr=None) + +class ipallocator: + def GET(self): + try: + user_data = web.input() + command = user_data.command + print "Processing: " + command + + dhcpInit = dhcp.getInstance() + + if command == "getIpAddr": + mac = user_data.mac + zone_id = user_data.dc + pod_id = user_data.pod + print mac, zone_id, pod_id + freeIP = dhcpInit.allocateIP(mac) + if not freeIP: + return "0,0,0" + print "Find an available IP: " + freeIP + + return freeIP + "," + dhcpInit.getNetmask() + "," + dhcpInit.getRouter() + elif command == "releaseIpAddr": + ip = user_data.ip + zone_id = user_data.dc + pod_id = user_data.pod + dhcpInit.releaseIP(ip) + except: + return None + +if __name__ == "__main__": + app.run() diff --git a/scripts/storage/secondary/installrtng.sh b/scripts/storage/secondary/installrtng.sh index ff801b5d536..0d15db51f19 100755 --- a/scripts/storage/secondary/installrtng.sh +++ b/scripts/storage/secondary/installrtng.sh @@ -1,14 +1,16 @@ #!/bin/bash # $Id: installrtng.sh 11251 2010-07-23 23:40:44Z abhishek $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/secondary/installrtng.sh $ usage() { - printf "Usage: %s: -m -f [-F]\n" $(basename $0) >&2 + printf "Usage: %s: -m -f [-F] [-t