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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations