Search in sources :

Example 1 with ClientGeneralException

use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.

the class UcsComputeDevice method prepareOsInstallNetwork.

@Override
public Map<String, Boolean> prepareOsInstallNetwork(URI computeSystemId, URI computeElementId) throws InternalException {
    LOGGER.info("prepareOsInstallNetwork");
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElementId);
    String osInstallVlan = cs.getOsInstallNetwork();
    Map<String, Boolean> vlanMap = null;
    try {
        vlanMap = ucsmService.setOsInstallVlan(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), ce.getDn(), osInstallVlan);
    } catch (ClientGeneralException e) {
        LOGGER.error("Unable to set os install vlan: " + cs.getOsInstallNetwork() + " On computeElement : " + ce.getId(), e);
        throw ComputeSystemControllerException.exceptions.unableToSetOsInstallNetwork(osInstallVlan, ce.getId().toString(), e);
    }
    return vlanMap;
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 2 with ClientGeneralException

use of com.emc.cloud.platform.clientlib.ClientGeneralException 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 ClientGeneralException

use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.

the class UCSMServiceImpl method setLsBootDefOnLsServer.

private LsServer setLsBootDefOnLsServer(String ucsmURL, String username, String password, String spDn, BootType bootType, Map<String, Map<String, Integer>> hbaToStoragePortMap, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    String version = getDeviceVersion(ucsmURL, username, password);
    LsServer lsServerCurrent = getManagedObject(ucsmURL, username, password, spDn, true, LsServer.class);
    if (lsServerCurrent == null) {
        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);
    }
    ConfigConfMo lsbootDefConfigMo = new ConfigConfMo();
    lsbootDefConfigMo.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);
    lsServer.getContent().add(factory.createLsbootDef(createLsBootDef(bootType, spDn, version, lsServerCurrent, hbaToStoragePortMap)));
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    lsbootDefConfigMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer returnedLsServer = pushLsServer(computeSession, factory, lsbootDefConfigMo, errorMessage);
    List<com.emc.cloud.platform.ucs.out.model.LsbootDef> lsBootDefs = getSubElements(returnedLsServer.getContent(), com.emc.cloud.platform.ucs.out.model.LsbootDef.class);
    boolean operationVerified = false;
    switch(bootType) {
        case LAN:
            List<com.emc.cloud.platform.ucs.out.model.LsbootLan> lsBootLans = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootLan.class);
            if (lsBootLans != null) {
                for (com.emc.cloud.platform.ucs.out.model.LsbootLan lsBootLan : lsBootLans) {
                    if (lsBootLan.getOrder().equals("1")) {
                        operationVerified = true;
                        break;
                    }
                }
            }
            break;
        case SAN:
            if (UcsmVersionChecker.verifyVersionDetails("2.2", version) < 0) {
                // UCS Model change as of 2.2
                List<com.emc.cloud.platform.ucs.out.model.LsbootStorage> lsBootStorages = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootStorage.class);
                if (lsBootStorages != null) {
                    for (com.emc.cloud.platform.ucs.out.model.LsbootStorage lsBootStorage : lsBootStorages) {
                        if (lsBootStorage.getOrder().equals("1")) {
                            operationVerified = true;
                            break;
                        }
                    }
                }
            } else {
                List<com.emc.cloud.platform.ucs.out.model.LsbootSan> lsBootSans = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootSan.class);
                if (lsBootSans != null) {
                    for (com.emc.cloud.platform.ucs.out.model.LsbootSan lsBootSan : lsBootSans) {
                        if (lsBootSan.getOrder().equals("1")) {
                            operationVerified = true;
                            break;
                        }
                    }
                }
            }
            break;
        case NONE:
            if ((lsBootDefs != null) && (lsBootDefs.isEmpty())) {
                operationVerified = true;
            }
            break;
        case EMPTY:
            if ((lsBootDefs != null) && (lsBootDefs.size() == 1) && ((lsBootDefs.get(0).getContent() == null) || (lsBootDefs.get(0).getContent().size() == 0))) {
                operationVerified = true;
            }
    }
    if (!operationVerified) {
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to set boot definition '" + bootType.name() + "' on LsServer : " + spDn });
    }
    return returnedLsServer;
}
Also used : LsbootSan(com.emc.cloud.platform.ucs.in.model.LsbootSan) LsbootLan(com.emc.cloud.platform.ucs.in.model.LsbootLan) LsbootStorage(com.emc.cloud.platform.ucs.in.model.LsbootStorage) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo) LsbootDef(com.emc.cloud.platform.ucs.in.model.LsbootDef)

Example 4 with ClientGeneralException

use of com.emc.cloud.platform.clientlib.ClientGeneralException in project coprhd-controller by CoprHD.

the class UCSMServiceImpl method getAllLsServers.

private List<LsServer> getAllLsServers(String ucsmURL, String username, String password, boolean serviceProfilesOnly) throws ClientGeneralException {
    List<LsServer> lsServers = Collections.synchronizedList(new ArrayList<LsServer>());
    try {
        ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
        ConfigResolveClass configResolveClass = new ConfigResolveClass();
        configResolveClass.setClassId(NamingClassId.LS_SERVER);
        configResolveClass.setInHierarchical("true");
        // configResolveClass.getContent();
        com.emc.cloud.platform.ucs.out.model.ConfigResolveClass configResolveClassOut = computeSession.execute(factory.createConfigResolveClass(configResolveClass), com.emc.cloud.platform.ucs.out.model.ConfigResolveClass.class);
        ConfigSet configSet = null;
        if (configResolveClassOut.getContent() != null && !configResolveClassOut.getContent().isEmpty()) {
            for (Object object : configResolveClassOut.getContent()) {
                if (object instanceof JAXBElement<?>) {
                    if (!(((JAXBElement) object).getValue() instanceof ConfigSet)) {
                        continue;
                    }
                    configSet = ((JAXBElement<ConfigSet>) object).getValue();
                    if (configSet != null && configSet.getManagedObject() != null && !configSet.getManagedObject().isEmpty()) {
                        for (JAXBElement<?> managedObject : configSet.getManagedObject()) {
                            if (managedObject.getValue() instanceof LsServer) {
                                LsServer lsServer = (LsServer) managedObject.getValue();
                                if (serviceProfilesOnly && !(lsServer.getType().equals("instance"))) {
                                    continue;
                                }
                                lsServers.add(lsServer);
                            }
                        }
                    }
                }
            }
        }
    } catch (ClientGeneralException e) {
        log.error("Unable to get all lsServers", e);
        throw e;
    }
    return lsServers;
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) JAXBElement(javax.xml.bind.JAXBElement) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 5 with ClientGeneralException

use of com.emc.cloud.platform.clientlib.ClientGeneralException 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)

Aggregations

ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)25 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)12 ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)7 ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)7 ConfigSet (com.emc.cloud.platform.ucs.out.model.ConfigSet)5 MalformedURLException (java.net.MalformedURLException)5 JAXBElement (javax.xml.bind.JAXBElement)5 ConfigResolveClass (com.emc.cloud.platform.ucs.in.model.ConfigResolveClass)4 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)3 EqFilter (com.emc.cloud.platform.ucs.in.model.EqFilter)2 FilterFilter (com.emc.cloud.platform.ucs.in.model.FilterFilter)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 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2 QName (javax.xml.namespace.QName)2 ClientHttpRequest (com.emc.cloud.platform.clientlib.ClientHttpRequest)1 AaaLogin (com.emc.cloud.platform.ucs.in.model.AaaLogin)1 ConfigResolveDn (com.emc.cloud.platform.ucs.in.model.ConfigResolveDn)1 DnSet (com.emc.cloud.platform.ucs.in.model.DnSet)1