public void Initialize() { vmPowershellCmdlets = new ServiceManagementCmdletTestHelper(); vmPowershellCmdlets.ImportAzurePublishSettingsFile(); defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName); Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName); storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount); Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName); destination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd")); patchDestination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd")); destinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd")); patchDestinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd")); var destinationBlob = new CloudPageBlob(new Uri(destinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary)); var patchDestinationBlob = new CloudPageBlob(new Uri(patchDestinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary)); var policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Delete | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List, SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(1) }; var destinationBlobToken = destinationBlob.GetSharedAccessSignature(policy); var patchDestinationBlobToken = patchDestinationBlob.GetSharedAccessSignature(policy); destinationSasUri += destinationBlobToken; patchDestinationSasUri += patchDestinationBlobToken; blobUrlRoot = string.Format(@"http://{0}.blob.core.windows.net/", defaultAzureSubscription.CurrentStorageAccount); perfFile = "perf.csv"; }
public void Initialize() { vmPowershellCmdlets = new ServiceManagementCmdletTestHelper(); vmPowershellCmdlets.ImportAzurePublishSettingsFile(); defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName); Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName); storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount); Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName); blobUrlRoot = string.Format(@"http://{0}.blob.core.windows.net/", defaultAzureSubscription.CurrentStorageAccount); perfFile = "perf.csv"; }
public void GetStorageKeysProcess() { Func<string, StorageService> func = null; StorageServiceKeyOperationContext storageServiceKeyOperationContext = null; using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel)) { try { GetAzureStorageKeyCommand getAzureStorageKeyCommand = this; if (func == null) { func = (string s) => base.Channel.GetStorageKeys(s, this.StorageAccountName); } StorageService storageService = ((CmdletBase<IServiceManagement>)getAzureStorageKeyCommand).RetryCall<StorageService>(func); if (storageService != null) { StorageServiceKeyOperationContext storageAccountName = new StorageServiceKeyOperationContext(); storageAccountName.StorageAccountName = this.StorageAccountName; storageAccountName.Primary = storageService.StorageServiceKeys.Primary; storageAccountName.Secondary = storageService.StorageServiceKeys.Secondary; storageServiceKeyOperationContext = storageAccountName; } Operation operation = base.WaitForOperation(base.CommandRuntime.ToString()); storageServiceKeyOperationContext.set_OperationDescription(base.CommandRuntime.ToString()); storageServiceKeyOperationContext.set_OperationId(operation.OperationTrackingId); storageServiceKeyOperationContext.set_OperationStatus(operation.Status); base.WriteObject(storageServiceKeyOperationContext, true); } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; if (communicationException as EndpointNotFoundException == null || base.IsVerbose()) { this.WriteErrorDetails(communicationException); } else { base.WriteObject(null); return; } } } }
public void NewStorageKeyProcess() { Func<string, StorageService> func = null; StorageServiceKeyOperationContext storageServiceKeyOperationContext = null; RegenerateKeys regenerateKey = new RegenerateKeys(); regenerateKey.KeyType = this.KeyType; RegenerateKeys regenerateKey1 = regenerateKey; using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel)) { try { CmdletExtensions.WriteVerboseOutputForObject(this, regenerateKey1); NewAzureStorageKeyCommand newAzureStorageKeyCommand = this; if (func == null) { func = (string s) => base.Channel.RegenerateStorageServiceKeys(s, this.StorageAccountName, regenerateKey1); } StorageService storageService = ((CmdletBase<IServiceManagement>)newAzureStorageKeyCommand).RetryCall<StorageService>(func); if (storageService != null) { StorageServiceKeyOperationContext storageAccountName = new StorageServiceKeyOperationContext(); storageAccountName.StorageAccountName = this.StorageAccountName; storageAccountName.Primary = storageService.StorageServiceKeys.Primary; storageAccountName.Secondary = storageService.StorageServiceKeys.Secondary; storageServiceKeyOperationContext = storageAccountName; } Operation operation = base.WaitForOperation(base.CommandRuntime.ToString()); storageServiceKeyOperationContext.set_OperationDescription(base.CommandRuntime.ToString()); storageServiceKeyOperationContext.set_OperationId(operation.OperationTrackingId); storageServiceKeyOperationContext.set_OperationStatus(operation.Status); base.WriteObject(storageServiceKeyOperationContext, true); } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; this.WriteErrorDetails(communicationException); } } }
public static void SetDefaultStorage() { if (!string.IsNullOrEmpty(GetDefaultStorage(CredentialHelper.DefaultStorageName, CredentialHelper.Location))) { defaultAzureSubscription = vmPowershellCmdlets.SetAzureSubscription(defaultAzureSubscription.SubscriptionName, CredentialHelper.DefaultStorageName); storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount); Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName); blobUrlRoot = (vmPowershellCmdlets.GetAzureStorageAccount(defaultAzureSubscription.CurrentStorageAccount)[0].Endpoints.ToArray())[0]; } else { Console.WriteLine("Unable to get the default storege account"); } }
public static void AssemblyInit(TestContext context) { vmPowershellCmdlets = new ServiceManagementCmdletTestHelper(); vmPowershellCmdlets.ImportAzurePublishSettingsFile(); if (string.IsNullOrEmpty(Resource.DefaultSubscriptionName)) { Console.WriteLine("No subscription is selected!"); } else { defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName); Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName); if (defaultAzureSubscription.CurrentStorageAccount == null || Utilities.CheckRemove(vmPowershellCmdlets.GetAzureStorageAccount, defaultAzureSubscription.CurrentStorageAccount)) { string defaultStorage = Utilities.GetUniqueShortName("storage"); vmPowershellCmdlets.NewAzureStorageAccount(defaultStorage, Resource.Location); defaultAzureSubscription = vmPowershellCmdlets.SetAzureSubscription(defaultAzureSubscription.SubscriptionName, defaultStorage); } storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount); Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName); blobUrlRoot = (vmPowershellCmdlets.GetAzureStorageAccount(defaultAzureSubscription.CurrentStorageAccount)[0].Endpoints.ToArray())[0]; locationName = vmPowershellCmdlets.GetAzureLocationName(new[] { Resource.Location }, false); // Get-AzureLocation if (String.IsNullOrEmpty(locationName)) { Console.WriteLine("No location is selected!"); } Console.WriteLine("Location Name: {0}", locationName); imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false); // Get-AzureVMImage if (String.IsNullOrEmpty(imageName)) { Console.WriteLine("No image is selected!"); } Console.WriteLine("Image Name: {0}", imageName); } }
public void Initialize() { vmPowershellCmdlets = new ServiceManagementCmdletTestHelper(); vmPowershellCmdlets.ImportAzurePublishSettingsFile(); // Import-AzurePublishSettingsFile defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName); // Set-AzureSubscription Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName); storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount); // Get-AzureStorageKey Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName); locationName = vmPowershellCmdlets.GetAzureLocationName(new[] { Resource.Location }, false); // Get-AzureLocation Console.WriteLine("Location Name: {0}", locationName); imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "MSFT", "testvmimage" }, false); // Get-AzureVMImage Console.WriteLine("Image Name: {0}", imageName); if (vmPowershellCmdlets.TestAzureServiceName(serviceName)) { Console.WriteLine("Service Name: {0} already exists.", serviceName); } else { vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, "p@ssw0rd", locationName); Console.WriteLine("Service Name: {0} is created.", serviceName); } }