Example #1
0
        public static List <ResourceIdentifier> GetResourceIdsFromClient(string resourceType, string resourceGroupName)
        {
            IAzureContext             context = AzureRmProfileProvider.Instance?.Profile?.DefaultContext;
            IResourceManagementClient client  = AzureSession.Instance.ClientFactory.CreateArmClient <ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
            var odataQuery = new ODataQuery <GenericResourceFilter>(r => r.ResourceType == resourceType);

            var allProviders = string.IsNullOrWhiteSpace(resourceGroupName)
                ? client.Resources.ListAsync(odataQuery)
                : client.ResourceGroups.ListResourcesAsync(resourceGroupName, odataQuery);

            var timeoutDuration = _timeout == -1 ? TimeSpan.FromMinutes(5) : TimeSpan.FromSeconds(_timeout);
            var hasNotTimedOut  = allProviders.Wait(timeoutDuration);
            var hasResult       = allProviders.Result != null;
            var isSuccessful    = hasNotTimedOut && hasResult;

#if DEBUG
            if (!isSuccessful)
            {
                throw new InvalidOperationException(!hasResult ? "Result from client.Providers is null" : Resources.TimeOutForProviderList);
            }
#endif

            return(isSuccessful
                ? allProviders.Result.Select(resource => new ResourceIdentifier(resource.Id)).ToList()
                : new List <ResourceIdentifier>());
        }
Example #2
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="authorizationManagementClient">The management client instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     AuthorizationManagementClient = authorizationManagementClient;
     this.ResourceManagementClient = resourceManagementClient;
 }
Example #3
0
        /// <summary>
        /// Processes creating web test resources.
        /// </summary>
        /// <param name="name">Web test name.</param>
        /// <param name="url">Web test URL.</param>
        /// <param name="authType"><see cref="AuthType"/> value.</param>
        /// <param name="accessToken">Access token value.</param>
        /// <param name="testType"><see cref="TestType"/> value. Default is <c>TestType.UriPingTest</c>.</param>
        /// <returns>Returns <c>True</c>; if processed successfully; otherwise returns <c>False</c>.</returns>
        public async Task <bool> ProcessAsync(string name, string url, AuthType authType = AuthType.None, string accessToken = null, TestType testType = TestType.UrlPingTest)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            var credentials = await this.GetCredentialsAsync().ConfigureAwait(false);

            this._resourceManagementClient = new ResourceManagementClient(credentials);
            this._insightsManagementClient = new InsightsManagementClient(credentials);

            var insightsResource = await this.GetInsightsResourceAsync(this._resourceManagementClient).ConfigureAwait(false);

            var webTest = this._webTests.SingleOrDefault(p => p.TestType == testType);

            if (webTest == null)
            {
                return(false);
            }

            var webTestResource = await this.CreateOrUpdateWebTestAsync(name, url, authType, accessToken, webTest, this._resourceManagementClient, insightsResource).ConfigureAwait(false);

            var result = await this.CreateOrUpdateAlertsAsync(name, webTest, this._insightsManagementClient, webTestResource, insightsResource).ConfigureAwait(false);

            return(result);
        }
