use of javax.cim.CIMObjectPath in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getUptime.
/**
* Returns the system uptime.
*
* @param client - WBEMClient
* @return system uptime
* @throws WBEMException
*/
public String getUptime(WBEMClient client) throws WBEMException {
String startTime = null;
CIMObjectPath path = CimObjectPathCreator.createInstance(_agent_name, _namespace);
CloseableIterator<CIMInstance> it = null;
try {
it = client.enumerateInstances(path, false, true, true, null);
while (it.hasNext()) {
CIMInstance ins = it.next();
startTime = cimStringProperty(ins, _StartTime);
}
} finally {
if (it != null) {
it.close();
}
}
return startTime == null ? null : getUptimeFormatted(startTime);
}
use of javax.cim.CIMObjectPath in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method addZoneAlias.
/**
* Create an instance of an alias object on the switch. The alias object can have
* a single member that has to be of type WWN.
* <p>
* This function will retry if the alias creation fails because the session is lost or timed out. The total number of tries is set to 2.
*
* @param client an instance of WBEMClient with an open session to SMI provider
* @param zoneServiceIns an instance of zone service for the fabric
* @param fabricId the fabric name
* @param fabricWwn the fabric WWN
* @param alias the object containing the attributes of the alias to be created
* @throws WBEMException
*/
@SuppressWarnings("rawtypes")
public CIMObjectPath addZoneAlias(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, ZoneWwnAlias alias) throws WBEMException {
CIMObjectPath aliasPath = null;
CIMArgument[] outargs = new CIMArgument[1];
CIMArgument[] inargs = new CIMArgument[1];
inargs[0] = _cimArgumentFactory.string(_CollectionAlias, alias.getName());
_log.info("Creating alias: " + alias.getName());
UnsignedInteger32 result = new UnsignedInteger32(Integer.MAX_VALUE);
int count = 0;
while (result.intValue() != 0 && count < 2) {
result = (UnsignedInteger32) client.invokeMethod(zoneServiceIns.getObjectPath(), _CreateZoneAlias, inargs, outargs);
if (result.intValue() == 0 && outargs[0].getValue() != null) {
aliasPath = (CIMObjectPath) outargs[0].getValue();
_log.info("Created alias: " + alias.getName() + " with path " + aliasPath);
break;
} else if (result.intValue() == 32770) {
// session timed out or was stolen
_log.info("Created alias: " + alias.getName() + " failed with result.intvalue() 32770: " + "Transaction Not Started. Retry to get a new session lock.");
endSession(client, zoneServiceIns, false);
zoneServiceIns = startSession(client, fabricId, fabricWwn);
count++;
} else {
throw new NetworkDeviceControllerException("Created alias failed: " + alias.getName() + " with result.intValue() " + result.intValue());
}
}
if (aliasPath == null) {
if (count >= 2) {
_log.info("Failed to create alias " + alias.getName() + ". The maximum number of retries (" + (count + 1) + ") was reached without successfully starting a transaction.");
}
} else {
// add WWN as alias member to alias
addZoneOrAliasMember(client, zoneServiceIns, fabricWwn, aliasPath, alias.getAddress());
}
return aliasPath;
}
use of javax.cim.CIMObjectPath in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getAliases.
/**
* Gets the list of aliases for a given fabric
* This function uses the associations to improve performance and parses the
* alias name and member address from the paths:
* Brocade_ZoneMembershipSettingDataInZoneAlias {
* ManagedElement =
* "root/brocade1:Brocade_ZoneAlias.InstanceID=\"NAME=Hala_REST_API_ZONE_12;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneAlias\""
* ;
* SettingData =
* "root/brocade1:Brocade_ZoneMembershipSettingData.InstanceID=\"NAME=2010101010101010;ZMTYPE=5;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneMembershipSettingData\""
* ;
* };
*
* @param client an instance of WBEMClient
* @param fabricId the name of the fabric
* @param fabricWwn the WWN of the fabric
* @throws WBEMException
*/
public List<ZoneWwnAlias> getAliases(WBEMClient client, String fabricId, String fabricWwn) throws WBEMException {
Map<String, ZoneWwnAlias> aliases = new HashMap<String, ZoneWwnAlias>();
if (fabricWwn == null) {
fabricWwn = getFabricWwn(client, fabricId);
}
fabricWwn = fabricWwn.replaceAll(":", "");
CloseableIterator<CIMInstance> it = null;
try {
CIMObjectPath path = CimObjectPathCreator.createInstance(_Brocade_ZoneMembershipSettingDataInZoneAlias, _namespace);
it = client.enumerateInstances(path, false, true, true, null);
CIMInstance ins = null;
String aliasPath = null;
String memberPath = null;
String wwn = null;
ZoneWwnAlias alias = null;
while (it.hasNext()) {
ins = it.next();
_log.debug(ins.toString());
aliasPath = cimStringProperty(ins, _ManagedElement);
memberPath = cimStringProperty(ins, _SettingData);
wwn = getPropertyValueFromString(memberPath, SmisConstants.CP_FABRIC);
if (StringUtils.equalsIgnoreCase(wwn, fabricWwn)) {
try {
alias = new ZoneWwnAlias();
alias.setAddress(formatWWN(getPropertyValueFromString(memberPath, SmisConstants.CP_NSNAME)));
alias.setName(getPropertyValueFromString(aliasPath, SmisConstants.CP_NSNAME));
// Use a map to handle the unsupported scenario when an alias has more than one member
// in this code the alias will arbitrarily have the the last members discovered.
// this is needed to ensure code dependent on this code does not receive duplicates
aliases.put(alias.getName(), alias);
_log.debug("Retreived alias name " + alias.getName() + " and address " + alias.getAddress());
} catch (Exception e) {
// if the WWN is not a valid one and setAddress will throw an error
// Catch it , log it , skip it it and move forward with processing the rest of the data
_log.warn("An exception was encountered while processing " + wwn + " may be it is malformed " + e.getMessage());
}
}
}
} catch (Exception ex) {
_log.warn("An exception was encountered while getting the aliases for " + "fabric: " + fabricId + ". The exception is: " + ex.getMessage());
} finally {
if (it != null) {
it.close();
}
}
return new ArrayList<ZoneWwnAlias>(aliases.values());
}
use of javax.cim.CIMObjectPath in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method removeZoneOrAliasMember.
/**
* Removes a WWN that is a member of an alias or a zone, or remove an alias that
* is a member of a zone.
*
* @param client and instance of WBEMClient with an open session to the network
* system.
* @param member the CIM path to the zone or alias member
* @param zoneOrAlias the entity whose membership is being modified which can be
* an alias or a zone. If it is a zone, this function can support adding a member
* of type WWN or alias. If it is an alias, this function will support WWN members only.
* @param alias true if the member being added is of type alias, in which case the
* entity modified should be of a zone.
* @throws WBEMException
*/
public void removeZoneOrAliasMember(WBEMClient client, CIMObjectPath member, CIMObjectPath zoneOrAlias, boolean alias) throws WBEMException {
CloseableIterator<CIMObjectPath> zoneItr = null;
try {
if (alias) {
zoneItr = client.referenceNames(zoneOrAlias, _Brocade_ZoneAliasInZone, null);
while (zoneItr.hasNext()) {
CIMObjectPath associationPath = zoneItr.next();
if (member.equals(associationPath.getKeyValue("Member"))) {
client.deleteInstance(associationPath);
_log.info("Zone member of type alias : " + associationPath + " was removed.");
break;
}
}
} else {
if (zoneOrAlias.getObjectName().equals(_Brocade_Zone)) {
zoneItr = client.referenceNames(zoneOrAlias, _Brocade_ZoneMembershipSettingDataInZone, null);
} else {
// zone alias
zoneItr = client.referenceNames(zoneOrAlias, _Brocade_ZoneMembershipSettingDataInZoneAlias, null);
}
while (zoneItr.hasNext()) {
CIMObjectPath associationPath = zoneItr.next();
if (member.equals(associationPath.getKeyValue("SettingData"))) {
client.deleteInstance(associationPath);
_log.info("Zone or alias member: " + associationPath + " was removed.");
break;
}
}
}
} finally {
if (zoneItr != null) {
zoneItr.close();
}
}
}
use of javax.cim.CIMObjectPath in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method addZoneOrAliasMember.
/**
* Add a member to a zone or alias. The member can be a WWN or an alias
* name when the entity modified is a zone. The member can only be a WWN when
* the entity modified is an alias.
*
* @param client an instance of WBEMClient with an open session to SMI provider
* @param zoneServiceIns an instance of zone service for the fabric
* @param fabricWwn the fabric WWN
* @param zonePath the CIM path of the zone object
* @param member to be added to the zone or alias.
* @return the CIM path to the newly created alias
* @throws WBEMException
*/
@SuppressWarnings("rawtypes")
public boolean addZoneOrAliasMember(WBEMClient client, CIMInstance zoneServiceIns, String fabricWwn, CIMObjectPath zonePath, String member) throws WBEMException {
CIMArgument[] outargs = new CIMArgument[1];
CIMArgument[] inargs = null;
UnsignedInteger32 result = null;
if (EndpointUtility.isValidEndpoint(member, EndpointType.WWN)) {
_log.info("Add zone or alias member of type wwn " + member);
inargs = new CIMArgument[3];
inargs[0] = _cimArgumentFactory.uint16(_ConnectivityMemberType, 2);
inargs[1] = _cimArgumentFactory.string(_ConnectivityMemberID, member.replaceAll(":", ""));
inargs[2] = _cimArgumentFactory.reference(_SystemSpecificCollection, zonePath);
result = (UnsignedInteger32) client.invokeMethod(zoneServiceIns.getObjectPath(), _CreateZoneMembershipSettingData, inargs, outargs);
} else {
_log.info("Add zoneor alias member of type alias " + member);
inargs = new CIMArgument[2];
inargs[0] = _cimArgumentFactory.reference(_Zone, zonePath);
CIMObjectPath aliasPath = getZoneAliasPath(member, fabricWwn);
inargs[1] = _cimArgumentFactory.reference(_ZoneAlias, aliasPath);
result = (UnsignedInteger32) client.invokeMethod(zoneServiceIns.getObjectPath(), _AddZoneAlias, inargs, outargs);
}
_log.info("Add zone or alias member returned code " + result.toString());
// 0 means success and 8 means member already exists
return result.intValue() == 0 || result.intValue() == 8;
}
Aggregations