• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Model.DescribeInstancesRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Amazon.EC2.Model.DescribeInstancesRequest的典型用法代码示例。如果您正苦于以下问题:C# DescribeInstancesRequest类的具体用法?C# DescribeInstancesRequest怎么用?C# DescribeInstancesRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DescribeInstancesRequest类属于Amazon.EC2.Model命名空间,在下文中一共展示了DescribeInstancesRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetInstance

        public void GetInstance()
        {
            // Arrange
            const string instanceId = "eight";
            var request = new DescribeInstancesRequest { InstanceIds = new List<string> { instanceId } };
            var response = new DescribeInstancesResponse
            {
                Reservations = new List<Reservation>
                {
                    new Reservation
                    {
                        Instances = new List<Instance>
                        {
                            GenerateInstance(instanceId, InstanceStateName.Running)
                        }
                    }
                }
            };
            Ec2ClientMock.Setup(x => x.DescribeInstances(It.Is<DescribeInstancesRequest>(
                req => req.InstanceIds.First() == request.InstanceIds.First()
            ))).Returns(response);

            // Act
            Instance instance = InstanceService.GetInstance(instanceId);

            // Assert
            instance.State.Name.Should().Be(InstanceStateName.Running);
        }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:28,代码来源:InstanceServiceTests.cs


示例2: Run

        public void Run()
        {
            var instanceRequest = new DescribeInstancesRequest
            {
                InstanceIds = new List<string>()
                {
                    instance.InstanceId
                }
            };

            var limit = 600;

            DescribeInstancesResponse response = null;

            while (limit > 0)
            {
                response = awsClient.Ec2Client.DescribeInstances(instanceRequest);

                if (response.Reservations[0].Instances[0].State.Code == 16)
                    break;

                limit --;

                Thread.Sleep(1000);
            }

            if (response != null && response.Reservations[0].Instances[0].State.Code == 16)
                FinishedSuccessfully = true;
            else
            {
                Error = string.Format("Instance not launched yet. Last state: {0}.", response.Reservations[0].Instances[0].State.Name);
            }
        }
开发者ID:clearctvm,项目名称:octopus_aws_pilot,代码行数:33,代码来源:AwsCheckTheStateStep.cs


示例3: GetRegionData

        public RegionDetails GetRegionData(AwsRegionLocations region)
        {
            var regionEndpoint = region.ToAwsRegionEndpoint();

            // Get an Ec2Client for the current region
            var client = ec2Clients.GetOrAdd(region, r => AWSClientFactory.CreateAmazonEC2Client(credentials, regionEndpoint));

            // Get instances within the region
            // Start by creating the request
            var request = new DescribeInstancesRequest();

            // Add a filter to the request so that it only returns instances that are either in "Running" or "Pending" state.
            request.Filters.Add(new Filter("instance-state-code", new List<string>()
            {
                ((ushort)InstanceStatuses.Running).ToString(),
                ((ushort)InstanceStatuses.Pending).ToString()
            }));

            // Send the request to Amazon
            var reservations = client.DescribeInstances(request).Reservations;

            return new RegionDetails()
            {
                Name = regionEndpoint.SystemName,
                Region = region,
                Instances = reservations.SelectMany(x => x.Instances).Select(x => x.ToInstanceInfo()).ToList()
            };
        }
开发者ID:modulexcite,项目名称:2015-Slides-and-Demos,代码行数:28,代码来源:Ec2Caller.cs


示例4: GetInstances

 public IEnumerable<Instance> GetInstances(IEnumerable<string> instanceIds)
 {
     var instancesRequest = new DescribeInstancesRequest();
     instancesRequest.InstanceIds.AddRange(instanceIds);
     var instances = _client.DescribeInstances(instancesRequest);
     return instances.Reservations.SelectMany(x => x.Instances);
 }
开发者ID:kjelliverb,项目名称:condep-test,代码行数:7,代码来源:Ec2InstanceHandler.cs


示例5: ListInstancesByTag

 public List<Reservation> ListInstancesByTag(string tagKey, string tagValue)
 {
     var describeInstancesRequest = new DescribeInstancesRequest()
     {
         Filter = new List<Filter>
                     {
                         new Filter()
                             {
                                 Name = "tag:" + tagKey,
                                 Value = new List<string>
                                     {
                                         tagValue
                                     },
                             },
                         new Filter()
                             {
                                 Name = "instance-state-name",
                                 Value = new List<string>
                                     {
                                         "running"
                                     },
                             }
                     }
     };
     try
     {
         var describeInstancesResponse = amazonEc2.DescribeInstances(describeInstancesRequest);
         return describeInstancesResponse.DescribeInstancesResult.Reservation;
     }
     catch (Exception ex)
     {
         logger.Log("AWS ERROR: " + ex.Message);
         throw new Exception("Cannot list instances");
     }
 }
