/// <summary>
        /// Allows creation of a new LUN
        ///
        /// <para>
        /// Allows the creation of a LUN for a volume.A LUN is an instance of a
        /// volume export that makes a volume accessible to a host.
        /// </para>
        /// <para>
        /// At least one host must be specified via <c>HostGuids</c> or
        /// <c>SpuSerials</c> - either one option must be specified but not
        /// both. If the <c>Locak</c> option is provided and set to <c>true</c>
        /// then the volume will be exported with ALUA, otherwise with ALUA
        /// turned off.
        /// </para>
        /// </summary>
        /// <param name="input">
        /// An input definition for the new LUN. Review the CreateLunInput
        /// properties for configuration details
        /// </param>
        /// <returns>The new LUN if successful</returns>
        public Lun CreateLun(CreateLunInput input)
        {
            GraphQLParameters parameters = new GraphQLParameters();

            parameters.Add(@"input", input);

            TokenResponse token = RunMutation <TokenResponse>(@"createLUN", parameters);

            if (!DeliverToken(token))
            {
                throw new Exception("Token delivery failed");
            }

            // wait until the new LUN is reporting in nebulon ON
            Thread.Sleep(TOKEN_WAITTIME_MS);

            // Query for LUN
            LunFilter filter = new LunFilter();

            filter.LunGuid           = new GuidFilter();
            filter.LunGuid.MustEqual = token.WaitOn;

            LunList lunList = GetLuns(null, filter, null);

            if (lunList.FilteredCount != 1)
            {
                throw new Exception("Unexpected number of results returned");
            }

            return(lunList.Items[0]);
        }
        /// <summary>
        /// Retrieves a list of LUN objects
        /// </summary>
        /// <param name="page">
        /// The requested page from the server. This is an optional
        /// argument and if omitted the server will default to returning the
        /// first page with a maximum of <c>100</c> items.
        /// </param>
        /// <param name="filter">
        /// A filter object to filter the LUNs on the
        /// server.If omitted, the server will return all objects as a
        /// paginated response.
        /// </param>
        /// <param name="sort">
        /// A sort definition object to sort the LUN objects
        /// on supported properties.If omitted objects are returned in the
        /// order as they were created in.
        /// </param>
        /// <returns>A paginated list of LUNs</returns>
        public LunList GetLuns(
            PageInput page   = null,
            LunFilter filter = null,
            LunSort sort     = null)
        {
            GraphQLParameters parameters = new GraphQLParameters();

            parameters.Add("page", page, true);
            parameters.Add("filter", filter, true);
            parameters.Add("sort", sort, true);

            // this should return exactly one item.
            return(RunQuery <LunList>(@"getLUNs", parameters));
        }
예제 #3
0
        /// <summary>
        /// Compiles a single filter from a list of filters by combining them
        /// with a logical AND
        /// </summary>
        /// <param name="filters">
        /// List of filters to combine
        /// </param>
        /// <returns></returns>
        private LunFilter GenerateFilter(List <LunFilter> filters)
        {
            LunFilter result = null;

            foreach (LunFilter filter in filters)
            {
                if (result == null)
                {
                    result = filter;
                    continue;
                }

                filter.And = result;
                result     = filter;
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Performs execution of the command
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                List <LunFilter> filters = new List <LunFilter>();

                if (ParameterPresent("Guid"))
                {
                    LunFilter f = new LunFilter();
                    f.LunGuid           = new GuidFilter();
                    f.LunGuid.MustEqual = Guid;
                    filters.Add(f);
                }

                if (ParameterPresent("LunId"))
                {
                    LunFilter f = new LunFilter();
                    f.LunId           = new IntFilter();
                    f.LunId.MustEqual = LunId;
                    filters.Add(f);
                }

                if (ParameterPresent("Volume"))
                {
                    LunFilter f = new LunFilter();
                    f.VolumeGuid           = new GuidFilter();
                    f.VolumeGuid.MustEqual = Volume.Guid;
                    filters.Add(f);
                }

                if (ParameterPresent("NPod"))
                {
                    LunFilter f = new LunFilter();
                    f.NPodGuid           = new GuidFilter();
                    f.NPodGuid.MustEqual = NPod.Guid;
                    filters.Add(f);
                }

                if (ParameterPresent("Spu"))
                {
                    LunFilter f = new LunFilter();
                    f.SpuSerial           = new StringFilter();
                    f.SpuSerial.MustEqual = Spu.Serial;
                    filters.Add(f);
                }

                if (ParameterPresent("Server"))
                {
                    LunFilter f = new LunFilter();
                    f.HostGuid           = new GuidFilter();
                    f.HostGuid.MustEqual = Server.Guid;
                    filters.Add(f);
                }

                // convert to filter
                LunFilter filter = GenerateFilter(filters);

                PageInput page = PageInput.First;
                LunList   list = Connection.GetLuns(page, filter, null);

                foreach (Lun item in list.Items)
                {
                    WriteObject(item);
                }

                while (list.More)
                {
                    // advance the page
                    page.Page = page.Page + 1;

                    list = Connection.GetLuns(page, filter, null);
                    foreach (Lun item in list.Items)
                    {
                        WriteObject(item);
                    }
                }
            }
            catch (AggregateException exceptions)
            {
                foreach (Exception ex in exceptions.InnerExceptions)
                {
                    WriteError(ex);
                }
            }
            catch (Exception ex)
            {
                WriteError(ex);
            }
        }