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


C# Model.RunInstancesRequest类代码示例

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


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

示例1: CreateInstances

        public IEnumerable<string> CreateInstances(string boostrapId, string imageId, int numberOfInstances, string securityGroupId)
        {
            const string userData = @"<powershell>
            netsh advfirewall firewall add rule name=""WinRM Public in"" protocol=TCP dir=in profile=any localport=5985 remoteip=any localip=any action=allow
            </powershell>";

            var runInstancesRequest = new RunInstancesRequest()
            {
                ImageId = imageId,
                InstanceType = "t2.micro",
                MinCount = numberOfInstances,
                MaxCount = numberOfInstances,
                KeyName = "ConDep",
                UserData = Convert.ToBase64String(Encoding.UTF8.GetBytes(userData)),
                NetworkInterfaces = new List<InstanceNetworkInterfaceSpecification>
                {
                    new InstanceNetworkInterfaceSpecification
                    {
                        AssociatePublicIpAddress = true,
                        DeviceIndex = 0,
                        SubnetId = "subnet-7eba6d1b",
                        Groups = new List<string>
                        {
                            securityGroupId
                        },
                        DeleteOnTermination = true,
                    }
                }
            };

            RunInstancesResponse runResponse = _client.RunInstances(runInstancesRequest);
            return runResponse.Reservation.Instances.Select(x => x.InstanceId);
        }
开发者ID:kjelliverb,项目名称:condep-test,代码行数:33,代码来源:Ec2InstanceHandler.cs