开发者ID:Rahul-Sindhu,项目名称:ChaosMonkey,代码行数:35,代码来源:Ec2Factory.cs


示例6: GetAllocatedIpAddresses

        public IEnumerable<string> GetAllocatedIpAddresses()
        {
            var request = new DescribeInstancesRequest();
            var response = _ec2Client.DescribeInstances(request);

            return response.Reservations
                .SelectMany(x => x.Instances.Select(y => y.PrivateIpAddress))
                .Where(x => x != null);
        }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:9,代码来源:NetworkService.cs


示例7: getReservationsInRegion

		public static List<Reservation> getReservationsInRegion(this API_AmazonEC2 amazonEC2, string region)
		{
		        "Gettting Reservations in region: {0}".info(region);
				var ec2ClientInRegion = amazonEC2.getEC2Client(region);
				var describesInstance = new DescribeInstancesRequest(); 				
				var reservations = ec2ClientInRegion.DescribeInstances(describesInstance)
													.DescribeInstancesResult
													.Reservation; 				
				return reservations;									  
		}
开发者ID:paul-green,项目名称:O2.Platform.Scripts,代码行数:10,代码来源:API_AmazonEC2.cs


示例8: Execute

        public override void Execute()
        {
            AmazonEC2Client client = new AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY);
            DescribeInstancesRequest request = new DescribeInstancesRequest();
            DescribeInstancesResponse response = client.DescribeInstances(request);

            Dictionary<string, List<RunningInstance>> instances = new Dictionary<string, List<RunningInstance>>();
            foreach (Reservation r in response.DescribeInstancesResult.Reservation)
                foreach (RunningInstance i in r.RunningInstance)
                {
                    if (!instances.ContainsKey(i.ImageId))
                        instances[i.ImageId] = new List<RunningInstance>();

                    instances[i.ImageId].Add(i);
                }

            List<string> allImageIds = new List<string>();
            foreach (string imageId in instances.Keys)
                allImageIds.Add(imageId);

            DescribeImagesRequest imageReq = new DescribeImagesRequest();
            imageReq.ImageId = allImageIds;
            DescribeImagesResponse imageResp = client.DescribeImages(imageReq);

            Dictionary<string, Image> imageDescriptions = new Dictionary<string, Image>();
            foreach (Image image in imageResp.DescribeImagesResult.Image)
                imageDescriptions.Add(image.ImageId, image);

            foreach (string imageId in instances.Keys)
            {
                if (imageDescriptions.ContainsKey(imageId))
                    Console.WriteLine("--- {0} {1} ({2} {3})",
                        imageId,
                        imageDescriptions[imageId].ImageLocation,
                        imageDescriptions[imageId].Platform,
                        imageDescriptions[imageId].Architecture);
                else
                    Console.WriteLine("--- {0} (AMI not found)", imageId);

                foreach (RunningInstance i in instances[imageId])
                {
                    DateTime launchTime = DateTime.Parse(i.LaunchTime);
                    Console.Write("{0}\t{1}\t{2}\t{3}\t{4}", launchTime, i.InstanceType, i.InstanceState.Name, i.InstanceId, i.StateTransitionReason);
                    if (ips)
                        Console.Write("\t{0}\t{1}", i.PublicDnsName, i.PrivateDnsName);
                    Console.WriteLine();
                }

                Console.WriteLine();
            }
        }
开发者ID:siganakis,项目名称:s3-tool-encrypted,代码行数:51,代码来源:Instances.cs


示例9: GetInstances

        static void GetInstances(AWSCredentials credentials)
        {
            IAmazonEC2 client = AWSClientFactory.CreateAmazonEC2Client(credentials, RegionEndpoint.USEast1);

            DescribeInstancesRequest request = new DescribeInstancesRequest();
            request.Filters.Add(new Filter("instance-state-code", new List<string>() { "0", "16" }));

            DescribeInstancesResponse describeInstancesResponse = client.DescribeInstances();
            List<Reservation> reservations = describeInstancesResponse.Reservations;

            foreach (Instance instance in reservations.SelectMany(x => x.Instances))
            {
                Console.WriteLine("Instance with ID {0} is currently {1}", instance.InstanceId, instance.State.Name);
            }
        }
开发者ID:modulexcite,项目名称:2015-Slides-and-Demos,代码行数:15,代码来源:Program.cs


