Search in sources :

Example 1 with ConfigSet

use of com.emc.cloud.platform.ucs.out.model.ConfigSet 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 2 with ConfigSet

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

the class UCSMServiceImpl method getComputeBlades.

@Override
public List<ComputeBlade> getComputeBlades(String ucsmURL, String username, String password) throws ClientGeneralException {
    List<ComputeBlade> blades = new ArrayList<ComputeBlade>();
    try {
        ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
        ConfigResolveClass configResolveClass = new ConfigResolveClass();
        configResolveClass.setClassId(NamingClassId.COMPUTE_ITEM);
        configResolveClass.setInHierarchical("true");
        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 ComputeBlade) {
                                blades.add((ComputeBlade) managedObject.getValue());
                            }
                        }
                    }
                }
            }
        }
    } catch (ClientGeneralException e) {
        log.warn("Unable to get compute elements", e);
        throw e;
    }
    return blades;
}
Also used : ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) ArrayList(java.util.ArrayList) 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 3 with ConfigSet

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

the class UCSMServiceImpl method getVlanById.

@Override
public FabricVlan getVlanById(String ucsmURL, String username, String password, String vlanId) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigResolveClass configResolveClass = new ConfigResolveClass();
    configResolveClass.setClassId(NamingClassId.FABRIC_VLAN);
    configResolveClass.setInHierarchical("true");
    FilterFilter inFilter = new FilterFilter();
    EqFilter eqFilter = new EqFilter();
    eqFilter.setProperty("id");
    eqFilter.setClazz(NamingClassId.FABRIC_VLAN);
    eqFilter.setValue(vlanId);
    inFilter.setAbstractFilter(factory.createEq(eqFilter));
    configResolveClass.getContent().add(new JAXBElement<FilterFilter>(new QName("inFilter"), FilterFilter.class, inFilter));
    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 FabricVlan) {
                            return (FabricVlan) managedObject.getValue();
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) JAXBElement(javax.xml.bind.JAXBElement) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) FilterFilter(com.emc.cloud.platform.ucs.in.model.FilterFilter) EqFilter(com.emc.cloud.platform.ucs.in.model.EqFilter) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet)

Example 4 with ConfigSet

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

the class UCSMServiceImpl method createServiceProfileFromTemplate.

/**
 * Create Service Profile from ServiceProfileTemplate
 *
 * @param ucsmURL
 * @param username
 * @param password
 * @param serviceProfileDns
 * @param errorMessage
 * @return
 * @throws ClientGeneralException
 */
