cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthon...@apache.org
Subject git commit: updated refs/heads/4.3 to 0847ccf
Date Thu, 05 Dec 2013 09:21:08 GMT
Updated Branches:
  refs/heads/4.3 26020fc07 -> 0847ccfe9


XS VMmetadata platform contains virtual platform related info, CS should save platform info
in DB to migrate the VM to other Cluster

Conflicts:
	engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
	plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
	server/src/com/cloud/template/TemplateManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0847ccfe
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0847ccfe
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0847ccfe

Branch: refs/heads/4.3
Commit: 0847ccfe9778fa74851a2f65c8d63eea4a0baa96
Parents: 26020fc
Author: Anthony Xu <anthony.xu@citrix.com>
Authored: Wed Dec 4 23:54:56 2013 -0800
Committer: Anthony Xu <anthony.xu@citrix.com>
Committed: Thu Dec 5 01:17:56 2013 -0800

----------------------------------------------------------------------
 core/src/com/cloud/agent/api/StopAnswer.java    |  21 ++--
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  65 ++++------
 .../xen/resource/CitrixResourceBase.java        | 122 +++++++++----------
 .../xen/resource/XenServer610Resource.java      |  13 --
 .../xen/resource/XenServerPoolVms.java          |   4 +-
 .../com/cloud/template/TemplateManagerImpl.java |  29 ++++-
 utils/src/com/cloud/utils/StringUtils.java      |  26 ++++
 7 files changed, 139 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/core/src/com/cloud/agent/api/StopAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/StopAnswer.java b/core/src/com/cloud/agent/api/StopAnswer.java
index 614835e..e417e0b 100755
--- a/core/src/com/cloud/agent/api/StopAnswer.java
+++ b/core/src/com/cloud/agent/api/StopAnswer.java
@@ -18,36 +18,29 @@ package com.cloud.agent.api;
 
 public class StopAnswer extends RebootAnswer {
 
-    private String hypervisortoolsversion;
-    Integer timeOffset;
+    private String platform;
 
     protected StopAnswer() {
     }
 
-    public StopAnswer(StopCommand cmd, String details, String hypervisortoolsversion, Integer
timeOffset, boolean success) {
+    public StopAnswer(StopCommand cmd, String details, String platform, boolean success)
{
         super(cmd,  details, success);
-        this.hypervisortoolsversion = hypervisortoolsversion;
-        this.timeOffset = timeOffset;
+        this.platform = platform;
     }
 
     public StopAnswer(StopCommand cmd, String details, boolean success) {
         super(cmd,  details, success);
-        this.hypervisortoolsversion = null;
-        this.timeOffset = null;
+        this.platform = null;
     }
 
 
     public StopAnswer(StopCommand cmd, Exception e) {
         super(cmd, e);
-        this.hypervisortoolsversion = null;
-        this.timeOffset = null;
+        this.platform = null;
     }
 
-    public String getHypervisorToolsVersion() {
-        return hypervisortoolsversion;
+    public String getPlatform() {
+        return platform;
     }
 
-    public Integer getTimeOffset() {
-        return timeOffset;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 2bdec95..f2a2102 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -957,14 +957,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                             }
 
                             StopCommand cmd = new StopCommand(vm, getExecuteInSequence());
-                            StopAnswer answer = (StopAnswer)_agentMgr.easySend(destHostId,
cmd);
+                            StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId,
cmd);
                             if ( answer != null ) {
-                                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                                if (hypervisortoolsversion != null) {
-                                    if (vm.getType() == VirtualMachine.Type.User) {
+                                if (vm.getType() == VirtualMachine.Type.User) {
+                                    String platform = answer.getPlatform();
+                                    if (platform != null) {
                                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                                         _userVmDao.loadDetails(userVm);
-                                        userVm.setDetail("hypervisortoolsversion",  hypervisortoolsversion);
+                                        userVm.setDetail("platform",  platform);
                                         _userVmDao.saveDetails(userVm);
                                     }
                                 }
@@ -1126,12 +1126,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         try {
             StopAnswer answer = (StopAnswer) _agentMgr.send(vm.getHostId(), stop);
             if ( answer != null ) {
-                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                if (hypervisortoolsversion != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
+                if (vm.getType() == VirtualMachine.Type.User) {
+                    String platform = answer.getPlatform();
+                    if (platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("hypervisortoolsversion",  hypervisortoolsversion);
+                        userVm.setDetail("platform",  platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1364,12 +1364,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
 
             if ( answer != null ) {
-                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                if (hypervisortoolsversion != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
+                if (vm.getType() == VirtualMachine.Type.User) {
+                    String platform = answer.getPlatform();
+                    if ( platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("hypervisortoolsversion",  hypervisortoolsversion);
+                        userVm.setDetail("platform",  platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1377,16 +1377,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             stopped = answer.getResult();
             if (!stopped) {
                 throw new CloudRuntimeException("Unable to stop the virtual machine due to
" + answer.getDetails());
-            } else {
-                Integer timeoffset = answer.getTimeOffset();
-                if (timeoffset != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
-                        UserVmVO userVm = _userVmDao.findById(vm.getId());
-                        _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("timeoffset", timeoffset.toString());
-                        _userVmDao.saveDetails(userVm);
-                    }
-                }
             }
             vmGuru.finalizeStop(profile, answer);
 
@@ -2567,21 +2557,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                     hostDesc + " due to storage failure",
                     "Virtual Machine " + vm.getInstanceName() + " (id: " + vm.getId() + ")
running on host [" + vm.getHostId() + "] stopped due to storage failure.");
         }
-        // track hypervsion tools version
-        if( info.hvtoolsversion != null && !info.hvtoolsversion.isEmpty() ) {
+        // track platform info
+        if( info.platform != null && !info.platform.isEmpty() ) {
             if (vm.getType() == VirtualMachine.Type.User) {
                 UserVmVO userVm = _userVmDao.findById(vm.getId());
                 _userVmDao.loadDetails(userVm);
-                userVm.setDetail("hypervisortoolsversion",  info.hvtoolsversion);
-                _userVmDao.saveDetails(userVm);
-            }
-        }
-        // track hypervsion tools version
-        if( info.hvtoolsversion != null && !info.hvtoolsversion.isEmpty() ) {
-            if (vm.getType() == VirtualMachine.Type.User) {
-                UserVmVO userVm = _userVmDao.findById(vm.getId());
-                _userVmDao.loadDetails(userVm);
-                userVm.setDetail("hypervisortoolsversion",  info.hvtoolsversion);
+                userVm.setDetail("platform",  info.platform);
                 _userVmDao.saveDetails(userVm);
             }
         }
@@ -2967,18 +2948,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         public String name;
         public State state;
         public String hostUuid;
-        public String hvtoolsversion;
         public VMInstanceVO vm;
+        public String platform;
 
 
         @SuppressWarnings("unchecked")
-        public AgentVmInfo(String name, VMInstanceVO vm, State state, String host, String
hvtoolsversion) {
+        public AgentVmInfo(String name, VMInstanceVO vm, State state, String host, String
platform) {
             this.name = name;
             this.state = state;
             this.vm = vm;
             this.hostUuid = host;
-            this.hvtoolsversion= hvtoolsversion;
-
+            this.platform = platform;
+            
         }
 
         public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
@@ -2992,9 +2973,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         public String getHostUuid() {
             return hostUuid;
         }
-
-        public String getHvtoolsversion() {
-            return hvtoolsversion;
+        
+        public String getPlatform() {
+            return platform;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 7916447..86e2176 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -187,6 +187,7 @@ import com.cloud.utils.S3Utils;
 import com.cloud.utils.StringUtils;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.StringUtils;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.PowerState;
@@ -1296,23 +1297,6 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             vmr.VCPUsMax = 32L;
         }
 
-        Map<String, String> details = vmSpec.getDetails();
-        if ( details != null ) {
-            String timeoffset = details.get("timeoffset");
-            if (timeoffset != null) {
-                Map<String, String> platform = vmr.platform;
-                platform.put("timeoffset", timeoffset);
-                vmr.platform = platform;
-            }
-
-            String coresPerSocket = details.get("cpu.corespersocket");
-            if (coresPerSocket != null) {
-                Map<String, String> platform = vmr.platform;
-                platform.put("cores-per-socket", coresPerSocket);
-                vmr.platform = platform;
-            }            
-        }
-
         vmr.VCPUsAtStartup = (long) vmSpec.getCpus();
         vmr.consoles.clear();
 
@@ -1397,9 +1381,40 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
  
     
     protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws
Exception {
+
+        Map<String, String> details = vmSpec.getDetails();
+        if ( details != null ) {
+            String platformstring = details.get("platform");
+            if (platformstring != null && !platformstring.isEmpty() ) {
+                Map<String, String> platform = StringUtils.stringToMap(platformstring);
+                vm.setPlatform(conn, platform);
+            } else {
+                String timeoffset = details.get("timeoffset");
+                if (timeoffset != null) {
+                    Map<String, String> platform = vm.getPlatform(conn);
+                    platform.put("timeoffset", timeoffset);
+                    vm.setPlatform(conn, platform);
+                }
+                String coresPerSocket = details.get("cpu.corespersocket");
+                if (coresPerSocket != null) {
+                    Map<String, String> platform = vm.getPlatform(conn);
+                    platform.put("cores-per-socket", coresPerSocket);
+                    vm.setPlatform(conn, platform);
+                }
+
+                String xentoolsversion = details.get("hypervisortoolsversion");
+                if ( xentoolsversion == null || !xentoolsversion.equalsIgnoreCase("xenserver61")
) {
+                     Map<String, String> platform = vm.getPlatform(conn);
+                     platform.remove("device_id");
+                     vm.setPlatform(conn, platform);
+                 }
+
+            }
+        }
     }
 
 
+
     protected String handleVmStartFailure(Connection conn, String vmName, VM vm, String message,
Throwable th) {
         String msg = "Unable to start " + vmName + " due to " + message;
         s_logger.warn(msg, th);
@@ -3078,7 +3093,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 s_logger.trace("VM " + record.nameLabel + ": powerstate = " + ps + "; vm
state=" + state.toString());
             }
             Host host = record.residentOn;
-            String xstoolsversion = getVMXenToolsVersion(record.platform);
+            String platformstring = StringUtils.mapToString(record.platform);
             String host_uuid = null;
             if( ! isRefNull(host) ) {
                 try {
@@ -3090,7 +3105,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 } catch (XmlRpcException e) {
                     s_logger.error("Failed to get host uuid for host " + host.toWireString(),
e);
                 }
-                vmStates.put(record.nameLabel, new Ternary<String, State, String>(host_uuid,
state, xstoolsversion));
+                vmStates.put(record.nameLabel, new Ternary<String, State, String>(host_uuid,
state, platformstring));
             }
         }
 
@@ -4077,6 +4092,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     @Override
     public StopAnswer execute(StopCommand cmd) {
         String vmName = cmd.getVmName();
+        String platformstring = null;
         try {
             Connection conn = getConnection();
             Set<VM> vms = VM.getByNameLabel(conn, vmName);
@@ -4106,7 +4122,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             }
             for (VM vm : vms) {
                 VM.Record vmr = vm.getRecord(conn);
-
+                platformstring = StringUtils.mapToString(vmr.platform);
                 if (vmr.isControlDomain) {
                     String msg = "Tring to Shutdown control domain";
                     s_logger.warn(msg);
@@ -4116,7 +4132,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 if (vmr.powerState == VmPowerState.RUNNING && !isRefNull(vmr.residentOn)
&& !vmr.residentOn.getUuid(conn).equals(_host.uuid)) {
                     String msg = "Stop Vm " + vmName + " failed due to this vm is not running
on this host: " + _host.uuid + " but host:" + vmr.residentOn.getUuid(conn);
                     s_logger.warn(msg);
-                    return new StopAnswer(cmd, msg, false);
+                    return new StopAnswer(cmd, msg, platformstring, false);
                 }
 
                 State state = s_vms.getState(_cluster, vmName);
@@ -4145,24 +4161,13 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 } catch (Exception e) {
                     String msg = "Catch exception " + e.getClass().getName() + " when stop
VM:" + cmd.getVmName() + " due to " + e.toString();
                     s_logger.debug(msg);
-                    return new StopAnswer(cmd, msg, false);
+                    return new StopAnswer(cmd, msg, platformstring, false);
                 } finally {
 
                     try {
                         if (vm.getPowerState(conn) == VmPowerState.HALTED) {
                             disconnectManagedVolumes(conn, vm);
 
-                            Map<String, String> platform = vm.getPlatform(conn);
-                            Integer timeoffset = null;
-                            try {
-                                if (platform.containsKey("timeoffset")) {
-                                    timeoffset = Integer.valueOf(platform.get("timeoffset"));
-                                }
-                            } catch (NumberFormatException e) {
-                                s_logger.error("Error while reading the platform:timeoffset
field of the instance", e);
-                            }
-                            String xentoolsversion = getVMXenToolsVersion(platform);
-
                             Set<VIF> vifs = vm.getVIFs(conn);
                             List<Network> networks = new ArrayList<Network>();
                             for (VIF vif : vifs) {
@@ -4183,11 +4188,8 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                                     // network might be destroyed by other host
                                 }
                             }
-                            return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed",
xentoolsversion, timeoffset, true);
+                            return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed",
platformstring ,true);
                         }
-                    } catch (XenAPIException e) {
-                        String msg = "VM destroy failed in Stop " + vmName + " Command due
to " + e.toString();
-                        s_logger.warn(msg, e);
                     } catch (Exception e) {
                         String msg = "VM destroy failed in Stop " + vmName + " Command due
to " + e.getMessage();
                         s_logger.warn(msg, e);
@@ -4200,19 +4202,12 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 }
             }
 
-        } catch (XenAPIException e) {
+        } catch (Exception e) {
             String msg = "Stop Vm " + vmName + " fail due to " + e.toString();
             s_logger.warn(msg, e);
-            return new StopAnswer(cmd, msg, false);
-        } catch (XmlRpcException e) {
-            String msg = "Stop Vm " + vmName + " fail due to " + e.getMessage();
-            s_logger.warn(msg, e);
-            return new StopAnswer(cmd, msg, false);
-        } catch (Exception e) {
-            s_logger.warn("Unable to stop " + vmName + " due to ",  e);
-            return new StopAnswer(cmd, e);
+            return new StopAnswer(cmd, msg, platformstring, false);
         }
-        return new StopAnswer(cmd, "Stop VM failed", false);
+        return new StopAnswer(cmd, "Stop VM failed", platformstring, false);
     }
 
    
@@ -8278,13 +8273,12 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 String vm_name = record.nameLabel;
                 VmPowerState ps = record.powerState;
                 final State state = convertToState(ps);
-                String xstoolsversion = getVMXenToolsVersion(record.platform);
                 Host host = record.residentOn;
                 String host_uuid = null;
                 if( ! isRefNull(host) ) {
                     host_uuid = host.getUuid(conn);
                     synchronized (_cluster.intern()) {
-                        s_vms.put(_cluster, host_uuid, vm_name, state, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm_name, state, null);
                     }
                 }
                 if (s_logger.isTraceEnabled()) {
@@ -8315,19 +8309,19 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
 
             for (final Map.Entry<String, Ternary<String, State, String>> entry
: newStates.entrySet()) {
                 final String vm = entry.getKey();
-                String xstoolsversion = entry.getValue().third();
+                String platform = entry.getValue().third();
                 State newState = entry.getValue().second();
                 String host_uuid = entry.getValue().first();
                 final Ternary<String, State, String> oldState = oldStates.remove(vm);
                 
-                // check if xstoolsversion changed
-                if (xstoolsversion != null && oldState != null){
-                    if (xstoolsversion != oldState.third() && newState != State.Stopped
&& newState != State.Stopping){
-                        s_logger.warn("Detecting a change in xstoolsversion for " + vm);
-                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, xstoolsversion));
+                // check if platform changed
+                if (platform != null && oldState != null){
+                    if (!platform.equals(oldState.third()) && newState != State.Stopped
&& newState != State.Stopping){
+                        s_logger.warn("Detecting a change in platform for " + vm);
+                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, platform));
 
                         s_logger.debug("11. The VM " + vm + " is in " + newState + " state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                         continue;
                     }
                 }
@@ -8335,10 +8329,10 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 if (host_uuid != null && oldState != null){
                     if (!host_uuid.equals(oldState.first()) && newState != State.Stopped
&& newState != State.Stopping){
                         s_logger.warn("Detecting a change in host for " + vm);
-                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, null));
+                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, platform));
 
                         s_logger.debug("11. The VM " + vm + " is in " + newState + " state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                         continue;
                     }
                 }
@@ -8357,31 +8351,31 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                     continue;
                 }
                 if (oldState == null) {
-                    s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                    s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     s_logger.warn("Detecting a new state but couldn't find a old state so
adding it to the changes: " + vm);
-                    changes.put(vm, new Ternary<String, State, String>(host_uuid, newState,
null));
+                    changes.put(vm, new Ternary<String, State, String>(host_uuid, newState,
platform));
                 } else if (oldState.second() == State.Starting) {
                     if (newState == State.Running) {
                         s_logger.debug("12. The VM " + vm + " is in " + State.Running + "
state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     } else if (newState == State.Stopped) {
                         s_logger.warn("Ignoring vm " + vm + " because of a lag in starting
the vm.");
                     }
                 } else if (oldState.second() == State.Migrating) {
                     if (newState == State.Running) {
                         s_logger.debug("Detected that an migrating VM is now running: " +
vm);
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     }
                 } else if (oldState.second() == State.Stopping) {
                     if (newState == State.Stopped) {
                         s_logger.debug("13. The VM " + vm + " is in " + State.Stopped + "
state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     } else if (newState == State.Running) {
                         s_logger.warn("Ignoring vm " + vm + " because of a lag in stopping
the vm. ");
                     }
                 } else if (oldState.second() != newState) {
                     s_logger.debug("14. The VM " + vm + " is in " + newState + " state was
" + oldState.second());
-                    s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                    s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     if (newState == State.Stopped) {
                         /*
                          * if (s_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has
been killed for storage. ");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
index 2603922..69c45f0 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
@@ -462,17 +462,4 @@ public class XenServer610Resource extends XenServer56FP1Resource {
         return "xenserver56";
     }
     
-    @Override
-    protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws
Exception {
-        Map<String, String> details = vmSpec.getDetails();
-        if ( details!= null ) {
-            String xentoolsversion = details.get("hypervisortoolsversion");
-            if ( xentoolsversion == null || !xentoolsversion.equalsIgnoreCase("xenserver61")
) {
-                 Map<String, String> platform = vm.getPlatform(conn);
-                 platform.remove("device_id");
-                 vm.setPlatform(conn, platform);
-             }
-         }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
index f22fb28..694353c 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
@@ -52,9 +52,9 @@ public class XenServerPoolVms {
     }
     
 
-    public void put(String clusterId, String hostUuid, String name, State state, String xstoolsversion){
+    public void put(String clusterId, String hostUuid, String name, State state, String platform){
         HashMap<String, Ternary<String, State, String>> vms= getClusterVmState(clusterId);
-        vms.put(name, new Ternary<String, State, String>(hostUuid, state, xstoolsversion));
+        vms.put(name, new Ternary<String, State, String>(hostUuid, state, platform));
     }
     
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index cbcd611..25aace9 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -185,6 +186,7 @@ import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = { TemplateManager.class, TemplateApiService.class })
@@ -200,6 +202,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     @Inject
     VMTemplateZoneDao _tmpltZoneDao;
     @Inject
+    protected UserVmDetailsDao _vmDetailsDao;
+    @Inject
     protected VMTemplateDetailsDao _templateDetailsDao;
     @Inject
     VMInstanceDao _vmInstanceDao;
@@ -1636,13 +1640,26 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         VMTemplateVO template = _tmpltDao.persist(privateTemplate);
         // Increment the number of templates
         if (template != null) {
-            Map<String, String> detailsStr = cmd.getDetails();
-            if (detailsStr != null) {
-                List<VMTemplateDetailVO> details = new ArrayList<VMTemplateDetailVO>();
-                for (String key : detailsStr.keySet()) {
-                    details.add(new VMTemplateDetailVO(template.getId(), key, detailsStr.get(key)));
+            Map<String, String> details = new HashMap<String, String>();
+            if ( volume != null ) {
+                Long vmId = volume.getInstanceId();
+                if ( vmId != null ) {
+	            UserVmVO userVm = _userVmDao.findById(vmId);
+                    if (userVm == null) {
+                        _userVmDao.loadDetails(userVm);
+                        details.putAll(userVm.getDetails());
+                    }
+                }
+            }
+            if(cmd.getDetails() != null) {
+                details.putAll(cmd.getDetails());
+            }
+            if( !details.isEmpty()) {
+                List<VMTemplateDetailVO> tdetails = new ArrayList<VMTemplateDetailVO>();
+                for (String key : details.keySet()) {
+                    tdetails.add(new VMTemplateDetailVO(template.getId(), key, details.get(key)));
                 }
-                _templateDetailsDao.saveDetails(details);
+                this._templateDetailsDao.saveDetails(tdetails);
             }
 
             _resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.template);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0847ccfe/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index 7aafff1..914d218 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -19,6 +19,9 @@ package com.cloud.utils;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
 import java.util.regex.Pattern;
 
 import org.owasp.esapi.StringUtilities;
@@ -190,4 +193,27 @@ public class StringUtils {
         int found = searchable.lastIndexOf(separator);
         return found > 0 ? found :  end - start;
     }
+
+
+    public static Map<String, String> stringToMap(String s){
+        Map<String, String> map=new HashMap<String, String>();
+        String[] elements = s.split(";");
+        for (String parts: elements) {
+            String[] keyValue = parts.split(":");
+            map.put(keyValue[0], keyValue[1]);
+        }
+        return map;
+    }
+
+
+    public static String mapToString(Map<String, String> map){
+        String s = "";
+        for (Map.Entry<String, String> entry: map.entrySet()) {
+            s += entry.getKey() + ":" + entry.getValue() +";";
+        }
+        if (s.length() > 0) {
+            s = s.substring(0, s.length()-1);
+        }
+        return s;
+    }
 }


Mime
View raw message