cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From frankzh...@apache.org
Subject [1/2] git commit: CloudStack CLOUDSTACK-723 Enhanced baremetal servers support on Cisco UCS
Date Tue, 29 Jan 2013 00:26:00 GMT
CloudStack CLOUDSTACK-723
Enhanced baremetal servers support on Cisco UCS


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

Branch: refs/heads/ucs
Commit: 997e9fb7b0dec0eaec5cae3e7f8e75e41dc55ce4
Parents: 301b0b9
Author: frank <frank.zhang@citrix.com>
Authored: Mon Jan 28 16:29:54 2013 -0800
Committer: frank <frank.zhang@citrix.com>
Committed: Mon Jan 28 16:29:54 2013 -0800

----------------------------------------------------------------------
 .../ucs/src/com/cloud/ucs/manager/UcsCommands.java |   39 ++++++++
 .../src/com/cloud/ucs/manager/UcsManagerImpl.java  |   74 ++++++++++++---
 .../src/com/cloud/ucs/structure/ComputeBlade.java  |    3 +
 utils/src/com/cloud/utils/xmlobject/XmlObject.java |   10 --
 4 files changed, 102 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/997e9fb7/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
index 32c017d..b6f22c7 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
@@ -41,4 +41,43 @@ public class UcsCommands {
         cmd.putElement("dn", dn);
         return cmd.toString();
     }
