Search in sources :

Example 1 with LsPower

use of com.emc.cloud.platform.ucs.out.model.LsPower in project coprhd-controller by CoprHD.

the class UCSMServiceTest method testSetLsServerPowerState.

@Test(groups = "onDemand1")
public void testSetLsServerPowerState() throws ClientGeneralException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<String, LsServer> associatedLsServers = ucsmService.getAllAssociatedLsServers(UCSM_SERVICE, UCSM_HOST_USERNAME, UCSM_HOST_PASSWORD);
    String powerStateToSet = null;
    if (associatedLsServers != null && !associatedLsServers.isEmpty()) {
        for (LsServer lsServer : associatedLsServers.values()) {
            if (SP_DN.equals(lsServer.getDn())) {
                if (lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
                    for (Object object : lsServer.getContent()) {
                        if (object instanceof JAXBElement<?>) {
                            if (((JAXBElement) object).getValue() instanceof LsPower) {
                                LsPower lsPower = ((JAXBElement<LsPower>) object).getValue();
                                if ("up".equals(lsPower.getState())) {
                                    powerStateToSet = "down";
                                } else if ("down".equals(lsPower.getState())) {
                                    powerStateToSet = "up";
                                }
                                LsServer lsServerOut = ucsmService.setLsServerPowerState(UCSM_SERVICE, UCSM_HOST_USERNAME, UCSM_HOST_PASSWORD, lsServer.getDn(), powerStateToSet, new StringBuilder());
                                if (lsServerOut.getContent() != null && !lsServerOut.getContent().isEmpty()) {
                                    for (Object object2 : lsServerOut.getContent()) {
                                        if (object2 instanceof JAXBElement<?>) {
                                            if (((JAXBElement) object2).getValue() instanceof LsPower) {
                                                LsPower lsPower2 = ((JAXBElement<LsPower>) object2).getValue();
                                                Assert.assertTrue(powerStateToSet.equals(lsPower2.getState()));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    System.out.println("Number of associated lsServers found: " + associatedLsServers.size());
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) JAXBElement(javax.xml.bind.JAXBElement) LsPower(com.emc.cloud.platform.ucs.out.model.LsPower) Test(org.testng.annotations.Test)

Aggregations

LsPower (com.emc.cloud.platform.ucs.out.model.LsPower)1 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)1 JAXBElement (javax.xml.bind.JAXBElement)1 Test (org.testng.annotations.Test)1