示例10: GetInstances

 public IEnumerable<Instance> GetInstances()
 {
     AmazonEC2Client client = _GetClient();
     var describeInstancesRequest = new DescribeInstancesRequest();
     var response = client.DescribeInstances(describeInstancesRequest);
     var instances = response.DescribeInstancesResult.Reservation.SelectMany(x => x.RunningInstance).Select(x => new{ x.InstanceId, State = x.InstanceState.Name, x.IpAddress, x.InstanceType, x.PublicDnsName, InstanceName = x.Tag.Where(y => y.Key == "Name").Select(z => z.Value).First(), });
     return instances.Select(instance => new Instance
                                             {
                                                 Name = instance.InstanceName,
                                                 State = instance.State,
                                                 Dns = instance.PublicDnsName,
                                                 Id = instance.InstanceId,
                                                 Ip = instance.IpAddress
                                             });
 }
开发者ID:mg-alfa-dev,项目名称:aws,代码行数:15,代码来源:ClientUtils.cs


示例11: GetInstances

 public IEnumerable<Instance> GetInstances()
 {
     var client = _GetClient();
     var describeInstancesRequest = new DescribeInstancesRequest();
     var response = client.DescribeInstances(describeInstancesRequest);
     return response.DescribeInstancesResult.Reservation
         .SelectMany(x => x.RunningInstance)
         .Select(x =>
                 new Instance
                 {
                     Id = x.InstanceId,
                     Name = x.Tag.Where(y => y.Key == "Name").Select(y => y.Value).First(),
                     State = x.InstanceState.Name,
                     Dns = x.PublicDnsName,
                     Ip = x.IpAddress,
                 });
 }
开发者ID:awithy,项目名称:aws,代码行数:17,代码来源:ClientUtils.cs