+    
+    public static String associateProfileToBlade(String cookie, String profileDn, String
bladeDn) {
+        XmlObject cmd = new XmlObject("configConfMos").putElement("inHierarchical", "true").putElement(
+                "inConfigs", new XmlObject("inConfigs").putElement(
+                        "pair", new XmlObject("pair").putElement("key", profileDn).putElement(
+                                "lsServer", new XmlObject("lsServer")
+                                .putElement("agentPolicyName", "")
+                                .putElement("biosProfileName", "")
+                                .putElement("bootPolicyName", "")
+                                .putElement("descr", "")
+                                .putElement("dn", profileDn)
+                                .putElement("dynamicConPolicyName", "")
+                                .putElement("extIPState", "none")
+                                .putElement("hostFwPolicyName", "")
+                                .putElement("identPoolName", "")
+                                .putElement("localDiskPolicyName", "")
+                                .putElement("maintPolicyName", "")
+                                .putElement("mgmtAccessPolicyName", "")
+                                .putElement("mgmtFwPolicyName", "")
+                                .putElement("powerPolicyName", "")
+                                .putElement("scrubPolicyName", "")
+                                .putElement("solPolicyName", "")
+                                .putElement("srcTemplName", "")
+                                .putElement("statsPolicyName", "default")
+                                .putElement("status", "")
+                                .putElement("usrLbl", "")
+                                .putElement("", "")
+                                .putElement("vconProfileName", "")
+                                .putElement("lsBinding", new XmlObject("lsBinding")
+                                            .putElement("pnDn", bladeDn)
+                                            .putElement("restrictMigration", "no")
+                                            .putElement("rn", "pn")
+                                        )
+                                )
+                        )
+                );
+        
+        return cmd.dump();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/997e9fb7/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
index d19e535..c82c8b4 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
@@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.ClusterResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.dao.ClusterDao;
@@ -30,6 +31,8 @@ import com.cloud.host.HostVO;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.org.Cluster;
 import com.cloud.resource.ResourceService;
+import com.cloud.ucs.database.UcsBladeDao;
+import com.cloud.ucs.database.UcsBladeVO;
 import com.cloud.ucs.database.UcsManagerDao;
 import com.cloud.ucs.database.UcsManagerVO;
 import com.cloud.ucs.structure.ComputeBlade;
@@ -45,6 +48,7 @@ import com.cloud.utils.xmlobject.XmlObject;
 import com.cloud.utils.xmlobject.XmlObjectParser;
 
 @Local(value = { UcsManager.class })
+@Component
 public class UcsManagerImpl implements UcsManager {
     public static final Logger s_logger = Logger.getLogger(UcsManagerImpl.class);
 
@@ -56,6 +60,8 @@ public class UcsManagerImpl implements UcsManager {
     private ClusterDao clusterDao;
     @Inject
     private ClusterDetailsDao clusterDetailsDao;
+    @Inject
+    private UcsBladeDao bladeDao;
 
     private Map<Long, String> cookies = new HashMap<Long, String>();
 
@@ -79,6 +85,17 @@ public class UcsManagerImpl implements UcsManager {
         return "UcsManager";
     }
 
+    private void discoverBlades(UcsManagerVO ucsMgrVo) {
+        List<ComputeBlade> blades = listBlades(ucsMgrVo.getId());
+        for (ComputeBlade b : blades) {
+            UcsBladeVO vo = new UcsBladeVO();
+            vo.setDn(b.getDn());
+            vo.setUcsManagerId(ucsMgrVo.getId());
+            vo.setUuid(UUID.randomUUID().toString());
+            bladeDao.persist(vo);
+        }
+    }
+    
     @Override
     @DB
     public AddUcsManagerResponse addUcsManager(AddUcsManagerCmd cmd) {
@@ -99,18 +116,12 @@ public class UcsManagerImpl implements UcsManager {
         rsp.setName(vo.getName());
         rsp.setUrl(vo.getUrl());
         rsp.setZoneId(String.valueOf(vo.getZoneId()));
+        
+        discoverBlades(vo);
+        
         return rsp;
     }
 
-    private String getUcsManagerIp() {
-        SearchCriteriaService<UcsManagerVO, UcsManagerVO> serv = SearchCriteria2.create(UcsManagerVO.class);
-        List<UcsManagerVO> vos = serv.list();
-        if (vos.isEmpty()) {
-            throw new CloudRuntimeException("Cannot find any UCS manager, you must add it
first");
-        }
-        return vos.get(0).getUrl();
-    }
-
     private String getCookie(Long ucsMgrId) {
         try {
             String cookie = cookies.get(ucsMgrId);
@@ -172,11 +183,7 @@ public class UcsManagerImpl implements UcsManager {
         return xo.get("lsClone.outConfig.lsServer.dn");
     }
 
-    private String buildProfileNameForHost(HostVO vo) {
-        return String.format("z%sp%sc%sh%s", vo.getDataCenterId(), vo.getPodId(), vo.getClusterId(),
vo.getId());
-    }
-
-    private boolean isBladeAssociated(Long ucsMgrId, String dn) {
+    private boolean isProfileAssociated(Long ucsMgrId, String dn) {
         UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
         UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
         String cookie = getCookie(ucsMgrId);
@@ -188,6 +195,45 @@ public class UcsManagerImpl implements UcsManager {
 
     @Override
     public void associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
+        SearchCriteriaService<UcsBladeVO, UcsBladeVO> q = SearchCriteria2.create(UcsBladeVO.class);
+        q.addAnd(q.getEntity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
+        q.addAnd(q.getEntity().getId(), Op.EQ, cmd.getBladeId());
+        UcsBladeVO bvo = q.find();
+        if (bvo == null) {
+            throw new IllegalArgumentException(String.format("cannot find UCS blade[id:%s,
ucs manager id:%s]", cmd.getBladeId(), cmd.getUcsManagerId()));
+        }
+        
+        if (bvo.getHostId() != null) {
+            throw new CloudRuntimeException(String.format("blade[id:%s,  dn:%s] has been
associated with host[id:%s]", bvo.getId(), bvo.getDn(), bvo.getHostId()));
+        }
+        
+        UcsManagerVO mgrvo = ucsDao.findById(cmd.getUcsManagerId());
+        String cookie = getCookie(cmd.getUcsManagerId());
+        String pdn = cloneProfile(mgrvo.getId(), cmd.getProfileDn(), "profile-for-blade-"
+ bvo.getId());
+        String ucscmd = UcsCommands.associateProfileToBlade(cookie, pdn, bvo.getDn());
+        UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
+        String res = client.call(ucscmd);
+        int count = 0;
+        int timeout = 600;
+        while (count < timeout) {
+            if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) {
+                break;
+            }
+            
+            try {
+                TimeUnit.SECONDS.sleep(2);
+            } catch (InterruptedException e) {
+                throw new CloudRuntimeException(e);
+            }
+            
+            count += 2;
+        }
+        
+        if (count >= timeout) {
+            throw new CloudRuntimeException(String.format("associating profile[%s] to balde[%s]
timeout after 600 seconds", pdn, bvo.getDn()));
+        }
+        
+        s_logger.debug(String.format("successfully associated profile[%s] to blade[%s]",
pdn, bvo.getDn()));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/997e9fb7/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/ComputeBlade.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/ComputeBlade.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/ComputeBlade.java
index 9c7356c..6251ecf 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/ComputeBlade.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/ComputeBlade.java
@@ -159,4 +159,7 @@ public class ComputeBlade {
     public void setUuid(String uuid) {
         this.uuid = uuid;
     }
+    public boolean isAssociated() {
+        return this.assignedToDn.equals("");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/997e9fb7/utils/src/com/cloud/utils/xmlobject/XmlObject.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/xmlobject/XmlObject.java b/utils/src/com/cloud/utils/xmlobject/XmlObject.java
index e133d61..fc8043d 100755
--- a/utils/src/com/cloud/utils/xmlobject/XmlObject.java
+++ b/utils/src/com/cloud/utils/xmlobject/XmlObject.java
@@ -1,9 +1,5 @@
 package com.cloud.utils.xmlobject;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -12,12 +8,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.SAXException;
-
 import com.cloud.utils.exception.CloudRuntimeException;
 
 import edu.emory.mathcs.backport.java.util.Collections;


Mime
View raw message