Exemplo n.º 1
0
        /// <summary>
        /// Create a new node pool.
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/containerengine/CreateNodePool.cs.html">here</a> to see an example of how to use CreateNodePool API.</example>
        public async Task <CreateNodePoolResponse> CreateNodePool(CreateNodePoolRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called createNodePool");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/nodePools".Trim('/')));
            HttpMethod         method         = new HttpMethod("POST");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <CreateNodePoolResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"CreateNodePool failed with error: {e.Message}");
                throw;
            }
        }
        /// <summary>
        /// 创建节点池
        /// </summary>
        public async Task <CreateNodePoolResponse> CreateNodePoolAsync(CreateNodePoolRequest createNodePoolRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("cluster_id", createNodePoolRequest.ClusterId.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/api/v3/projects/{project_id}/clusters/{cluster_id}/nodepools", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json", createNodePoolRequest);
            HttpResponseMessage response = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <CreateNodePoolResponse>(response));
        }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            if (ClusterObject != null)
            {
                Zone        = ClusterObject.Zone;
                ClusterName = ClusterObject.Name;
                Project     = GetProjectNameFromUri(ClusterObject.SelfLink);
            }

            try
            {
                NodePool = NodePool ?? BuildNodePoolFromParams();
                var requestBody = new CreateNodePoolRequest()
                {
                    NodePool = NodePool
                };
                ProjectsResource.ZonesResource.ClustersResource.NodePoolsResource.CreateRequest request =
                    Service.Projects.Zones.Clusters.NodePools.Create(requestBody, Project, Zone, ClusterName);
                Operation createOperation = request.Execute();
                NodePool  createdNodePool = WaitForNodePoolCreation(createOperation);
                WriteObject(createdNodePool);
            }
            catch (GoogleApiException apiEx) when(apiEx.HttpStatusCode == HttpStatusCode.Conflict)
            {
                WriteResourceExistsError(
                    exceptionMessage: $"NodePool '{NodePool.Name}' already exists in cluster '{ClusterName}'"
                    + $"in zone '{Zone}' of project '{Project}'.",
                    errorId: "NodePoolAlreadyExists",
                    targetObject: NodePool.Name);
            }
            catch (GoogleApiException apiEx) when(apiEx.HttpStatusCode == HttpStatusCode.NotFound)
            {
                WriteResourceExistsError(
                    exceptionMessage: $"Cluster '{ClusterName}' cannot be found in zone '{Zone}'"
                    + $" of project '{Project}'.",
                    errorId: "ClusterNotFound",
                    targetObject: ClusterName);
            }
        }
        /**
         * Creates a node pool in a cluster and waits until the work request finished
         *
         * @param containerEngineClient the containerEngineclient used to create the node pool
         * @param compartmentId The compartment ID
         * @param clusterId The ID of the cluster that the node pool is added in
         * @param displayName The display name of the node pool
         * @param kubernetesVersion kubernetesVersion
         * @param nodeImageName The image to use on each node in the node pool
         * @param nodeShape The number of CPUs and the amount of memory allocated to each node in the node pool
         * @param initialNodeLabels The initial node label
         * @param nodePoolNodeConfigDetails The node pool size and the placementConfig of nodes.
         * @return the created node pool
         */
        private static async Task <NodePool> CreateNodePool(ContainerEngineClient containerEngineClient, string compartmentId,
                                                            string clusterId, string displayName, string kubernetesVersion, string nodeImageName,
                                                            string nodeShape, List <KeyValue> initialNodeLabels, CreateNodePoolNodeConfigDetails nodePoolNodeConfigDetails)
        {
            var createNodePoolDetails = new CreateNodePoolDetails
            {
                CompartmentId     = compartmentId,
                ClusterId         = clusterId,
                Name              = displayName,
                KubernetesVersion = kubernetesVersion,
                NodeImageName     = nodeImageName,
                InitialNodeLabels = initialNodeLabels,
                NodeConfigDetails = nodePoolNodeConfigDetails,
                NodeShape         = nodeShape
            };
            var createNodePoolRequest = new CreateNodePoolRequest
            {
                CreateNodePoolDetails = createNodePoolDetails
            };
            var createNodePoolResponse = await containerEngineClient.CreateNodePool(createNodePoolRequest);

            string workRequestId = createNodePoolResponse.OpcWorkRequestId;

            logger.Info($"Create node pool work request ID: {workRequestId}");

            GetWorkRequestResponse workRequestResponse = WaitForWorkRequestFinished(containerEngineClient, workRequestId);
            var nodePoolId = GetWorkRequestResourceId(workRequestResponse, "nodepool");

            logger.Info($"Node pool ID is {nodePoolId}");

            GetNodePoolRequest getNodePoolRequest = new GetNodePoolRequest
            {
                NodePoolId = nodePoolId
            };
            GetNodePoolResponse getNodePoolResponse = await containerEngineClient.GetNodePool(getNodePoolRequest);

            return(getNodePoolResponse.NodePool);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateNodePoolRequest request;

            try
            {
                request = new CreateNodePoolRequest
                {
                    CreateNodePoolDetails = CreateNodePoolDetails,
                    OpcRetryToken         = OpcRetryToken,
                    OpcRequestId          = OpcRequestId
                };

                response = client.CreateNodePool(request).GetAwaiter().GetResult();
                WriteOutput(response, CreateWorkRequestObject(response.OpcWorkRequestId));
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a node pool for a cluster.
        /// Documentation https://developers.google.com/container/v1/reference/nodePools/create
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated container service.</param>
        /// <param name="projectId">The Google Developers Console [project ID or project number](https://developers.google.com/console/help/new/#projectnumber).</param>
        /// <param name="zone">The name of the Google Compute Engine [zone](/compute/docs/zones#available) in which the cluster resides.</param>
        /// <param name="clusterId">The name of the cluster.</param>
        /// <param name="body">A valid container v1 body.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Create(containerService service, string projectId, string zone, string clusterId, CreateNodePoolRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (projectId == null)
                {
                    throw new ArgumentNullException(projectId);
                }
                if (zone == null)
                {
                    throw new ArgumentNullException(zone);
                }
                if (clusterId == null)
                {
                    throw new ArgumentNullException(clusterId);
                }

                // Make the request.
                return(service.NodePools.Create(body, projectId, zone, clusterId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request NodePools.Create failed.", ex);
            }
        }