示例2: StartServer

        public static Ec2Response StartServer(DeveloperOptions developerOptions)
        {
            try
            {
                var ec2Config = new AmazonEC2Config { AuthenticationRegion = developerOptions.RegionEndpont };

                var ec2Client = new AmazonEC2Client(
                    new BasicAWSCredentials(developerOptions.AccessKey, developerOptions.SecretAccessKey), ec2Config);

                var launchRequest = new RunInstancesRequest
                {
                    ImageId = developerOptions.AmiId,
                    InstanceType = developerOptions.InstanceType,
                    MinCount = 1,
                    MaxCount = 1,
                    KeyName = developerOptions.Ec2KeyPair,
                    SecurityGroupIds = new List<string> { developerOptions.SecurityGroupId }
                };
                var launchResponse = ec2Client.RunInstances(launchRequest);
                if (launchResponse.HttpStatusCode.Equals(HttpStatusCode.OK))
                {
                    while (true)
                    {
                        var instances = ec2Client.DescribeInstances();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            // TODO
            return null;
        }
开发者ID:ernestohs,项目名称:Apprenda-AWS-Integration,代码行数:35,代码来源:EC2AMIFactory.cs

示例3: Run

        public void Run()
        {
            var amiId = ConfigurationManager.AppSettings["aws-imiId"];
            var keyPair = ConfigurationManager.AppSettings["aws-keyPair"];
            var groupSecurity = ConfigurationManager.AppSettings["aws-groupSecurity"];

            var groups = new List<string>() { groupSecurity };

            var launchRequest = new RunInstancesRequest
            {
                ImageId = amiId,
                InstanceType = InstanceType.M3Medium,
                MinCount = 1,
                MaxCount = 1,
                KeyName = keyPair,
                SecurityGroupIds = groups,

            };

            try
            {
                var launchResponse = client.Ec2Client.RunInstances(launchRequest);

                var instances = launchResponse.Reservation.Instances;

                foreach (var item in instances)
                {
                    instance.InstanceId = item.InstanceId;
                    instance.Instance = item;
                }

                FinishedSuccessfully = true;
            }
            catch (Exception ex)
            {
                Error = ex.Message;
            }
        }
开发者ID:clearctvm,项目名称:octopus_aws_pilot,代码行数:38,代码来源:AwsLaunchNewInstanceStep.cs

示例4: CreateNode

        public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options)
        {
            EC2NodeOptions ops = options as EC2NodeOptions;
            if (ops == null && options != null)
                throw new Exception ("Only EC2NodeOptions can be used as NodeOptions for creating EC2 Nodes.");
            else if (ops == null)
                ops = new EC2NodeOptions ();

            RunInstancesRequest request = new RunInstancesRequest () {
                InstanceType = size.Id,
                ImageId = image.Id,
                MinCount = 1,
                MaxCount = 1,
                KeyName = auth.UserName,
            };
            RunInstancesResponse response = Client.RunInstances (request);

            foreach (var i in response.RunInstancesResult.Reservation.RunningInstance) {
                return EC2Node.FromRunningInstance (i, this);
            }

            return null;
        }
开发者ID:jacksonh,项目名称:MCloud,代码行数:23,代码来源:EC2Driver.cs

示例5: ProcessRecord

 protected override void ProcessRecord()
 {
     AmazonEC2 client = base.GetClient();
     Amazon.EC2.Model.RunInstancesRequest request = new Amazon.EC2.Model.RunInstancesRequest();
     request.ImageId = this._ImageId;
     request.MinCount = this._MinCount;
     request.MaxCount = this._MaxCount;
     request.KeyName = this._KeyName;
     if (string.IsNullOrEmpty(this._SecurityGroup))
     {
         request.SecurityGroup.Add(this._SecurityGroup);
     }
     request.UserData = this._UserData;
     request.InstanceType = this._InstanceType;
     request.KernelId = this._KernelId;
     request.RamdiskId = this._RamdiskId;
     request.SubnetId = this._SubnetId;
     request.AdditionalInfo = this._AdditionalInfo;
     request.DisableApiTermination = this._DisableApiTermination;
     request.InstanceInitiatedShutdownBehavior = this._InstanceInitiatedShutdownBehavior;
     Amazon.EC2.Model.RunInstancesResponse response = client.RunInstances(request);
     base.WriteObject(response.RunInstancesResult.Reservation, true);
 }
开发者ID:ksikes,项目名称:Amazon.Powershell,代码行数:23,代码来源:RunInstancesCmdlet.cs

示例6: RunInstances

        /// <summary>
        /// Launches the specified number of instances using an AMI for which you have permissions.
        /// 
        ///  
        /// <para>
        /// When you launch an instance, it enters the <code>pending</code> state. After the instance
        /// is ready for you, it enters the <code>running</code> state. To check the state of
        /// your instance, call <a>DescribeInstances</a>.
        /// </para>
        ///  
        /// <para>
        /// If you don't specify a security group when launching an instance, Amazon EC2 uses
        /// the default security group. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html">Security
        /// Groups</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        ///  
        /// <para>
        /// Linux instances have access to the public key of the key pair at boot. You can use
        /// this key to provide secure access to the instance. Amazon EC2 public images use this
        /// feature to provide secure access without passwords. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Key
        /// Pairs</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        ///  
        /// <para>
        /// You can provide optional user data when launching an instance. For more information,
        /// see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html">Instance
        /// Metadata</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        ///  
        /// <para>
        /// If any of the AMIs have a product code attached for which the user has not subscribed,
        /// <code>RunInstances</code> fails.
        /// </para>
        ///  
        /// <para>
        /// T2 instance types can only be launched into a VPC. If you do not have a default VPC,
        /// or if you do not specify a subnet ID in the request, <code>RunInstances</code> fails.
        /// </para>
        ///  
        /// <para>
        /// For more information about troubleshooting, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_InstanceStraightToTerminated.html">What
        /// To Do If An Instance Immediately Terminates</a>, and <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html">Troubleshooting
        /// Connecting to Your Instance</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the RunInstances service method.</param>
        /// 
        /// <returns>The response from the RunInstances service method, as returned by EC2.</returns>
        public RunInstancesResponse RunInstances(RunInstancesRequest request)
        {
            var marshaller = new RunInstancesRequestMarshaller();
            var unmarshaller = RunInstancesResponseUnmarshaller.Instance;

            return Invoke<RunInstancesRequest,RunInstancesResponse>(request, marshaller, unmarshaller);
        }
开发者ID:reidwooten99apps,项目名称:aws-sdk-net,代码行数:55,代码来源:AmazonEC2Client.cs

示例7: invokeRunInstances

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

示例8: RunInstances

 /// <summary>
 /// <para>Launches the specified number of instances using an AMI for which you have permissions.</para> <para>When you launch an instance, it
 /// enters the <c>pending</c> state. After the instance is ready for you, it enters the <c>running</c> state. To check the state of your
 /// instance, call DescribeInstances.</para> <para>If you don't specify a security group when launching an instance, Amazon EC2 uses the default
 /// security group. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html" >Security
 /// Groups</a> in the <i>Amazon Elastic Compute Cloud User Guide</i> .</para> <para>Linux instances have access to the public key of the key
 /// pair at boot. You can use this key to provide secure access to the instance. Amazon EC2 public images use this feature to provide secure
 /// access without passwords. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html" >Key
 /// Pairs</a> in the <i>Amazon Elastic Compute Cloud User Guide</i> .</para> <para>You can provide optional user data when launching an
 /// instance. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html" >Instance
 /// Metadata</a> in the <i>Amazon Elastic Compute Cloud User Guide</i> .</para> <para>If any of the AMIs have a product code attached for which
 /// the user has not subscribed, <c>RunInstances</c> fails.</para>
 /// </summary>
 /// 
 /// <param name="runInstancesRequest">Container for the necessary parameters to execute the RunInstances service method on AmazonEC2.</param>
 /// 
 /// <returns>The response from the RunInstances service method, as returned by AmazonEC2.</returns>
 /// 
 public RunInstancesResponse RunInstances(RunInstancesRequest runInstancesRequest)
 {
     IAsyncResult asyncResult = invokeRunInstances(runInstancesRequest, null, null, true);
     return EndRunInstances(asyncResult);
 }
开发者ID:rsparkyc,项目名称:aws-sdk-net,代码行数:23,代码来源:AmazonEC2Client.cs

示例9: RunInstances

		internal RunInstancesResponse RunInstances(RunInstancesRequest request)
        {
            var task = RunInstancesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
开发者ID:virajs,项目名称:aws-sdk-net,代码行数:13,代码来源:AmazonEC2Client.cs

示例10: AssignAgentIps

        public List<string> AssignAgentIps(AmazonEC2Client ec2Client, TestSuite testSuite)
        {
            int requiredInstances = testSuite.Tests.Count(testToGiveIp => string.IsNullOrWhiteSpace(testToGiveIp.Agent));

            if (requiredInstances > 0)
            {
                var runInstancesRequest = new RunInstancesRequest
                {
                    ImageId = "ami-df844ba8",
                    InstanceType = "t1.micro",
                    MinCount = requiredInstances,
                    MaxCount = requiredInstances,
                    KeyName = "Fourth"
                };
                runInstancesRequest.SecurityGroups.Add("Controller");
                RunInstancesResponse runResponse = ec2Client.RunInstances(runInstancesRequest);
                List<Instance> instances = runResponse.Reservation.Instances;
                List<string> instanceIDs = instances.Select(item => item.InstanceId).ToList();
                WaitForInstancesToBeRunning(ec2Client, instanceIDs);
                var instancesRequest = new DescribeInstancesRequest {InstanceIds = instanceIDs};
                DescribeInstancesResponse statusResponse = ec2Client.DescribeInstances(instancesRequest);
                List<string> ipAddresses =
                    statusResponse.Reservations[0].Instances.Select(x => x.PublicIpAddress).ToList();
                //we now have our running instances and we need to assign the ips to our tests
                foreach (Test test in testSuite.Tests.Where(test => string.IsNullOrWhiteSpace(test.Agent)))
                {
                    //assign the first free Id
                    test.Agent = ipAddresses.First();
                    //then remove it from the list
                    ipAddresses.RemoveAt(0);
                }

                //now we need to make sure all instances are ready
                MakeSureAgentsCanBeUsed(ec2Client, instanceIDs);
                return instanceIDs;
            }
            return null;
        }
开发者ID:TomPallister,项目名称:PerformanceDsl,代码行数:38,代码来源:PerformanceServer.cs

示例11: RunInstance

        /// <summary>
        /// Creates (Runs) a new EC2 instance from the stored AMI image.
        /// </summary>
        /// <param name="imageId"></param>
        /// <param name="numberOfInstances"></param>
        /// <param name="keyName"></param>
        /// <param name="userData"></param>
        /// <param name="securityGroups"></param>
        /// <param name="availabilityZone">The AWS availability zone (us-east-1a, us-east-1b, us-east-1c, us-east-1d, eu-west-1a, eu-west-1b)</param>
        /// <returns>Returns a list of ALL instances not terminated, not just the ones started.</returns>
        public List<string> RunInstance(string imageId, int numberOfInstances, string keyName, string userData, string[] securityGroups, string availabilityZone)
        {
            var request = new RunInstancesRequest
                              {
                                  ImageId = imageId,
                                  MinCount = numberOfInstances,
                                  MaxCount = numberOfInstances,
                                  KeyName = keyName,
                                  UserData = userData,
                                  SecurityGroup = new List<string>(securityGroups)
                              };

            if (!string.IsNullOrEmpty(availabilityZone))
            {
                request.Placement = new Placement { AvailabilityZone = availabilityZone };
            }

            RunInstancesResponse response = Client.RunInstances(request);

            return response.RunInstancesResult.Reservation.RunningInstance.Select(runningInstance => runningInstance.InstanceId).ToList();
        }
开发者ID:scalvert,项目名称:AWS-MSBuild-Task-Library,代码行数:31,代码来源:EC2Helper.cs

示例12: CreateAndLaunchInstance

        private void CreateAndLaunchInstance(AwsRegionLocations region)
        {
            // Get an Ec2Client for the current region
            var client = ec2Clients.GetOrAdd(region, r => AWSClientFactory.CreateAmazonEC2Client(credentials, region.ToAwsRegionEndpoint()));

            var securityGroupId = EnsureSecurityGroupExists(region);
            var availableSubnets = client.DescribeSubnets().Subnets.OrderByDescending(x => x.AvailableIpAddressCount);
            var networkSpecification = new InstanceNetworkInterfaceSpecification()
            {
                DeviceIndex = 0,
                SubnetId = availableSubnets.First().SubnetId,
                Groups = new List<string>() { securityGroupId },
                AssociatePublicIpAddress = true
            };
            var networkSpecifications = new List<InstanceNetworkInterfaceSpecification>() { networkSpecification };

            var launchRequest = new RunInstancesRequest()
            {
                ImageId = GetAmiId(client, amiName),
                InstanceType = "t2.micro",
                MinCount = 1,
                MaxCount = 1,
                KeyName = keyPairName,
                NetworkInterfaces = networkSpecifications
            };

            client.RunInstances(launchRequest);
        }
开发者ID:modulexcite,项目名称:2015-Slides-and-Demos,代码行数:28,代码来源:Ec2Caller.cs

示例13: launch

        public void launch()
        {
            //instance started.
            if (string.IsNullOrEmpty(_instanceId) == false)
            {
                return;
            }

            try
            {
                RunInstancesRequest request = new RunInstancesRequest();

                request.ImageId = _amiId;
                request.MinCount = 1;
                request.MaxCount = 1;

                if (_defaultSecurityGroup == false)
                {
                    request.SecurityGroup.Add(_securityGroups);
                }
                else
                {
                    if(securitryGroupExistOnServer() == false)
                    {
                        createSecurityGroup();
                    }
                    request.SecurityGroup.Add(_securityGroups);
                }

                string keyPath = CAwsConfig.Instance.getKeyFilePath(_keyPairName);
                if (string.IsNullOrEmpty(keyPath) == true ||
                    File.Exists(keyPath) == false)
                {
                    if (keyExistOnServer() == false)
                    {
                        createKayPair();
                    }
                }
                request.KeyName = _keyPairName;

                RunInstancesResponse response = _service.RunInstances(request);
                if (response.IsSetRunInstancesResult())
                {
                    RunInstancesResult runInstancesResult = response.RunInstancesResult;
                    if (runInstancesResult.IsSetReservation())
                    {
                        if (runInstancesResult.Reservation.RunningInstance[0].IsSetInstanceId())
                        {
                            _instanceId = runInstancesResult.Reservation.RunningInstance[0].InstanceId;
                        }
                        if (runInstancesResult.Reservation.RunningInstance[0].IsSetPublicDnsName())
                        {
                            _publicDns = runInstancesResult.Reservation.RunningInstance[0].PublicDnsName;
                        }
                    }
                }

                if (string.IsNullOrEmpty(_instanceId) == true)
                    throw new Exception("No instance id is returned.");

                //return after the instance started up
                bool pending = true;
                while (pending == true)
                {
                    System.Threading.Thread.Sleep(5 * 1000);

                    DescribeInstancesRequest describeRequest = new DescribeInstancesRequest();
                    describeRequest.InstanceId.Add(_instanceId);
                    DescribeInstancesResponse describeResponse = _service.DescribeInstances(describeRequest);
                    DescribeInstancesResult describeResult = describeResponse.DescribeInstancesResult;

                    if (describeResult.Reservation.Count != 1)
                        throw new Exception("more than one instance with the same id");
                    if (describeResult.Reservation[0].RunningInstance.Count != 1)
                        throw new Exception("more than one running instance has the same id");

                    pending = describeResult.Reservation[0].RunningInstance[0].InstanceState.Name != "running";
                }
            }
            catch (AmazonEC2Exception ex)
            {
                throw new Exception("Caught Exception: " + ex.XML);
            }
        }
开发者ID:qrush,项目名称:ec2bootstrapper,代码行数:84,代码来源:CEc2Instance.cs

示例14: CreateInstanceAsync

        private async Task CreateInstanceAsync(CancellationToken? cancellationToken = null)
        {
            this.Logger.Log("Creating a new instance. AMI: {0}, size: {1}", this.Specification.Ami, this.Specification.Size.Name);
            var runInstanceRequest = new RunInstancesRequest()
            {
                ImageId = this.Specification.Ami,
                InstanceType = this.Specification.Size.Key,
                MinCount = 1,
                MaxCount = 1,
                KeyName = this.privateKeyPair.KeyName,
                SecurityGroups = new List<string>() { this.SecurityGroupName },
            };
            if (!string.IsNullOrWhiteSpace(this.Specification.AvailabilityZone))
            {
                runInstanceRequest.Placement = new Placement() { AvailabilityZone = this.Specification.AvailabilityZone };
            }

            var runResponse = await this.Client.RunInstancesAsync(runInstanceRequest);
            var instances = runResponse.Reservation.Instances;
            this.InstanceId = instances[0].InstanceId;
            this.Logger.Log("New instance created. Instance ID: {0}", this.InstanceId);

            await this.SetupInstanceAsync(cancellationToken);
        }
开发者ID:modulexcite,项目名称:ec2manager,代码行数:24,代码来源:Ec2Instance.cs

示例15: CreateVPCInstances

        /// <summary>
        /// This function creates a set of instances into an EC2 VPC. It returns the Ids of the created instances if successful, or 
        /// sets the error code and message otherwise
        /// </summary>
        /// <param name="regionEndpoint">Region where instances should be created</param>
        /// <param name="SubnetId">Id of the VPC subnet where the instances will be launched</param>
        /// <param name="AMI_ID">Id of the AMI that will be used as a base for the instances</param>
        /// <param name="SecurityGroupId">The name of the security group to be assigned to the instance(s)</param>
        /// <param name="KeyPairName">The name of the keypair to be assigned to the instance(s)</param>
        /// <param name="InstanceType">The type of the instance(s)</param>
        /// <param name="InstanceCount">The number of instances to be launched</param>
        /// <param name="UserData">The user-data script that will be run as the instance(s) is(are) initialized</param>
        /// <returns>The list of Instance Ids if successful</returns>
        public List<string> CreateVPCInstances(RegionEndpoint regionEndpoint, string SubnetId, string AMI_ID, string SecurityGroupId, string KeyPairName, string InstanceType, int InstanceCount = 1, string UserData = "")
        {
            List<string> InstanceIds = new List<string> ();

            // Initialize error values
            ErrorCode    = 0;
            ErrorMessage = "";

            // Create the list with security groups
            List<string> SecurityGroups = new List<string> () { SecurityGroupId };

            // Create the network interface object (to connect with the VPC)
            var NetworkInterface = new InstanceNetworkInterfaceSpecification ()
            {
                DeviceIndex              = 0,
                SubnetId                 = SubnetId,
                Groups                   = SecurityGroups,
                AssociatePublicIpAddress = true
            };
            List<InstanceNetworkInterfaceSpecification> NetworkInterfaces = new List<InstanceNetworkInterfaceSpecification> () { NetworkInterface };

            // Create the request object
            var launchRequest = new RunInstancesRequest ()
            {
                ImageId           = AMI_ID,
                InstanceType      = InstanceType,
                MinCount          = InstanceCount,
                MaxCount          = InstanceCount,
                KeyName           = KeyPairName,
                NetworkInterfaces = NetworkInterfaces,
                UserData          = Gadgets.Base64Encode (UserData)
            };

            // Launch the instances
            try
            {
                var launchResponse = EC2client.RunInstances (launchRequest);

                // Check response for errors
                if (launchResponse.HttpStatusCode != HttpStatusCode.OK)
                {
                    ErrorCode = Convert.ToInt32 (launchResponse.HttpStatusCode);
                    ErrorMessage = "Http Error [" + launchResponse.HttpStatusCode.ToString () + "]";
                }
                else
                {
                    List<Instance> createdInstances = launchResponse.Reservation.Instances;
                    foreach (Instance instance in createdInstances)
                    {
                        InstanceIds.Add (instance.InstanceId);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorCode    = -1;
                ErrorMessage = ex.Message + "::" + ex.InnerException;
            }

            return InstanceIds;
        }
开发者ID:trista-lg,项目名称:AWSHelpers,代码行数:74,代码来源:AWSEC2Helper.cs


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