Example #4
0
        public static void Main(string[] args)
        {
            AzureProfile profile = GetAzureProfile();

            string location = PromptUserForLocation();

            using (IResourceManagementClient resourceManagementClient =
                       AzureSession.ClientFactory.CreateClient <ResourceManagementClient>(profile, AzureEnvironment.Endpoint.ResourceManager))
            {
                // Register with the Batch resource provider.
                resourceManagementClient.Providers.Register(BatchNameSpace);

                try
                {
                    CreateResourceGroupAsync(resourceManagementClient, location).Wait();

                    PerformBatchAccountOperationsAsync(profile, location).Wait();

                    DeleteResourceGroupAsync(resourceManagementClient).Wait();
                }
                catch (AggregateException aex)
                {
                    foreach (Exception inner in aex.InnerExceptions)
                    {
                        Console.WriteLine("Unexpected error encountered: {0}", inner.ToString());
                    }
                }
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        public override void ExecuteCmdlet()
        {
            IAzureContext             context = DefaultContext;
            IResourceManagementClient client  = AzureSession.Instance.ClientFactory.CreateCustomArmClient <ResourceManagementClient>(
                context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
                AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager),
                AzureSession.Instance.ClientFactory.GetCustomHandlers());

            client.SubscriptionId = context.Subscription.Id;

            // If no parameters are specified, show all defaults
            if (!ResourceGroup)
            {
                if (context.IsPropertySet(Resources.DefaultResourceGroupKey))
                {
                    var defaultResourceGroup = client.ResourceGroups.Get(context.GetProperty(Resources.DefaultResourceGroupKey));
                    WriteObject(defaultResourceGroup);
                }
            }

            // If any parameters are specified, show only defaults with switch parameters set to true
            if (ResourceGroup)
            {
                if (context.IsPropertySet(Resources.DefaultResourceGroupKey))
                {
                    var defaultResourceGroup = client.ResourceGroups.Get(context.GetProperty(Resources.DefaultResourceGroupKey));
                    WriteObject(defaultResourceGroup);
                }
            }
        }
        public void StorageSyncServiceGetTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create StorageSyncService Name
                string resourceName = TestUtilities.GenerateName("sssget");

                var parameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();

                StorageSyncService resource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, resourceName, parameters);
                resource = storageSyncManagementClient.StorageSyncServices.Get(resourceGroupName, resourceName);
                StorageSyncManagementTestUtilities.VerifyStorageSyncServiceProperties(resource, false);

                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, resourceName);
                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
        public void StorageSyncServiceBadRequestTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create StorageSyncService Name
                string resourceName = TestUtilities.GenerateName("#$%badsss");

                var parameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();

                // Try Create StorageSyncService
                Assert.Throws <StorageSyncErrorException>(() => storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, resourceName, parameters));

                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Example #8
0
        public void RegisteredServerCreateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create RegisteredServer Name
                string storageSyncServiceName = TestUtilities.GenerateName("sss-rscreate");
                Guid   serverGuid             = TestUtilities.GenerateGuid();

                var storageSyncServiceParameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();
                var registeredServerParameters   = StorageSyncManagementTestUtilities.GetDefaultRegisteredServerParameters(serverGuid);

                StorageSyncService storageSyncServiceResource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, storageSyncServiceName, storageSyncServiceParameters);
                Assert.NotNull(storageSyncServiceResource);
                StorageSyncManagementTestUtilities.VerifyStorageSyncServiceProperties(storageSyncServiceResource, true);

                RegisteredServer resource = storageSyncManagementClient.RegisteredServers.Create(resourceGroupName, storageSyncServiceResource.Name, serverGuid.ToString(), registeredServerParameters);
                Assert.NotNull(resource);
                StorageSyncManagementTestUtilities.VerifyRegisteredServerProperties(resource, true);

                storageSyncManagementClient.RegisteredServers.Delete(resourceGroupName, storageSyncServiceResource.Name, serverGuid.ToString());
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, storageSyncServiceResource.Name);
                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Example #9
0
        static void PollForCompletion(IResourceManagementClient armClient, string resourceGroupName,
                                      string deploymentName, VariableDictionary variables)
        {
            var currentPollWait  = 1;
            var previousPollWait = 0;
            var continueToPoll   = true;

            while (continueToPoll)
            {
                Thread.Sleep(TimeSpan.FromSeconds(Math.Min(currentPollWait, 30)));

                Log.Verbose("Polling for status of deployment...");
                var deployment = armClient.Deployments.Get(resourceGroupName, deploymentName).Deployment;
                Log.Verbose($"Provisioning state: {deployment.Properties.ProvisioningState}");

                switch (deployment.Properties.ProvisioningState)
                {
                case "Succeeded":
                    Log.Info($"Deployment {deploymentName} complete.");
                    Log.Info(GetOperationResults(armClient, resourceGroupName, deploymentName));
                    CaptureOutputs(deployment.Properties.Outputs, variables);
                    continueToPoll = false;
                    break;

                case "Failed":
                    throw new CommandException($"Azure Resource Group deployment {deploymentName} failed:\n" + GetOperationResults(armClient, resourceGroupName, deploymentName));

                default:
                    var temp = previousPollWait;
                    previousPollWait = currentPollWait;
                    currentPollWait  = temp + currentPollWait;
                    break;
                }
            }
        }
        public void StorageSyncServiceDeleteTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create StorageSyncService Name
                string resourceName = TestUtilities.GenerateName("sssdelete");

                // Delete an account which does not exist
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, resourceName);

                var parameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();

                // Create StorageSyncService
                StorageSyncService resource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, resourceName, parameters);

                // Delete StorageSyncService
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, resourceName);

                // Delete StorageSyncService which was just deleted
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, resourceName);

                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
        public ArmDeploymentTests()
        {
            emptyTemplate = new TemplateBuilder().Template;
            location      = "North Europe";

            client = new Mock <IResourceManagementClient>().Object;
        }
