public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse  = context.HttpResponse;
            describeTagsResponse.RequestId     = context.StringValue("DescribeTags.RequestId");
            describeTagsResponse.TotalNum      = context.LongValue("DescribeTags.TotalNum");
            describeTagsResponse.CurrentPage   = context.LongValue("DescribeTags.CurrentPage");
            describeTagsResponse.PageSize      = context.LongValue("DescribeTags.PageSize");
            describeTagsResponse.NextPageToken = context.StringValue("DescribeTags.NextPageToken");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < context.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.ProjectId    = context.StringValue("DescribeTags.Tags[" + i + "].ProjectId");
                tag.TagId        = context.StringValue("DescribeTags.Tags[" + i + "].TagId");
                tag.TagName      = context.StringValue("DescribeTags.Tags[" + i + "].TagName");
                tag.Description  = context.StringValue("DescribeTags.Tags[" + i + "].Description");
                tag.Count        = context.IntegerValue("DescribeTags.Tags[" + i + "].Count");
                tag.CreationTime = context.StringValue("DescribeTags.Tags[" + i + "].CreationTime");

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
Example #2
0
        /// <summary>
        /// Get the name of the instances with the given instanceID from EC2
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static string GetInstanceName(string instanceId)
        {
            AmazonEC2Client ec2 = CreateClient();

            DescribeTagsRequest rq = new DescribeTagsRequest();

            rq.Filters.Add(new Filter()
            {
                Name = "resource-id", Values = new List <string>()
                {
                    instanceId
                }
            });

            DescribeTagsResponse rs = ec2.DescribeTags(rq);

            string name = "";

            TagDescription tag = rs.Tags.Find(item => item.Key == "Name");

            if (tag != null)
            {
                name = tag.Value;
            }

            return(name);
        }
Example #3
0
        /// <summary>
        /// List all volumes found in region
        /// </summary>
        public static void ListVolumes()
        {
            var ec2 = Ec2Helper.CreateClient();

            DescribeVolumesRequest  rq = new DescribeVolumesRequest();
            DescribeVolumesResponse rs = ec2.DescribeVolumes(rq);

            foreach (Volume v in rs.Volumes)
            {
                Console.WriteLine(v.VolumeId);


                DescribeTagsRequest trq = new DescribeTagsRequest();
                trq.Filters.Add(new Filter()
                {
                    Name = "resource-id", Values = new List <string>()
                    {
                        v.VolumeId
                    }
                });
                DescribeTagsResponse trs = ec2.DescribeTags(trq);
                foreach (TagDescription t in trs.Tags)
                {
                    Console.WriteLine("  " + t.Key + "=" + t.Value);
                }
            }
        }
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = _ctx.HttpResponse;
            describeTagsResponse.RequestId    = _ctx.StringValue("DescribeTags.RequestId");

            List <DescribeTagsResponse.DescribeTags_TagInfos> describeTagsResponse_items = new List <DescribeTagsResponse.DescribeTags_TagInfos>();

            for (int i = 0; i < _ctx.Length("DescribeTags.Items.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_TagInfos tagInfos = new DescribeTagsResponse.DescribeTags_TagInfos();
                tagInfos.TagKey   = _ctx.StringValue("DescribeTags.Items[" + i + "].TagKey");
                tagInfos.TagValue = _ctx.StringValue("DescribeTags.Items[" + i + "].TagValue");

                List <string> tagInfos_dBInstanceIds = new List <string>();
                for (int j = 0; j < _ctx.Length("DescribeTags.Items[" + i + "].DBInstanceIds.Length"); j++)
                {
                    tagInfos_dBInstanceIds.Add(_ctx.StringValue("DescribeTags.Items[" + i + "].DBInstanceIds[" + j + "]"));
                }
                tagInfos.DBInstanceIds = tagInfos_dBInstanceIds;

                describeTagsResponse_items.Add(tagInfos);
            }
            describeTagsResponse.Items = describeTagsResponse_items;

            return(describeTagsResponse);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("ResourceId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ResourceId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ResourceType", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ResourceType = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Tags", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Tag, TagUnmarshaller>(TagUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #6
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            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("nextToken", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.NextToken = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("tagSet/item", targetDepth))
                    {
                        var unmarshaller = TagDescriptionUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Tags.Add(item);
                        continue;
                    }
                }
            }

            return(response);
        }
