Exemple #1
0
        /// <summary>
        /// Parses a URI referring to a LUN.
        /// </summary>
        /// <param name="uri">The URI to parse</param>
        /// <returns>The LUN info</returns>
        /// <remarks>
        /// Note the LUN info is incomplete, only as much of the information as is encoded
        /// into the URL is available.
        /// </remarks>
        public static LunInfo ParseUri(Uri uri)
        {
            string address;
            int port;
            string targetGroupTag = string.Empty;
            string targetName = string.Empty;
            ulong lun = 0;

            if (uri.Scheme != "iscsi")
            {
                ThrowInvalidURI(uri.OriginalString);
            }

            address = uri.Host;
            port = uri.Port;
            if (uri.Port == -1)
            {
                port = TargetAddress.DefaultPort;
            }

            string[] uriSegments = uri.Segments;
            if (uriSegments.Length == 2)
            {
                targetName = uriSegments[1].Replace("/", string.Empty);
            }
            else if (uriSegments.Length == 3)
            {
                targetGroupTag = uriSegments[1].Replace("/", string.Empty);
                targetName = uriSegments[2].Replace("/", string.Empty);
            }
            else
            {
                ThrowInvalidURI(uri.OriginalString);
            }

            TargetInfo targetInfo = new TargetInfo(targetName, new TargetAddress[] { new TargetAddress(address, port, targetGroupTag) });

            foreach (var queryElem in uri.Query.Substring(1).Split('&'))
            {
                if (queryElem.StartsWith("LUN=", StringComparison.OrdinalIgnoreCase))
                {
                    lun = ulong.Parse(queryElem.Substring(4), CultureInfo.InvariantCulture);
                    if (lun < 256)
                    {
                        lun = lun << (6 * 8);
                    }
                }
            }

            return new LunInfo(targetInfo, (long)lun, LunClass.Unknown, false, string.Empty, string.Empty, string.Empty);
        }
 /// <summary>
 /// Connects to a Target.
 /// </summary>
 /// <param name="target">The Target to connect to.</param>
 /// <returns>The session representing the target connection.</returns>
 public Session ConnectTo(TargetInfo target)
 {
     return ConnectTo(target.Name, target.Addresses);
 }
Exemple #3
0
 internal LunInfo(TargetInfo targetInfo, long lun, LunClass type, bool removable, string vendor, string product, string revision)
 {
     _targetInfo = targetInfo;
     _lun = lun;
     _deviceType = type;
     _removable = removable;
     _vendorId = vendor;
     _productId = product;
     _productRevision = revision;
 }