CloudStack CLOUDSTACK-723

Enhanced baremetal servers support on Cisco UCS

init
This commit is contained in:
frank 2013-01-25 15:00:09 -08:00
parent fb050894f5
commit 301b0b9090
22 changed files with 1121 additions and 2 deletions

1
api/src/org/apache/cloudstack/api/ApiConstants.java Normal file → Executable file
View File

@ -426,6 +426,7 @@ public class ApiConstants {
public static final String CONDITION_IDS = "conditionids";
public static final String COUNTERPARAM_LIST = "counterparam";
public static final String AUTOSCALE_USER_ID = "autoscaleuserid";
public static final String UCS_DN = "ucsdn";
public enum HostDetails {
all, capacity, events, stats, min;

37
plugins/hypervisors/ucs/pom.xml Executable file
View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-hypervisor-ucs</artifactId>
<version>4.1.0-SNAPSHOT</version>
<name>cloud-plugin-hypervisor-ucs</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,16 @@
package com.cloud.ucs.database;
import java.util.List;
import java.util.Map;
import javax.naming.ConfigurationException;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria2;
public interface UcsManagerDao extends GenericDao<UcsManagerVO, Long> {
}

View File

@ -0,0 +1,12 @@
package com.cloud.ucs.database;
import javax.ejb.Local;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@Local(value = { UcsManagerDao.class })
@DB(txn = false)
public class UcsManagerDaoImpl extends GenericDaoBase<UcsManagerVO, Long> implements UcsManagerDao {
}

View File

@ -0,0 +1,78 @@
package com.cloud.ucs.database;
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="ucs_manager")
public class UcsManagerVO {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="zone_id")
private long zoneId;
@Column(name="uuid")
private String uuid;
@Column(name="name")
private String name;
@Column(name="url")
private String url;
@Column(name="username")
private String username;
@Column(name="password")
private String password;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public long getZoneId() {
return zoneId;
}
public void setZoneId(long zoneId) {
this.zoneId = zoneId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,107 @@
package com.cloud.ucs.manager;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseCmd.CommandType;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
@APICommand(description="Adds a Ucs manager", responseObject=AddUcsManagerResponse.class)
public class AddUcsManagerCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddUcsManagerCmd.class);
@Inject
private UcsManager mgr;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone id for the ucs manager", required=true)
private Long zoneId;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of UCS manager")
private String name;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="the name of UCS url")
private String url;
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="the username of UCS")
private String username;
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="the password of UCS")
private String password;
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {
try {
AddUcsManagerResponse rsp = mgr.addUcsManager(this);
rsp.setObjectName("ucsmanager");
rsp.setResponseName(getCommandName());
this.setResponseObject(rsp);
} catch (Exception e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return "addUcsManagerResponse";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -0,0 +1,53 @@
package com.cloud.ucs.manager;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class AddUcsManagerResponse extends BaseResponse {
@SerializedName(ApiConstants.ID) @Param(description="the ID of the ucs manager")
private String id;
@SerializedName(ApiConstants.NAME) @Param(description="the name of ucs manager")
private String name;
@SerializedName(ApiConstants.URL) @Param(description="the url of ucs manager")
private String url;
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID of ucs manager")
private String zoneId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getZoneId() {
return zoneId;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
}

View File

@ -0,0 +1,75 @@
package com.cloud.ucs.manager;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
@APICommand(description="associate a profile to a blade", responseObject=AssociateUcsProfileToBladesInClusterResponse.class)
public class AssociateUcsProfileToBladeCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AssociateUcsProfileToBladeCmd.class);
@Inject
private UcsManager mgr;
private Long ucsManagerId;
private String profileDn;
private Long bladeId;
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {
try {
mgr.associateProfileToBlade(this);
AssociateUcsProfileToBladesInClusterResponse rsp = new AssociateUcsProfileToBladesInClusterResponse();
rsp.setResponseName(getCommandName());
rsp.setObjectName("associateucsprofiletobalde");
this.setResponseObject(rsp);
} catch (Exception e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return "associateucsprofiletobladeresponse";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
public Long getUcsManagerId() {
return ucsManagerId;
}
public void setUcsManagerId(Long ucsManagerId) {
this.ucsManagerId = ucsManagerId;
}
public String getProfileDn() {
return profileDn;
}
public void setProfileDn(String profileDn) {
this.profileDn = profileDn;
}
public Long getBladeId() {
return bladeId;
}
public void setBladeId(Long bladeId) {
this.bladeId = bladeId;
}
}

View File

@ -0,0 +1,6 @@
package com.cloud.ucs.manager;
import org.apache.cloudstack.api.BaseResponse;
public class AssociateUcsProfileToBladesInClusterResponse extends BaseResponse {
}

View File

@ -0,0 +1,61 @@
package com.cloud.ucs.manager;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
@APICommand(description="List ucs manager", responseObject=ListUcsManagerResponse.class)
public class ListUcsManagerCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ListUcsManagerCmd.class);
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the zone id", required=true)
private Long zoneId;
@Inject
private UcsManager mgr;
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {
try {
ListResponse<ListUcsManagerResponse> response = mgr.listUcsManager(this);
response.setResponseName(getCommandName());
response.setObjectName("ucsmanager");
this.setResponseObject(response);
} catch (Exception e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return "listucsmanagerreponse";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
}

View File

@ -0,0 +1,42 @@
package com.cloud.ucs.manager;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class ListUcsManagerResponse extends BaseResponse {
@SerializedName(ApiConstants.ID) @Param(description="id of ucs manager")
private String id;
@SerializedName(ApiConstants.NAME) @Param(description="name of ucs manager")
private String name;
@SerializedName(ApiConstants.ZONE_ID) @Param(description="zone id the ucs manager belongs to")
private String zoneId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getZoneId() {
return zoneId;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
}

View File

@ -0,0 +1,62 @@
package com.cloud.ucs.manager;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseCmd.CommandType;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
@APICommand(description="List profile in ucs manager", responseObject=ListUcsProfileResponse.class)
public class ListUcsProfileCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ListUcsProfileCmd.class);
@Inject UcsManager mgr;
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id for the ucs manager", required=true)
private Long ucsManagerId;
public Long getUcsManagerId() {
return ucsManagerId;
}
public void setUcsManagerId(Long ucsManagerId) {
this.ucsManagerId = ucsManagerId;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {
try {
ListResponse<ListUcsProfileResponse> response = mgr.listUcsProfiles(this);
response.setResponseName(getCommandName());
response.setObjectName("ucsprofile");
this.setResponseObject(response);
} catch (Exception e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return "listucsprofileresponse";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
}

View File

@ -0,0 +1,20 @@
package com.cloud.ucs.manager;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class ListUcsProfileResponse extends BaseResponse {
@SerializedName(ApiConstants.UCS_DN) @Param(description="the dn of ucs profile")
private String dn;
public String getDn() {
return dn;
}
public void setDn(String dn) {
this.dn = dn;
}
}

View File

@ -0,0 +1,22 @@
package com.cloud.ucs.manager;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringTemplate {
public static String replaceTokens(String text, Map<String, String> replacements) {
Pattern pattern = Pattern.compile("\\[(.+?)\\]");
Matcher matcher = pattern.matcher(text);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
String replacement = replacements.get(matcher.group(1));
if (replacement != null) {
matcher.appendReplacement(buffer, "");
buffer.append(replacement);
}
}
matcher.appendTail(buffer);
return buffer.toString();
}
}

View File

@ -0,0 +1,44 @@
package com.cloud.ucs.manager;
import com.cloud.utils.xmlobject.XmlObject;
public class UcsCommands {
public static String loginCmd(String username, String password) {
XmlObject cmd = new XmlObject("aaaLogin");
cmd.putElement("inName", username);
cmd.putElement("inPassword", password);
return cmd.dump();
}
public static String listComputeBlades(String cookie) {
XmlObject cmd = new XmlObject("configResolveClass");
cmd.putElement("classId", "computeBlade");
cmd.putElement("cookie", cookie);
cmd.putElement("inHierarchical", "false");
return cmd.dump();
}
public static String listProfiles(String cookie) {
XmlObject cmd = new XmlObject("configFindDnsByClassId");
cmd.putElement("classId", "lsServer");
cmd.putElement("cookie", cookie);
return cmd.dump();
}
public static String cloneProfile(String cookie, String srcDn, String newProfileName) {
XmlObject cmd = new XmlObject("lsClone");
cmd.putElement("cookie", cookie);
cmd.putElement("dn", srcDn);
cmd.putElement("inTargetOrg", "org-root");
cmd.putElement("inServerName", newProfileName);
cmd.putElement("inHierarchical", "false");
return cmd.dump();
}
public static String configResolveDn(String cookie, String dn) {
XmlObject cmd = new XmlObject("configResolveDn");
cmd.putElement("cookie", cookie);
cmd.putElement("dn", dn);
return cmd.toString();
}
}

View File

@ -0,0 +1,33 @@
package com.cloud.ucs.manager;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import com.cloud.utils.exception.CloudRuntimeException;
public class UcsHttpClient {
private static HttpClient client = new HttpClient();
private String url;
public UcsHttpClient(String ip) {
this.url = String.format("http://%s/nuova", ip);
}
public String call(String xml) {
PostMethod post = new PostMethod(url);
post.setRequestEntity(new StringRequestEntity(xml));
post.setRequestHeader("Content-type", "text/xml");
try {
int result = client.executeMethod(post);
if (result != 200) {
throw new CloudRuntimeException("Call failed: " + post.getResponseBodyAsString());
}
return post.getResponseBodyAsString();
} catch (Exception e) {
throw new CloudRuntimeException(e.getMessage(), e);
} finally {
post.releaseConnection();
}
}
}

View File

@ -0,0 +1,15 @@
package com.cloud.ucs.manager;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.utils.component.Manager;
public interface UcsManager extends Manager {
AddUcsManagerResponse addUcsManager(AddUcsManagerCmd cmd);
ListResponse<ListUcsProfileResponse> listUcsProfiles(ListUcsProfileCmd cmd);
ListResponse<ListUcsManagerResponse> listUcsManager(ListUcsManagerCmd cmd);
void associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd);
}

View File

@ -0,0 +1,212 @@
package com.cloud.ucs.manager;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ResponseGenerator;
import org.apache.cloudstack.api.ServerApiException;
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 com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.dao.ClusterDao;
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.UcsManagerDao;
import com.cloud.ucs.database.UcsManagerVO;
import com.cloud.ucs.structure.ComputeBlade;
import com.cloud.ucs.structure.UcsProfile;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.xmlobject.XmlObject;
import com.cloud.utils.xmlobject.XmlObjectParser;
@Local(value = { UcsManager.class })
public class UcsManagerImpl implements UcsManager {
public static final Logger s_logger = Logger.getLogger(UcsManagerImpl.class);
@Inject
private UcsManagerDao ucsDao;
@Inject
private ResourceService resourceService;
@Inject
private ClusterDao clusterDao;
@Inject
private ClusterDetailsDao clusterDetailsDao;
private Map<Long, String> cookies = new HashMap<Long, String>();
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return "UcsManager";
}
@Override
@DB
public AddUcsManagerResponse addUcsManager(AddUcsManagerCmd cmd) {
UcsManagerVO vo = new UcsManagerVO();
vo.setUuid(UUID.randomUUID().toString());
vo.setPassword(cmd.getPassword());
vo.setUrl(cmd.getUrl());
vo.setUsername(cmd.getUsername());
vo.setZoneId(cmd.getZoneId());
vo.setName(cmd.getName());
Transaction txn = Transaction.currentTxn();
txn.start();
ucsDao.persist(vo);
txn.commit();
AddUcsManagerResponse rsp = new AddUcsManagerResponse();
rsp.setId(String.valueOf(vo.getId()));
rsp.setName(vo.getName());
rsp.setUrl(vo.getUrl());
rsp.setZoneId(String.valueOf(vo.getZoneId()));
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);
if (cookie == null) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String login = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
cookie = client.call(login);
cookies.put(ucsMgrId, cookie);
}
return cookie;
} catch (Exception e) {
throw new CloudRuntimeException("Cannot get cookie", e);
}
}
private List<ComputeBlade> listBlades(Long ucsMgrId) {
String cookie = getCookie(ucsMgrId);
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cmd = UcsCommands.listComputeBlades(cookie);
String ret = client.call(cmd);
return ComputeBlade.fromXmString(ret);
}
private List<UcsProfile> getUcsProfiles(Long ucsMgrId) {
String cookie = getCookie(ucsMgrId);
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
String cmd = UcsCommands.listProfiles(cookie);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String res = client.call(cmd);
List<UcsProfile> profiles = UcsProfile.fromXmlString(res);
return profiles;
}
@Override
public ListResponse<ListUcsProfileResponse> listUcsProfiles(ListUcsProfileCmd cmd) {
List<UcsProfile> profiles = getUcsProfiles(cmd.getUcsManagerId());
ListResponse<ListUcsProfileResponse> response = new ListResponse<ListUcsProfileResponse>();
List<ListUcsProfileResponse> rs = new ArrayList<ListUcsProfileResponse>();
for (UcsProfile p : profiles) {
ListUcsProfileResponse r = new ListUcsProfileResponse();
r.setObjectName("ucsprofile");
r.setDn(p.getDn());
rs.add(r);
}
response.setResponses(rs);
return response;
}
private String cloneProfile(Long ucsMgrId, String srcDn, String newProfileName) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.cloneProfile(cookie, srcDn, newProfileName);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
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) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.configResolveDn(cookie, dn);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
return xo.get("outConfig.lsServer.assocState").equals("associated");
}
@Override
public void associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
}
@Override
public ListResponse<ListUcsManagerResponse> listUcsManager(ListUcsManagerCmd cmd) {
SearchCriteriaService<UcsManagerVO, UcsManagerVO> serv = SearchCriteria2.create(UcsManagerVO.class);
serv.addAnd(serv.getEntity().getZoneId(), Op.EQ, cmd.getZoneId());
List<UcsManagerVO> vos = serv.list();
List<ListUcsManagerResponse> rsps = new ArrayList<ListUcsManagerResponse>(vos.size());
for (UcsManagerVO vo : vos) {
ListUcsManagerResponse rsp = new ListUcsManagerResponse();
rsp.setObjectName("ucsmanager");
rsp.setId(String.valueOf(vo.getId()));
rsp.setName(vo.getName());
rsp.setZoneId(String.valueOf(vo.getZoneId()));
rsps.add(rsp);
}
ListResponse<ListUcsManagerResponse> response = new ListResponse<ListUcsManagerResponse>();
response.setResponses(rsps);
return response;
}
}

