ec2-cli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfb27bf9c00d31c8e4877d8f201d9937b0427423
4
- data.tar.gz: d64e49221a5f933b1c817a354c93bec005ac512f
3
+ metadata.gz: 6643c6ddd2d54d0943b2e835ad28ae9fafe26339
4
+ data.tar.gz: 40f9e928961f7f03f5a067873d5cc5345bff7a4d
5
5
  SHA512:
6
- metadata.gz: e858dde8a358a8bfe6dafd33863756244295046a41f185cff2bcfe80b7df4163e6e1791a070e508d49c0be0d17f660753c73a1136c6caa6db9a251f35554fee9
7
- data.tar.gz: 8f02aded40d033cfb2fdf064c6a136b821e874d4c9dd819145dfea44f3c2d557885d9ecb0861a5e57a6d4de30675019b04db703c31fc19423cfbf2ca66c051e2
6
+ metadata.gz: b7eaf7ec5178727ad5fcda3591c7ba08719154bde085e7f3492061061d6cc0bb4c4a8f6cb4e91c6fcb630a5a710e789d1e3aa086d410f13751a5c96ed01747f0
7
+ data.tar.gz: ffe67a76bd09612674bc28a9c7a284c936c0e90fe81026bb35882aab421c6f427b87838dd0b70fb17a7cf41c720be1c71eaec5e43041e88d4626c7a46c66ebea
@@ -0,0 +1 @@
1
+ pkg/
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+
3
+ end_time=$(($(date +"%s") * 1000))
4
+ aws logs get-log-events --log-group-name ${1:-groupName} --log-stream-name ${2:-streamName} --end-time $end_time
5
+
6
+ while :
7
+ do
8
+ start_time=$end_time
9
+ end_time=$(($(date +"%s") * 1000))
10
+ aws logs get-log-events --log-group-name ${1:-groupName} --log-stream-name ${2:-streamName} --start-time $start_time --end-time $end_time
11
+ sleep 1
12
+ done
13
+
data/bin/ec2 CHANGED
@@ -6,7 +6,7 @@ require "tablelize"
6
6
 
7
7
  module Ec2
8
8
  class Cli < Thor
9
- desc "version", "Show thois tool version"
9
+ desc "version", "Show this tool version"
10
10
  def version
11
11
  puts "v#{VERSION}"
12
12
  end
data/bin/r53 ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ require "http"
3
+ require "thor"
4
+ require "json"
5
+ require "tablelize"
6
+
7
+ module R53
8
+ class Cli < Thor
9
+ desc "version", "Show this tool version"
10
+ def version
11
+ puts "v#{VERSION}"
12
+ end
13
+
14
+ desc "zones", "Lists all hosted zones"
15
+ def zones
16
+ _get_zones
17
+ end
18
+
19
+ desc "ls [ZONE]", "Lists all records optionally filtered by ZONE"
20
+ def ls(zone=nil)
21
+ list_records(zone)
22
+ end
23
+
24
+ private
25
+ def _get_zones
26
+ json = `aws route53 list-hosted-zones`
27
+ data = JSON.load(json)
28
+
29
+ rows = []
30
+ # rows << ["ID", "TYPE", "HOSTED ZONE", "COMMENT"]
31
+ rows << ["ID", "TYPE", "HOSTED ZONE"]
32
+ data.fetch("HostedZones", {}).each do |v|
33
+ # type = v["Config"]["PrivateZone"] === true ? "\e[38;5;246mprivate\e[0m" : "\e[38;5;221mpublic\e[0m"
34
+ type = v["Config"]["PrivateZone"] === true ? "private" : "public"
35
+ comment = v["Config"].fetch("Comment", "")
36
+ hosted_id = v["Id"].gsub("/hostedzone/", "")
37
+ # rows << [hosted_id, type, v["Name"], comment]
38
+ rows << [hosted_id, type, v["Name"]]
39
+ end
40
+
41
+ Tablelize::table rows
42
+ end
43
+
44
+ def get_zones(filter=nil)
45
+ json = `aws route53 list-hosted-zones --query 'HostedZones[].[Id,Name]'`
46
+ data = JSON.load(json)
47
+
48
+ zones = []
49
+ data.each do |id, name|
50
+ if filter and not name.match(filter)
51
+ # puts "==> Skipping #{id} :: #{name} because of #{filter}"
52
+ next
53
+ end
54
+
55
+ # puts "==> Adding #{id} :: #{name} because of #{filter}"
56
+ zones << id
57
+ end
58
+
59
+ zones
60
+ end
61
+
62
+ def list_records(zone)
63
+ rows = []
64
+ rows << ["TYPE", "TTL", "NAME", "TARGETS"]
65
+ zones = get_zones(zone)
66
+ zones.each do |id|
67
+ rows += list_zone(id)
68
+ end
69
+
70
+ # puts rows.to_json
71
+ # exit 1
72
+
73
+ Tablelize::table rows
74
+ end
75
+
76
+ def list_zone(zone_id)
77
+ json = `aws route53 list-resource-record-sets --hosted-zone-id #{zone_id}`
78
+ data = JSON.load(json)
79
+
80
+ rows = []
81
+ data.fetch("ResourceRecordSets", {}).each do |v|
82
+ if v["ResourceRecords"]
83
+ first_added = false
84
+ v["ResourceRecords"].each do |vv|
85
+ target = vv["Value"]
86
+ # rows << [".", ".", ".", target]
87
+ if first_added
88
+ rows << ["-", "-", "-", target]
89
+ else
90
+ rows << [v["Type"], v["Type"], v["Name"], target]
91
+ first_added = true
92
+ end
93
+ end
94
+ elsif v["AliasTarget"]
95
+ target = v["AliasTarget"]["DNSName"]
96
+ rows << [v["Type"], "", v["Name"], target]
97
+ else
98
+ p v
99
+ exit 1
100
+ end
101
+ end
102
+
103
+ rows
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ R53::Cli.start ARGV
@@ -1,5 +1,5 @@
1
1
  module Ec2
2
2
 
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
 
5
5
  end
data/main.go ADDED
@@ -0,0 +1,61 @@
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "time"
6
+
7
+ "github.com/aws/aws-sdk-go/aws/session"
8
+ "github.com/aws/aws-sdk-go/service/ec2"
9
+ )
10
+
11
+ func main() {
12
+ sess := session.Must(session.NewSessionWithOptions(session.Options{
13
+ SharedConfigState: session.SharedConfigEnable,
14
+ }))
15
+
16
+ ec2Svc := ec2.New(sess)
17
+ res, err := ec2Svc.DescribeInstances(nil)
18
+ if err != nil {
19
+ fmt.Println(err)
20
+ }
21
+
22
+ format := "%-14s %-14s %-19s %-20s %-13s %s\n"
23
+ fmt.Printf(format, "PRIVATE IP", "PUBLIC IP", "INSTANCE ID", "LAUNCH TIME", "STATE", "NAME")
24
+
25
+ for i := range(res.Reservations) {
26
+ inst := res.Reservations[i].Instances[0]
27
+
28
+ publicIp := ""
29
+ if inst.PublicIpAddress != nil {
30
+ publicIp = *inst.PublicIpAddress
31
+ }
32
+
33
+ privateIp := ""
34
+ if inst.PrivateIpAddress != nil {
35
+ privateIp = *inst.PrivateIpAddress
36
+ }
37
+
38
+ name := ""
39
+ for j := range(inst.Tags) {
40
+ if *inst.Tags[j].Key == "Name" {
41
+ name = *inst.Tags[j].Value
42
+ }
43
+ }
44
+
45
+ // launchTime := inst.LaunchTime.Format(time.Stamp)
46
+ // launchTime := inst.LaunchTime.Format("2006-01-02 08:28:32.000Z")
47
+ launchTime := inst.LaunchTime.Format(time.RFC3339)
48
+ stateName := *inst.State.Name
49
+ instanceId := *inst.InstanceId
50
+
51
+ // if stateName == "terminated" && name == "" {
52
+ // continue
53
+ // }
54
+
55
+ if name == "" {
56
+ continue
57
+ }
58
+
59
+ fmt.Printf(format, privateIp, publicIp, instanceId, launchTime, stateName, name)
60
+ }
61
+ }
@@ -0,0 +1,16 @@
1
+ # ec2-cli
2
+
3
+ A simple tool to display EC2 instances. More functionality on the way.
4
+
5
+
6
+ ### Installation
7
+
8
+ ```
9
+ gem install ec2-cli
10
+ ```
11
+
12
+ ### Usage
13
+
14
+ ```
15
+ ec2 ls
16
+ ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ptdorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -42,16 +42,23 @@ description: List your Ec2 instances.
42
42
  email:
43
43
  - ptdorf@gmail.com
44
44
  executables:
45
+ - aws-tail
45
46
  - ec2
47
+ - r53
46
48
  extensions: []
47
49
  extra_rdoc_files: []
48
50
  files:
51
+ - ".gitignore"
49
52
  - Gemfile
50
53
  - Gemfile.lock
51
54
  - Rakefile
55
+ - bin/aws-tail
52
56
  - bin/ec2
57
+ - bin/r53
53
58
  - ec2-cli.gemspec
54
59
  - lib/ec2/version.rb
60
+ - main.go
61
+ - readme.md
55
62
  homepage: https://github.com/ptdorf/ec2-cli
56
63
  licenses:
57
64
  - MIT