Search in sources :

Example 1 with LsPower

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

the class UCSMServiceImpl method setLsServerPowerState.

/**
 * @param ucsmURL
 * @param username
 * @param password
 * @param lsServerDN
 *            - is the DN of the lsServer (unique for the UCSM that's
 *            represented by ucsmURL)
 * @param powerState
 *            - is "up" or "down"
 * @return
 * @throws ClientGeneralException
 */
@Override
public LsServer setLsServerPowerState(String ucsmURL, String username, String password, String lsServerDN, String powerState, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo configConfMo = new ConfigConfMo();
    configConfMo.setInHierarchical("true");
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(lsServerDN);
    LsPower lsPower = new LsPower();
    lsPower.setRn("power");
    lsPower.setState(powerState);
    lsServer.getContent().add(factory.createLsPower(lsPower));
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    configConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer returnedLsServer = pushLsServer(computeSession, factory, configConfMo, errorMessage);
    List<LsPower> lsPowers = getSubElements(returnedLsServer.getContent(), LsPower.class);
    if ((lsPowers == null) || lsPowers.isEmpty() || (lsPowers.get(0) == null) || !lsPowers.get(0).getState().equals(powerState)) {
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to set power state to '" + powerState + "' on LsServer : " + lsServerDN });
    }
    return returnedLsServer;
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) LsPower(com.emc.cloud.platform.ucs.in.model.LsPower) ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 2 with LsPower

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

the class ConfigMOMarshallingTest method testMarshalling.

@Test(groups = "onDemand")
public void testMarshalling() throws ClientGeneralException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, JAXBException {
    String lsServerDN = "org-root/ls-vlad2-os-install";
    String powerState = "up";
    ConfigConfMo configConfMo = new ConfigConfMo();
    configConfMo.setInHierarchical("true");
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(lsServerDN);
    LsPower lsPower = new LsPower();
    lsPower.setRn("power");
    lsPower.setState(powerState);
    lsServer.getContent().add(factory.createLsPower(lsPower));
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    configConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    JAXBElement<ConfigConfMo> jaxbElement = factory.createConfigConfMo(configConfMo);
    StringWriter writer = new StringWriter();
    if (jaxbElement != null) {
        Marshaller marshaller = ucsInContext.createMarshaller();
        marshaller.marshal(jaxbElement, writer);
    }
    String payload = writer.toString();
    System.out.println("Payload : " + payload);
}
Also used : Marshaller(javax.xml.bind.Marshaller) LsPower(com.emc.cloud.platform.ucs.in.model.LsPower) ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo) StringWriter(java.io.StringWriter) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig) Test(org.testng.annotations.Test)

Aggregations

ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)2 ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)2 LsPower (com.emc.cloud.platform.ucs.in.model.LsPower)2 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)1 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)1 StringWriter (java.io.StringWriter)1 Marshaller (javax.xml.bind.Marshaller)1 Test (org.testng.annotations.Test)1