示例#1
0
        private void clearAll()
        {
            // We assume no-one else is using this FreeNAS server right now. We delete everything on it. >:D
            // We do, however, avoid deleting anything beginning with 'blade', so its sort-of safe to run this on
            // the production FreeNAS install, if no-one else is using it, and the only iscsi info you want to keep
            // begins with this string.

            FreeNASWithCaching foo = new FreeNASWithCaching(nashostname, nasusername, naspassword);

            foreach (iscsiTarget tgt in foo.getISCSITargets().Where(x => !x.targetName.StartsWith("blade")))
            {
                foo.deleteISCSITarget(tgt);
            }

            foreach (iscsiExtent ext in foo.getExtents().Where(x => !x.iscsi_target_extent_name.StartsWith("blade")))
            {
                foo.deleteISCSIExtent(ext);
            }

            foreach (iscsiTargetToExtentMapping tte in foo.getTargetToExtents())
            {
                var tgt = foo.getISCSITargets().SingleOrDefault(x => x.id == tte.iscsi_target);
                var ext = foo.getExtents().SingleOrDefault(x => x.id == tte.iscsi_extent);
                if (tgt == null || ext == null)
                {
                    foo.deleteISCSITargetToExtent(tte);
                }
            }

            foo.waitUntilISCSIConfigFlushed();
        }