use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class NetworkScheduler method unexportVolumes.
/**
* Called from the unexportVolume call. and others. This method builds the NetworkFabricInfo to be passed to the
* NetworkDeviceController for automatic unzoning.
*
* @param volUris Collection of URIs for volumes whose references are to be deleted
* @param exportGroupUris List of URIs of all the export groups being processed that might contain the volumes.
* @param storagePortUri the URI of the StoragePort
* @param initiatorPort String WWPN with colons
* @param hasExistingVolumes If true, will not mark a zone as last reference, keeping them from being deleted
* @return List<NetworkFCZoneInfo> detailing zones to be removed or at least unreferenced
* @throws IOException
*/
public List<NetworkFCZoneInfo> unexportVolumes(URI varrayURI, Collection<URI> volUris, List<URI> exportGroupUris, URI storagePortUri, String initiatorPort, boolean hasExistingVolumes) {
List<NetworkFCZoneInfo> ourReferences = new ArrayList<NetworkFCZoneInfo>();
VirtualArray virtualArray = _dbClient.queryObject(VirtualArray.class, varrayURI);
if (virtualArray != null && virtualArray.getAutoSanZoning() == false) {
_log.info("Automatic SAN zoning is disabled in virtual array: " + virtualArray.getLabel());
return null;
}
initiatorPort = formatWWN(initiatorPort);
// Get the StoragePort
StoragePort port = null;
try {
port = _dbClient.queryObject(StoragePort.class, storagePortUri);
if (port == null) {
return null;
}
} catch (DatabaseException ex) {
return null;
}
// See if we can find our zone references
List<String> endPoints = new ArrayList<String>();
endPoints.add(initiatorPort);
endPoints.add(formatWWN(port.getPortNetworkId()));
// Make the key for our endPoints
String key = null;
{
NetworkFCZoneInfo fabricInfo = new NetworkFCZoneInfo();
fabricInfo.setEndPoints(endPoints);
key = fabricInfo.makeEndpointsKey();
}
// Create a map of the references keyed by volUri concatenated with export group URI.
// This allows for multiple export groups to export the same volume, and the zone will not
// be deleted until the volume's references are removed from all export groups.
// Then we can tell if other volumes are using this.
Map<String, FCZoneReference> volRefMap = makeExportToReferenceMap(key);
// If there were no references at all, we don't do anything.
if (volRefMap.isEmpty()) {
return null;
} else {
// Do this for each of the Export Groups being processed.
for (URI volUri : volUris) {
for (URI exportGroupUri : exportGroupUris) {
FCZoneReference ourReference = volRefMap.get(make2UriKey(volUri, exportGroupUri));
if (ourReference == null) {
continue;
}
// We need a fabricInfo for each,
// so as to remove the FCZoneReference that is keyed on volume/exportGroup.
NetworkFCZoneInfo fabricInfo = createZoneInfoForRef(ourReference, volUri, initiatorPort, port.getPortNetworkId(), null, exportGroupUri);
ourReferences.add(fabricInfo);
volRefMap.remove(make2UriKey(volUri, exportGroupUri));
}
}
// See if all the remaining entries have been marked for deletion.
boolean live = false;
for (FCZoneReference ref : volRefMap.values()) {
if (ref.getInactive() == false) {
// Here is an apparent live reference; look up the volume and make
// sure it's still active too.
BlockObject vol = BlockObject.fetch(_dbClient, ref.getVolumeUri());
ExportGroup group = _dbClient.queryObject(ExportGroup.class, ref.getGroupUri());
if (vol != null && vol.getInactive() == false && group != null && group.getInactive() == false) {
live = true;
} else {
// mark the errant reference inactive
_dbClient.markForDeletion(ref);
}
}
}
// sets existingZone which will prohibit deletion.
for (NetworkFCZoneInfo fabricInfo : ourReferences) {
fabricInfo.setLastReference(!live);
if (hasExistingVolumes) {
fabricInfo.setExistingZone(true);
}
// Pick an alternate device, just in case
NetworkLite portNet = getStoragePortNetwork(port);
NetworkLite iniNet = BlockStorageScheduler.lookupNetworkLite(_dbClient, StorageProtocol.block2Transport("FC"), initiatorPort);
List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
for (NetworkSystem ns : networkSystems) {
if (!ns.getId().equals(fabricInfo.getNetworkDeviceId())) {
fabricInfo.setAltNetworkDeviceId(ns.getId());
break;
}
}
}
return ourReferences;
}
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class NetworkScheduler method findInitiatorTargetsInVarray.
/**
* Given a list of storage ports, the find the ones that can be targets for
* the initiator in a given virtual array. The target port must be tagged to
* the virtual array and have connectivity to the initiator either via that
* same network as the initiator or via a network that is routed to the
* initiator's network. When a mix of local and routed targets are found,
* only the local ones are returned.
*
* @param varrayURI - VirtualArray URI
* @param initiator Initiator
* @param port StoragePort
* @return a list of storage ports that can be the target of the initiator.
*/
public static List<URI> findInitiatorTargetsInVarray(DbClient dbClient, URI varrayURI, Initiator initiator, Set<StoragePort> storagePorts) {
NetworkLite iniNetwork = BlockStorageScheduler.lookupNetworkLite(dbClient, Transport.FC, initiator.getInitiatorPort());
List<URI> targetPorts = new ArrayList<URI>();
if (iniNetwork != null) {
for (StoragePort storagePort : storagePorts) {
if (iniNetwork.getId().equals(storagePort.getNetwork()) && storagePort.getTaggedVirtualArrays() != null && storagePort.getTaggedVirtualArrays().contains(varrayURI.toString())) {
targetPorts.add(storagePort.getId());
}
}
if (targetPorts.isEmpty()) {
for (StoragePort storagePort : storagePorts) {
if (iniNetwork.connectedToNetwork(storagePort.getNetwork()) && storagePort.getTaggedVirtualArrays() != null && storagePort.getTaggedVirtualArrays().contains(varrayURI.toString())) {
targetPorts.add(storagePort.getId());
}
}
}
}
return targetPorts;
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method addZones.
@Override
public BiosCommandResult addZones(NetworkSystem networkSystem, List<Zone> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
BiosCommandResult result = null;
// a zone-name-to-result map to hold the results for each zone
Map<String, String> addZonesResults = new HashMap<String, String>();
try {
validateFabric(networkSystem, fabricWwn, fabricId);
Map<NetworkLite, List<Zone>> zonesPerFabric = getAllZonesForZones(zones, false, fabricId, fabricWwn);
WBEMClient client = getNetworkDeviceClient(networkSystem);
for (NetworkLite network : zonesPerFabric.keySet()) {
addZonesResults.putAll(addZonesStrategy(client, zonesPerFabric.get(network), network.getNativeId(), NetworkUtil.getNetworkWwn(network), activateZones));
}
_log.info(toMessage(addZonesResults));
result = getBiosCommandResult(addZonesResults);
} catch (NetworkDeviceControllerException ex) {
_log.error("Cannot add zones: " + ex.getLocalizedMessage());
throw ex;
}
return result;
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method getAllZonesForZones.
/**
* For a list of zones requested by clients, check is routing is needed and created
* the required zone to support both use cases: switched and routed endpoints. For
* switched endpoints the same list of zone is returned. For routed endpoints,
* for each zone in the primary fabrics, an identical zone in the target fabrics
* will also be created.
*
* @param zones the zones to be created or deleted.
*
* @return a map of zones to be created grouped by fabric. When the zone members
* are in different fabrics (i.e. routed), there will be a zone to create in each
* member's fabric
*/
private Map<NetworkLite, List<Zone>> getAllZonesForZones(List<Zone> zones, boolean delete, String fabricId, String fabricWwn) {
Map<NetworkLite, List<Zone>> allZones = new HashMap<NetworkLite, List<Zone>>();
// or two networks that are routed to each other
for (Zone zone : zones) {
Map<ZoneMember, NetworkLite> epNetworks = getEndpointNetworks(zone, fabricId, fabricWwn);
if (!epNetworks.isEmpty()) {
Set<NetworkLite> networks = new HashSet<NetworkLite>(epNetworks.values());
if (networks.size() == 2) {
// need to create zone for
// ensure the other members can be routed as well
NetworkLite network = networks.iterator().next();
for (ZoneMember member : epNetworks.keySet()) {
if (network.getId().equals(epNetworks.get(member).getId()) || (network.hasRoutedNetworks(epNetworks.get(member).getId()))) {
_log.info("Verified zone {} endpoints are connected", zone.getName());
} else {
if (!delete) {
// only error on create. For delete, always try.
_log.info("Cannot create zone {} because the member are found to be not connected", zone.getName());
throw NetworkDeviceControllerException.exceptions.zoneEndpointsNotConnected(zone.getName());
}
}
}
// zones, the zone may not be properly named.
if (!delete) {
if (zone.getName() != null && !zone.getName().toLowerCase().startsWith("lsan_")) {
String name = "lsan_" + (zone.getName() == null ? "" : zone.getName());
if (name.length() > ZONE_NAME_MAX_LENGTH) {
name = name.substring(0, ZONE_NAME_MAX_LENGTH - 1);
}
zone.setName(name);
}
}
}
for (NetworkLite network : networks) {
List<Zone> netZones = allZones.get(network);
if (netZones == null) {
netZones = new ArrayList<Zone>();
allZones.put(network, netZones);
}
netZones.add(zone);
}
} else if (delete) {
// if delete zone does not have member or member that are not in end point list
// include them anyway for deletion
NetworkLite networkLite = NetworkUtil.getNetworkLiteByFabricId(fabricId, fabricWwn, _dbClient);
if (networkLite != null) {
List<Zone> zoneList = allZones.get(networkLite);
if (zoneList == null) {
zoneList = new ArrayList<Zone>();
allZones.put(networkLite, zoneList);
}
zoneList.add(zone);
}
}
}
return allZones;
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class ExportGroupService method isInitiatorInStorageSystemsNetwork.
/**
* Determines is an initiator is in one of the StorageSystems networks.
* This is changed to accomodate VPlex, which uses two Varrays per ExportGroup for distributed export.
*
* @param exportGroup -- the ExportGroup
* @param initiator [in] - the initiator
* @param system [in] - collection of StorageSystems
* @param varrays [out] - the varrays considered for the export
* @return true iff the initiator belongs to a Network and that Network has the VirtualArray
*/
private boolean isInitiatorInStorageSystemsNetwork(ExportGroup exportGroup, Initiator initiator, Collection<URI> systems, Set<String> outVarrays) {
boolean foundAnAssociatedNetwork = false;
Set<String> exportGroupVarrays = new HashSet<String>();
exportGroupVarrays.add(exportGroup.getVirtualArray().toString());
for (URI systemURI : systems) {
List<URI> arrayVarrays = ExportUtils.getVarraysForStorageSystemVolumes(exportGroup, systemURI, _dbClient);
for (URI arrayVarray : arrayVarrays) {
if (!exportGroupVarrays.contains(arrayVarray.toString())) {
exportGroupVarrays.add(arrayVarray.toString());
}
}
}
outVarrays.addAll(exportGroupVarrays);
Set<NetworkLite> networks = NetworkUtil.getEndpointAllNetworksLite(initiator.getInitiatorPort(), _dbClient);
if (networks == null || networks.isEmpty()) {
// No network associated with the initiator, so it should be removed from the list
_log.info(String.format("Initiator %s (%s) is not associated with any network.", initiator.getInitiatorPort(), initiator.getId().toString()));
return false;
} else {
// Search through the networks determining if the any are associated with ExportGroup's VirtualArray.
for (NetworkLite networkLite : networks) {
if (networkLite == null) {
continue;
}
Set<String> varraySet = networkLite.fetchAllVirtualArrays();
if (varraySet != null) {
Set<String> intersection = Sets.intersection(varraySet, exportGroupVarrays);
if (!intersection.isEmpty()) {
_log.info(String.format("Initiator %s (%s) was found to be associated to VirtualArrays %s through network %s.", initiator.getInitiatorPort(), initiator.getId().toString(), intersection.toString(), networkLite.getNativeGuid()));
foundAnAssociatedNetwork = true;
// Though we could break this loop here, let's continue the loop so that
// we can log what other networks that the initiator is seen in
}
}
}
}
return foundAnAssociatedNetwork;
}
Aggregations