Example #12
0
        static string GetOperationResults(IResourceManagementClient armClient, string resourceGroupName, string deploymentName)
        {
            var operations = armClient?.DeploymentOperations.List(resourceGroupName, deploymentName);

            if (operations == null)
            {
                return(null);
            }

            var log = new StringBuilder("Operations details:\n");

            foreach (var operation in operations)
            {
                if (operation?.Properties == null)
                {
                    continue;
                }

                log.AppendLine($"Resource: {operation.Properties.TargetResource?.ResourceName}");
                log.AppendLine($"Type: {operation.Properties.TargetResource?.ResourceType}");
                log.AppendLine($"Timestamp: {operation.Properties.Timestamp?.ToLocalTime():s}");
                log.AppendLine($"Deployment operation: {operation.Id}");
                log.AppendLine($"Status: {operation.Properties.StatusCode}");
                log.AppendLine($"Provisioning State: {operation.Properties.ProvisioningState}");
                if (operation.Properties.StatusMessage != null)
                {
                    log.AppendLine($"Status Message: {JsonConvert.SerializeObject(operation.Properties.StatusMessage)}");
                }
            }

            return(log.ToString());
        }
Example #13
0
        public void CloudEndpointInvokeChangeDetectionTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create CloudEndpoint Name
                string storageSyncServiceName = TestUtilities.GenerateName("sss-cepchangedetection");
                string syncGroupName          = TestUtilities.GenerateName("sg-cepchangedetection");
                string cloudEndpointName      = TestUtilities.GenerateName("cepchangedetection");

                var storageSyncServiceParameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();
                var syncGroupParameters          = StorageSyncManagementTestUtilities.GetDefaultSyncGroupParameters();
                var cloudEndpointParameters      = StorageSyncManagementTestUtilities.GetDefaultCloudEndpointParameters();

                StorageSyncService storageSyncServiceResource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, storageSyncServiceName, storageSyncServiceParameters);
                Assert.NotNull(storageSyncServiceResource);
                StorageSyncManagementTestUtilities.VerifyStorageSyncServiceProperties(storageSyncServiceResource, true);

                SyncGroup syncGroupResource = storageSyncManagementClient.SyncGroups.Create(resourceGroupName, storageSyncServiceResource.Name, syncGroupName, syncGroupParameters);
                Assert.NotNull(syncGroupResource);
                StorageSyncManagementTestUtilities.VerifySyncGroupProperties(syncGroupResource, true);

                CloudEndpoint cloudEndpointResource = storageSyncManagementClient.CloudEndpoints.Create(resourceGroupName, storageSyncServiceResource.Name, syncGroupResource.Name, cloudEndpointName, cloudEndpointParameters);
                Assert.NotNull(cloudEndpointResource);
                StorageSyncManagementTestUtilities.VerifyCloudEndpointProperties(cloudEndpointResource, true);

                // invoke with directory path
                storageSyncManagementClient.CloudEndpoints.TriggerChangeDetection(
                    resourceGroupName: resourceGroupName,
                    storageSyncServiceName: storageSyncServiceName,
                    syncGroupName: syncGroupName,
                    cloudEndpointName: cloudEndpointName,
                    parameters: new TriggerChangeDetectionParameters(
                        directoryPath: "",
                        changeDetectionMode: ChangeDetectionMode.Recursive));

                // invoke with individual paths
                storageSyncManagementClient.CloudEndpoints.TriggerChangeDetection(
                    resourceGroupName: resourceGroupName,
                    storageSyncServiceName: storageSyncServiceName,
                    syncGroupName: syncGroupName,
                    cloudEndpointName: cloudEndpointName,
                    parameters: new TriggerChangeDetectionParameters(
                        paths: new string[] { "dir1/subdir1", "file.txt" }));

                storageSyncManagementClient.CloudEndpoints.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupName, cloudEndpointName);
                storageSyncManagementClient.SyncGroups.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupName);
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, storageSyncServiceResource.Name);
                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Example #14
0
        public void SyncGroupGetTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create SyncGroup Name
                string storageSyncServiceName = TestUtilities.GenerateName("ssscreate-sgget");
                string syncGroupName          = TestUtilities.GenerateName("sgget");

                var storageSyncServiceParameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();
                var syncGroupParameters          = StorageSyncManagementTestUtilities.GetDefaultSyncGroupParameters();

                StorageSyncService storageSyncServiceResource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, storageSyncServiceName, storageSyncServiceParameters);
                Assert.NotNull(storageSyncServiceResource);
                StorageSyncManagementTestUtilities.VerifyStorageSyncServiceProperties(storageSyncServiceResource, true);

                SyncGroup syncGroupResource = storageSyncManagementClient.SyncGroups.Create(resourceGroupName, storageSyncServiceResource.Name, syncGroupName, syncGroupParameters);
                syncGroupResource = storageSyncManagementClient.SyncGroups.Get(resourceGroupName, storageSyncServiceResource.Name, syncGroupName);
                StorageSyncManagementTestUtilities.VerifySyncGroupProperties(syncGroupResource, false);

                storageSyncManagementClient.SyncGroups.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupName);
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, storageSyncServiceResource.Name);
                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
        public override void ExecuteCmdlet()
        {
            IAzureContext             context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
            IResourceManagementClient resourceManagementclient = AzureSession.Instance.ClientFactory.CreateCustomArmClient <ResourceManagementClient>(
                context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
                AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager),
                AzureSession.Instance.ClientFactory.GetCustomHandlers());

            resourceManagementclient.SubscriptionId = context.Subscription.Id;

            if (ResourceGroupName != null)
            {
                ResourceGroup defaultResourceGroup;
                if (ShouldProcess(Resources.DefaultResourceGroupTarget, string.Format(Resources.DefaultResourceGroupChangeWarning, ResourceGroupName)))
                {
                    if (!resourceManagementclient.ResourceGroups.CheckExistence(ResourceGroupName) && (Force.IsPresent || ShouldContinue(string.Format(Resources.CreateResourceGroupMessage, ResourceGroupName), Resources.CreateResourceGroupCaption)))
                    {
                        ResourceGroup parameters = new ResourceGroup("West US");
                        resourceManagementclient.ResourceGroups.CreateOrUpdate(ResourceGroupName, parameters);
                    }

                    defaultResourceGroup = resourceManagementclient.ResourceGroups.Get(ResourceGroupName);
                    ModifyContext((profile, client) => SetDefaultProperty(profile));
                    WriteObject(defaultResourceGroup);
                }
            }
        }
 public static void RemoveResourceGroup(IResourceManagementClient resourcesClient, string rgName)
 {
     if (!IsTestTenant)
     {
         resourcesClient.ResourceGroups.Delete(rgName);
     }
 }
 /// <summary>
 /// The Get Operation Status operation returns the status of the
 /// specified operation. After calling an asynchronous operation, you
 /// can call Get Operation Status to determine whether the operation
 /// has succeeded, failed, or is still in progress.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Internal.Resources.IResourceManagementClient.
 /// </param>
 /// <param name='operationStatusLink'>
 /// Required. Location value returned by the Begin operation.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse GetLongRunningOperationStatus(this IResourceManagementClient operations, string operationStatusLink)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IResourceManagementClient)s).GetLongRunningOperationStatusAsync(operationStatusLink);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #18
0
        /// <summary>
        /// Deletes the resource group.
        /// </summary>
        /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// to use when deleting the resource group.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        private static async Task DeleteResourceGroupAsync(IResourceManagementClient resourceManagementClient)
        {
            Console.WriteLine("Deleting resource group {0}", ResourceGroupName);
            await resourceManagementClient.ResourceGroups.DeleteAsync(ResourceGroupName);

            Console.WriteLine("Resource group deleted");
            Console.WriteLine();
        }
Example #19
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="authorizationManagementClient">The management client instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     GalleryTemplatesClient = galleryTemplatesClient;
     AuthorizationManagementClient = authorizationManagementClient;
     this.ResourceManagementClient = resourceManagementClient;
 }
Example #20
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="authorizationManagementClient">The management client instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     GalleryTemplatesClient        = galleryTemplatesClient;
     AuthorizationManagementClient = authorizationManagementClient;
     this.ResourceManagementClient = resourceManagementClient;
 }
        public virtual Rest.Azure.IPage <GenericResource> ListResources(
            Rest.Azure.OData.ODataQuery <GenericResourceFilter> filter = null,
            string NextPageLink = null)
        {
            IResourceManagementClient armClient = ResourceClient;

            return(string.IsNullOrEmpty(NextPageLink) ?
                   armClient.Resources.List(filter) :
                   armClient.Resources.ListNext(NextPageLink));
        }
Example #22
0
        public virtual IEnumerable <PSKeyVaultIdentityItem> ListResources(Rest.Azure.OData.ODataQuery <GenericResourceFilter> filter = null, ulong first = ulong.MaxValue, ulong skip = ulong.MinValue)
        {
            IResourceManagementClient armClient = this.ResourceClient;

            return(new GenericPageEnumerable <GenericResource>(
                       delegate()
            {
                return armClient.Resources.List(filter);
            }, armClient.Resources.ListNext, first, skip).Select(r => new PSKeyVaultIdentityItem(r)));
        }
        private IEnumerable <PSKeyVaultIdentityItem> ListByResourceGroup(
            string resourceGroupName,
            Rest.Azure.OData.ODataQuery <GenericResourceFilter> filter,
            ulong first = ulong.MaxValue,
            ulong skip  = ulong.MinValue)
        {
            IResourceManagementClient armClient = ResourceClient;

            return(new GenericPageEnumerable <GenericResource>(() => armClient.ResourceGroups.ListResources(resourceGroupName, filter), armClient.ResourceGroups.ListResourcesNext, first, skip).Select(r => new PSKeyVaultIdentityItem(r)));
        }
        private Rest.Azure.IPage <GenericResource> ListByResourceGroup(
            string resourceGroupName,
            Rest.Azure.OData.ODataQuery <GenericResourceFilter> filter = null,
            string NextPageLink = null)
        {
            IResourceManagementClient armClient = ResourceClient;

            return(string.IsNullOrEmpty(NextPageLink) ?
                   armClient.ResourceGroups.ListResources(resourceGroupName, filter) :
                   armClient.ResourceGroups.ListResourcesNext(NextPageLink));
        }
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     ResourceManagementClient      = resourceManagementClient;
     GalleryTemplatesClient        = galleryTemplatesClient;
     EventsClient                  = eventsClient;
     AuthorizationManagementClient = authorizationManagementClient;
 }
Example #26
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     ResourceManagementClient = resourceManagementClient;
     GalleryTemplatesClient = galleryTemplatesClient;
     EventsClient = eventsClient;
     AuthorizationManagementClient = authorizationManagementClient;
 }
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="storageClientWrapper">The IStorageClientWrapper instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     IStorageClientWrapper storageClientWrapper,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient)
 {
     ResourceManagementClient = resourceManagementClient;
     StorageClientWrapper = storageClientWrapper;
     GalleryTemplatesClient = galleryTemplatesClient;
     EventsClient = eventsClient;
 }
Example #28
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="storageClientWrapper">The IStorageClientWrapper instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="eventsClient">The IEventsClient instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     IStorageClientWrapper storageClientWrapper,
     GalleryTemplatesClient galleryTemplatesClient,
     IEventsClient eventsClient)
 {
     ResourceManagementClient = resourceManagementClient;
     StorageClientWrapper     = storageClientWrapper;
     GalleryTemplatesClient   = galleryTemplatesClient;
     EventsClient             = eventsClient;
 }
Example #29
0
        /// <summary>
        /// Obtains a list of locations via the specified <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// and prompts the user to select a location from the list.
        /// </summary>
        /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// to use when obtaining a list of datacenter locations.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        private static async Task <string> PromptUserForLocationAsync(IResourceManagementClient resourceManagementClient)
        {
            // Obtain the list of available datacenter locations for Batch accounts supported by this subscription
            ProviderGetResult batchProvider = await resourceManagementClient.Providers.GetAsync(BatchNameSpace);

            ProviderResourceType batchResource = batchProvider.Provider.ResourceTypes.Where(p => p.Name == BatchAccountResourceType).First();

            string[] locations = batchResource.Locations.ToArray();

            // Ask the user where they would like to create the resource group and account
            return(PromptForSelectionFromCollection(locations, "Enter the number of the location where you'd like to create your Batch account: "));
        }
Example #30
0
        /// <summary>
        /// Creates a resource group. The user's Batch account will be created under this resource group.
        /// </summary>
        /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// to use when creating the resource group.</param>
        /// <param name="location">The location where the resource group will be created.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        private static async Task CreateResourceGroupAsync(IResourceManagementClient resourceManagementClient, string location)
        {
            ResourceGroupExistsResult existsResult = await resourceManagementClient.ResourceGroups.CheckExistenceAsync(ResourceGroupName);

            if (!existsResult.Exists)
            {
                Console.WriteLine("Creating resource group {0}", ResourceGroupName);
                await resourceManagementClient.ResourceGroups.CreateOrUpdateAsync(ResourceGroupName, new ResourceGroup(location));

                Console.WriteLine("Resource group created");
                Console.WriteLine();
            }
        }
Example #31
0
        /// <summary>
        /// Creates new ResourcesClient instance
        /// </summary>
        /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
        /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
        /// <param name="authorizationManagementClient">The management client instance</param>
        public ResourcesClient(
            IResourceManagementClient resourceManagementClient,
#if !NETSTANDARD
            GalleryTemplatesClient galleryTemplatesClient,
#endif
            IAuthorizationManagementClient authorizationManagementClient)
        {
#if !NETSTANDARD
            GalleryTemplatesClient = galleryTemplatesClient;
#endif
            AuthorizationManagementClient = authorizationManagementClient;
            this.ResourceManagementClient = resourceManagementClient;
        }
Example #32
0
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="authorizationManagementClient">The management client instance</param>
 public ResourcesClient(
     IResourceManagementClient resourceManagementClient,
     GalleryTemplatesClient galleryTemplatesClient,
     // TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
     //IEventsClient eventsClient,
     IAuthorizationManagementClient authorizationManagementClient)
 {
     GalleryTemplatesClient = galleryTemplatesClient;
     // TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
     //EventsClient = eventsClient;
     AuthorizationManagementClient = authorizationManagementClient;
     this.ResourceManagementClient = resourceManagementClient;
 }
        /// <summary>
        /// Creates new ResourcesClient instance
        /// </summary>
        /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
        /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
        /// <param name="eventsClient">The IEventsClient instance</param>
        public ResourcesClient(
            IResourceManagementClient resourceManagementClient,
            GalleryTemplatesClient galleryTemplatesClient,
            // TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
            //IEventsClient eventsClient,
            IAuthorizationManagementClient authorizationManagementClient)
        {
            ResourceManagementClient = resourceManagementClient;
            GalleryTemplatesClient = galleryTemplatesClient;

            // TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
            //EventsClient = eventsClient;
            AuthorizationManagementClient = authorizationManagementClient;
        }
Example #34
0
        public void CloudEndpointDeleteTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                IResourceManagementClient    resourcesClient             = StorageSyncManagementTestUtilities.GetResourceManagementClient(context, handler);
                IStorageSyncManagementClient storageSyncManagementClient = StorageSyncManagementTestUtilities.GetStorageSyncManagementClient(context, handler);

                // Create ResourceGroup
                string resourceGroupName = StorageSyncManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create CloudEndpoint Name
                string storageSyncServiceName = TestUtilities.GenerateName("sss-cepdelete");
                string syncGroupName          = TestUtilities.GenerateName("sg-cepdelete");
                string cloudEndpointName      = TestUtilities.GenerateName("cepdelete");

                var storageSyncServiceParameters = StorageSyncManagementTestUtilities.GetDefaultStorageSyncServiceParameters();
                var syncGroupParameters          = StorageSyncManagementTestUtilities.GetDefaultSyncGroupParameters();
                var cloudEndpointParameters      = StorageSyncManagementTestUtilities.GetDefaultCloudEndpointParameters();

                StorageSyncService storageSyncServiceResource = storageSyncManagementClient.StorageSyncServices.Create(resourceGroupName, storageSyncServiceName, storageSyncServiceParameters);
                Assert.NotNull(storageSyncServiceResource);
                StorageSyncManagementTestUtilities.VerifyStorageSyncServiceProperties(storageSyncServiceResource, true);

                SyncGroup syncGroupResource = storageSyncManagementClient.SyncGroups.Create(resourceGroupName, storageSyncServiceResource.Name, syncGroupName, syncGroupParameters);
                Assert.NotNull(syncGroupResource);
                StorageSyncManagementTestUtilities.VerifySyncGroupProperties(syncGroupResource, true);

                // Delete CloudEndpoint before its created.
                storageSyncManagementClient.CloudEndpoints.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupResource.Name, cloudEndpointName);

                CloudEndpoint cloudEndpointResource = storageSyncManagementClient.CloudEndpoints.Create(resourceGroupName, storageSyncServiceResource.Name, syncGroupResource.Name, cloudEndpointName, cloudEndpointParameters);
                Assert.NotNull(cloudEndpointResource);
                StorageSyncManagementTestUtilities.VerifyCloudEndpointProperties(cloudEndpointResource, true);

                // Delete CloudEndpoint
                storageSyncManagementClient.CloudEndpoints.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupResource.Name, cloudEndpointName);

                // Delete CloudEndpoint which was just deleted
                storageSyncManagementClient.CloudEndpoints.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupResource.Name, cloudEndpointName);

                storageSyncManagementClient.SyncGroups.Delete(resourceGroupName, storageSyncServiceResource.Name, syncGroupName);
                storageSyncManagementClient.StorageSyncServices.Delete(resourceGroupName, storageSyncServiceResource.Name);
                StorageSyncManagementTestUtilities.RemoveResourceGroup(resourcesClient, resourceGroupName);
            }
        }
 /// <summary>
 /// Creates new ResourcesClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 /// <param name="galleryTemplatesClient">The IGalleryClient instance</param>
 /// <param name="authorizationManagementClient">The management client instance</param>
 public ResourceManagerSdkClient(
     IResourceManagementClient resourceManagementClient)
 {
     this.ResourceManagementClient = resourceManagementClient;
 }
Example #36
0
        /// <summary>
        /// Obtains a list of locations via the specified <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// and prompts the user to select a location from the list.
        /// </summary>
        /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/> 
        /// to use when obtaining a list of datacenter locations.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        private static async Task<string> PromptUserForLocationAsync(IResourceManagementClient resourceManagementClient)
        {
            // Obtain the list of available datacenter locations for Batch accounts supported by this subscription
            ProviderGetResult batchProvider = await resourceManagementClient.Providers.GetAsync(BatchNameSpace);
            ProviderResourceType batchResource = batchProvider.Provider.ResourceTypes.Where(p => p.Name == BatchAccountResourceType).First();
            string[] locations = batchResource.Locations.ToArray();

            // Ask the user where they would like to create the resource group and account
            return PromptForSelectionFromCollection(locations, "Enter the number of the location where you'd like to create your Batch account: ");
        }
Example #37
0
 /// <summary>
 /// Creates a resource group. The user's Batch account will be created under this resource group.
 /// </summary>
 /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/> 
 /// to use when creating the resource group.</param>
 /// <param name="location">The location where the resource group will be created.</param>
 /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
 private static async Task CreateResourceGroupAsync(IResourceManagementClient resourceManagementClient, string location)
 {
     ResourceGroupExistsResult existsResult = await resourceManagementClient.ResourceGroups.CheckExistenceAsync(ResourceGroupName);
     if (!existsResult.Exists)
     {
         Console.WriteLine("Creating resource group {0}", ResourceGroupName);
         await resourceManagementClient.ResourceGroups.CreateOrUpdateAsync(ResourceGroupName, new ResourceGroup(location));
         Console.WriteLine("Resource group created");
         Console.WriteLine();
     }
 }
Example #38
0
 /// <summary>
 /// Deletes the resource group.
 /// </summary>
 /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/> 
 /// to use when deleting the resource group.</param>
 /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
 private static async Task DeleteResourceGroupAsync(IResourceManagementClient resourceManagementClient)
 {
     Console.Write("Hit ENTER to delete resource group {0}: ", ResourceGroupName);
     Console.ReadLine();
     Console.WriteLine("Deleting resource group {0}...", ResourceGroupName);
     await resourceManagementClient.ResourceGroups.DeleteAsync(ResourceGroupName);
     Console.WriteLine("Resource group deleted");
     Console.WriteLine();
 }
 /// <summary>
 /// Creates new BatchClient instance
 /// </summary>
 /// <param name="batchManagementClient">The IBatchManagementClient instance</param>
 public BatchClient(IBatchManagementClient batchManagementClient, IResourceManagementClient resourceManagementClient)
 {
     BatchManagementClient = batchManagementClient;
     ResourceManagementClient = resourceManagementClient;
 }
Example #40
0
 /// <summary>
 /// Creates new TagsClient instance
 /// </summary>
 /// <param name="resourceManagementClient">The IResourceManagementClient instance</param>
 public TagsClient(IResourceManagementClient resourceManagementClient)
 {
     ResourceManagementClient = resourceManagementClient;
 }