Search in sources :

Example 6 with ConfigConfMo

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

use of com.emc.cloud.platform.ucs.in.model.ConfigConfMo 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)

Example 8 with ConfigConfMo

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

the class UCSMServiceImpl method removeOsInstallVlan.

@Override
public void removeOsInstallVlan(String ucsmURL, String username, String password, String spDn, String osInstallVlanId, Map<String, Boolean> vlanMap) throws ClientGeneralException {
    FabricVlan fabricVlan = getVlanById(ucsmURL, username, password, osInstallVlanId);
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    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);
    LsServer lsServerOut = getManagedObject(ucsmURL, username, password, spDn, true, LsServer.class);
    if (null == fabricVlan) {
        log.error("Unable to fetch FabricVlan {}", osInstallVlanId);
        String[] s = { "Unable to fetch FabricVlan - " + osInstallVlanId };
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
    }
    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);
    }
    com.emc.cloud.platform.ucs.out.model.VnicEther firstVnic = getFirstVnic(lsServerOut);
    String interfaceName = firstVnic.getName();
    log.info("Restoring VLANs on " + lsServerOut.getName() + " after OS install on interface: " + interfaceName);
    Map<String, Boolean> vlansOnInterface = getVlansSetOnInterface(lsServerOut, interfaceName);
    if ((vlansOnInterface.size() != 1) || (vlansOnInterface.get(fabricVlan.getName()) == null)) {
        String[] s = { "Error restoring VLANs after OS Installation on " + lsServerOut.getName() + ".  VNICs were modified during OS install.  Interface " + interfaceName + " does not contain just the OS install VLAN.  It contains " + vlansOnInterface.keySet() };
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
    }
    VnicEther vnicEther = new VnicEther();
    vnicEther.setDn(spDn + "/ether-" + interfaceName);
    vnicEther.setNwTemplName(firstVnic.getNwTemplName());
    boolean shouldDeleteOsInstallVlan = true;
    for (String vlan : vlanMap.keySet()) {
        if (vlan.equals(fabricVlan.getName())) {
            shouldDeleteOsInstallVlan = false;
        }
        VnicEtherIf vnicEtherIfToAdded = new VnicEtherIf();
        vnicEtherIfToAdded.setRn("if-" + vlan);
        vnicEtherIfToAdded.setName(vlan);
        vnicEtherIfToAdded.setStatus("");
        if (vlanMap.get(vlan)) {
            vnicEtherIfToAdded.setDefaultNet(DEFAULT_NETWORK_VALUES.YES.getValue());
        }
        vnicEther.getContent().add(factory.createVnicEtherIf(vnicEtherIfToAdded));
        log.info("  Adding VLAN " + vlan + " to be restored to interface " + interfaceName + " of " + lsServerOut.getName());
    }
    if (shouldDeleteOsInstallVlan) {
        VnicEtherIf vnicEtherIf = new VnicEtherIf();
        vnicEtherIf.setRn("if-" + fabricVlan.getName());
        vnicEtherIf.setStatus(MO_DELETED_STATUS);
        vnicEtherIf.setName(fabricVlan.getName());
        vnicEther.getContent().add(factory.createVnicEtherIf(vnicEtherIf));
        log.info("  Adding VLAN " + fabricVlan.getName() + " to be removed from interface " + interfaceName + " of " + lsServerOut.getName());
    }
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createVnicEther(vnicEther));
    setOsInstallVlanConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    StringBuilder errorMessage = new StringBuilder();
    com.emc.cloud.platform.ucs.out.model.VnicEther returnedVnicEther = pushConfigConfMo(computeSession, factory, setOsInstallVlanConfMo, com.emc.cloud.platform.ucs.out.model.VnicEther.class, true, errorMessage).get(// expect 1
    0);
    List<VnicEtherIf> vnicEtherIfs = getSubElements(returnedVnicEther.getContent(), VnicEtherIf.class);
    for (String vlan : vlanMap.keySet()) {
        for (VnicEtherIf vnicEtherIf : vnicEtherIfs) {
            if (vnicEtherIf.getName().equals(vlan)) {
                throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to restore vNIC after OS Install with vLAN " + vlan });
            }
        }
    }
    for (VnicEtherIf vnicEtherIf : vnicEtherIfs) {
        if (vnicEtherIf.getName().equals(fabricVlan.getName())) {
            throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to remove OS Install vLAN " + fabricVlan.getName() });
        }
    }
}
Also used : VnicEtherIf(com.emc.cloud.platform.ucs.in.model.VnicEtherIf) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) 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) VnicEther(com.emc.cloud.platform.ucs.in.model.VnicEther) ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo)

Example 9 with ConfigConfMo

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

the class UCSMServiceImpl method unbindServiceProfile.

@Override
public LsServer unbindServiceProfile(String ucsmURL, String username, String password, String spDn, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo disAssocSPFromBladeMO = new ConfigConfMo();
    disAssocSPFromBladeMO.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);
    LsBinding lsBinding = new LsBinding();
    lsBinding.setPnDn("");
    lsBinding.setStatus(MO_DELETED_STATUS);
    lsServer.getContent().add(factory.createLsBinding(lsBinding));
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    disAssocSPFromBladeMO.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer updatedLsServer = pushLsServer(computeSession, factory, disAssocSPFromBladeMO, errorMessage);
    log.info("The new Oper State of the Service Profile is : " + updatedLsServer.getOperState());
    return updatedLsServer;
}
Also used : LsBinding(com.emc.cloud.platform.ucs.in.model.LsBinding) 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)

Example 10 with ConfigConfMo

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

the class UCSMServiceImpl method deleteServiceProfile.

@Override
public void deleteServiceProfile(String ucsmURL, String username, String password, String spDn, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo deleteSPMO = new ConfigConfMo();
    deleteSPMO.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.setStatus(MO_DELETED_STATUS);
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    deleteSPMO.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    pushLsServer(computeSession, factory, deleteSPMO, errorMessage);
    log.info("Deleted the Service Profile with dn : " + spDn);
}
Also used : ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig)

Aggregations

ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)10 ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)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 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 Marshaller (javax.xml.bind.Marshaller)1 Test (org.testng.annotations.Test)1