Example #7
0
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = context.HttpResponse;
            describeTagsResponse.RequestId    = context.StringValue("DescribeTags.RequestId");

            List <DescribeTagsResponse.TagInfos> items = new List <DescribeTagsResponse.TagInfos>();

            for (int i = 0; i < context.Length("DescribeTags.Items.Length"); i++)
            {
                DescribeTagsResponse.TagInfos tagInfos = new DescribeTagsResponse.TagInfos();
                tagInfos.TagKey   = context.StringValue("DescribeTags.Items[" + i + "].TagKey");
                tagInfos.TagValue = context.StringValue("DescribeTags.Items[" + i + "].TagValue");

                List <string> dBInstanceIds = new List <string>();
                for (int j = 0; j < context.Length("DescribeTags.Items[" + i + "].DBInstanceIds.Length"); j++)
                {
                    dBInstanceIds.Add(context.StringValue("DescribeTags.Items[" + i + "].DBInstanceIds[" + j + "]"));
                }
                tagInfos.DBInstanceIds = dBInstanceIds;

                items.Add(tagInfos);
            }
            describeTagsResponse.Items = items;

            return(describeTagsResponse);
        }
Example #8
0
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = _ctx.HttpResponse;
            describeTagsResponse.RequestId    = _ctx.StringValue("DescribeTags.RequestId");
            describeTagsResponse.TotalCount   = _ctx.LongValue("DescribeTags.TotalCount");
            describeTagsResponse.PageNumber   = _ctx.LongValue("DescribeTags.PageNumber");
            describeTagsResponse.PageSize     = _ctx.LongValue("DescribeTags.PageSize");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < _ctx.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.Key = _ctx.StringValue("DescribeTags.Tags[" + i + "].Key");

                List <string> tag_values = new List <string>();
                for (int j = 0; j < _ctx.Length("DescribeTags.Tags[" + i + "].Values.Length"); j++)
                {
                    tag_values.Add(_ctx.StringValue("DescribeTags.Tags[" + i + "].Values[" + j + "]"));
                }
                tag.Values = tag_values;

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, DescribeTagsResponse response)
        {
            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("NextToken", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.NextToken = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("Tags/member", targetDepth))
                    {
                        var unmarshaller = TagDescriptionUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Tags.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
Example #10
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("nextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("tags", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ConfigurationTag, ConfigurationTagUnmarshaller>(ConfigurationTagUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonEC2Config config = new AmazonEC2Config();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonEC2Client client = new AmazonEC2Client(creds, config);

            DescribeTagsResponse resp = new DescribeTagsResponse();

            do
            {
                DescribeTagsRequest req = new DescribeTagsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.DescribeTags(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Tags)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DescribeTagsResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = context.HttpResponse;
            describeTagsResponse.RequestId    = context.StringValue("DescribeTags.RequestId");
            describeTagsResponse.TotalCount   = context.IntegerValue("DescribeTags.TotalCount");
            describeTagsResponse.PageSize     = context.IntegerValue("DescribeTags.PageSize");
            describeTagsResponse.PageNumber   = context.IntegerValue("DescribeTags.PageNumber");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < context.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.Key    = context.StringValue("DescribeTags.Tags[" + i + "].Key");
                tag._Value = context.StringValue("DescribeTags.Tags[" + i + "].Value");

                List <string> tag_fileSystemIds = new List <string>();
                for (int j = 0; j < context.Length("DescribeTags.Tags[" + i + "].FileSystemIds.Length"); j++)
                {
                    tag_fileSystemIds.Add(context.StringValue("DescribeTags.Tags[" + i + "].FileSystemIds[" + j + "]"));
                }
                tag.FileSystemIds = tag_fileSystemIds;

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
Example #14
0
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = context.HttpResponse;
            describeTagsResponse.RequestId    = context.StringValue("DescribeTags.RequestId");
            describeTagsResponse.PageSize     = context.IntegerValue("DescribeTags.PageSize");
            describeTagsResponse.PageNumber   = context.IntegerValue("DescribeTags.PageNumber");
            describeTagsResponse.TotalCount   = context.IntegerValue("DescribeTags.TotalCount");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < context.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.TagKey   = context.StringValue("DescribeTags.Tags[" + i + "].TagKey");
                tag.TagValue = context.StringValue("DescribeTags.Tags[" + i + "].TagValue");

                DescribeTagsResponse.DescribeTags_Tag.DescribeTags_ResourceTypeCount resourceTypeCount = new DescribeTagsResponse.DescribeTags_Tag.DescribeTags_ResourceTypeCount();
                resourceTypeCount.Instance      = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Instance");
                resourceTypeCount.Disk          = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Disk");
                resourceTypeCount.Volume        = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Volume");
                resourceTypeCount.Image         = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Image");
                resourceTypeCount.Snapshot      = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Snapshot");
                resourceTypeCount.Securitygroup = context.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Securitygroup");
                tag.ResourceTypeCount           = resourceTypeCount;

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
Example #15
0
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse()
            {
                HttpResponse = context.HttpResponse,
                RequestId    = context.StringValue("DescribeTags.RequestId"),
                PageSize     = context.IntegerValue("DescribeTags.PageSize"),
                PageNumber   = context.IntegerValue("DescribeTags.PageNumber"),
                TotalCount   = context.IntegerValue("DescribeTags.TotalCount")
            };
            List <DescribeTagsResponse.Tag> tags = new List <DescribeTagsResponse.Tag>();

            for (int i = 0; i < context.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.Tag tag = new DescribeTagsResponse.Tag()
                {
                    TagKey   = context.StringValue($"DescribeTags.Tags[{i}].TagKey"),
                    TagValue = context.StringValue($"DescribeTags.Tags[{i}].TagValue")
                };
                DescribeTagsResponse.Tag.ResourceTypeCount_ resourceTypeCount = new DescribeTagsResponse.Tag.ResourceTypeCount_()
                {
                    Instance      = context.IntegerValue($"DescribeTags.Tags[{i}].ResourceTypeCount.Instance"),
                    Disk          = context.IntegerValue($"DescribeTags.Tags[{i}].ResourceTypeCount.Disk"),
                    Image         = context.IntegerValue($"DescribeTags.Tags[{i}].ResourceTypeCount.Image"),
                    Snapshot      = context.IntegerValue($"DescribeTags.Tags[{i}].ResourceTypeCount.Snapshot"),
                    Securitygroup = context.IntegerValue($"DescribeTags.Tags[{i}].ResourceTypeCount.Securitygroup")
                };
                tag.ResourceTypeCount = resourceTypeCount;

                tags.Add(tag);
            }
            describeTagsResponse.Tags = tags;

            return(describeTagsResponse);
        }
Example #16
0
        /// <summary>
        /// List all volumes found in region
        /// </summary>
        public static void ListVolumes()
        {
            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            DescribeVolumesRequest  rq = new DescribeVolumesRequest();
            DescribeVolumesResponse rs = ec2.DescribeVolumes(rq);

            foreach (Volume v in rs.DescribeVolumesResult.Volume)
            {
                Console.WriteLine(v.VolumeId);


                DescribeTagsRequest trq = new DescribeTagsRequest();
                trq.WithFilter(new Filter()
                {
                    Name = "resource-id", Value = new List <string>()
                    {
                        v.VolumeId
                    }
                });
                DescribeTagsResponse trs = ec2.DescribeTags(trq);
                foreach (ResourceTag t in trs.DescribeTagsResult.ResourceTag)
                {
                    Console.WriteLine("  " + t.Key + "=" + t.Value);
                }
            }
        }
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = _ctx.HttpResponse;
            describeTagsResponse.RequestId    = _ctx.StringValue("DescribeTags.RequestId");
            describeTagsResponse.NextToken    = _ctx.StringValue("DescribeTags.NextToken");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < _ctx.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.TagKey = _ctx.StringValue("DescribeTags.Tags[" + i + "].TagKey");

                List <string> tag_tagValues = new List <string>();
                for (int j = 0; j < _ctx.Length("DescribeTags.Tags[" + i + "].TagValues.Length"); j++)
                {
                    tag_tagValues.Add(_ctx.StringValue("DescribeTags.Tags[" + i + "].TagValues[" + j + "]"));
                }
                tag.TagValues = tag_tagValues;

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = context.HttpResponse;
            describeTagsResponse.RequestId    = context.StringValue("DescribeTags.RequestId");
            describeTagsResponse.PageSize     = context.IntegerValue("DescribeTags.PageSize");
            describeTagsResponse.PageNumber   = context.IntegerValue("DescribeTags.PageNumber");
            describeTagsResponse.TotalCount   = context.IntegerValue("DescribeTags.TotalCount");

            List <DescribeTagsResponse.DescribeTags_TagSet> describeTagsResponse_tagSets = new List <DescribeTagsResponse.DescribeTags_TagSet>();

            for (int i = 0; i < context.Length("DescribeTags.TagSets.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_TagSet tagSet = new DescribeTagsResponse.DescribeTags_TagSet();
                tagSet.TagKey        = context.StringValue("DescribeTags.TagSets[" + i + "].TagKey");
                tagSet.TagValue      = context.StringValue("DescribeTags.TagSets[" + i + "].TagValue");
                tagSet.InstanceCount = context.IntegerValue("DescribeTags.TagSets[" + i + "].InstanceCount");

                describeTagsResponse_tagSets.Add(tagSet);
            }
            describeTagsResponse.TagSets = describeTagsResponse_tagSets;

            return(describeTagsResponse);
        }
Example #19
0
        /// <summary>
        /// Describes one or more of the tags for your EC2 resources.
        /// </summary>
        /// <param name="instances">A list of instance IDs to be stopped.</param>
        /// <param name="settings">The <see cref="EC2Settings"/> used during the request to AWS.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <IList <TagDescription> > DescribeTags(IList <string> instances, EC2Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if ((instances == null) || (instances.Count == 0))
            {
                throw new ArgumentNullException("instances");
            }



            //Create Request
            AmazonEC2Client     client  = this.CreateClient(settings);
            DescribeTagsRequest request = new DescribeTagsRequest();

            List <string> list = new List <string>();

            list.AddRange(instances);

            request.Filters.Add(new Filter("resource-id", list));



            //Check Response
            DescribeTagsResponse response = await client.DescribeTagsAsync(request, cancellationToken);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Successfully terminated instances '{0}'", string.Join(",", instances));
                return(response.Tags);
            }
            else
            {
                _Log.Error("Failed to terminate instances '{0}'", string.Join(",", instances));
                return(new List <TagDescription>());
            }
        }
Example #20
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            int targetDepth = 2;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("tagSet/item", targetDepth))
                    {
                        response.Tags.Add(TagDescriptionUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                    if (context.TestExpression("nextToken", targetDepth))
                    {
                        response.NextToken = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
            }


            return(response);
        }
Example #21
0
        public static IEnumerable <Environment> GetEnvironments(IAmazonEC2 ec2)
        {
            List <Filter>        filters = GetEnvironmentTagFilters();
            DescribeTagsResponse result  = GetTagsSync(ec2, filters);
            List <Environment>   envs    = result.Tags.GroupBy(
                x => x.Value,
                (s, results) => new Environment
            {
                Name        = s,
                InstanceIds = results.Select(x => x.ResourceId).Distinct().ToList(),
            }).ToList();

            return(envs.Select(env => EnchanceEnvProperties(ec2, env)).ToList());
        }
Example #22
0
        public static DescribeTagsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeTagsResponse describeTagsResponse = new DescribeTagsResponse();

            describeTagsResponse.HttpResponse = _ctx.HttpResponse;
            describeTagsResponse.RequestId    = _ctx.StringValue("DescribeTags.RequestId");
            describeTagsResponse.PageSize     = _ctx.IntegerValue("DescribeTags.PageSize");
            describeTagsResponse.PageNumber   = _ctx.IntegerValue("DescribeTags.PageNumber");
            describeTagsResponse.TotalCount   = _ctx.IntegerValue("DescribeTags.TotalCount");

            List <DescribeTagsResponse.DescribeTags_Tag> describeTagsResponse_tags = new List <DescribeTagsResponse.DescribeTags_Tag>();

            for (int i = 0; i < _ctx.Length("DescribeTags.Tags.Length"); i++)
            {
                DescribeTagsResponse.DescribeTags_Tag tag = new DescribeTagsResponse.DescribeTags_Tag();
                tag.TagKey   = _ctx.StringValue("DescribeTags.Tags[" + i + "].TagKey");
                tag.TagValue = _ctx.StringValue("DescribeTags.Tags[" + i + "].TagValue");

                DescribeTagsResponse.DescribeTags_Tag.DescribeTags_ResourceTypeCount resourceTypeCount = new DescribeTagsResponse.DescribeTags_Tag.DescribeTags_ResourceTypeCount();
                resourceTypeCount.Instance         = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Instance");
                resourceTypeCount.Disk             = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Disk");
                resourceTypeCount.Volume           = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Volume");
                resourceTypeCount.Image            = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Image");
                resourceTypeCount.Snapshot         = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Snapshot");
                resourceTypeCount.Securitygroup    = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Securitygroup");
                resourceTypeCount.LaunchTemplate   = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.LaunchTemplate");
                resourceTypeCount.Eni              = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Eni");
                resourceTypeCount.Ddh              = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.Ddh");
                resourceTypeCount.KeyPair          = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.KeyPair");
                resourceTypeCount.SnapshotPolicy   = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.SnapshotPolicy");
                resourceTypeCount.ReservedInstance = _ctx.IntegerValue("DescribeTags.Tags[" + i + "].ResourceTypeCount.ReservedInstance");
                tag.ResourceTypeCount              = resourceTypeCount;

                describeTagsResponse_tags.Add(tag);
            }
            describeTagsResponse.Tags = describeTagsResponse_tags;

            return(describeTagsResponse);
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeTagsResponse response = new DescribeTagsResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DescribeTagsResult", 2))
                    {
                        response.DescribeTagsResult = DescribeTagsResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
Example #24
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DescribeTagsResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Tags/member", targetDepth))
                    {
                        response.Tags.Add(TagDescriptionUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                    if (context.TestExpression("NextToken", targetDepth))
                    {
                        response.NextToken = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }



            return;
        }
Example #25
0
        public static void Backup(string name, string description, string volumeid, string volumename, string instancename, string expires)
        {
            Console.WriteLine("Creating snapshot of " + volumeid + " / " + volumename + " / " + instancename);

            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            CreateSnapshotRequest rq = new CreateSnapshotRequest();

            rq.VolumeId    = volumeid;
            rq.Description = description;

            CreateSnapshotResponse rs = ec2.CreateSnapshot(rq);

            string snapshotid = rs.CreateSnapshotResult.Snapshot.SnapshotId;


            // build tags for snapshot

            List <Tag> tags = new List <Tag>();

            tags.Add(new Tag {
                Key = "Name", Value = name
            });
            tags.Add(new Tag {
                Key = "source", Value = "scheduler"
            });
            tags.Add(new Tag {
                Key = "instance", Value = instancename
            });
            tags.Add(new Tag {
                Key = "volume", Value = volumename
            });
            tags.Add(new Tag {
                Key = "expires", Value = expires.ToString()
            });


            // get tags from volume to be applied to snapshot

            DescribeTagsRequest trq = new DescribeTagsRequest();

            trq.WithFilter(new Filter()
            {
                Name = "resource-id", Value = new List <string>()
                {
                    volumeid
                }
            });
            DescribeTagsResponse trs = ec2.DescribeTags(trq);

            foreach (ResourceTag t in trs.DescribeTagsResult.ResourceTag)
            {
                if (t.Key != "nextSnapshot" && t.Key != "lastSnapshot" && t.Key != "Name")
                {
                    tags.Add(new Tag {
                        Key = t.Key, Value = t.Value
                    });
                }
            }


            // apply tags to snapshopt

            CreateTagsRequest rqq = new CreateTagsRequest();

            rqq.WithResourceId(snapshotid);

            rqq.WithTag(tags.ToArray());


            var createTagResponse = ec2.CreateTags(rqq);
        }