Search in sources :

Example 1 with ConfigConfig

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

the class UCSMServiceImpl method setOsInstallVlan.

@Override
public Map<String, Boolean> setOsInstallVlan(String ucsmURL, String username, String password, String spDn, String osInstallVlanId) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    FabricVlan fabricVlan = getVlanById(ucsmURL, username, password, osInstallVlanId);
    if (null == fabricVlan) {
        log.error("Unable to fetch FabricVlan {}", osInstallVlanId);
        String[] s = { "Unable to fetch FabricVlan - " + osInstallVlanId };
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
    }
    LsServer lsServerOut = getManagedObject(ucsmURL, username, password, spDn, true, LsServer.class);
    if (null == lsServerOut) {
        log.error("Unable to fetch LsServer for spDn {}", spDn);
        String[] s = { "Unable to fetch LsServer for spDn " + spDn };
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
    }
    String interfaceName = getFirstVnic(lsServerOut).getName();
    log.info("Selecting OS install interface " + interfaceName + " on " + lsServerOut.getName());
    /**
     * This is the list of vlans that were set on the interface that
     */
    Map<String, Boolean> vlanMap = getVlansSetOnInterface(lsServerOut, interfaceName);
    ConfigConfMo setOsInstallVlanConfMo = new ConfigConfMo();
    setOsInstallVlanConfMo.setInHierarchical(Boolean.toString(true));
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(spDn);
    VnicEther vnicEther = new VnicEther();
    vnicEther.setDn(spDn + "/ether-" + interfaceName);
    // Unbind vnic from vnic template
    vnicEther.setNwTemplName("");
    for (String vlan : vlanMap.keySet()) {
        if (vlan.equals(fabricVlan.getName())) {
            continue;
        }
        VnicEtherIf vnicEtherIfToBeDeleted = new VnicEtherIf();
        vnicEtherIfToBeDeleted.setRn("if-" + vlan);
        vnicEtherIfToBeDeleted.setStatus(MO_DELETED_STATUS);
        vnicEtherIfToBeDeleted.setName(vlan);
        vnicEther.getContent().add(factory.createVnicEtherIf(vnicEtherIfToBeDeleted));
        log.info("Removing VLAN " + vlan + " from interface " + interfaceName + " temporarily for OS installation on " + lsServerOut.getName());
    }
    VnicEtherIf vnicEtherIf = new VnicEtherIf();
    vnicEtherIf.setRn("if-" + fabricVlan.getName());
    vnicEtherIf.setDefaultNet("yes");
    vnicEtherIf.setStatus("");
    vnicEtherIf.setName(fabricVlan.getName());
    vnicEther.getContent().add(factory.createVnicEtherIf(vnicEtherIf));
    log.info("Adding OS install VLAN " + fabricVlan.getName() + " temporarily to interface " + interfaceName + " on " + lsServerOut.getName());
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createVnicEther(vnicEther));
    setOsInstallVlanConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    computeSession.execute(factory.createConfigConfMo(setOsInstallVlanConfMo), com.emc.cloud.platform.ucs.out.model.ConfigConfMo.class);
    return vlanMap;
}
Also used : VnicEtherIf(com.emc.cloud.platform.ucs.in.model.VnicEtherIf) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) VnicEther(com.emc.cloud.platform.ucs.in.model.VnicEther) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) 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 ConfigConfig

use of com.emc.cloud.platform.ucs.in.model.ConfigConfig 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 3 with ConfigConfig

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

the class UCSMServiceImpl method bindSPToTemplate.

@Override
public LsServer bindSPToTemplate(String ucsmURL, String username, String password, String serviceProfileDn, String sptDn, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo bindSPToSPTConfigConfMo = new ConfigConfMo();
    bindSPToSPTConfigConfMo.setInHierarchical(Boolean.toString(true));
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(serviceProfileDn);
    lsServer.setSrcTemplName(sptDn);
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    bindSPToSPTConfigConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer returnedLsServer = pushLsServer(computeSession, factory, bindSPToSPTConfigConfMo, errorMessage);
    if ((returnedLsServer == null) || (!returnedLsServer.getDn().equals(serviceProfileDn)) || (!returnedLsServer.getSrcTemplName().equals(sptDn))) {
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to bind SP to Template '" + sptDn + "' on LsServer : " + serviceProfileDn });
    }
    return returnedLsServer;
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) 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 4 with ConfigConfig

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

