コード例 #1
0
        /// <summary>
        /// Launch an instance from configuration
        /// </summary>
        /// <param name="request">Instance configuration</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <InstanceGrpc> LaunchAsync(LaunchInstanceRequest request, string userId)
        {
            Instance instance = launchInstanceAdapter.Transform(request);

            instance.UserId = userId;

            logger.LogDebug($"Created the instance {instance}");

            await instanceDbContext.AddAsync(instance);

            await instanceDbContext.SaveChangesAsync();

            logger.LogDebug($"The instance with Id {instance.Id} successfully save to the DB");

            return(instanceAdapter.Transform(instance));
        }
コード例 #2
0
        private void HandleOutput(LaunchInstanceRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case StatusParamSet:
                response = client.Waiters.ForLaunchInstance(request, waiterConfig, WaitForStatus).Execute();
                break;

            case Default:
                response = client.LaunchInstance(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.Instance);
        }
コード例 #3
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            LaunchInstanceRequest request;

            try
            {
                request = new LaunchInstanceRequest
                {
                    LaunchInstanceDetails = LaunchInstanceDetails,
                    OpcRetryToken         = OpcRetryToken
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a new instance in the specified compartment and the specified availability domain.
        /// For general information about instances, see Overview of the Compute Service.
        /// For information about access control and compartments, see Overview of the IAM Service.
        /// For information about availability domains, see Regions and Availability Domains.
        /// To get a list of availability domains, use the ListAvailabilityDomains operation in the
        /// Identity and Access Management Service API.
        /// All Oracle Cloud Infrastructure resources, including instances, get an Oracle-assigned,
        /// unique ID called an Oracle Cloud Identifier (OCID). When you create a resource, you can
        /// find its OCID in the response. You can also retrieve a resource's OCID by using a List API
        /// operation on that resource type, or by viewing the resource in the Console.
        /// To launch an instance using an image or a boot volume use the sourceDetails parameter in
        /// LaunchInstanceDetails.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public LaunchInstanceResponse LaunchInstance(LaunchInstanceRequest request)
        {
            var uri = new Uri(GetEndPoint(CoreServices.Instance, this.Region));

            using (var webResponse = this.RestClient.Post(uri, request.LaunchInstanceDetails, new HttpRequestHeaderParam {
                OpcRetryToken = request.OpcRetryToken
            }))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = reader.ReadToEnd();

                        return(new LaunchInstanceResponse()
                        {
                            Instance = this.JsonSerializer.Deserialize <Instance>(response),
                            ETag = webResponse.Headers.Get("etag"),
                            OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                            OpcWorkRequestId = webResponse.Headers.Get("opc-work-request-id")
                        });
                    }
        }
コード例 #5
0
        private static async Task <Instance> createInstance(ComputeClient computeClient, LaunchInstanceDetails launchInstanceDetails)
        {
            logger.Info("Launching an instance.....");
            LaunchInstanceRequest launchInstanceRequest = new LaunchInstanceRequest {
                LaunchInstanceDetails = launchInstanceDetails
            };
            LaunchInstanceResponse launchInstanceResponse = await computeClient.LaunchInstance(launchInstanceRequest);

            GetInstanceRequest getInstanceRequest = new GetInstanceRequest {
                InstanceId = launchInstanceResponse.Instance.Id
            };
            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetInstanceResponse getInstanceResponse = computeClient.Waiters.ForInstance(getInstanceRequest, waiterConfiguration, Instance.LifecycleStateEnum.Running).Execute();

            Instance instance = getInstanceResponse.Instance;

            return(instance);
        }
コード例 #6
0
        public Instance Transform(LaunchInstanceRequest request)
        {
            List <Volume> dataVolumes = request.DataVolumes
                                        .ToList()
                                        .ConvertAll(id => new Volume()
            {
                Id = id
            });

            return(new Instance()
            {
                Id = IdentityFabric.GenInstanceId(),
                Name = request.Name,
                SystemVolume = new Volume()
                {
                    Id = request.SystemVolume
                },
                DataVolumes = dataVolumes,
                InstanceType = request.InstanceType,
                InstanceState = InstanceState.PENDING
            });
        }
コード例 #7
0
        /// <summary>
        /// Launch a new instance by the provided confiduration
        /// </summary>
        /// <param name="configuration">Configurations</param>
        /// <returns></returns>
        public async Task <InstanceGrpc> LaunchAsync(LaunchInstanceConfiguration configuration)
        {
            return(await grpcCallerService.CallService(urls.Volumes, async channel =>
            {
                var client = new Instances.API.Instances.InstancesClient(channel);
                //new Instances.InstanceClient()

                logger.LogDebug("grpc client created, request = {@id}", "");

                LaunchInstanceRequest launchInstanceRequest = new LaunchInstanceRequest()
                {
                    Name = configuration.Name,
                    InstanceType = configuration.InstanceType,
                    SystemVolume = configuration.SystemVolumeId
                };
                launchInstanceRequest.DataVolumes.AddRange(configuration.DataVolumeIds);

                var response = await client.LaunchAsync(launchInstanceRequest);

                logger.LogDebug("grpc response {@response}", response);

                return response;
            }));
        }
コード例 #8
0
 /// <summary>
 /// Creates a waiter using the provided configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="config">Wait Configuration</param>
 /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <LaunchInstanceRequest, LaunchInstanceResponse> ForLaunchInstance(LaunchInstanceRequest request, WaiterConfiguration config, params WorkrequestsService.Models.WorkRequest.StatusEnum[] targetStates)
 {
     return(new Waiter <LaunchInstanceRequest, LaunchInstanceResponse>(() =>
     {
         var response = client.LaunchInstance(request).Result;
         var getWorkRequestRequest = new Oci.WorkrequestsService.Requests.GetWorkRequestRequest
         {
             WorkRequestId = response.OpcWorkRequestId
         };
         workRequestClient.Waiters.ForWorkRequest(getWorkRequestRequest, config, targetStates).Execute();
         return response;
     }));
 }
コード例 #9
0
 /// <summary>
 /// Creates a waiter using default wait configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="statuses">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <LaunchInstanceRequest, LaunchInstanceResponse> ForLaunchInstance(LaunchInstanceRequest request, params WorkrequestsService.Models.WorkRequest.StatusEnum[] targetStates)
 {
     return(this.ForLaunchInstance(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates));
 }
コード例 #10
0
        /// <summary>
        /// Launch instance from configuration request
        /// </summary>
        /// <param name="request">Configuration request</param>
        /// <param name="context">ServerCallContext</param>
        /// <returns></returns>
        public override async Task <InstanceGrpc> Launch(LaunchInstanceRequest request, ServerCallContext context)
        {
            string userId = identityService.GetUserIdentity();

            return(await instanceDataSource.LaunchAsync(request, userId));
        }