Skip to content

Commit fe54688

Browse files
author
frank
committed
Add disassocating profile to UCS
1 parent e34c803 commit fe54688

9 files changed

Lines changed: 144 additions & 14 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public class EventTypes {
443443
public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP";
444444

445445
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
446+
public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE";
446447

447448
static {
448449

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ listUcsProfiles=1
618618
listUcsBlades=1
619619
associateUcsProfileToBlade=1
620620
deleteUcsManager=1
621+
disassociateUcsProfileFromBlade=1
621622

622623
#### New Load Balancer commands
623624
createLoadBalancer=15

plugins/hypervisors/ucs/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@
5252
<artifactId>cloud-api</artifactId>
5353
<version>${project.version}</version>
5454
</dependency>
55+
<dependency>
56+
<groupId>javax.inject</groupId>
57+
<artifactId>javax.inject</artifactId>
58+
<version>1</version>
59+
</dependency>
5560
</dependencies>
5661
</project>

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java

100644100755
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ public static String configResolveDn(String cookie, String dn) {
6767
return cmd.toString();
6868
}
6969

70+
public static String disassociateProfileFromBlade(String cookie, String profileDn) {
71+
XmlObject cmd = new XmlObject("configConfMo");
72+
cmd.putElement("cookie", cookie);
73+
cmd.putElement("inHierarchical", "false")
74+
.putElement("inConfig", new XmlObject("inConfig")
75+
.putElement("lsServer", new XmlObject("lsServer")
76+
.putElement("dn", profileDn).putElement("lsBinding", new XmlObject("lsBinding").putElement("rn", "pn").putElement("status", "deleted"))
77+
)
78+
);
79+
80+
return cmd.dump();
81+
}
82+
83+
public static String deleteProfile(String cookie, String profileDn) {
84+
XmlObject cmd = new XmlObject("configConfMos");
85+
cmd.putElement("cookie", cookie);
86+
cmd.putElement("inHierarchical", "true")
87+
.putElement("inConfigs", new XmlObject("inConfigs").putElement("pair", new XmlObject("pair").putElement("key", profileDn)
88+
.putElement("lsServer", new XmlObject("lsServer").putElement("dn", profileDn).putElement("status", "deleted"))
89+
));
90+
return cmd.dump();
91+
}
92+
7093
public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) {
7194
XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement(
7295
"inConfigs", new XmlObject("inConfigs").putElement(
@@ -95,10 +118,10 @@ public static String associateProfileToBlade(String cookie, String profileDn, St
95118
.putElement("uuid", "")
96119
.putElement("vconProfileName", "")
97120
.putElement("lsBinding", new XmlObject("lsBinding")
98-
.putElement("pnDn", bladeDn)
99-
.putElement("restrictMigration", "no")
100-
.putElement("rn", "pn")
101-
)
121+
.putElement("pnDn", bladeDn)
122+
.putElement("restrictMigration", "no")
123+
.putElement("rn", "pn")
124+
)
102125
)
103126
)
104127
);

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.commons.httpclient.Header;
2121
import org.apache.commons.httpclient.HttpClient;
22+
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
2223
import org.apache.commons.httpclient.URI;
2324
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
2425
import org.apache.commons.httpclient.methods.PostMethod;
@@ -28,10 +29,14 @@
2829
import com.cloud.utils.exception.CloudRuntimeException;
2930

3031
public class UcsHttpClient {
31-
private static HttpClient client = new HttpClient();
32+
private static HttpClient client;
3233
private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
3334
private final String url;
3435

36+
static {
37+
client = new HttpClient();
38+
}
39+
3540
public UcsHttpClient(String ip) {
3641
url = String.format("http://%s/nuova", ip);
3742
Protocol.registerProtocol("https", ucsHttpsProtocol);

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ public interface UcsManager extends Manager, PluggableService {
4242
ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd);
4343

4444
void deleteUcsManager(Long id);
45+
46+
UcsBladeResponse disassociateProfile(Long bladeId);
4547
}

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@
3030
import javax.inject.Inject;
3131
import javax.naming.ConfigurationException;
3232

33-
import org.apache.cloudstack.api.AddUcsManagerCmd;
34-
import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
35-
import org.apache.cloudstack.api.ListUcsBladeCmd;
36-
import org.apache.cloudstack.api.ListUcsManagerCmd;
37-
import org.apache.cloudstack.api.ListUcsProfileCmd;
33+
import org.apache.cloudstack.api.*;
3834
import org.apache.cloudstack.api.response.ListResponse;
3935
import org.apache.cloudstack.api.response.UcsBladeResponse;
4036
import org.apache.cloudstack.api.response.UcsManagerResponse;
4137
import org.apache.cloudstack.api.response.UcsProfileResponse;
42-
import org.apache.log4j.Logger;
43-
import org.apache.cloudstack.api.DeleteUcsManagerCmd;
38+
import org.apache.log4j.Logger;
4439

4540
import com.cloud.configuration.Config;
4641
import com.cloud.configuration.dao.ConfigurationDao;
@@ -296,7 +291,14 @@ private List<UcsProfile> getUcsProfiles(Long ucsMgrId) {
296291
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
297292
String res = client.call(cmd);
298293
List<UcsProfile> profiles = UcsProfile.fromXmlString(res);
299-
return profiles;
294+
List<UcsProfile> unassociated = new ArrayList<UcsProfile>();
295+
for (UcsProfile p : profiles) {
296+
if (isProfileAssociated(mgrvo.getId(), p.getDn())) {
297+
continue;
298+
}
299+
unassociated.add(p);
300+
}
301+
return unassociated;
300302
}
301303

302304
@Override
@@ -324,13 +326,25 @@ private String cloneProfile(Long ucsMgrId, String srcDn, String newProfileName)
324326
return xo.get("outConfig.lsServer.dn");
325327
}
326328

329+
327330
private boolean isProfileAssociated(Long ucsMgrId, String dn) {
328331
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
329332
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
330333
String cookie = getCookie(ucsMgrId);
331334
String cmd = UcsCommands.configResolveDn(cookie, dn);
332335
String res = client.call(cmd);
333336
XmlObject xo = XmlObjectParser.parseFromString(res);
337+
338+
return xo.get("outConfig.lsServer.assocState").equals("associated");
339+
}
340+
341+
private boolean isBladeAssociated(Long ucsMgrId, String dn) {
342+
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
343+
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
344+
String cookie = getCookie(ucsMgrId);
345+
String cmd = UcsCommands.configResolveDn(cookie, dn);
346+
String res = client.call(cmd);
347+
XmlObject xo = XmlObjectParser.parseFromString(res);
334348
s_logger.debug(String.format("association response is %s", res));
335349

336350
if (xo.get("outConfig.computeBlade.association").equals("none")) {
@@ -363,7 +377,7 @@ public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cm
363377
int count = 0;
364378
int timeout = 600;
365379
while (count < timeout) {
366-
if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) {
380+
if (isBladeAssociated(mgrvo.getId(), bvo.getDn())) {
367381
break;
368382
}
369383

@@ -504,6 +518,7 @@ public List<Class<?>> getCommands() {
504518
cmds.add(AddUcsManagerCmd.class);
505519
cmds.add(AssociateUcsProfileToBladeCmd.class);
506520
cmds.add(DeleteUcsManagerCmd.class);
521+
cmds.add(DisassociateUcsProfileCmd.class);
507522
return cmds;
508523
}
509524

@@ -517,4 +532,21 @@ public void deleteUcsManager(Long id) {
517532
}
518533
ucsDao.remove(id);
519534
}
535+
536+
@Override
537+
public UcsBladeResponse disassociateProfile(Long bladeId) {
538+
UcsBladeVO blade = bladeDao.findById(bladeId);
539+
UcsManagerVO mgrvo = ucsDao.findById(blade.getUcsManagerId());
540+
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
541+
String cookie = getCookie(mgrvo.getId());
542+
String cmd = UcsCommands.disassociateProfileFromBlade(cookie, blade.getProfileDn());
543+
client.call(cmd);
544+
cmd = UcsCommands.deleteProfile(cookie, blade.getProfileDn());
545+
client = new UcsHttpClient(mgrvo.getUrl());
546+
client.call(cmd);
547+
blade.setProfileDn(null);
548+
bladeDao.update(blade.getId(), blade);
549+
UcsBladeResponse rsp = bladeVOToResponse(blade);
550+
return rsp;
551+
}
520552
}

plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java

100644100755
File mode changed.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.apache.cloudstack.api;
2+
3+
import com.cloud.event.EventTypes;
4+
import com.cloud.exception.*;
5+
import com.cloud.ucs.manager.UcsManager;
6+
import com.cloud.user.Account;
7+
import org.apache.cloudstack.api.response.SuccessResponse;
8+
import org.apache.cloudstack.api.response.UcsBladeResponse;
9+
import org.apache.log4j.Logger;
10+
11+
import javax.inject.Inject;
12+
13+
/**
14+
* Created with IntelliJ IDEA.
15+
* User: frank
16+
* Date: 9/13/13
17+
* Time: 6:23 PM
18+
* To change this template use File | Settings | File Templates.
19+
*/
20+
@APICommand(name="disassociateUcsProfileFromBlade", description="disassociate a profile from a blade", responseObject=UcsBladeResponse.class)
21+
public class DisassociateUcsProfileCmd extends BaseAsyncCmd {
22+
private static Logger logger = Logger.getLogger(DisassociateUcsProfileCmd.class);
23+
24+
@Inject
25+
private UcsManager mgr;
26+
27+
@Parameter(name=ApiConstants.UCS_BLADE_ID, type=CommandType.UUID, entityType=UcsBladeResponse.class, description="blade id", required=true)
28+
private Long bladeId;
29+
30+
@Override
31+
public String getEventType() {
32+
return EventTypes.EVENT_UCS_DISASSOCIATED_PROFILE;
33+
}
34+
35+
@Override
36+
public String getEventDescription() {
37+
return "disassociate a profile from blade";
38+
}
39+
40+
@Override
41+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
42+
try {
43+
UcsBladeResponse rsp = mgr.disassociateProfile(bladeId);
44+
rsp.setResponseName(getCommandName());
45+
this.setResponseObject(rsp);
46+
} catch(Exception e) {
47+
logger.warn(e.getMessage(), e);
48+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
49+
}
50+
}
51+
52+
@Override
53+
public String getCommandName() {
54+
return "disassociateucsprofilefrombladeresponse";
55+
}
56+
57+
@Override
58+
public long getEntityOwnerId() {
59+
return Account.ACCOUNT_ID_SYSTEM;
60+
}
61+
}

0 commit comments

Comments
 (0)