the class UCSMServiceImpl method unbindSPFromTemplate.

@Override
public LsServer unbindSPFromTemplate(String ucsmURL, String username, String password, String serviceProfileDn, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo unbindSPFromSPTConfigConfMo = new ConfigConfMo();
    unbindSPFromSPTConfigConfMo.setInHierarchical(Boolean.toString(true));
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(serviceProfileDn);
    lsServer.setSrcTemplName("");
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    unbindSPFromSPTConfigConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer pushedObject = pushLsServer(computeSession, factory, unbindSPFromSPTConfigConfMo, errorMessage);
    String pushedObjectTemplateName = null;
    if (pushedObject != null) {
        pushedObjectTemplateName = pushedObject.getSrcTemplName();
    }
    if ((pushedObject == null) || (pushedObjectTemplateName != null && !pushedObjectTemplateName.equals(""))) {
        // COP-26669
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "ServiceProfile failed to disassociate : " + serviceProfileDn });
    }
    return pushedObject;
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) 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 5 with ConfigConfig

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

the class UCSMServiceImpl method getManagedObject.

@Override
public <T> T getManagedObject(String ucsmURL, String username, String password, String dn, boolean hierarchical, Class<T> returnType) throws ClientGeneralException {
    T managedObject = null;
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigResolveDn configResolveDn = new ConfigResolveDn();
    configResolveDn.setDn(dn);
    configResolveDn.setInHierarchical(new Boolean(hierarchical).toString());
    com.emc.cloud.platform.ucs.out.model.ConfigResolveDn configResolveClassOut = computeSession.execute(factory.createConfigResolveDn(configResolveDn), com.emc.cloud.platform.ucs.out.model.ConfigResolveDn.class);
    com.emc.cloud.platform.ucs.out.model.ConfigConfig configConfig = null;
    if (configResolveClassOut.getContent() != null && !configResolveClassOut.getContent().isEmpty()) {
        for (Object object : configResolveClassOut.getContent()) {
            if (object instanceof JAXBElement<?>) {
                if (!(((JAXBElement) object).getValue() instanceof com.emc.cloud.platform.ucs.out.model.ConfigConfig)) {
                    continue;
                }
                configConfig = ((JAXBElement<com.emc.cloud.platform.ucs.out.model.ConfigConfig>) object).getValue();
                if (configConfig != null && configConfig.getManagedObject() != null) {
                    if (returnType.isInstance(configConfig.getManagedObject().getValue())) {
                        managedObject = returnType.cast(configConfig.getManagedObject().getValue());
                        /**
                         * Short circuit.... No need to run through the
                         * other elements, as only one element is expected!
                         */
                        return managedObject;
                    }
                }
            }
        }
    }
    return managedObject;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) ConfigResolveDn(com.emc.cloud.platform.ucs.in.model.ConfigResolveDn) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig)

Aggregations

ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)11 ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)10 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)9 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)7 LsBinding (com.emc.cloud.platform.ucs.in.model.LsBinding)2 LsPower (com.emc.cloud.platform.ucs.in.model.LsPower)2 VnicEther (com.emc.cloud.platform.ucs.in.model.VnicEther)2 VnicEtherIf (com.emc.cloud.platform.ucs.in.model.VnicEtherIf)2 FabricVlan (com.emc.cloud.platform.ucs.out.model.FabricVlan)2 ConfigResolveDn (com.emc.cloud.platform.ucs.in.model.ConfigResolveDn)1 LsbootDef (com.emc.cloud.platform.ucs.in.model.LsbootDef)1 LsbootLan (com.emc.cloud.platform.ucs.in.model.LsbootLan)1 LsbootSan (com.emc.cloud.platform.ucs.in.model.LsbootSan)1 LsbootStorage (com.emc.cloud.platform.ucs.in.model.LsbootStorage)1 StringWriter (java.io.StringWriter)1 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 Test (org.testng.annotations.Test)1