Apprenda.SaaSGrid.Addons.NetApp.NetAppFactory.DeleteVolume C# (CSharp) Метод

DeleteVolume() публичный статический Метод

public static DeleteVolume ( DeveloperParameters d, string connectionData ) : NetAppResponse
d DeveloperParameters
connectionData string
Результат Apprenda.SaaSGrid.Addons.NetApp.Models.NetAppResponse
        public static NetAppResponse DeleteVolume(DeveloperParameters d, string connectionData)
        {
            using (var psInstance = PowerShell.Create())
            {
                // STEP 1: first things first. we need to set the execution policy for this script to be unrestricted. because we're assuming not everyone signs their powershell scripts.
                psInstance.AddCommand("Set-ExecutionPolicy");
                psInstance.AddArgument("Unrestricted");
                psInstance.AddArgument("Process");
                psInstance.AddParameter("-Force");
                psInstance.Invoke();
                var debugStream = string.Empty;
                var errorStream = string.Empty;
                debugStream += psInstance.Streams.Debug.Aggregate(debugStream, (current, debug) => current + debug);
                debugStream += psInstance.Streams.Progress.Aggregate(debugStream,
                    (current, debug) => current + debug);
                psInstance.Commands.Clear();

                // -------------------------------------------------------------------------------------------/
                // STEP 2: We need to copy the file locally. Now - for all intensive purposes, we're going to assume the file is in 1 of three places
                //  - Locally on the platform (in which an absolute path is provided)
                //  - Accessible server within the datacenter (in which a server name and path are provided)
                //  - Cloud Storage (in which an HTTPS link is provided)
                //
                //   Anything else is custom or Phase II at this time.
                // -------------------------------------------------------------------------------------------/

                // case 1, 2: local or server
                const string executingPs1File = ".\\DeleteVolume.ps1";
                var remotePs1File = d.ScriptRepository + "\\DeleteVolume.ps1";
                psInstance.AddCommand("Copy-Item");
                psInstance.AddParameter("-Path", remotePs1File);
                psInstance.AddParameter("-Destination", executingPs1File);
                psInstance.AddParameter("-Force");
                psInstance.Invoke();
                debugStream += psInstance.Streams.Debug.Aggregate(debugStream, (current, debug) => current + debug);
                debugStream += psInstance.Streams.Progress.Aggregate(debugStream,
                    (current, debug) => current + debug);
                if (psInstance.Streams.Error.Count > 0)
                {
                    errorStream += psInstance.Streams.Error.Aggregate(errorStream, (current, error) => current + error);
                    return new NetAppResponse
                    {
                        IsSuccess = false,
                        ErrorOut = errorStream,
                        ConnectionData = string.Empty,
                        ConsoleOut = "Could not copy file to execute. Please check connectivity to the server.",
                        ReturnCode = -1
                    };
                }

                // Step 3 - let's remove the volume.
                // So normally the only change here from our existing provisioning process is that we need to pull the volume name from the
                // connection string. so, let's extract it.

                var volumeToDelete = ExtractFromConnectionString(connectionData);
                psInstance.AddCommand(executingPs1File);
                psInstance.AddParameter("-username", d.AdminUserName);
                psInstance.AddParameter("-password", d.AdminPassword);
                psInstance.AddParameter("-vserver", d.VServer);
                psInstance.AddParameter("-endpoint", d.ClusterMgtEndpoint);
                psInstance.AddParameter("-volName", volumeToDelete);

                psInstance.Invoke();
                debugStream += psInstance.Streams.Debug.Aggregate(debugStream, (current, debug) => current + debug);
                debugStream += psInstance.Streams.Progress.Aggregate(debugStream,
                    (current, debug) => current + debug);
                if (psInstance.Streams.Error.Count <= 0)
                    return new NetAppResponse
                    {
                        IsSuccess = true,
                        ErrorOut = string.Empty,
                        ConnectionData = string.Empty,
                        ConsoleOut = debugStream
                    };
                errorStream += psInstance.Streams.Error.Aggregate(errorStream, (current, error) => current + error);
                return new NetAppResponse
                {
                    IsSuccess = false,
                    ErrorOut = errorStream,
                    ConnectionData = string.Empty,
                    ConsoleOut = "Could not copy file to execute. Please check connectivity to the server.",
                    ReturnCode = -1
                };
            }
        }

Usage Example

Пример #1
0
        // Deprovision NetApp
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var deprovisionResult = new OperationResult {
                IsSuccess = false
            };

            try
            {
                // this loads in the developer options and the manifest parameters
                // validation will also occur here, so if this fails it will be caught prior to any invocation on the cluster.
                var developerOptions = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest);
                // for assumptions now, delete a volume
                var netappresponse = NetAppFactory.DeleteVolume(developerOptions, request.ConnectionData);
                // use the class's conversion method.
                return(netappresponse.ToOperationResult());
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }
            return(deprovisionResult);
        }