diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index ff596749a63..dc2040031f8 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -443,6 +443,7 @@ public class EventTypes {
public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP";
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
+ public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE";
static {
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 69a31207220..492661ef409 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -618,6 +618,7 @@ listUcsProfiles=1
listUcsBlades=1
associateUcsProfileToBlade=1
deleteUcsManager=1
+disassociateUcsProfileFromBlade=1
#### New Load Balancer commands
createLoadBalancer=15
diff --git a/plugins/hypervisors/ucs/pom.xml b/plugins/hypervisors/ucs/pom.xml
index 24bdc948e73..fe89d26b4a7 100755
--- a/plugins/hypervisors/ucs/pom.xml
+++ b/plugins/hypervisors/ucs/pom.xml
@@ -52,5 +52,10 @@
cloud-api
${project.version}
+
+ javax.inject
+ javax.inject
+ 1
+
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
old mode 100644
new mode 100755
index c0753f463cd..52e5edfdb9c
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
@@ -67,6 +67,29 @@ public class UcsCommands {
return cmd.toString();
}
+ public static String disassociateProfileFromBlade(String cookie, String profileDn) {
+ XmlObject cmd = new XmlObject("configConfMo");
+ cmd.putElement("cookie", cookie);
+ cmd.putElement("inHierarchical", "false")
+ .putElement("inConfig", new XmlObject("inConfig")
+ .putElement("lsServer", new XmlObject("lsServer")
+ .putElement("dn", profileDn).putElement("lsBinding", new XmlObject("lsBinding").putElement("rn", "pn").putElement("status", "deleted"))
+ )
+ );
+
+ return cmd.dump();
+ }
+
+ public static String deleteProfile(String cookie, String profileDn) {
+ XmlObject cmd = new XmlObject("configConfMos");
+ cmd.putElement("cookie", cookie);
+ cmd.putElement("inHierarchical", "true")
+ .putElement("inConfigs", new XmlObject("inConfigs").putElement("pair", new XmlObject("pair").putElement("key", profileDn)
+ .putElement("lsServer", new XmlObject("lsServer").putElement("dn", profileDn).putElement("status", "deleted"))
+ ));
+ return cmd.dump();
+ }
+
public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) {
XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement(
"inConfigs", new XmlObject("inConfigs").putElement(
@@ -95,10 +118,10 @@ public class UcsCommands {
.putElement("uuid", "")
.putElement("vconProfileName", "")
.putElement("lsBinding", new XmlObject("lsBinding")
- .putElement("pnDn", bladeDn)
- .putElement("restrictMigration", "no")
- .putElement("rn", "pn")
- )
+ .putElement("pnDn", bladeDn)
+ .putElement("restrictMigration", "no")
+ .putElement("rn", "pn")
+ )
)
)
);
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java
old mode 100644
new mode 100755
index 945d921a8d3..7758c4cd6e2
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java
@@ -19,6 +19,7 @@ package com.cloud.ucs.manager;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -28,10 +29,14 @@ import org.apache.commons.httpclient.protocol.Protocol;
import com.cloud.utils.exception.CloudRuntimeException;
public class UcsHttpClient {
- private static HttpClient client = new HttpClient();
+ private static HttpClient client;
private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
private final String url;
+ static {
+ client = new HttpClient();
+ }
+
public UcsHttpClient(String ip) {
url = String.format("http://%s/nuova", ip);
Protocol.registerProtocol("https", ucsHttpsProtocol);
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java
index 0833e31f0f3..babec3aca8e 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java
@@ -42,4 +42,6 @@ public interface UcsManager extends Manager, PluggableService {
ListResponse listUcsBlades(ListUcsBladeCmd cmd);
void deleteUcsManager(Long id);
+
+ UcsBladeResponse disassociateProfile(Long bladeId);
}
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 4aec48c1c85..05b1214d9c9 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
@@ -30,17 +30,12 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.cloudstack.api.AddUcsManagerCmd;
-import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
-import org.apache.cloudstack.api.ListUcsBladeCmd;
-import org.apache.cloudstack.api.ListUcsManagerCmd;
-import org.apache.cloudstack.api.ListUcsProfileCmd;
+import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UcsBladeResponse;
import org.apache.cloudstack.api.response.UcsManagerResponse;
import org.apache.cloudstack.api.response.UcsProfileResponse;
-import org.apache.log4j.Logger;
-import org.apache.cloudstack.api.DeleteUcsManagerCmd;
+import org.apache.log4j.Logger;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
@@ -296,7 +291,14 @@ public class UcsManagerImpl implements UcsManager {
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String res = client.call(cmd);
List profiles = UcsProfile.fromXmlString(res);
- return profiles;
+ List unassociated = new ArrayList();
+ for (UcsProfile p : profiles) {
+ if (isProfileAssociated(mgrvo.getId(), p.getDn())) {
+ continue;
+ }
+ unassociated.add(p);
+ }
+ return unassociated;
}
@Override
@@ -324,6 +326,7 @@ public class UcsManagerImpl implements UcsManager {
return xo.get("outConfig.lsServer.dn");
}
+
private boolean isProfileAssociated(Long ucsMgrId, String dn) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
@@ -331,6 +334,17 @@ public class UcsManagerImpl implements UcsManager {
String cmd = UcsCommands.configResolveDn(cookie, dn);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
+
+ return xo.get("outConfig.lsServer.assocState").equals("associated");
+ }
+
+ 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);
s_logger.debug(String.format("association response is %s", res));
if (xo.get("outConfig.computeBlade.association").equals("none")) {
@@ -363,7 +377,7 @@ public class UcsManagerImpl implements UcsManager {
int count = 0;
int timeout = 600;
while (count < timeout) {
- if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) {
+ if (isBladeAssociated(mgrvo.getId(), bvo.getDn())) {
break;
}
@@ -504,6 +518,7 @@ public class UcsManagerImpl implements UcsManager {
cmds.add(AddUcsManagerCmd.class);
cmds.add(AssociateUcsProfileToBladeCmd.class);
cmds.add(DeleteUcsManagerCmd.class);
+ cmds.add(DisassociateUcsProfileCmd.class);
return cmds;
}
@@ -517,4 +532,21 @@ public class UcsManagerImpl implements UcsManager {
}
ucsDao.remove(id);
}
+
+ @Override
+ public UcsBladeResponse disassociateProfile(Long bladeId) {
+ UcsBladeVO blade = bladeDao.findById(bladeId);
+ UcsManagerVO mgrvo = ucsDao.findById(blade.getUcsManagerId());
+ UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
+ String cookie = getCookie(mgrvo.getId());
+ String cmd = UcsCommands.disassociateProfileFromBlade(cookie, blade.getProfileDn());
+ client.call(cmd);
+ cmd = UcsCommands.deleteProfile(cookie, blade.getProfileDn());
+ client = new UcsHttpClient(mgrvo.getUrl());
+ client.call(cmd);
+ blade.setProfileDn(null);
+ bladeDao.update(blade.getId(), blade);
+ UcsBladeResponse rsp = bladeVOToResponse(blade);
+ return rsp;
+ }
}
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java
old mode 100644
new mode 100755
diff --git a/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java
new file mode 100755
index 00000000000..ed2098954d5
--- /dev/null
+++ b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java
@@ -0,0 +1,61 @@
+package org.apache.cloudstack.api;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.*;
+import com.cloud.ucs.manager.UcsManager;
+import com.cloud.user.Account;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.UcsBladeResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: frank
+ * Date: 9/13/13
+ * Time: 6:23 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@APICommand(name="disassociateUcsProfileFromBlade", description="disassociate a profile from a blade", responseObject=UcsBladeResponse.class)
+public class DisassociateUcsProfileCmd extends BaseAsyncCmd {
+ private static Logger logger = Logger.getLogger(DisassociateUcsProfileCmd.class);
+
+ @Inject
+ private UcsManager mgr;
+
+ @Parameter(name=ApiConstants.UCS_BLADE_ID, type=CommandType.UUID, entityType=UcsBladeResponse.class, description="blade id", required=true)
+ private Long bladeId;
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_UCS_DISASSOCIATED_PROFILE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "disassociate a profile from blade";
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
+ try {
+ UcsBladeResponse rsp = mgr.disassociateProfile(bladeId);
+ rsp.setResponseName(getCommandName());
+ this.setResponseObject(rsp);
+ } catch(Exception e) {
+ logger.warn(e.getMessage(), e);
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return "disassociateucsprofilefrombladeresponse";
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+}