当前位置: 首页>>代码示例>>C#>>正文


C# Model.DescribeInstancesRequest类代码示例

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


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


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