Ejemplo n.º 1
0
        private static async Task <string> CreateLog(LoggingManagementClient client, string logGroup, string logDisplayName)
        {
            CreateLogRequest createLogRequest = new CreateLogRequest
            {
                LogGroupId = logGroup,
                // Create a createLogDetails to pass to Create Log Request
                CreateLogDetails = new CreateLogDetails
                {
                    DisplayName = logDisplayName,
                    LogType     = CreateLogDetails.LogTypeEnum.Custom
                }
            };

            // Pass createLogRequest to client to create the log
            logger.Info($"Creating Log {logDisplayName}");
            logger.Info("=============");
            CreateLogResponse createLogResponse = await client.CreateLog(createLogRequest);

            string workRequestId = createLogResponse.OpcWorkRequestId;

            logger.Info($"CreateLog work request ID is {workRequestId}");

            GetWorkRequestResponse workRequestResponse = WaitForWorkRequestFinished(client, workRequestId);
            string logId = GetLogId(workRequestResponse);

            logger.Info($"Created Log: {logDisplayName} under Log Group: {logGroup} with Log OCID:{logId}");
            return(logId);
        }
        /**
         * Update a cluster and waits for it to become active
         *
         * @param containerEngineClient the service client to use to delete the cluster
         * @param clusterId the cluster ID
         * @param newClusterName The new cluster name
         *
         */
        private static async Task UpdateCluster(
            ContainerEngineClient containerEngineClient, string clusterId, string newClusterName)
        {
            UpdateClusterDetails updateClusterDetails = new UpdateClusterDetails
            {
                Name = newClusterName
            };
            UpdateClusterRequest updateClusterRequest = new UpdateClusterRequest
            {
                ClusterId            = clusterId,
                UpdateClusterDetails = updateClusterDetails
            };
            UpdateClusterResponse updateClusterResponse = await containerEngineClient.UpdateCluster(updateClusterRequest);

            string workRequestId = updateClusterResponse.OpcWorkRequestId;
            GetWorkRequestResponse workRequestResponse = WaitForWorkRequestFinished(containerEngineClient, workRequestId);

            GetClusterRequest getClusterRequest = new GetClusterRequest
            {
                ClusterId = clusterId
            };
            GetClusterResponse getClusterResponse = await containerEngineClient.GetCluster(getClusterRequest);

            Cluster cluster = getClusterResponse.Cluster;

            logger.Info($"Cluster name is changed to {cluster.Name}");
        }
Ejemplo n.º 3
0
        /**
         * Get log id from a finished WorkRequestResponse
         * @param Work Request response
         *
         * @return log OCID
         */
        private static string GetLogId(GetWorkRequestResponse getWorkRequestResponse)
        {
            string logId = null;
            List <WorkRequestResource> resources = getWorkRequestResponse.WorkRequest.Resources;

            foreach (WorkRequestResource resource in resources)
            {
                if (resource.EntityType.Equals("log"))
                {
                    logId = resource.Identifier;
                    break;
                }
            }
            return(logId);
        }
        /**
         * Get the first work request resource ID that match the entity type
         *
         * @param getWorkRequestResponse The work request response for getting work request resource ID
         * @param entityType resource entity type
         *
         * @return work request resource ID
         */
        private static string GetWorkRequestResourceId(GetWorkRequestResponse getWorkRequestResponse, string entityType)
        {
            string resourceId = null;
            var    resources  = getWorkRequestResponse.WorkRequest.Resources;

            foreach (var resource in resources)
            {
                if (resource.EntityType.Equals(entityType))
                {
                    resourceId = resource.Identifier;
                    break;
                }
            }
            return(resourceId);
        }
        /**
         * Creates a Cluster and waits for it to become active
         *
         * @param containerEngineClient the containerEngineclient used to create the cluster
         * @param vcnId the ID of the VCN which will own the subnets
         * @param subnetIds list of subnet ids
         * @param kubernetesVersion kubernetesVersion
         * @param compartmentId
         *
         * @return the created cluster
         */
        private static async Task <Cluster> CreateCluster(
            ContainerEngineClient containerEngineClient, string vcnId, List <string> subnetIds,
            string kubernetesVersion, string compartmentId)
        {
            logger.Info("Creating Cluster.......");

            CreateClusterDetails createClusterDetails = new CreateClusterDetails
            {
                Name              = ClusterDisplayName,
                CompartmentId     = compartmentId,
                VcnId             = vcnId,
                KubernetesVersion = kubernetesVersion,
                Options           = new ClusterCreateOptions
                {
                    ServiceLbSubnetIds = subnetIds
                }
            };
            CreateClusterRequest createClusterRequest = new CreateClusterRequest
            {
                CreateClusterDetails = createClusterDetails
            };
            CreateClusterResponse clusterResponse = await containerEngineClient.CreateCluster(createClusterRequest);

            string workRequestId = clusterResponse.OpcWorkRequestId;

            logger.Info($"cluster work request ID is {workRequestId}");

            GetWorkRequestResponse workRequestResponse = WaitForWorkRequestFinished(containerEngineClient, workRequestId);

            var clusterId = GetClusterId(workRequestResponse);

            logger.Info($"cluster ID is {clusterId}");

            GetClusterRequest getClusterRequest = new GetClusterRequest
            {
                ClusterId = clusterId
            };
            GetClusterResponse getClusterResponse = await containerEngineClient.GetCluster(getClusterRequest);

            return(getClusterResponse.Cluster);
        }
        /**
         * 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);
        }