diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index 82dbcf7cd22..e877d30e1c0 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -1635,6 +1635,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"); 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/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/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index deac42cbc3e..cb8d096caa2 100644 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -134,7 +134,7 @@ public enum Config { CPUOverprovisioningFactor("Advanced", ManagementServer.class, String.class, "cpu.overprovisioning.factor", "1", "Used for CPU overprovisioning calculation; available CPU will be (actualCpuCapacity * cpu.overprovisioning.factor)", null), NetworkType("Advanced", ManagementServer.class, String.class, "network.type", "vlan", "The type of network that this deployment will use.", "vlan,direct"), LinkLocalIpNums("Advanced", ManagementServer.class, Integer.class, "linkLocalIp.nums", "10", "The number of link local ip that needed by domR(in power of 2)", null), - HypervisorDefaultType("Advanced", ManagementServer.class, String.class, "hypervisor.type", HypervisorType.KVM.toString(), "The type of hypervisor that this deployment will use.", "kvm|xenserver"), + HypervisorDefaultType("Advanced", ManagementServer.class, String.class, "hypervisor.type", HypervisorType.KVM.toString(), "The type of hypervisor that this deployment will use.", "kvm,xenserver"), HypervisorList("Advanced", ManagementServer.class, String.class, "hypervisor.list", HypervisorType.KVM + "," + HypervisorType.XenServer + "," + HypervisorType.VmWare, "The list of hypervisors that this deployment will use.", "kvm,xenserver,vmware"), ManagementHostIPAdr("Advanced", ManagementServer.class, String.class, "host", "localhost", "The ip address of management server", null), UseSecondaryStorageVm("Advanced", ManagementServer.class, Boolean.class, "secondary.storage.vm", "false", "Deploys a VM per zone to manage secondary storage if true, otherwise secondary storage is mounted on management server", null), diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageDiscoverer.java b/server/src/com/cloud/storage/secondary/SecondaryStorageDiscoverer.java index 6aa0138ae50..c0883c2d0ab 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageDiscoverer.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageDiscoverer.java @@ -196,6 +196,7 @@ public class SecondaryStorageDiscoverer extends DiscovererBase implements Discov Map> srs = new HashMap>(); DummySecondaryStorageResource storage = new DummySecondaryStorageResource(_useServiceVM); + Map details = new HashMap(); details.put("mount.path", uri.toString());