use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method executeInSession.
/**
* Common code for opening sessions and executing alias-type commands
*
* @param networkSystem the network system when the commands will execute
* @param aliases a list of aliases to be created/updated/deleted
* @param fabricId the name of fabric where the aliases will be changed
* @param fabricWwn the WWN of fabric where the aliases will be changed
* @param methodName the method to be executed
* @param methodLogName the method name to be used for logging
* @return the command that contains a map of results-per-alias keyed
* by alias name
* @throws NetworkDeviceControllerException
*/
private BiosCommandResult executeInSession(NetworkSystem networkSystem, List<ZoneWwnAlias> aliases, String fabricId, String fabricWwn, String methodName, String methodLogName) throws NetworkDeviceControllerException {
// a alias-name-to-result map to hold the results for each alias
Map<String, String> aliasUpdateResults = new HashMap<String, String>();
if (aliases.isEmpty()) {
throw DeviceControllerException.exceptions.entityNullOrEmpty("aliases");
}
WBEMClient client = getNetworkDeviceClient(networkSystem);
CIMInstance zoneServiceIns = null;
try {
if (fabricWwn == null) {
fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
} else {
validateFabric(networkSystem, fabricWwn, fabricId);
}
_log.info("{} started.", methodLogName);
_log.info("Attempting to start a zoning session");
zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
if (zoneServiceIns == null) {
_log.info("Failed to start a zoning session.");
throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
}
Method method = getClass().getMethod(methodName, new Class[] { WBEMClient.class, CIMInstance.class, String.class, String.class, ZoneWwnAlias.class });
for (ZoneWwnAlias alias : aliases) {
try {
if ((Boolean) method.invoke(this, client, zoneServiceIns, fabricId, fabricWwn, alias)) {
aliasUpdateResults.put(alias.getName(), SUCCESS);
} else {
aliasUpdateResults.put(alias.getName(), NO_CHANGE);
}
} catch (Exception ex) {
aliasUpdateResults.put(alias.getName(), ERROR + " : " + ex.getMessage());
_log.info("Exception was encountered but will try the rest of the batch. Error message: ", ex);
}
}
_log.info("Attempting to close zoning session.");
// If no aliases were changed, just close the session without commit and return.
if (!hasResult(aliasUpdateResults, SUCCESS)) {
_log.info("{} was not successful for any entity. Closing the session with no commit", methodLogName);
if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
_log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
}
} else {
// if aliases were changed, commit them before ending the session
if (!_smisHelper.endSession(client, zoneServiceIns, true)) {
throw NetworkDeviceControllerException.exceptions.zoneSessionCommitFailed(fabricId);
}
}
_log.info("{} completed successfully.", methodLogName);
} catch (Exception e1) {
try {
if (zoneServiceIns != null) {
_log.info("Attempting to terminate zoning session.");
_smisHelper.endSession(client, zoneServiceIns, false);
}
} catch (WBEMException e) {
_log.error("Failed to terminate zoning session." + e.getLocalizedMessage(), e);
}
_log.error("Failed to " + methodLogName + ": " + e1.getLocalizedMessage(), e1);
throw NetworkDeviceControllerException.exceptions.operationFailed(methodLogName, e1);
}
_log.info(methodLogName + " results: " + toMessage(aliasUpdateResults));
return getBiosCommandResult(aliasUpdateResults);
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class DCNMDialog method getFabricIds.
/**
* Get the list of Vsan Ids.
*
* @return List<String>
* @throws Exception
*/
public List<String> getFabricIds() throws Exception {
// A set is used because in the case of a disconnected network the same Vsan can
// show up twice. Conerted to list at end.
Set<String> fabricIds = new HashSet<String>();
List<Zoneset> zonesets = new ArrayList<Zoneset>();
CIMObjectPath path = CimObjectPathCreator.createInstance("Cisco_Vsan", _namespace);
CloseableIterator<CIMInstance> vsanIt = null;
try {
vsanIt = _client.enumerateInstances(path, false, true, true, null);
while (vsanIt.hasNext()) {
String vsanId = null;
CIMInstance vsanIns = vsanIt.next();
CIMProperty prop = vsanIns.getProperty("OtherIdentifyingInfo");
String[] idinfoValue = (String[]) prop.getValue();
if (idinfoValue.length == 2 && idinfoValue[0].equals("Fabric")) {
vsanId = idinfoValue[1];
}
if (vsanId != null) {
fabricIds.add(vsanId);
}
}
} finally {
if (vsanIt != null) {
vsanIt.close();
}
}
List<String> alist = new ArrayList<String>();
alist.addAll(fabricIds);
return alist;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class DCNMDialog method getPortConnection.
List<FCEndpoint> getPortConnection() throws Exception {
List<FCEndpoint> connections = new ArrayList<FCEndpoint>();
CIMObjectPath path = CimObjectPathCreator.createInstance("CISCO_LogicalComputerSystem", _namespace);
CloseableIterator<CIMInstance> lcsIt = null;
CloseableIterator<CIMInstance> lportIt = null;
CloseableIterator<CIMInstance> pepIt = null;
try {
lcsIt = _client.enumerateInstances(path, false, true, true, null);
while (lcsIt.hasNext()) {
CIMInstance lcsIns = lcsIt.next();
// Get the VSAN of this Logical COmputer System
String fabricId = null;
String[] identifyingDescriptions = (String[]) lcsIns.getProperty("IdentifyingDescriptions").getValue();
String[] otherIdentifyingInfo = (String[]) lcsIns.getProperty("OtherIdentifyingInfo").getValue();
if (identifyingDescriptions.length >= 2 && identifyingDescriptions[1].equals("VsanId") && otherIdentifyingInfo.length >= 2) {
fabricId = otherIdentifyingInfo[1];
}
// Find the associated CISCO_LogicalFCPort structures
lportIt = _client.associatorInstances(lcsIns.getObjectPath(), "CISCO_FCPortsInLogicalComputerSystem", "CISCO_LogicalFCPort", null, null, false, null);
// Iterate through all the ports in this Vsan, finding connections.
while (lportIt.hasNext()) {
CIMInstance lportIns = lportIt.next();
_log.debug("logical port: " + cimStringProperty(lportIns, "Name") + " wwpn " + cimStringProperty(lportIns, "PermanentAddress"));
String systemName = getSystemNameFromLogicalPort(lportIns);
pepIt = _client.associatorInstances(lportIns.getObjectPath(), "CISCO_FCPortSAPImplementation", "CISCO_ProtocolEndPoint", null, null, false, null);
while (pepIt.hasNext()) {
CIMInstance pepIns = pepIt.next();
_log.debug("endpoint: " + cimStringProperty(pepIns, "Name"));
FCProtocolEndpoint pep = new FCProtocolEndpoint(pepIns);
pep.findConnections(_client, _namespace);
for (String key : pep.connections.keySet()) {
_log.debug("connection: " + key);
FCProtocolEndpoint cep = pep.connections.get(key);
FCEndpoint conn = new FCEndpoint();
// conn.setFabricId(fabricId)
conn.setRemotePortName(formatWWN(cep.wwpn));
conn.setLabel(conn.getRemotePortName());
conn.setRemoteNodeName(formatWWN(cep.wwnn));
conn.setSwitchPortName(formatWWN(cimStringProperty(lportIns, "PermanentAddress")));
conn.setSwitchInterface(cimStringProperty(lportIns, "Name"));
conn.setFabricId(fabricId);
conn.setSwitchName(systemName);
connections.add(conn);
}
}
pepIt.close();
pepIt = null;
}
lportIt.close();
lportIt = null;
}
} finally {
if (lcsIt != null) {
lcsIt.close();
}
if (lportIt != null) {
lportIt.close();
}
if (pepIt != null) {
pepIt.close();
}
}
return connections;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class DCNMDialog method getSystemNameFromLogicalPort.
/**
* Given an instance of a CISCO_LogicalFCPort, get the system name housing this port.
*
* @param lportIns
* @return system name String
* @throws Exception
*/
private String getSystemNameFromLogicalPort(CIMInstance lportIns) throws Exception {
String systemName = null;
CloseableIterator<CIMInstance> fcportIt = null;
CloseableIterator<CIMInstance> physcomputerIt = null;
try {
fcportIt = _client.associatorInstances(lportIns.getObjectPath(), null, "CISCO_FCPort", null, null, false, null);
while (fcportIt.hasNext()) {
CIMInstance fcportIns = fcportIt.next();
physcomputerIt = _client.associatorInstances(fcportIns.getObjectPath(), null, "CISCO_PhysicalComputerSystem", null, null, false, null);
while (physcomputerIt.hasNext()) {
CIMInstance physins = physcomputerIt.next();
systemName = cimStringProperty(physins, "ElementName");
}
physcomputerIt.close();
physcomputerIt = null;
}
} finally {
if (fcportIt != null) {
fcportIt.close();
}
if (physcomputerIt != null) {
physcomputerIt.close();
}
}
return systemName;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class DCNMDialog method getZonesetsInVsan.
/**
* Returns the zonesets in a VSAN as given by its CIMInstance.
* This generates the nested objects Zone and ZoneMember in the Zonesets.
*
* @param vsanIns CIMInstance of vsan
* @return List<Zoneset>
* @throws javax.wbem.WBEMException
*/
private List<Zoneset> getZonesetsInVsan(CIMInstance vsanIns) throws WBEMException {
List<Zoneset> inactiveZonesets = new ArrayList<Zoneset>();
Zoneset activeZoneset = null;
// Iterate through the zonesets.
CloseableIterator<CIMInstance> zstIt = null;
try {
zstIt = _client.associatorInstances(vsanIns.getObjectPath(), "CIM_HostedCollection", "CISCO_Zoneset", null, null, false, null);
while (zstIt.hasNext()) {
CIMInstance zsIns = zstIt.next();
Zoneset zs = makeZoneset(zsIns);
_log.debug("zoneset: " + zs.name);
if (zs.active == true) {
activeZoneset = zs;
} else {
inactiveZonesets.add(zs);
}
}
} catch (WBEMException ex) {
// Problem where iterator isn't returned in associators();
} finally {
if (zstIt != null) {
zstIt.close();
}
}
List<Zoneset> zonesets = new ArrayList<Zoneset>();
if (activeZoneset != null) {
zonesets.add(activeZoneset);
}
zonesets.addAll(inactiveZonesets);
return zonesets;
}
Aggregations