예제 #1
0
        /// <summary>
        /// Performs execution of the command
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                CreateVolumeInput input = new CreateVolumeInput();
                input.Name            = Name;
                input.NPodGuid        = NPod.Guid;
                input.SizeBytes       = SizeBytes;
                input.Mirrored        = Mirrored.IsPresent;
                input.OwnerSpuSerial  = OwnerSpuSerial;
                input.BackupSpuSerial = BackupSpuSerial;
                input.Force           = Force.IsPresent;

                Volume volume = Connection.CreateVolume(input);
                WriteObject(volume);
            }
            catch (AggregateException exceptions)
            {
                foreach (Exception ex in exceptions.InnerExceptions)
                {
                    WriteError(ex);
                }
            }
            catch (Exception ex)
            {
                WriteError(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Allows creation of a new volume
        /// </summary>
        /// <param name="input">
        /// Configuration definition for the new volume
        /// </param>
        /// <returns>The created volume</returns>
        public Volume CreateVolume(CreateVolumeInput input)
        {
            // setup parameters
            GraphQLParameters parameters = new GraphQLParameters();

            parameters.Add("input", input);

            TokenResponse tokenResponse = RunMutation <TokenResponse>(
                @"createVolumeV3", parameters);

            RecipeRecordIdentifier identifier = DeliverTokenV2(tokenResponse);

            if (identifier == null)
            {
                throw new Exception("Uncomprehensive information returned from server");
            }

            // wait for recipe completion
            DateTime start = DateTime.UtcNow;

            // recipe filter
            NPodRecipeFilter filter = new NPodRecipeFilter();

            filter.NPodGuid   = identifier.NPodGuid;
            filter.RecipeGuid = identifier.RecipeGuid;

            while (true)
            {
                Thread.Sleep(1000);

                // query for recipes
                RecipeRecordList recipes = GetNPodRecipes(filter);

                // if there is no record in the cloud wait a few more seconds
                // this case should not exist. TODO: Remove in next version.
                if (recipes.Items.Length == 0)
                {
                    continue;
                }

                // based on the query there should be exactly one
                RecipeRecord recipe = recipes.Items[0];

                // execution failed
                if (recipe.State == RecipeState.Failed)
                {
                    string error = string.Concat("volume creation failed", recipe.Status);
                    throw new Exception(error);
                }

                // execution completed
                if (recipe.State == RecipeState.Completed)
                {
                    VolumeFilter volumeFilter = new VolumeFilter();
                    volumeFilter.Guid           = new GuidFilter();
                    volumeFilter.Guid.MustEqual = tokenResponse.WaitOn;

                    VolumeList list = GetVolumes(null, volumeFilter, null);

                    if (list.FilteredCount >= 0)
                    {
                        return(list.Items[0]);
                    }
                }

                // still ongoing
                double duration      = (DateTime.UtcNow - start).TotalSeconds;
                double timeRemaining = NPOD_CREATE_WAITTIME_SEC - duration;

                if (timeRemaining <= 0)
                {
                    throw new Exception("Snapshot creation timed out");
                }
            }
        }