示例12: AmazonExecute

        /// <summary>
        /// Connect to an Amazon subscription and obtain information about instance reservations.
        /// </summary>
        protected override void AmazonExecute()
        {
            var request = new DescribeInstancesRequest
            {
                InstanceId = this.InstanceIds.Get(this.ActivityContext)
            };

            try
            {
                var response = EC2Client.DescribeInstances(request);
                this.Reservations.Set(this.ActivityContext, response.DescribeInstancesResult.Reservation);
            }
            catch (EndpointNotFoundException ex)
            {
                this.LogBuildMessage(ex.Message);
            }
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:20,代码来源:DescribeInstances.cs


示例13: GetInstances

        public List<Instance> GetInstances()
        {
            var instances = new List<Instance>();

            var ec2Request = new DescribeInstancesRequest();

            var ec2Response = _client.DescribeInstances(ec2Request);
            foreach (var reservation in ec2Response.Reservations)
            {
                var instance = reservation.Instances.Single();
                instances.Add(instance);
                //var name = instance.Tags.Single(x => x.Key == "Name").Value;
                //sr.WriteLine("{0} {1} {2} {3}", i++, name, instance.State.Name, instance.PublicDnsName);
            }

            return instances;
        }
开发者ID:hiblen,项目名称:AWSToolkit,代码行数:17,代码来源:AwsFacade.cs


示例14: ProcessRecord

        protected override void ProcessRecord()
        {
            AmazonEC2 client = base.GetClient();
            Amazon.EC2.Model.DescribeInstancesRequest request = new Amazon.EC2.Model.DescribeInstancesRequest();
            if (!string.IsNullOrEmpty(this._InstanceId))
            {
                request.InstanceId.Add(this._InstanceId);
            }
            Amazon.EC2.Model.DescribeInstancesResponse response = client.DescribeInstances(request);

            foreach(Reservation reservation in response.DescribeInstancesResult.Reservation)
            {
                base.WriteObject(reservation.RunningInstance);
            }

            
        }
开发者ID:ksikes,项目名称:Amazon.Powershell,代码行数:17,代码来源:DescribeInstancesCmdlet.cs


示例15: InstanceDescriptions

        public List<RunningInstance> InstanceDescriptions(IEnumerable<string> instanceIds)
        {
            try
            {
                var request = new DescribeInstancesRequest().WithInstanceId(instanceIds.ToArray());
                var response = this.client.DescribeInstances(request);

                return response
                    .DescribeInstancesResult
                    .Reservation
                    .SelectMany(reservation => reservation.RunningInstance)
                    .ToList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred getting instance states: ");
                Console.WriteLine(ex.Message);
                return new List<RunningInstance>();
            }
        }
开发者ID:koushikajay,项目名称:Alfred,代码行数:20,代码来源:EC2.cs


示例16: GetAllEc2Instances

        public static IList<Ec2Record> GetAllEc2Instances(bool force = false)
        {
            if (m_Ec2Records == null || force)
            {
                var ec2 = Ec2ConnectionProvider.GetEc2Connection();

                DescribeInstancesRequest request = new DescribeInstancesRequest();
                DescribeInstancesResponse res = ec2.DescribeInstances(request);

                m_Ec2Records = new List<Ec2Record>();

                res.DescribeInstancesResult.Reservations.ForEach(
                    reservation => reservation.Instances.ForEach(
                        runningInstance => m_Ec2Records.Add(
                            new Ec2Record()
                                {
                                    InstanceId = runningInstance.InstanceId,
                                    Status = runningInstance.State.Name,
                                    Type = runningInstance.InstanceType,
                                    Platform = string.IsNullOrWhiteSpace(runningInstance.Platform) ? "Linux" : "Windows",
                                    Ip = string.IsNullOrEmpty(runningInstance.PublicIpAddress) ? "-" : runningInstance.PublicIpAddress,
                                    PrivateIp = runningInstance.PrivateIpAddress,
                                    PublicDns = runningInstance.PublicDnsName,
                                    PrivateDns = string.IsNullOrEmpty(runningInstance.PrivateDnsName) ? "-" : runningInstance.PrivateDnsName,
                                    Name = AwsTags.GetValueFromEc2Tag(runningInstance.Tags, "Name"),
                                    AttachedVolumes = VolumeProvider.GetVolumesByEc2Id(runningInstance.InstanceId),
                                    LaunchTime = runningInstance.LaunchTime,
                                    SecurityGroups = runningInstance
                                                        .SecurityGroups
                                                        .Select(group => group.GroupName)
                                                        .ToList()
                                }
                                               )
                                       )
                    );
            }

            return m_Ec2Records;
        }
开发者ID:kwasiak,项目名称:awsmonitor,代码行数:39,代码来源:Ec2InstanceProvider.cs


示例17: InvokeListInstances

        public static void InvokeListInstances()
        {
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(
                appConfig["AWSAccessKey"],
                appConfig["AWSSecretKey"],
                RegionEndpoint.USWest2
                );

            DescribeInstancesRequest request = new DescribeInstancesRequest();

            try
            {
                DescribeInstancesResponse ec2Response = ec2.DescribeInstances(request);
                int numInstances = 0;
                numInstances = ec2Response.DescribeInstancesResult.Reservation.Count;
                Console.WriteLine("You have " + numInstances + " Amazon EC2 instance(s) running.");
            }
            catch (AmazonEC2Exception ex)
            {
                if (ex.ErrorCode.Equals("OptInRequired"))
                {
                    Console.WriteLine("You are not signed for Amazon EC2.");
                    Console.WriteLine("You can sign up at http://aws.amazon.com/ec2.");
                }
                else
                {
                    Console.WriteLine("Caught Exception: " + ex.Message);
                    Console.WriteLine("Response Status Code: " + ex.StatusCode);
                    Console.WriteLine("Error Code: " + ex.ErrorCode);
                    Console.WriteLine("Error Type: " + ex.ErrorType);
                    Console.WriteLine("Request ID: " + ex.RequestId);
                }
            }
            Console.WriteLine();
        }
开发者ID:bernardoleary,项目名称:MyBigBro,代码行数:37,代码来源:AmazonEC2ListInstancesSample.cs


示例18: GetInstances

        public DescribeInstancesResult GetInstances(Ec2Key ec2Key)
        {
            _logger.Debug("GetInstances Start.");

            AmazonEC2 ec2 = CreateAmazonEc2Client(ec2Key);

            var ec2Request = new DescribeInstancesRequest();

            DescribeInstancesResponse describeInstancesResponse = ec2.DescribeInstances(ec2Request);

            DescribeInstancesResult result = describeInstancesResponse.DescribeInstancesResult;

            _logger.Debug("GetInstances End.");

            return result;
        }
开发者ID:escherrer,项目名称:EC2Utilities,代码行数:16,代码来源:Ec2ResourceAccess.cs


示例19: BeginDescribeInstances

        /// <summary>
        /// Initiates the asynchronous execution of the DescribeInstances operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DescribeInstances operation on AmazonEC2Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDescribeInstances
        ///         operation.</returns>
        public IAsyncResult BeginDescribeInstances(DescribeInstancesRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new DescribeInstancesRequestMarshaller();
            var unmarshaller = DescribeInstancesResponseUnmarshaller.Instance;

            return BeginInvoke<DescribeInstancesRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:19,代码来源:AmazonEC2Client.cs


示例20: invokeDescribeInstances

 IAsyncResult invokeDescribeInstances(DescribeInstancesRequest describeInstancesRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new DescribeInstancesRequestMarshaller().Marshall(describeInstancesRequest);
     var unmarshaller = DescribeInstancesResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
开发者ID:rsparkyc,项目名称:aws-sdk-net,代码行数:8,代码来源:AmazonEC2Client.cs



注:本文中的Amazon.EC2.Model.DescribeInstancesRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Model.RunInstancesRequest类代码示例发布时间:2022-05-24
下一篇:
C# EC2.AmazonEC2Config类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap