mirror of https://github.com/apache/cloudstack.git
Add disassocating profile to UCS
This commit is contained in:
parent
e34c80398e
commit
fe5468881a
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -618,6 +618,7 @@ listUcsProfiles=1
|
|||
listUcsBlades=1
|
||||
associateUcsProfileToBlade=1
|
||||
deleteUcsManager=1
|
||||
disassociateUcsProfileFromBlade=1
|
||||
|
||||
#### New Load Balancer commands
|
||||
createLoadBalancer=15
|
||||
|
|
|
|||
|
|
@ -52,5 +52,10 @@
|
|||
<artifactId>cloud-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
|||
7
plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java
Normal file → Executable file
7
plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java
Normal file → Executable file
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -42,4 +42,6 @@ public interface UcsManager extends Manager, PluggableService {
|
|||
ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd);
|
||||
|
||||
void deleteUcsManager(Long id);
|
||||
|
||||
UcsBladeResponse disassociateProfile(Long bladeId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<UcsProfile> profiles = UcsProfile.fromXmlString(res);
|
||||
return profiles;
|
||||
List<UcsProfile> unassociated = new ArrayList<UcsProfile>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue