use of com.emc.cloud.platform.ucs.out.model.LsServer 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;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer 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;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer 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;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer 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;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer 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;
}
Aggregations