@Override
public LsServer createServiceProfileFromTemplate(String ucsmURL, String username, String password, String serviceProfileTemplateDn, String serviceProfileName, StringBuffer errorMessage) throws ClientGeneralException {
    if (serviceProfileTemplateDn == null || serviceProfileTemplateDn.isEmpty()) {
        throw new ClientGeneralException(ClientMessageKeys.EXPECTED_PARAMETER_WAS_NULL, new String[] { "serviceProfileTemplateDn" });
    }
    LsServer createdServiceProfile = null;
    List<LsServer> existingLsServers = getAllLsServers(ucsmURL, username, password, false);
    if (StringUtils.isNotBlank(serviceProfileName)) {
        String serviceProfileNameToUse = serviceProfileName;
        int index = 0;
        boolean serviceProfileNameIsDuplicate = isServiceProfileDuplicate(existingLsServers, serviceProfileNameToUse);
        if (!serviceProfileNameIsDuplicate) {
            if (serviceProfileNameToUse.length() > 32) {
                serviceProfileNameToUse = StringUtils.substringBefore(serviceProfileName, ".");
                if (serviceProfileNameToUse.length() > 32) {
                    serviceProfileNameToUse = StringUtils.substring(serviceProfileNameToUse, 0, 32);
                }
                serviceProfileNameIsDuplicate = isServiceProfileDuplicate(existingLsServers, serviceProfileNameToUse);
            }
        }
        while (serviceProfileNameIsDuplicate) {
            index++;
            serviceProfileNameToUse = serviceProfileName + "_" + Integer.toString(index);
            if (serviceProfileNameToUse.length() > 32) {
                serviceProfileNameToUse = StringUtils.substringBefore(serviceProfileName, ".") + "_" + Integer.toString(index);
                if (serviceProfileNameToUse.length() > 32) {
                    serviceProfileNameToUse = StringUtils.substring(serviceProfileNameToUse, 0, 32 - (Integer.toString(index).length() + 1));
                }
            }
            serviceProfileNameIsDuplicate = isServiceProfileDuplicate(existingLsServers, serviceProfileNameToUse);
        }
        try {
            ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
            LsInstantiateNNamedTemplate namedTemplate = new LsInstantiateNNamedTemplate();
            namedTemplate.setDn(serviceProfileTemplateDn);
            namedTemplate.setInHierarchical(Boolean.toString(false));
            String orgName = serviceProfileTemplateDn.substring(0, serviceProfileTemplateDn.lastIndexOf("/"));
            namedTemplate.setInTargetOrg(orgName);
            Dn dn = new Dn();
            dn.setValue(serviceProfileNameToUse);
            DnSet dnSet = new DnSet();
            dnSet.getDn().add(dn);
            namedTemplate.getContent().add(factory.createLsInstantiateNNamedTemplateInNameSet(dnSet));
            com.emc.cloud.platform.ucs.out.model.LsInstantiateNNamedTemplate namedTemplateOut = computeSession.execute(factory.createLsInstantiateNNamedTemplate(namedTemplate), com.emc.cloud.platform.ucs.out.model.LsInstantiateNNamedTemplate.class);
            if (namedTemplateOut != null && namedTemplateOut.getContent() != null) {
                if (!namedTemplateOut.getContent().isEmpty()) {
                    /*
                         * Expecting only one element to be returned!
                         */
                    for (Serializable contentElement : namedTemplateOut.getContent()) {
                        if (contentElement instanceof JAXBElement<?> && ((JAXBElement<?>) contentElement).getValue() != null) {
                            if (((JAXBElement<?>) contentElement).getValue() instanceof ConfigSet) {
                                ConfigSet configSet = (ConfigSet) ((JAXBElement<?>) contentElement).getValue();
                                for (JAXBElement<?> contentElement2 : configSet.getManagedObject()) {
                                    if (contentElement2.getValue() != null && contentElement2.getValue() instanceof LsServer) {
                                        createdServiceProfile = (LsServer) contentElement2.getValue();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            String errorDescription = null;
            if (namedTemplateOut != null) {
                errorDescription = namedTemplateOut.getErrorDescr();
            }
            if (errorDescription != null) {
                log.error("Error received from UCS: " + errorDescription);
                errorMessage.append("Error received from UCS: " + errorDescription);
            }
        } catch (ClientGeneralException e) {
            log.error("Unable to create service profile : " + serviceProfileName + " From SPT : " + serviceProfileTemplateDn, e);
            throw e;
        }
    } else {
        throw new ClientGeneralException(ClientMessageKeys.EXPECTED_PARAMETER_WAS_NULL, new String[] { "serviceProfileName" });
    }
    if (createdServiceProfile != null) {
        // re-fetch service profile so we have the correct uuid; else uuid of lsServer says 'derived'
        createdServiceProfile = getLsServerByDn(ucsmURL, username, password, createdServiceProfile.getDn());
    }
    return createdServiceProfile;
}
Also used : Serializable(java.io.Serializable) LsInstantiateNNamedTemplate(com.emc.cloud.platform.ucs.in.model.LsInstantiateNNamedTemplate) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) DnSet(com.emc.cloud.platform.ucs.in.model.DnSet) ConfigResolveDn(com.emc.cloud.platform.ucs.in.model.ConfigResolveDn) Dn(com.emc.cloud.platform.ucs.in.model.DnSet.Dn) JAXBElement(javax.xml.bind.JAXBElement) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet)

Example 5 with ConfigSet

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

the class UCSMServiceImpl method getLsServer.

public LsServer getLsServer(ComputeSession computeSession, String uuid) throws ClientGeneralException {
    try {
        ConfigResolveClass configResolveClass = new ConfigResolveClass();
        configResolveClass.setClassId(NamingClassId.LS_SERVER);
        configResolveClass.setInHierarchical("true");
        // configResolveClass.getContent()
        FilterFilter inFilter = new FilterFilter();
        EqFilter eqFilter = new EqFilter();
        eqFilter.setClazz(NamingClassId.LS_SERVER);
        eqFilter.setProperty("uuid");
        eqFilter.setValue(uuid);
        inFilter.setAbstractFilter(factory.createEq(eqFilter));
        configResolveClass.getContent().add(new JAXBElement<>(new QName("inFilter"), FilterFilter.class, inFilter));
        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) {
                                return (LsServer) managedObject.getValue();
                            }
                        }
                    }
                }
            }
        }
    } catch (ClientGeneralException e) {
        log.error("Unable to get all associated lsServers", e);
        throw e;
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) JAXBElement(javax.xml.bind.JAXBElement) FilterFilter(com.emc.cloud.platform.ucs.in.model.FilterFilter) EqFilter(com.emc.cloud.platform.ucs.in.model.EqFilter) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Aggregations

ConfigSet (com.emc.cloud.platform.ucs.out.model.ConfigSet)8 JAXBElement (javax.xml.bind.JAXBElement)8 ConfigResolveClass (com.emc.cloud.platform.ucs.in.model.ConfigResolveClass)6 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)5 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)5 QName (javax.xml.namespace.QName)5 EqFilter (com.emc.cloud.platform.ucs.in.model.EqFilter)4 FilterFilter (com.emc.cloud.platform.ucs.in.model.FilterFilter)4 ConfigResolveDn (com.emc.cloud.platform.ucs.in.model.ConfigResolveDn)1 ConfigResolveDns (com.emc.cloud.platform.ucs.in.model.ConfigResolveDns)1 DnSet (com.emc.cloud.platform.ucs.in.model.DnSet)1 Dn (com.emc.cloud.platform.ucs.in.model.DnSet.Dn)1 LsInstantiateNNamedTemplate (com.emc.cloud.platform.ucs.in.model.LsInstantiateNNamedTemplate)1 OrFilter (com.emc.cloud.platform.ucs.in.model.OrFilter)1 ComputeBlade (com.emc.cloud.platform.ucs.out.model.ComputeBlade)1 DnSet (com.emc.cloud.platform.ucs.out.model.DnSet)1 Dn (com.emc.cloud.platform.ucs.out.model.DnSet.Dn)1 FabricVlan (com.emc.cloud.platform.ucs.out.model.FabricVlan)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1