public Reservation RunInstances(string vmImageId, string instanceType, string keyName, int numberOfInstances) { try { AWSModel.RunInstancesRequest request = new AWSModel.RunInstancesRequest(); request.ImageId = vmImageId; if (!string.IsNullOrEmpty(instanceType)) { request.InstanceType = instanceType; } if (!string.IsNullOrEmpty(keyName)) { request.KeyName = keyName; } else { request.KeyName = Settings.IaasKeyName; } request.MaxCount = numberOfInstances; AWSModel.RunInstancesResponse response = ec2.RunInstances(request); if (response != null) { Reservation reservation = new Reservation(); reservation.ReservationId = response.RunInstancesResult.Reservation.ReservationId; foreach (AWSModel.RunningInstance runningIns in response.RunInstancesResult.Reservation.RunningInstance) { if (reservation.Instances == null) { reservation.Instances = new List <Instance>(); } Instance instance = ModelUtil.CreateInstance(runningIns); reservation.Instances.Add(instance); } return(reservation); } return(null); } catch (WebException e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (AmazonEC2Exception e) { throw new MonoscapeEC2Exception(e.Message, e); } }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { RunInstancesResponse response = new RunInstancesResponse(); int targetDepth = 2; while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression(".", targetDepth)) { response.Reservation = ReservationUnmarshaller.GetInstance().Unmarshall(context); continue; } } } return response; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { RunInstancesResponse response = new RunInstancesResponse(); int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) targetDepth = 2; while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if ( context.TestExpression(".", targetDepth)) { response.Reservation = ReservationUnmarshaller.Instance.Unmarshall(context); continue; } } } return response; }