View File

@ -0,0 +1,162 @@
package com.cloud.ucs.structure;
import java.util.ArrayList;
import java.util.List;
import com.cloud.utils.xmlobject.XmlObject;
import com.cloud.utils.xmlobject.XmlObjectParser;
public class ComputeBlade {
String adminPower;
String adminState;
String assignedToDn;
String association;
String availability;
String availableMemory;
String chassisId;
String dn;
String name;
String numOfAdaptors;
String numOfCores;
String numOfCoresEnabled;
String numOfCpus;
String numOfEthHostIfs;
String numOfFcHostIfs;
String numOfThreads;
String operPower;
String totalMemory;
String uuid;
public static List<ComputeBlade> fromXmString(String xmlstr) {
XmlObject root = XmlObjectParser.parseFromString(xmlstr);
List<XmlObject> lst = root.getAsList("configResolveClass.outConfigs.computeBlade");
List<ComputeBlade> blades = new ArrayList<ComputeBlade>();
if (lst == null) {
return blades;
}
for (XmlObject xo : lst) {
blades.add(fromXmlObject(xo));
}
return blades;
}
public static ComputeBlade fromXmlObject(XmlObject obj) {
ComputeBlade ret = new ComputeBlade();
return obj.evaluateObject(ret);
}
public String getAdminPower() {
return adminPower;
}
public void setAdminPower(String adminPower) {
this.adminPower = adminPower;
}
public String getAdminState() {
return adminState;
}
public void setAdminState(String adminState) {
this.adminState = adminState;
}
public String getAssignedToDn() {
return assignedToDn;
}
public void setAssignedToDn(String assignedToDn) {
this.assignedToDn = assignedToDn;
}
public String getAssociation() {
return association;
}
public void setAssociation(String association) {
this.association = association;
}
public String getAvailability() {
return availability;
}
public void setAvailability(String availability) {
this.availability = availability;
}
public String getAvailableMemory() {
return availableMemory;
}
public void setAvailableMemory(String availableMemory) {
this.availableMemory = availableMemory;
}
public String getChassisId() {
return chassisId;
}
public void setChassisId(String chassisId) {
this.chassisId = chassisId;
}
public String getDn() {
return dn;
}
public void setDn(String dn) {
this.dn = dn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumOfAdaptors() {
return numOfAdaptors;
}
public void setNumOfAdaptors(String numOfAdaptors) {
this.numOfAdaptors = numOfAdaptors;
}
public String getNumOfCores() {
return numOfCores;
}
public void setNumOfCores(String numOfCores) {
this.numOfCores = numOfCores;
}
public String getNumOfCoresEnabled() {
return numOfCoresEnabled;
}
public void setNumOfCoresEnabled(String numOfCoresEnabled) {
this.numOfCoresEnabled = numOfCoresEnabled;
}
public String getNumOfCpus() {
return numOfCpus;
}
public void setNumOfCpus(String numOfCpus) {
this.numOfCpus = numOfCpus;
}
public String getNumOfEthHostIfs() {
return numOfEthHostIfs;
}
public void setNumOfEthHostIfs(String numOfEthHostIfs) {
this.numOfEthHostIfs = numOfEthHostIfs;
}
public String getNumOfFcHostIfs() {
return numOfFcHostIfs;
}
public void setNumOfFcHostIfs(String numOfFcHostIfs) {
this.numOfFcHostIfs = numOfFcHostIfs;
}
public String getNumOfThreads() {
return numOfThreads;
}
public void setNumOfThreads(String numOfThreads) {
this.numOfThreads = numOfThreads;
}
public String getOperPower() {
return operPower;
}
public void setOperPower(String operPower) {
this.operPower = operPower;
}
public String getTotalMemory() {
return totalMemory;
}
public void setTotalMemory(String totalMemory) {
this.totalMemory = totalMemory;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -0,0 +1,37 @@
package com.cloud.ucs.structure;
import java.util.ArrayList;
import java.util.List;
import com.cloud.utils.xmlobject.XmlObject;
import com.cloud.utils.xmlobject.XmlObjectParser;
public class UcsProfile {
private String dn;
public static UcsProfile fromXmlObject(XmlObject xo) {
UcsProfile p = new UcsProfile();
return xo.evaluateObject(p);
}
public static List<UcsProfile> fromXmlString(String xmlstr) {
List<UcsProfile> ps = new ArrayList<UcsProfile>();
XmlObject xo = XmlObjectParser.parseFromString(xmlstr);
List<XmlObject> xos = xo.getAsList("outDns.dn");
if (xos != null) {
for (XmlObject x : xos) {
UcsProfile p = UcsProfile.fromXmlObject(x);
ps.add(p);
}
}
return ps;
}
public String getDn() {
return dn;
}
public void setDn(String dn) {
this.dn = dn;
}
}

5
plugins/pom.xml Normal file → Executable file
View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@ -15,8 +16,7 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloudstack-plugins</artifactId>
<name>Apache CloudStack Plugin POM</name>
@ -40,6 +40,7 @@
<module>hypervisors/ovm</module>
<module>hypervisors/xen</module>
<module>hypervisors/kvm</module>
<module>hypervisors/ucs</module>
<module>network-elements/elastic-loadbalancer</module>
<module>network-elements/ovs</module>
<module>network-elements/nicira-nvp</module>

View File

@ -4,6 +4,7 @@ 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;
import java.util.HashMap;
@ -57,6 +58,10 @@ public class XmlObject {
private Object recurGet(XmlObject obj, Iterator<String> it) {
String key = it.next();
Object e = obj.elements.get(key);
if (e == null) {
return null;
}
if (!it.hasNext()) {
return e;
} else {
@ -161,4 +166,22 @@ public class XmlObject {
}
return sb.toString();
}
public <T> T evaluateObject(T obj) {
Class<?> clazz = obj.getClass();
try {
do {
Field[] fs = clazz.getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
Object value = get(f.getName());
f.set(obj, value);
}
clazz = clazz.getSuperclass();
} while (clazz != null && clazz != Object.class);
return obj;
} catch (Exception e) {
throw new CloudRuntimeException(e);
}
}
}