Add support for XS6.2 Fox hotfix

This commit is contained in:
Anthony Xu 2014-03-28 16:45:16 -07:00
parent d4d5cabb50
commit 58b2b6b9e1
6 changed files with 143 additions and 31 deletions

View File

@ -29,7 +29,6 @@ import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.host.HostInfo;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -42,6 +41,7 @@ import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
@ -148,8 +148,8 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
host = hostDao.findById(ep.getId());
hostDao.loadDetails(host);
boolean snapshotHotFix = Boolean.parseBoolean(host.getDetail(HostInfo.XS620_SNAPSHOT_HOTFIX));
if (snapshotHotFix) {
String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XSHasFixFox);
if (snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase("true")) {
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(ep.getId()));
}
}

View File

@ -74,6 +74,7 @@ import com.cloud.hypervisor.xen.resource.XenServer610Resource;
import com.cloud.hypervisor.xen.resource.XenServer620Resource;
import com.cloud.hypervisor.xen.resource.XenServerConnectionPool;
import com.cloud.hypervisor.xen.resource.Xenserver625Resource;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import com.cloud.resource.Discoverer;
import com.cloud.resource.DiscovererBase;
import com.cloud.resource.ResourceStateAdapter;
@ -93,8 +94,12 @@ import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.Pool;
import com.xensource.xenapi.Session;
import com.xensource.xenapi.PoolPatch;
import com.xensource.xenapi.HostPatch;
import com.xensource.xenapi.Types.SessionAuthenticationFailed;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.Types.UuidInvalid;
@Local(value = Discoverer.class)
public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
@ -143,11 +148,36 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
}
}
protected boolean xenserverHotFixEnabled() {
//temporary fix, we should call xenserver api to get the hot fix is enabled or not.
return Boolean.parseBoolean(_configDao.getValue(Config.XenServerHotFix.name()));
protected boolean poolHasHotFix(Connection conn, String hostIp) {
try {
Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
Host.Record re = entry.getValue();
if (!re.address.equalsIgnoreCase(hostIp)){
continue;
}
Set<HostPatch> patches = re.patches;
PoolPatch poolPatch = PoolPatch.getByUuid(conn, XenserverConfigs.FixFoxUuid);
for(HostPatch patch : patches) {
PoolPatch pp = patch.getPoolPatch(conn);
if (pp.equals(poolPatch) && patch.getApplied(conn)) {
s_logger.debug("host " + hostIp + " does have Fox Hotfix");
return true;
}
}
}
return false;
} catch (UuidInvalid e) {
s_logger.debug("host " + hostIp + " doesn't have Fox Hotfix");
} catch (Exception e) {
s_logger.debug("can't get patches information, consider it doesn't have Fox Hotfix");
}
return false;
}
@Override
public Map<? extends ServerResource, Map<String, String>>
find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
@ -195,6 +225,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
Pool.Record pr = pool.getRecord(conn);
String poolUuid = pr.uuid;
Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
boolean xsHotFixFoxEnabled = poolHasHotFix(conn, hostIp);
/*set cluster hypervisor type to xenserver*/
ClusterVO clu = _clusterDao.findById(clusterId);
@ -260,8 +291,6 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
hostOS = record.softwareVersion.get("platform_name");
}
//Boolean xs620hotfix = record.tags.contains(xs620snapshothotfix);
Boolean xs620hotfix = xenserverHotFixEnabled();
String hostOSVer = prodVersion;
String hostKernelVer = record.softwareVersion.get("linux");
@ -270,7 +299,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
continue;
}
CitrixResourceBase resource = createServerResource(dcId, podId, record);
CitrixResourceBase resource = createServerResource(dcId, podId, record, xsHotFixFoxEnabled);
s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion);
Map<String, String> details = new HashMap<String, String>();
@ -291,7 +320,6 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
details.put(HostInfo.HOST_OS_VERSION, hostOSVer);
details.put(HostInfo.HOST_OS_KERNEL_VERSION, hostKernelVer);
details.put(HostInfo.HYPERVISOR_VERSION, xenVersion);
details.put(HostInfo.XS620_SNAPSHOT_HOTFIX, xs620hotfix.toString());
String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.XenServer);
String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(dcId, HypervisorType.XenServer);
@ -364,7 +392,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
}
protected CitrixResourceBase createServerResource(long dcId, Long podId, Host.Record record) {
protected CitrixResourceBase createServerResource(long dcId, Long podId, Host.Record record, boolean hotfix) {
String prodBrand = record.softwareVersion.get("product_brand");
if (prodBrand == null) {
prodBrand = record.softwareVersion.get("platform_name").trim();
@ -394,14 +422,6 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.0"))
return new XenServer610Resource();
else if (prodBrand.equals("XenServer") && prodVersion.equals("6.2.0")) {
/*
Set<String> tags =record.tags;
if (tags.contains(xs620snapshothotfix)) {
return new Xenserver625Resource();
} else {
return new XenServer620Resource();
}*/
boolean hotfix = xenserverHotFixEnabled();
if (hotfix) {
return new Xenserver625Resource();
} else {

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.hypervisor.xen.resource;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AttachIsoCommand;
@ -185,6 +186,8 @@ import com.xensource.xenapi.GPUGroup;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.HostCpu;
import com.xensource.xenapi.HostMetrics;
import com.xensource.xenapi.HostPatch;
import com.xensource.xenapi.PoolPatch;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.PGPU;
@ -852,7 +855,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
}
private String revertToSnapshot(Connection conn, VM vmSnapshot, String vmName, String oldVmUuid, Boolean snapshotMemory, String hostUUID) throws XenAPIException,
protected String revertToSnapshot(Connection conn, VM vmSnapshot, String vmName, String oldVmUuid, Boolean snapshotMemory, String hostUUID) throws XenAPIException,
XmlRpcException {
String results =
@ -5600,6 +5603,25 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return ConnPool.connect(_host.uuid, _host.pool, _host.ip, _username, _password, _wait);
}
protected boolean hostHasFixFox(Connection conn) {
try {
Host host = Host.getByUuid(conn, _host.uuid);
Host.Record re = host.getRecord(conn);
Set<HostPatch> patches = re.patches;
PoolPatch poolPatch = PoolPatch.getByUuid(conn, XenserverConfigs.FixFoxUuid);
for(HostPatch patch : patches) {
PoolPatch pp = patch.getPoolPatch(conn);
if (pp.equals(poolPatch) && patch.getApplied(conn)) {
return true;
}
}
} catch (Exception e) {
s_logger.debug("can't get patches information", e);
}
return false;
}
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
final StringBuilder caps = new StringBuilder();
try {
@ -5618,6 +5640,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
details.put("product_brand", productBrand);
details.put("product_version", _host.productVersion);
Boolean hasFixFox = hostHasFixFox(conn);
details.put(XenserverConfigs.XSHasFixFox, hasFixFox.toString());
if (hr.softwareVersion.get("product_version_text_short") != null) {
details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));

View File

@ -21,22 +21,24 @@ package com.cloud.hypervisor.xen.resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.VM;
import org.apache.cloudstack.hypervisor.xenserver.XenServerResourceNewBase;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.resource.ServerResource;
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
import com.cloud.storage.resource.StorageSubsystemCommandHandlerBase;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SSHCmdHelper;
@Local(value=ServerResource.class)
public class Xenserver625Resource extends XenServerResourceNewBase {
@ -46,13 +48,6 @@ public class Xenserver625Resource extends XenServerResourceNewBase {
super();
}
@Override
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
super.fillHostInfo(conn, cmd);
Map<String, String> details = cmd.getHostDetails();
details.put("Xenserer620HotFix", "Xenserver-Vdi-Copy-HotFix");
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer625GuestOsType(stdType, bootFromCD);
@ -111,5 +106,55 @@ public class Xenserver625Resource extends XenServerResourceNewBase {
}
@Override
protected boolean setupServer(Connection conn) {
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.ip, 22);
try {
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
throw new CloudRuntimeException("Unable to authenticate");
}
}
String cmd = "rm -f /opt/xensource/sm/hostvmstats.py " +
"/opt/xensource/bin/copy_vhd_to_secondarystorage.sh " +
"/opt/xensource/bin/copy_vhd_from_secondarystorage.sh " +
"/opt/xensource/bin/create_privatetemplate_from_snapshot.sh " +
"/opt/xensource/bin/vhd-util " +
"/opt/cloud/bin/copy_vhd_to_secondarystorage.sh " +
"/opt/cloud/bin/copy_vhd_from_secondarystorage.sh " +
"/opt/cloud/bin/create_privatetemplate_from_snapshot.sh " +
"/opt/cloud/bin/vhd-util";
SSHCmdHelper.sshExecuteCmd(sshConnection, cmd);
} catch (Exception e) {
s_logger.debug("Catch exception " + e.toString(), e);
} finally {
sshConnection.close();
}
return super.setupServer(conn);
}
@Override
protected String revertToSnapshot(Connection conn, VM vmSnapshot,
String vmName, String oldVmUuid, Boolean snapshotMemory, String hostUUID)
throws Types.XenAPIException, XmlRpcException {
String results = callHostPluginAsync(conn, "cloud-plugin-storage",
"revert_memory_snapshot", 10 * 60 * 1000, "snapshotUUID",
vmSnapshot.getUuid(conn), "vmName", vmName, "oldVmUuid",
oldVmUuid, "snapshotMemory", snapshotMemory.toString(), "hostUUID", hostUUID);
String errMsg = null;
if (results == null || results.isEmpty()) {
errMsg = "revert_memory_snapshot return null";
} else {
if (results.equals("0")) {
return results;
} else {
errMsg = "revert_memory_snapshot exception";
}
}
s_logger.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
}

View File

@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.hypervisor.xenserver;
public final class XenserverConfigs {
public static final String XSHasFixFox = "xs_has_fixfox";
public static final String FixFoxUuid = "996dd2e7-ad95-49cc-a0be-2c9adc4dfb0b";
}

View File

@ -49,7 +49,6 @@ setup_heartbeat_file.sh=..,0755,/opt/cloud/bin
check_heartbeat.sh=..,0755,/opt/cloud/bin
xenheartbeat.sh=..,0755,/opt/cloud/bin
launch_hb.sh=..,0755,/opt/cloud/bin
vhd-util=..,0755,/opt/cloud/bin
upgrade_snapshot.sh=..,0755,/opt/cloud/bin
cloud-clean-vlan.sh=..,0755,/opt/cloud/bin
cloud-prepare-upgrade.sh=..,0755,/opt/cloud/bin