| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e34c803 commit fe54688
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -443,6 +443,7 @@ public class EventTypes { | |||
| 443 | 443 | public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP"; | |
| 444 | 444 | ||
| 445 | 445 | public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE"; | |
| 446 | + public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE"; | ||
| 446 | 447 | ||
| 447 | 448 | static { | |
| 448 | 449 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -618,6 +618,7 @@ listUcsProfiles=1 | |||
| 618 | 618 | listUcsBlades=1 | |
| 619 | 619 | associateUcsProfileToBlade=1 | |
| 620 | 620 | deleteUcsManager=1 | |
| 621 | + disassociateUcsProfileFromBlade=1 | ||
| 621 | 622 | ||
| 622 | 623 | #### New Load Balancer commands | |
| 623 | 624 | createLoadBalancer=15 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,5 +52,10 @@ | |||
| 52 | 52 | <artifactId>cloud-api</artifactId> | |
| 53 | 53 | <version>${project.version}</version> | |
| 54 | 54 | </dependency> | |
| 55 | + <dependency> | ||
| 56 | + <groupId>javax.inject</groupId> | ||
| 57 | + <artifactId>javax.inject</artifactId> | ||
| 58 | + <version>1</version> | ||
| 59 | + </dependency> | ||
| 55 | 60 | </dependencies> | |
| 56 | 61 | </project> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,6 +67,29 @@ public static String configResolveDn(String cookie, String dn) { | |||
| 67 | 67 | return cmd.toString(); | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 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 | + | ||
| 70 | 93 | public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) { | |
| 71 | 94 | XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement( | |
| 72 | 95 | "inConfigs", new XmlObject("inConfigs").putElement( | |
@@ -95,10 +118,10 @@ public static String associateProfileToBlade(String cookie, String profileDn, St | |||
| 95 | 118 | .putElement("uuid", "") | |
| 96 | 119 | .putElement("vconProfileName", "") | |
| 97 | 120 | .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 | + ) | ||
| 102 | 125 | ) | |
| 103 | 126 | ) | |
| 104 | 127 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | 20 | import org.apache.commons.httpclient.Header; | |
| 21 | 21 | import org.apache.commons.httpclient.HttpClient; | |
| 22 | + import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; | ||
| 22 | 23 | import org.apache.commons.httpclient.URI; | |
| 23 | 24 | import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; | |
| 24 | 25 | import org.apache.commons.httpclient.methods.PostMethod; | |
@@ -28,10 +29,14 @@ | |||
| 28 | 29 | import com.cloud.utils.exception.CloudRuntimeException; | |
| 29 | 30 | ||
| 30 | 31 | public class UcsHttpClient { | |
| 31 | - private static HttpClient client = new HttpClient(); | ||
| 32 | + private static HttpClient client; | ||
| 32 | 33 | private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443); | |
| 33 | 34 | private final String url; | |
| 34 | 35 | ||
| 36 | + static { | ||
| 37 | + client = new HttpClient(); | ||
| 38 | + } | ||
| 39 | + | ||
| 35 | 40 | public UcsHttpClient(String ip) { | |
| 36 | 41 | url = String.format("http://%s/nuova", ip); | |
| 37 | 42 | Protocol.registerProtocol("https", ucsHttpsProtocol); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,4 +42,6 @@ public interface UcsManager extends Manager, PluggableService { | |||
| 42 | 42 | ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd); | |
| 43 | 43 | ||
| 44 | 44 | void deleteUcsManager(Long id); | |
| 45 | + | ||
| 46 | + UcsBladeResponse disassociateProfile(Long bladeId); | ||
| 45 | 47 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,17 +30,12 @@ | |||
| 30 | 30 | import javax.inject.Inject; | |
| 31 | 31 | import javax.naming.ConfigurationException; | |
| 32 | 32 | ||
| 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.*; | ||
| 38 | 34 | import org.apache.cloudstack.api.response.ListResponse; | |
| 39 | 35 | import org.apache.cloudstack.api.response.UcsBladeResponse; | |
| 40 | 36 | import org.apache.cloudstack.api.response.UcsManagerResponse; | |
| 41 | 37 | 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; | ||
| 44 | 39 | ||
| 45 | 40 | import com.cloud.configuration.Config; | |
| 46 | 41 | import com.cloud.configuration.dao.ConfigurationDao; | |
@@ -296,7 +291,14 @@ private List<UcsProfile> getUcsProfiles(Long ucsMgrId) { | |||
| 296 | 291 | UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); | |
| 297 | 292 | String res = client.call(cmd); | |
| 298 | 293 | 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; | ||
| 300 | 302 | } | |
| 301 | 303 | ||
| 302 | 304 | @Override | |
@@ -324,13 +326,25 @@ private String cloneProfile(Long ucsMgrId, String srcDn, String newProfileName) | |||
| 324 | 326 | return xo.get("outConfig.lsServer.dn"); | |
| 325 | 327 | } | |
| 326 | 328 | ||
| 329 | + | ||
| 327 | 330 | private boolean isProfileAssociated(Long ucsMgrId, String dn) { | |
| 328 | 331 | UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId); | |
| 329 | 332 | UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); | |
| 330 | 333 | String cookie = getCookie(ucsMgrId); | |
| 331 | 334 | String cmd = UcsCommands.configResolveDn(cookie, dn); | |
| 332 | 335 | String res = client.call(cmd); | |
| 333 | 336 | 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); | ||
| 334 | 348 | s_logger.debug(String.format("association response is %s", res)); | |
| 335 | 349 | ||
| 336 | 350 | if (xo.get("outConfig.computeBlade.association").equals("none")) { | |
@@ -363,7 +377,7 @@ public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cm | |||
| 363 | 377 | int count = 0; | |
| 364 | 378 | int timeout = 600; | |
| 365 | 379 | while (count < timeout) { | |
| 366 | - if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) { | ||
| 380 | + if (isBladeAssociated(mgrvo.getId(), bvo.getDn())) { | ||
| 367 | 381 | break; | |
| 368 | 382 | } | |
| 369 | 383 | ||
@@ -504,6 +518,7 @@ public List<Class<?>> getCommands() { | |||
| 504 | 518 | cmds.add(AddUcsManagerCmd.class); | |
| 505 | 519 | cmds.add(AssociateUcsProfileToBladeCmd.class); | |
| 506 | 520 | cmds.add(DeleteUcsManagerCmd.class); | |
| 521 | + cmds.add(DisassociateUcsProfileCmd.class); | ||
| 507 | 522 | return cmds; | |
| 508 | 523 | } | |
| 509 | 524 | ||
@@ -517,4 +532,21 @@ public void deleteUcsManager(Long id) { | |||
| 517 | 532 | } | |
| 518 | 533 | ucsDao.remove(id); | |
| 519 | 534 | } | |
| 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 | + } | ||
| 520 | 552 | } | |
| Original file line number | Diff line number | Diff 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments