Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the Pool class.
 /// </summary>
 /// <param name="id">The ID of the resource.</param>
 /// <param name="name">The name of the resource.</param>
 /// <param name="type">The type of the resource.</param>
 /// <param name="etag">The ETag of the resource, used for concurrency
 /// statements.</param>
 /// <param name="displayName">The display name for the pool.</param>
 /// <param name="lastModified">The last modified time of the
 /// pool.</param>
 /// <param name="creationTime">The creation time of the pool.</param>
 /// <param name="provisioningState">The current state of the
 /// pool.</param>
 /// <param name="provisioningStateTransitionTime">The time at which the
 /// pool entered its current state.</param>
 /// <param name="allocationState">Whether the pool is resizing.</param>
 /// <param name="allocationStateTransitionTime">The time at which the
 /// pool entered its current allocation state.</param>
 /// <param name="vmSize">The size of virtual machines in the pool. All
 /// VMs in a pool are the same size.</param>
 /// <param name="deploymentConfiguration">This property describes how
 /// the pool nodes will be deployed - using Cloud Services or Virtual
 /// Machines.</param>
 /// <param name="currentDedicatedNodes">The number of compute nodes
 /// currently in the pool.</param>
 /// <param name="currentLowPriorityNodes">The number of
 /// Spot/low-priority compute nodes currently in the pool.</param>
 /// <param name="scaleSettings">Settings which configure the number of
 /// nodes in the pool.</param>
 /// <param name="autoScaleRun">The results and errors from the last
 /// execution of the autoscale formula.</param>
 /// <param name="interNodeCommunication">Whether the pool permits
 /// direct communication between nodes.</param>
 /// <param name="networkConfiguration">The network configuration for
 /// the pool.</param>
 /// <param name="taskSlotsPerNode">The number of task slots that can be
 /// used to run concurrent tasks on a single compute node in the
 /// pool.</param>
 /// <param name="taskSchedulingPolicy">How tasks are distributed across
 /// compute nodes in a pool.</param>
 /// <param name="userAccounts">The list of user accounts to be created
 /// on each node in the pool.</param>
 /// <param name="metadata">A list of name-value pairs associated with
 /// the pool as metadata.</param>
 /// <param name="startTask">A task specified to run on each compute
 /// node as it joins the pool.</param>
 /// <param name="certificates">The list of certificates to be installed
 /// on each compute node in the pool.</param>
 /// <param name="applicationPackages">The list of application packages
 /// to be installed on each compute node in the pool.</param>
 /// <param name="applicationLicenses">The list of application licenses
 /// the Batch service will make available on each compute node in the
 /// pool.</param>
 /// <param name="resizeOperationStatus">Contains details about the
 /// current or last completed resize operation.</param>
 /// <param name="mountConfiguration">A list of file systems to mount on
 /// each node in the pool.</param>
 /// <param name="identity">The type of identity used for the Batch
 /// Pool.</param>
 public Pool(string id = default(string), string name = default(string), string type = default(string), string etag = default(string), string displayName = default(string), System.DateTime?lastModified = default(System.DateTime?), System.DateTime?creationTime = default(System.DateTime?), PoolProvisioningState?provisioningState = default(PoolProvisioningState?), System.DateTime?provisioningStateTransitionTime = default(System.DateTime?), AllocationState?allocationState = default(AllocationState?), System.DateTime?allocationStateTransitionTime = default(System.DateTime?), string vmSize = default(string), DeploymentConfiguration deploymentConfiguration = default(DeploymentConfiguration), int?currentDedicatedNodes = default(int?), int?currentLowPriorityNodes = default(int?), ScaleSettings scaleSettings = default(ScaleSettings), AutoScaleRun autoScaleRun = default(AutoScaleRun), InterNodeCommunicationState?interNodeCommunication = default(InterNodeCommunicationState?), NetworkConfiguration networkConfiguration = default(NetworkConfiguration), int?taskSlotsPerNode = default(int?), TaskSchedulingPolicy taskSchedulingPolicy = default(TaskSchedulingPolicy), IList <UserAccount> userAccounts = default(IList <UserAccount>), IList <MetadataItem> metadata = default(IList <MetadataItem>), StartTask startTask = default(StartTask), IList <CertificateReference> certificates = default(IList <CertificateReference>), IList <ApplicationPackageReference> applicationPackages = default(IList <ApplicationPackageReference>), IList <string> applicationLicenses = default(IList <string>), ResizeOperationStatus resizeOperationStatus = default(ResizeOperationStatus), IList <MountConfiguration> mountConfiguration = default(IList <MountConfiguration>), BatchPoolIdentity identity = default(BatchPoolIdentity))
     : base(id, name, type, etag)
 {
     DisplayName       = displayName;
     LastModified      = lastModified;
     CreationTime      = creationTime;
     ProvisioningState = provisioningState;
     ProvisioningStateTransitionTime = provisioningStateTransitionTime;
     AllocationState = allocationState;
     AllocationStateTransitionTime = allocationStateTransitionTime;
     VmSize = vmSize;
     DeploymentConfiguration = deploymentConfiguration;
     CurrentDedicatedNodes   = currentDedicatedNodes;
     CurrentLowPriorityNodes = currentLowPriorityNodes;
     ScaleSettings           = scaleSettings;
     AutoScaleRun            = autoScaleRun;
     InterNodeCommunication  = interNodeCommunication;
     NetworkConfiguration    = networkConfiguration;
     TaskSlotsPerNode        = taskSlotsPerNode;
     TaskSchedulingPolicy    = taskSchedulingPolicy;
     UserAccounts            = userAccounts;
     Metadata              = metadata;
     StartTask             = startTask;
     Certificates          = certificates;
     ApplicationPackages   = applicationPackages;
     ApplicationLicenses   = applicationLicenses;
     ResizeOperationStatus = resizeOperationStatus;
     MountConfiguration    = mountConfiguration;
     Identity              = identity;
     CustomInit();
 }
Beispiel #2
0
        private async Task <bool> CreateBatchPool(CommandLineArgs cmdLine, string poolId)
        {
            var batchAccountName = cmdLine.ConnectionArgs.BatchAccountName;
            var batchAccountKey  = cmdLine.ConnectionArgs.BatchAccountKey.EncodeBase64();
            var batchUrl         = cmdLine.ConnectionArgs.BatchAccountUrl;

            var nodeCount = cmdLine.BatchArgs.BatchNodeCount;
            var vmSize    = cmdLine.BatchArgs.BatchVmSize;
            var os        = cmdLine.BatchArgs.BatchPoolOs;

            var userAssignedResourceId = cmdLine.IdentityArgs.ResourceId;
            var userAssignedPrinId     = cmdLine.IdentityArgs.PrincipalId;
            var userAssignedClientId   = cmdLine.IdentityArgs.ClientId;
            var resourceGroupName      = cmdLine.IdentityArgs.ResourceGroup;
            var subscriptionId         = cmdLine.IdentityArgs.SubscriptionId;


            log.LogInformation($"Creating pool [{poolId}]...");

            //var creds = new BatchSharedKeyCredential(batchAccountName, batchAccountKey);
            if (cmdLine.IdentityArgs != null)
            {
                AadHelper.ManagedIdentityClientId = cmdLine.IdentityArgs.ClientId;
            }
            var creds            = new CustomClientCredentials(AadHelper.TokenCredential);
            var managementClient = new BatchManagementClient(creds);

            managementClient.SubscriptionId = subscriptionId;

            //// From: https://docs.microsoft.com/en-us/azure/batch/managed-identity-pools
            bm.ImageReference imageReference;
            bm.VirtualMachineConfiguration virtualMachineConfiguration;
            switch (os)
            {
            case OsType.Linux:
                imageReference = new bm.ImageReference(publisher: "Canonical", offer: "UbuntuServer", sku: "18.04-lts", version: "latest");
                virtualMachineConfiguration = new bm.VirtualMachineConfiguration(imageReference: imageReference, nodeAgentSkuId: "batch.node.ubuntu 18.04");
                break;

            case OsType.Windows:
            default:
                imageReference = new bm.ImageReference(publisher: "MicrosoftWindowsServer", offer: "WindowsServer", sku: "2016-Datacenter-with-containers", version: "latest");
                virtualMachineConfiguration = new bm.VirtualMachineConfiguration(imageReference: imageReference, nodeAgentSkuId: "batch.node.windows amd64");

                break;
            }

            var deploymentConfig = new bm.DeploymentConfiguration()
            {
                VirtualMachineConfiguration = virtualMachineConfiguration
            };
            var ids = new Dictionary <string, bm.UserAssignedIdentities>();

            ids.Add(userAssignedResourceId, new bm.UserAssignedIdentities(principalId: userAssignedPrinId, clientId: userAssignedClientId));

            var poolIdentity = new bm.BatchPoolIdentity()
            {
                Type = bm.PoolIdentityType.UserAssigned, UserAssignedIdentities = ids
            };
            var scaleSettings = new bm.ScaleSettings()
            {
                FixedScale = new bm.FixedScaleSettings()
                {
                    TargetDedicatedNodes = nodeCount
                }
            };

            var poolParameters = new bm.Pool(name: poolId)
            {
                VmSize                  = vmSize,
                ScaleSettings           = scaleSettings,
                DeploymentConfiguration = deploymentConfig,
                Identity                = poolIdentity
            };

            try
            {
                var pool = await managementClient.Pool.CreateWithHttpMessagesAsync(
                    poolName : poolId,
                    resourceGroupName : resourceGroupName,
                    accountName : batchAccountName,
                    parameters : poolParameters,
                    cancellationToken : default(CancellationToken));

                if (!pool.Response.IsSuccessStatusCode)
                {
                    log.LogWarning($"Issue creating pool: {pool.Body.ProvisioningState.ToString()}");
                    return(false);
                }
            }
            catch (Exception exe)
            {
                log.LogError($"Error creating Batch Pool: {exe.ToString()}");
                return(false);
            }
            return(true);
        }