Exemplo n.º 1
0
        private static snapshotObjects getSnapshotObjectsFromNAS(NASAccess nas, string snapshotFullName)
        {
            snapshot shotToRestore = getSnapshot(nas, snapshotFullName);

            if (shotToRestore == null)
            {
                nas.invalidateSnapshots();
                shotToRestore = getSnapshot(nas, snapshotFullName);
                if (shotToRestore == null)
                {
                    throw new Exception("Cannot find snapshot " + snapshotFullName);
                }
            }

            // Now find the extent. We'll need to delete it before we can rollback the snapshot.
            iscsiExtent extent = getExtent(nas, snapshotFullName);

            if (extent == null)
            {
                nas.invalidateExtents();
                extent = getExtent(nas, snapshotFullName);
                if (extent == null)
                {
                    throw new Exception("Cannot find extent " + snapshotFullName);
                }
            }

            // Find the 'target to extent' mapping, since this will need to be deleted before we can delete the extent.
            iscsiTargetToExtentMapping tgtToExtent = getTgtToExtent(nas, extent);

            if (tgtToExtent == null)
            {
                nas.invalidateTargetToExtents();
                tgtToExtent = getTgtToExtent(nas, extent);
                if (tgtToExtent == null)
                {
                    throw new Exception("Cannot find target-to-extent mapping with ID " + extent.id + " for snapshot " + shotToRestore.name);
                }
            }

            // We find the target, as well, just to be sure that our cache is correct.
            if (nas.getISCSITargets().Count(x => x.id == tgtToExtent.iscsi_target) == 0)
            {
                nas.invalidateTargets();
                if (nas.getISCSITargets().Count(x => x.id == tgtToExtent.iscsi_target) == 0)
                {
                    throw new Exception("Cannot find target for snapshot " + snapshotFullName);
                }
            }
            return(new snapshotObjects()
            {
                extent = extent,
                shotToRestore = shotToRestore,
                tgtToExtent = tgtToExtent
            });
        }
Exemplo n.º 2
0
        public override void deleteISCSITargetToExtent(iscsiTargetToExtentMapping tgtToExtent)
        {
            lock (events)
            {
                events.Add(new mockedCall("deleteISCSITargetToExtent", "tgtToExtent: '" + tgtToExtent));
            }

            lock (tgtToExtents)
            {
                tgtToExtents.Remove(tgtToExtent.id);
            }
        }
Exemplo n.º 3
0
        public override iscsiTargetToExtentMapping addISCSITargetToExtent(string iscsiTargetID, iscsiExtent newExtent)
        {
            lock (events)
            {
                events.Add(new mockedCall("addISCSITargetToExtent", "iscsiTarget: '" + iscsiTargetID + "' newExtent: " + newExtent));
            }

            lock (tgtToExtents)
            {
                string newID = idGen.Next().ToString();
                iscsiTargetToExtentMapping newMapping = new iscsiTargetToExtentMapping()
                {
                    id = newID, iscsi_target = iscsiTargetID, iscsi_extent = newExtent.id, iscsi_lunid = "0"
                };
                tgtToExtents.Add(newID, newMapping);
                return(tgtToExtents[newID]);
            }
        }
Exemplo n.º 4
0
        public override void deleteISCSITargetToExtent(iscsiTargetToExtentMapping tgtToExtent)
        {
            lock (this)
            {
                waitingISCSIOperations++;
            }

            try
            {
                uncachedNAS.deleteISCSITargetToExtent(tgtToExtent);
                iscsiTargetToExtentMapping foo;
                TTEExtents.TryRemove(tgtToExtent.id, out foo);
            }
            finally
            {
                lock (this)
                {
                    waitingISCSIOperations--;
                }
                markThisThreadISCSIDirty();
            }
        }
Exemplo n.º 5
0
 public abstract void deleteISCSITargetToExtent(iscsiTargetToExtentMapping tgtToExtent);
Exemplo n.º 6
0
        private static iscsiTargetToExtentMapping getTgtToExtent(NASAccess nas, iscsiExtent extent)
        {
            iscsiTargetToExtentMapping tgtToExtent = nas.getTargetToExtents().SingleOrDefault(x => x.iscsi_extent == extent.id);

            return(tgtToExtent);
        }
Exemplo n.º 7
0
        public override void deleteISCSITargetToExtent(iscsiTargetToExtentMapping tgtToExtent)
        {
            string url = String.Format("http://{0}/api/v1.0/services/iscsi/targettoextent/{1}/", _serverIp, tgtToExtent.id);

            doReq(url, "DELETE", HttpStatusCode.NoContent);
        }