Search in sources :

Example 1 with FabricVlan

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

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

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

the class UCSMServiceImpl method getUcsVlans.

@Override
public List<FabricVlan> getUcsVlans(String ucsmURL, String username, String password) throws ClientGeneralException {
    List<FabricVlan> vlanList = new ArrayList<FabricVlan>();
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigResolveClass configResolveClass = new ConfigResolveClass();
    configResolveClass.setClassId(NamingClassId.FABRIC_VLAN);
    configResolveClass.setInHierarchical("false");
    com.emc.cloud.platform.ucs.out.model.ConfigResolveClass configResolveClassOut = computeSession.execute(factory.createConfigResolveClass(configResolveClass), com.emc.cloud.platform.ucs.out.model.ConfigResolveClass.class);
    for (JAXBElement<?> managedObject : getConfigSetManagedObjects(configResolveClassOut)) {
        if (managedObject.getValue() instanceof FabricVlan) {
            vlanList.add((FabricVlan) managedObject.getValue());
        }
    }
    return vlanList;
}
Also used : ArrayList(java.util.ArrayList) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan)

Example 4 with FabricVlan

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

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

the class UCSMServiceTest method testGetVlanById.

@Test(groups = "onDemand")
public void testGetVlanById() throws ClientGeneralException {
    String vlanId = "631";
    FabricVlan fabricVlan = ucsmService.getVlanById(UCSM_SERVICE2, UCSM_HOST2_USERNAME, UCSM_HOST2_PASSWORD, vlanId);
    Assert.assertNotNull(fabricVlan, "No VLAN with ID : " + vlanId + " exists in the Compute System");
    System.out.println("Found VLAN with Name : " + fabricVlan.getName());
}
Also used : FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) Test(org.testng.annotations.Test)

Aggregations

FabricVlan (com.emc.cloud.platform.ucs.out.model.FabricVlan)7 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)3 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)2 ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)2 ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)2 ConfigResolveClass (com.emc.cloud.platform.ucs.in.model.ConfigResolveClass)2 VnicEther (com.emc.cloud.platform.ucs.in.model.VnicEther)2 VnicEtherIf (com.emc.cloud.platform.ucs.in.model.VnicEtherIf)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 EqFilter (com.emc.cloud.platform.ucs.in.model.EqFilter)1 FilterFilter (com.emc.cloud.platform.ucs.in.model.FilterFilter)1 ComputeBlade (com.emc.cloud.platform.ucs.out.model.ComputeBlade)1 ConfigSet (com.emc.cloud.platform.ucs.out.model.ConfigSet)1 FabricVsan (com.emc.cloud.platform.ucs.out.model.FabricVsan)1 FcPIo (com.emc.cloud.platform.ucs.out.model.FcPIo)1 LsbootPolicy (com.emc.cloud.platform.ucs.out.model.LsbootPolicy)1 SwFcSanEp (com.emc.cloud.platform.ucs.out.model.SwFcSanEp)1 SwFcSanPc (com.emc.cloud.platform.ucs.out.model.SwFcSanPc)1 SwVsan (com.emc.cloud.platform.ucs.out.model.SwVsan)1 VnicLanConnTempl (com.emc.cloud.platform.ucs.out.model.VnicLanConnTempl)1