示例#1
0
        public override void ExecuteCmdlet()
        {
            ConfirmAction(Force.IsPresent,
                          Resources.RemoveWarningACR,
                          Resources.RemoveConfirmationACR,
                          string.Empty,
                          () =>
            {
                try
                {
                    AccessControlRecord existingAcr = null;
                    string acrName = null;
                    switch (ParameterSetName)
                    {
                    case StorSimpleCmdletParameterSet.IdentifyByName:
                        var allACRs = StorSimpleClient.GetAllAccessControlRecords();
                        existingAcr = allACRs.Where(x => x.Name.Equals(ACRName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                        acrName     = ACRName;
                        break;

                    case StorSimpleCmdletParameterSet.IdentifyByObject:
                        existingAcr = ACR;
                        acrName     = ACR.Name;
                        break;
                    }
                    if (existingAcr == null)
                    {
                        throw new ArgumentException(string.Format(Resources.NotFoundMessageACR, acrName));
                    }

                    var serviceConfig = new ServiceConfiguration()
                    {
                        AcrChangeList = new AcrChangeList()
                        {
                            Added   = new List <AccessControlRecord>(),
                            Deleted = new[] { existingAcr.InstanceId },
                            Updated = new List <AccessControlRecord>()
                        },
                        CredentialChangeList = new SacChangeList(),
                    };

                    if (WaitForComplete.IsPresent)
                    {
                        WriteVerbose("About to run a task to remove your ACR!");
                        var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                        HandleSyncTaskResponse(taskStatus, "delete");
                    }
                    else
                    {
                        WriteVerbose("About to create a task to remove your ACR!");
                        var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                        HandleAsyncTaskResponse(taskResponse, "delete");
                    }
                }
                catch (Exception exception)
                {
                    this.HandleException(exception);
                }
            });
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            try
            {
                var allACRs     = StorSimpleClient.GetAllAccessControlRecords();
                var existingAcr = allACRs.Where(x => x.Name.Equals(ACRName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (existingAcr == null)
                {
                    WriteVerbose(string.Format(Resources.NotFoundMessageACR, ACRName));
                    return;
                }

                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList = new AcrChangeList()
                    {
                        Added   = new List <AccessControlRecord>(),
                        Deleted = new List <string>(),
                        Updated = new []
                        {
                            new AccessControlRecord()
                            {
                                GlobalId      = existingAcr.GlobalId,
                                InitiatorName = IQNInitiatorName,
                                InstanceId    = existingAcr.InstanceId,
                                Name          = existingAcr.Name,
                                VolumeCount   = existingAcr.VolumeCount
                            },
                        }
                    },
                    CredentialChangeList = new SacChangeList(),
                };

                if (WaitForComplete.IsPresent)
                {
                    WriteVerbose("About to run a task to update your Access Control Record!");
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "update");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var updatedAcr = StorSimpleClient.GetAllAccessControlRecords()
                                         .Where(x => x.Name.Equals(ACRName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(updatedAcr);
                    }
                }
                else
                {
                    WriteVerbose("About to create a task to update your Access Control Record!");
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "update");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList = new AcrChangeList()
                    {
                        Added = new[]
                        {
                            new AccessControlRecord()
                            {
                                GlobalId      = null,
                                InitiatorName = IQNInitiatorName,
                                InstanceId    = null,
                                Name          = ACRName,
                                VolumeCount   = 0
                            },
                        },
                        Deleted = new List <string>(),
                        Updated = new List <AccessControlRecord>()
                    },
                    CredentialChangeList = new SacChangeList(),
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdAcr = StorSimpleClient.GetAllAccessControlRecords()
                                         .Where(x => x.Name.Equals(ACRName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(createdAcr);
                    }
                }
                else
                {
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "create");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        public override void ExecuteCmdlet()
        {
            ConfirmAction(Force.IsPresent,
                          Resources.RemoveWarningACR,
                          Resources.RemoveConfirmationACR,
                          string.Empty,
                          () =>
            {
                try
                {
                    StorageAccountCredentialResponse existingSac = null;
                    string sacName = null;

                    switch (ParameterSetName)
                    {
                    case StorSimpleCmdletParameterSet.IdentifyByName:
                        var allSACs = StorSimpleClient.GetAllStorageAccountCredentials();
                        existingSac = allSACs.Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                        sacName     = StorageAccountName;
                        break;

                    case StorSimpleCmdletParameterSet.IdentifyByObject:
                        existingSac = SAC;
                        sacName     = SAC.Name;
                        break;
                    }
                    if (existingSac == null)
                    {
                        WriteObject(null);
                        WriteVerbose(string.Format(Resources.SACNotFoundWithName, sacName));
                        return;
                    }

                    var serviceConfig = new ServiceConfiguration()
                    {
                        AcrChangeList        = new AcrChangeList(),
                        CredentialChangeList = new SacChangeList()
                        {
                            Added   = new List <StorageAccountCredential>(),
                            Deleted = new[] { existingSac.InstanceId },
                            Updated = new List <StorageAccountCredential>()
                        }
                    };

                    if (WaitForComplete.IsPresent)
                    {
                        WriteVerbose("About to run a task to remove your Storage Access Credential!");
                        var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                        HandleSyncTaskResponse(taskStatus, "delete");
                    }
                    else
                    {
                        WriteVerbose("About to create a task to remove your Storage Access Credential!");
                        var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                        HandleAsyncTaskResponse(taskResponse, "delete");
                    }
                }
                catch (Exception exception)
                {
                    this.HandleException(exception);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                var allSACs     = StorSimpleClient.GetAllStorageAccountCredentials();
                var existingSac = allSACs.Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (existingSac == null)
                {
                    throw new ArgumentException(string.Format(Resources.SACNotFoundWithName, StorageAccountName));
                }

                string encryptedKey;
                string thumbprint;
                string endpoint = GetEndpointFromHostname(existingSac.Hostname);
                if (!ValidateAndEncryptStorageCred(StorageAccountName, StorageAccountKey, endpoint, out encryptedKey, out thumbprint))
                {
                    return;
                }

                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList        = new AcrChangeList(),
                    CredentialChangeList = new SacChangeList()
                    {
                        Added   = new List <StorageAccountCredential>(),
                        Deleted = new List <string>(),
                        Updated = new[]
                        {
                            new StorageAccountCredential()
                            {
                                InstanceId  = existingSac.InstanceId,
                                CloudType   = existingSac.CloudType,
                                Hostname    = existingSac.Hostname,
                                Login       = existingSac.Login,
                                Password    = encryptedKey ?? existingSac.Password,
                                UseSSL      = UseSSL ?? existingSac.UseSSL,
                                VolumeCount = existingSac.VolumeCount,
                                Name        = existingSac.Name,
                                IsDefault   = existingSac.IsDefault,
                                PasswordEncryptionCertThumbprint = thumbprint,
                                Location = existingSac.Location
                            },
                        }
                    }
                };

                if (WaitForComplete.IsPresent)
                {
                    WriteVerbose("About to run a task to update your Storage Access credential!");
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "update");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var updatedSac = StorSimpleClient.GetAllStorageAccountCredentials()
                                         .Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(updatedSac);
                    }
                }
                else
                {
                    WriteVerbose("About to create a task to update your Storage Access credential!");
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "update");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                string endpoint = string.IsNullOrEmpty(Endpoint) ? StorSimpleConstants.DefaultStorageAccountEndpoint : Endpoint;

                //validate storage account credentials
                bool   storageAccountPresent;
                string encryptedKey;
                string thumbprint;
                string location = GetStorageAccountLocation(StorageAccountName, out storageAccountPresent);
                if (!storageAccountPresent ||
                    !ValidateAndEncryptStorageCred(StorageAccountName, StorageAccountKey, endpoint, out encryptedKey, out thumbprint))
                {
                    return;
                }

                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList        = new AcrChangeList(),
                    CredentialChangeList = new SacChangeList()
                    {
                        Added = new[]
                        {
                            new StorageAccountCredential()
                            {
                                CloudType = CloudType.Azure,
                                Hostname  = GetHostnameFromEndpoint(endpoint),
                                Login     = StorageAccountName,
                                Password  = encryptedKey,
                                PasswordEncryptionCertThumbprint = thumbprint,
                                UseSSL   = UseSSL,
                                Name     = StorageAccountName,
                                Location = location
                            },
                        },
                        Deleted = new List <string>(),
                        Updated = new List <StorageAccountCredential>()
                    }
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdSac = StorSimpleClient.GetAllStorageAccountCredentials()
                                         .Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(createdSac);
                    }
                }
                else
                {
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "create");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }