public override void ExecuteCmdlet()
        {
            try
            {
                var deviceid = StorSimpleClient.GetDeviceId(DeviceName);

                if (deviceid == null)
                {
                    WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
                    WriteObject(null);
                    return;
                }

                if (VolumeContainerName == null)
                {
                    var dataContainerList = StorSimpleClient.GetAllDataContainers(deviceid);
                    WriteObject(dataContainerList.DataContainers);
                    WriteVerbose(string.Format(Resources.ReturnedCountDataContainerMessage, dataContainerList.DataContainers.Count, dataContainerList.DataContainers.Count > 1 ? "s" : string.Empty));
                }
                else
                {
                    var dataContainer = StorSimpleClient.GetDataContainer(deviceid, VolumeContainerName);
                    if (dataContainer != null &&
                        dataContainer.DataContainerInfo != null &&
                        dataContainer.DataContainerInfo.InstanceId != null)
                    {
                        WriteObject(dataContainer.DataContainerInfo);
                        WriteVerbose(string.Format(Resources.FoundDataContainerMessage, VolumeContainerName));
                    }
                    else
                    {
                        WriteVerbose(string.Format(Resources.NotFoundDataContainerMessage, VolumeContainerName));
                    }
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemple #2
0
        public override void ExecuteCmdlet()
        {
            try
            {
                string deviceid = StorSimpleClient.GetDeviceId(DeviceName);
                if (deviceid == null)
                {
                    WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
                    WriteObject(null);
                    return;
                }

                if (EncryptionEnabled == true && string.IsNullOrEmpty(EncryptionKey))
                {
                    throw new ArgumentNullException("EncryptionKey");
                }

                string encryptedKey = null;
                StorSimpleCryptoManager storSimpleCryptoManager = new StorSimpleCryptoManager(StorSimpleClient);
                if (EncryptionEnabled == true)
                {
                    WriteVerbose(Resources.EncryptionInProgressMessage);
                    storSimpleCryptoManager.EncryptSecretWithRakPub(EncryptionKey, out encryptedKey);
                }

                if (string.IsNullOrEmpty(PrimaryStorageAccountCredential.InstanceId))
                {
                    //The SAC needs to be created inline
                    WriteVerbose(Resources.InlineSacCreationMessage);

                    var sac = PrimaryStorageAccountCredential;

                    //validate storage account credentials
                    bool   storageAccountPresent;
                    string encryptedPassword;
                    string thumbprint;
                    string endpoint = GetEndpointFromHostname(sac.Hostname);
                    string location = GetStorageAccountLocation(sac.Name, out storageAccountPresent);
                    if (!storageAccountPresent ||
                        !ValidateAndEncryptStorageCred(sac.Name, sac.Password, endpoint, out encryptedPassword, out thumbprint))
                    {
                        return;
                    }

                    sac.Password = encryptedPassword;
                    sac.PasswordEncryptionCertThumbprint = thumbprint;
                    sac.Location = location;
                }

                var dc = new DataContainerRequest
                {
                    IsDefault                       = false,
                    Name                            = VolumeContainerName,
                    BandwidthRate                   = BandWidthRateInMbps,
                    IsEncryptionEnabled             = EncryptionEnabled ?? false,
                    EncryptionKey                   = encryptedKey,
                    VolumeCount                     = 0,
                    PrimaryStorageAccountCredential = PrimaryStorageAccountCredential,
                    SecretsEncryptionThumbprint     = storSimpleCryptoManager.GetSecretsEncryptionThumbprint()
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.CreateDataContainer(deviceid, dc);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdDataContainer = StorSimpleClient.GetDataContainer(deviceid, VolumeContainerName);
                        WriteObject(createdDataContainer.DataContainerInfo);
                    }
                }

                else
                {
                    var taskstatus = StorSimpleClient.CreateDataContainerAsync(deviceid, dc);
                    HandleAsyncTaskResponse(taskstatus, "create");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }