pretty_aws 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rds-instances +159 -0
- data/bin/rds-security-groups +117 -0
- data/bin/rds-snapshots +89 -0
- data/lib/pretty_aws/ext.rb +96 -0
- data/lib/pretty_aws/rds_instance.rb +138 -0
- data/lib/pretty_aws/rds_snapshot.rb +61 -0
- data/lib/pretty_aws.rb +27 -0
- metadata +106 -0
data/bin/rds-instances
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/pretty_aws'
|
4
|
+
require 'thor'
|
5
|
+
require 'highline/import'
|
6
|
+
|
7
|
+
module PrettyAws
|
8
|
+
|
9
|
+
class RdsInstancesController < Thor
|
10
|
+
|
11
|
+
default_task :show
|
12
|
+
|
13
|
+
desc "classes", "show available instance class sizes"
|
14
|
+
def classes
|
15
|
+
puts RdsInstance::INSTANCE_CLASSES.join(', ')
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "update <name>", "update instance"
|
19
|
+
method_options :groups => :string, :storage => :string, :class => :string, :delayed => false
|
20
|
+
def update(name)
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
params[:security_groups]=options[:groups] if options[:groups]
|
24
|
+
params[:allocated_storage]=options[:storage] if options[:storage]
|
25
|
+
params[:instance_class]=options[:class] if options[:class]
|
26
|
+
params[:apply_immediately] = (!options[:delayed])
|
27
|
+
|
28
|
+
puts "updating #{name} with params:"
|
29
|
+
puts YAML.dump(params)
|
30
|
+
|
31
|
+
Base.rds.modify_db_instance(name,params)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "copy <source> <target> --class=<class>", 'copy database from lastest restore time'
|
36
|
+
method_option :class, :type => :string, :required => true
|
37
|
+
def copy(source, target)
|
38
|
+
params={}
|
39
|
+
params[:use_latest_restorable_time] = true
|
40
|
+
params[:instance_class] = options[:class]
|
41
|
+
params[:availability_zone] = 'us-east-1a'
|
42
|
+
puts "Copying #{source} as #{target} with class #{options[:class]}"
|
43
|
+
Base.rds.restore_db_instance_to_point_in_time(source,target,params)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "create", "create instances"
|
47
|
+
def create(arg=nil)
|
48
|
+
name = ask("What is the database named? (a-z only) ")
|
49
|
+
instance_class = choose do |menu|
|
50
|
+
menu.prompt = "Select a DB Size:"
|
51
|
+
RdsInstance::INSTANCE_CLASSES.each do |class_name|
|
52
|
+
menu.choice(class_name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
storage = ask("How much storage? (gb) ", Integer) { |q| q.in 5..500 }
|
56
|
+
username = ask("Username? ")
|
57
|
+
password = ask("Password? ") { |q| q.echo = "x" }
|
58
|
+
|
59
|
+
puts "creating database with params:"
|
60
|
+
p '', 'name', name
|
61
|
+
p '', 'class', instance_class
|
62
|
+
p '', 'storage', storage
|
63
|
+
p '', 'username', username
|
64
|
+
p '', 'password', password
|
65
|
+
|
66
|
+
RdsInstance.create(
|
67
|
+
:name => name,
|
68
|
+
:instance_class => instance_class,
|
69
|
+
:storage => storage,
|
70
|
+
:username => username,
|
71
|
+
:password => password
|
72
|
+
)
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "delete <name>", "delete named db"
|
78
|
+
def delete(name)
|
79
|
+
say("You are about to delete the database: #{name}")
|
80
|
+
yes = ask("Are you sure? (yes) ")
|
81
|
+
if yes=='yes'
|
82
|
+
RdsInstance.delete(name)
|
83
|
+
puts "delete!"
|
84
|
+
else
|
85
|
+
puts "abort"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "console [name]", 'log into mysql console'
|
90
|
+
def console(name)
|
91
|
+
item = RdsInstance.find(name)
|
92
|
+
exec "mysql -u #{item.username} -h #{item.address} -p"
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "show [name]", 'show instances'
|
96
|
+
method_options :verbose => false
|
97
|
+
def show(name=nil)
|
98
|
+
if name.nil?
|
99
|
+
items = RdsInstance.all
|
100
|
+
else
|
101
|
+
items = [RdsInstance.find(name)]
|
102
|
+
end
|
103
|
+
if options[:verbose]
|
104
|
+
puts YAML.dump(items.map(&:params))
|
105
|
+
end
|
106
|
+
puts "\n\n"
|
107
|
+
items.each do |item|
|
108
|
+
p('----->', item.name)
|
109
|
+
puts ""
|
110
|
+
p('', 'status', item.status)
|
111
|
+
p('', 'address', item.address)
|
112
|
+
p('', 'cpu size', item.cpu_size)
|
113
|
+
p('', 'storage', "#{item.storage}G")
|
114
|
+
p('', 'zone', item.zone)
|
115
|
+
p('', 'username', item.username)
|
116
|
+
p '', 'engine', item.engine
|
117
|
+
p '', 'created at', item.created_at
|
118
|
+
p '', 'restorable at', item.restorable_at
|
119
|
+
p '', 'backup period', item.backup_period
|
120
|
+
p '', 'backup window', item.backup_window
|
121
|
+
p '', 'mod window', item.mod_window
|
122
|
+
|
123
|
+
puts "\n\n"
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
no_tasks do
|
130
|
+
|
131
|
+
def print_header
|
132
|
+
# show the account
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
def p(gutter,col1='',col2='',col3='')
|
137
|
+
$stdout.printf("%-8s %-20s %-20s %-20s\n",gutter,col1,col2,col3)
|
138
|
+
end
|
139
|
+
def row(*cols)
|
140
|
+
prepend = cols.find { |c| c.is_a?(Hash) and c.has_key?(:prepend) }
|
141
|
+
if prepend.nil?
|
142
|
+
prepend = ''
|
143
|
+
else
|
144
|
+
cols.delete(prepend)
|
145
|
+
prepend = prepend[:prepend]
|
146
|
+
end
|
147
|
+
output = [ sprintf("%-8s",prepend) ]
|
148
|
+
cols.each do |col|
|
149
|
+
output << sprintf("%-20s", col)
|
150
|
+
end
|
151
|
+
output = output.join(" ") + "\n"
|
152
|
+
$stdout.print(output)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
PrettyAws::RdsInstancesController.start
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/pretty_aws'
|
4
|
+
require 'thor'
|
5
|
+
# require 'highline/import'
|
6
|
+
|
7
|
+
module PrettyAws
|
8
|
+
|
9
|
+
class RdsSecurityGroupsController < Thor
|
10
|
+
|
11
|
+
default_task :list
|
12
|
+
|
13
|
+
desc "create <name> --description", "create security group"
|
14
|
+
method_option :description, :type=>:string, :required=>true
|
15
|
+
def create(group_name)
|
16
|
+
Base.rds.create_db_security_group(group_name,options[:description])
|
17
|
+
puts "\n\n"
|
18
|
+
row group_name, 'created!'
|
19
|
+
puts "\n\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "delete <name>", "delete security group"
|
23
|
+
def delete(group_name)
|
24
|
+
Base.rds.delete_db_security_group(group_name)
|
25
|
+
puts "\n\n"
|
26
|
+
row group_name, 'deleted!'
|
27
|
+
puts "\n\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "revoke <group_name>", "revoke ingress for group"
|
31
|
+
method_options :ip => :string, :name => :string, :owner => :string
|
32
|
+
def revoke(group_name)
|
33
|
+
if ip_range=options[:ip]
|
34
|
+
Base.rds.revoke_db_security_group_ingress_overwrite(group_name,:cidrip=>ip_range)
|
35
|
+
puts "\n\n"
|
36
|
+
row group_name, 'revoke ip', ip_range
|
37
|
+
puts "\n\n"
|
38
|
+
end
|
39
|
+
if (name=options[:name]) and (owner=options[:owner])
|
40
|
+
Base.rds.revoke_db_security_group_ingress(group_name,:ec2_group_name=>name,:ec2_group_owner_id=>owner)
|
41
|
+
puts "\n\n"
|
42
|
+
row group_name, 'revoke ec2', name, owner
|
43
|
+
puts "\n\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "authorize <group_name> [--ip=ip range] [--name=ec2 group name] [--owner=ec2 owner]", "authorize ingress for group"
|
48
|
+
method_options :ip => :string, :name => :string, :owner => :string
|
49
|
+
def authorize(group_name)
|
50
|
+
if ip_range=options[:ip]
|
51
|
+
Base.rds.authorize_db_security_group_ingress(group_name,:cidrip=>ip_range)
|
52
|
+
puts "\n\n"
|
53
|
+
row group_name, 'authorize ip', ip_range
|
54
|
+
puts "\n\n"
|
55
|
+
end
|
56
|
+
if (name=options[:name]) and (owner=options[:owner])
|
57
|
+
Base.rds.authorize_db_security_group_ingress(group_name,:ec2_group_name=>name,:ec2_group_owner_id=>owner)
|
58
|
+
puts "\n\n"
|
59
|
+
row group_name, 'authorize ec2', name, owner
|
60
|
+
puts "\n\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "list [name]", 'show security groups'
|
65
|
+
method_options :verbose => :boolean
|
66
|
+
def list
|
67
|
+
|
68
|
+
items = Base.rds.describe_db_security_groups
|
69
|
+
|
70
|
+
if options[:verbose]
|
71
|
+
puts YAML.dump(items)
|
72
|
+
end
|
73
|
+
|
74
|
+
puts "\n\n\n\n"
|
75
|
+
|
76
|
+
items.each do |item|
|
77
|
+
row item[:db_security_group_name], :prepend => '~~~~~>'
|
78
|
+
row ""
|
79
|
+
row 'owner', item[:owner_id]
|
80
|
+
row 'description', item[:db_security_group_description]
|
81
|
+
row ''
|
82
|
+
row 'ec2 groups', 'Name', 'Owner', 'Status'
|
83
|
+
item[:ec2_security_groups].each do |group|
|
84
|
+
row '', group[:ec2_security_group_name], group[:ec2_security_group_owner_id], group[:status]
|
85
|
+
end
|
86
|
+
row ''
|
87
|
+
row 'ip ranges', 'Range', 'Status'
|
88
|
+
item[:ip_ranges].each do |ip_range|
|
89
|
+
row '', ip_range[:cidrip], ip_range[:status]
|
90
|
+
end
|
91
|
+
puts "\n\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
no_tasks do
|
97
|
+
def row(*cols)
|
98
|
+
prepend = cols.find { |c| c.is_a?(Hash) and c.has_key?(:prepend) }
|
99
|
+
if prepend.nil?
|
100
|
+
prepend = ''
|
101
|
+
else
|
102
|
+
cols.delete(prepend)
|
103
|
+
prepend = prepend[:prepend]
|
104
|
+
end
|
105
|
+
output = [ sprintf("%-8s",prepend) ]
|
106
|
+
cols.each do |col|
|
107
|
+
output << sprintf("%-20s", col)
|
108
|
+
end
|
109
|
+
output = output.join(" ") + "\n"
|
110
|
+
$stdout.print(output)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
PrettyAws::RdsSecurityGroupsController.start
|
data/bin/rds-snapshots
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/pretty_aws'
|
4
|
+
require 'thor'
|
5
|
+
require 'highline/import'
|
6
|
+
|
7
|
+
module PrettyAws
|
8
|
+
|
9
|
+
class RdsSnapshotsController < Thor
|
10
|
+
|
11
|
+
default_task :list
|
12
|
+
|
13
|
+
desc "list", 'list all snapshots'
|
14
|
+
def list
|
15
|
+
groups = RdsSnapshot.find_all_and_group
|
16
|
+
|
17
|
+
puts "\n\n"
|
18
|
+
groups.each do |name, items|
|
19
|
+
row(name, :prepend => '~~~~>')
|
20
|
+
puts ''
|
21
|
+
row('name', 'status','size','created_at')
|
22
|
+
items.each do |item|
|
23
|
+
row(item.id, item.status, item.storage+"G", item.created_at)
|
24
|
+
end
|
25
|
+
puts "\n\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "restore <snapshot id> <new db id>", "create new database from snapshot"
|
30
|
+
method_option :class, :type => :string, :required => true
|
31
|
+
def restore(id, db_id)
|
32
|
+
puts "\n\n"
|
33
|
+
puts "Restoring #{id} as #{db_id} with class #{options[:class]}"
|
34
|
+
puts "\n\n"
|
35
|
+
Base.rds.restore_db_instance_from_db_snapshot(id,db_id,options[:class])
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "create <db id> <snapshot id>", 'take snapshot of db'
|
39
|
+
def create(db_id, id)
|
40
|
+
puts "\n\n"
|
41
|
+
puts "Taking snapshot of #{db_id} as #{id}"
|
42
|
+
puts "\n\n"
|
43
|
+
Base.rds.create_db_snapshot(db_id,id)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "delete <snapshot id>", 'delete snapshot'
|
47
|
+
def delete(id)
|
48
|
+
puts "\n\n"
|
49
|
+
say("You are about to delete the snapshot: #{id}")
|
50
|
+
yes = ask("Are you sure? (yes) ")
|
51
|
+
if yes=='yes'
|
52
|
+
Base.rds.delete_db_snapshot(id)
|
53
|
+
puts "delete!"
|
54
|
+
else
|
55
|
+
puts "abort"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
no_tasks do
|
60
|
+
|
61
|
+
def print_header
|
62
|
+
# show the account
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def p(gutter,col1='',col2='',col3='')
|
67
|
+
$stdout.printf("%-8s %-20s %-20s %-20s\n",gutter,col1,col2,col3)
|
68
|
+
end
|
69
|
+
def row(*cols)
|
70
|
+
prepend = cols.find { |c| c.is_a?(Hash) and c.has_key?(:prepend) }
|
71
|
+
if prepend.nil?
|
72
|
+
prepend = ''
|
73
|
+
else
|
74
|
+
cols.delete(prepend)
|
75
|
+
prepend = prepend[:prepend]
|
76
|
+
end
|
77
|
+
output = [ sprintf("%-8s",prepend) ]
|
78
|
+
cols.each do |col|
|
79
|
+
output << sprintf("%-20s", col)
|
80
|
+
end
|
81
|
+
output = output.join(" ") + "\n"
|
82
|
+
$stdout.print(output)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
PrettyAws::RdsSnapshotsController.start
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module PrettyAws
|
2
|
+
module ExtendRds
|
3
|
+
|
4
|
+
def restore_db_instance_to_point_in_time(source,target,opts={})
|
5
|
+
params={}
|
6
|
+
params['SourceDBInstanceIdentifier'] = source
|
7
|
+
params['TargetDBInstanceIdentifier'] = target
|
8
|
+
params['UseLatestRestorableTime']=opts[:use_latest_restorable_time] if opts[:use_latest_restorable_time]
|
9
|
+
params['DBInstanceClass']=opts[:instance_class] if opts[:instance_class]
|
10
|
+
params['AvailabilityZone']=opts[:availability_zone] if opts[:availability_zone]
|
11
|
+
link = do_request("RestoreDBInstanceToPointInTime", params)
|
12
|
+
rescue Exception
|
13
|
+
on_exception
|
14
|
+
end
|
15
|
+
|
16
|
+
def restore_db_instance_from_db_snapshot(snapshot_id, db_id, instance_class)
|
17
|
+
params={}
|
18
|
+
params['DBSnapshotIdentifier']=snapshot_id
|
19
|
+
params['DBInstanceIdentifier']=db_id
|
20
|
+
params['DBInstanceClass']=instance_class
|
21
|
+
params['AvailabilityZone']='us-east-1a'
|
22
|
+
link = do_request("RestoreDBInstanceFromDBSnapshot", params)
|
23
|
+
rescue Exception
|
24
|
+
on_exception
|
25
|
+
end
|
26
|
+
|
27
|
+
def describe_db_snapshots
|
28
|
+
link = do_request('DescribeDBSnapshots',{},:pull_out_array=>[:describe_db_snapshots_result, :db_snapshots, :db_snapshot])
|
29
|
+
rescue Exception
|
30
|
+
on_exception
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_db_snapshot( db_id, snapshot_id )
|
34
|
+
|
35
|
+
params = {}
|
36
|
+
params['DBSnapshotIdentifier'] = snapshot_id
|
37
|
+
params['DBInstanceIdentifier'] = db_id
|
38
|
+
link = do_request("CreateDBSnapshot", params)
|
39
|
+
rescue Exception
|
40
|
+
on_exception
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_db_snapshot(id)
|
44
|
+
params = {}
|
45
|
+
params['DBSnapshotIdentifier'] = id
|
46
|
+
link=do_request('DeleteDBSnapshot',params)
|
47
|
+
rescue Exception
|
48
|
+
on_exception
|
49
|
+
end
|
50
|
+
|
51
|
+
def modify_db_instance(identifier, options={})
|
52
|
+
params = {}
|
53
|
+
params['DBInstanceIdentifier']=identifier
|
54
|
+
params['DBSecurityGroups']=options[:security_groups] if options[:security_groups]
|
55
|
+
params['AllocatedStorage']=options[:allocated_storage] if options[:allocated_storage]
|
56
|
+
params['DBInstanceClass']=options[:instance_class] if options[:instance_class]
|
57
|
+
params['ApplyImmediately']=options[:apply_immediately]
|
58
|
+
link = do_request("ModifyDBInstance",params)
|
59
|
+
rescue Exception
|
60
|
+
on_exception
|
61
|
+
end
|
62
|
+
|
63
|
+
def revoke_db_security_group_ingress_overwrite(group_name, options={})
|
64
|
+
params = {}
|
65
|
+
params['DBSecurityGroupName'] = group_name
|
66
|
+
if options[:ec2_group_name]
|
67
|
+
params['EC2SecurityGroupName'] = options[:ec2_group_name]
|
68
|
+
params['EC2SecurityGroupOwnerId'] = options[:ec2_group_owner_id]
|
69
|
+
end
|
70
|
+
if options[:cidrip]
|
71
|
+
params['CIDRIP'] = options[:cidrip]
|
72
|
+
end
|
73
|
+
link = do_request("RevokeDBSecurityGroupIngress", params)
|
74
|
+
rescue Exception
|
75
|
+
on_exception
|
76
|
+
end
|
77
|
+
def authorize_db_security_group_ingress(group_name, options={})
|
78
|
+
params = {}
|
79
|
+
params['DBSecurityGroupName'] = group_name
|
80
|
+
if options[:ec2_group_name]
|
81
|
+
params['EC2SecurityGroupName'] = options[:ec2_group_name]
|
82
|
+
params['EC2SecurityGroupOwnerId'] = options[:ec2_group_owner_id]
|
83
|
+
end
|
84
|
+
if options[:cidrip]
|
85
|
+
params['CIDRIP'] = options[:cidrip]
|
86
|
+
end
|
87
|
+
link = do_request("AuthorizeDBSecurityGroupIngress", params)
|
88
|
+
rescue Exception
|
89
|
+
on_exception
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
Aws::Rds.class_eval do
|
95
|
+
include PrettyAws::ExtendRds
|
96
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module PrettyAws
|
2
|
+
|
3
|
+
class NotFound < StandardError; end
|
4
|
+
class RdsInstance
|
5
|
+
|
6
|
+
INSTANCE_CLASSES = [ 'db.m1.small', 'db.m1.large', 'db.m1.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge' ]
|
7
|
+
|
8
|
+
def self.find(name)
|
9
|
+
params = Base.rds.describe_db_instances.detect { |params| params[:db_instance_identifier]==name }
|
10
|
+
if params.nil?
|
11
|
+
raise PrettyAws::NotFound
|
12
|
+
end
|
13
|
+
new(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all
|
17
|
+
Base.rds.describe_db_instances.collect { |params| new(params) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.wait_until(name, state)
|
21
|
+
$stdout.printf("%-8s %-25s", "-----|"," waiting for #{name} to be #{state} ")
|
22
|
+
while true
|
23
|
+
begin
|
24
|
+
item = find(name)
|
25
|
+
rescue
|
26
|
+
item = {:db_instance_status => nil}
|
27
|
+
end
|
28
|
+
if item[:db_instance_status]==state
|
29
|
+
$stdout.puts("done")
|
30
|
+
$stdout.flush
|
31
|
+
return true
|
32
|
+
else
|
33
|
+
$stdout.print('.')
|
34
|
+
$stdout.flush
|
35
|
+
sleep(3)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.create(params={})
|
41
|
+
required_params = [ :name, :instance_class, :storage, :username, :password ]
|
42
|
+
required_params.each { |key| raise "#{key} required" unless params.has_key?(key) }
|
43
|
+
Base.rds.create_db_instance(
|
44
|
+
params[:name],
|
45
|
+
params[:instance_class],
|
46
|
+
params[:storage],
|
47
|
+
params[:username],
|
48
|
+
params[:password],
|
49
|
+
:availability_zone => 'us-east-1a'
|
50
|
+
)
|
51
|
+
RdsInstance.wait_until(params[:name], 'available')
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.delete(name)
|
55
|
+
Base.rds.delete_db_instance(name)
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :params
|
59
|
+
|
60
|
+
def initialize(params)
|
61
|
+
@params=params
|
62
|
+
end
|
63
|
+
|
64
|
+
def name
|
65
|
+
@params[:db_instance_identifier]
|
66
|
+
end
|
67
|
+
|
68
|
+
def status
|
69
|
+
@params[:db_instance_status]
|
70
|
+
end
|
71
|
+
|
72
|
+
def address
|
73
|
+
if @params.has_key?(:endpoint) and @params[:endpoint].is_a?(Hash) and @params[:endpoint].has_key?(:address)
|
74
|
+
@address = @params[:endpoint][:address]
|
75
|
+
else
|
76
|
+
@address = nil
|
77
|
+
end
|
78
|
+
@address
|
79
|
+
end
|
80
|
+
|
81
|
+
def cpu_size
|
82
|
+
@params[:db_instance_class]
|
83
|
+
end
|
84
|
+
|
85
|
+
def storage
|
86
|
+
@params[:allocated_storage]
|
87
|
+
end
|
88
|
+
|
89
|
+
def zone
|
90
|
+
@params[:availability_zone]
|
91
|
+
end
|
92
|
+
|
93
|
+
def username
|
94
|
+
@params[:master_username]
|
95
|
+
end
|
96
|
+
|
97
|
+
def engine
|
98
|
+
@params[:engine]
|
99
|
+
end
|
100
|
+
|
101
|
+
def security_groups
|
102
|
+
security_groups = [ ]
|
103
|
+
item[:db_security_groups].each do |group|
|
104
|
+
p('', '', group[:db_security_group_name], group[:status])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def created_at
|
109
|
+
@params[:instance_create_time]
|
110
|
+
end
|
111
|
+
|
112
|
+
def restorable_at
|
113
|
+
@params[:latest_restorable_time]
|
114
|
+
end
|
115
|
+
|
116
|
+
def backup_period
|
117
|
+
@params[:backup_retention_period]
|
118
|
+
end
|
119
|
+
|
120
|
+
def backup_window
|
121
|
+
@params[:preferred_backup_window]
|
122
|
+
end
|
123
|
+
|
124
|
+
def mod_window
|
125
|
+
@params[:preferred_maintenance_window]
|
126
|
+
end
|
127
|
+
|
128
|
+
def [](name)
|
129
|
+
@params[name]
|
130
|
+
end
|
131
|
+
|
132
|
+
def has_key?(name)
|
133
|
+
@params.has_key?(name)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module PrettyAws
|
2
|
+
class RdsSnapshot
|
3
|
+
|
4
|
+
attr_reader :params
|
5
|
+
|
6
|
+
def self.find_all_and_group
|
7
|
+
group_by_db(all)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
Base.rds.describe_db_snapshots.collect { |params| new(params) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.group_by_db(items)
|
15
|
+
if items.nil?
|
16
|
+
return {}
|
17
|
+
end
|
18
|
+
grouped = { }
|
19
|
+
items.each do |item|
|
20
|
+
grouped[item.db_id] ||= [ ]
|
21
|
+
grouped[item.db_id] << item
|
22
|
+
end
|
23
|
+
grouped
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(params)
|
27
|
+
@params=params
|
28
|
+
end
|
29
|
+
|
30
|
+
def id
|
31
|
+
@params[:db_snapshot_identifier]
|
32
|
+
end
|
33
|
+
|
34
|
+
def storage
|
35
|
+
@params[:allocated_storage]
|
36
|
+
end
|
37
|
+
|
38
|
+
def db_id
|
39
|
+
@params[:db_instance_identifier]
|
40
|
+
end
|
41
|
+
|
42
|
+
def created_at
|
43
|
+
@params[:instance_create_time]
|
44
|
+
end
|
45
|
+
|
46
|
+
def status
|
47
|
+
@params[:status]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# {:status=>"creating",
|
54
|
+
# :availability_zone=>"us-east-1a",
|
55
|
+
# :db_snapshot_identifier=>"fidupsnapshot",
|
56
|
+
# :engine=>"mysql5.1",
|
57
|
+
# :instance_create_time=>"2010-04-26T03:59:18.967Z",
|
58
|
+
# :port=>"3306",
|
59
|
+
# :allocated_storage=>"30",
|
60
|
+
# :db_instance_identifier=>"fidup",
|
61
|
+
# :master_username=>"fi"}
|
data/lib/pretty_aws.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'aws'
|
4
|
+
require 'yaml'
|
5
|
+
require 'pp'
|
6
|
+
require 'pathname'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + '/pretty_aws/rds_instance'
|
10
|
+
require File.dirname(__FILE__) + '/pretty_aws/rds_snapshot'
|
11
|
+
require File.dirname(__FILE__) + '/pretty_aws/ext'
|
12
|
+
|
13
|
+
module PrettyAws
|
14
|
+
class Base
|
15
|
+
class << self
|
16
|
+
def root
|
17
|
+
@root ||= Pathname.new(File.expand_path('~/.pretty_aws'))
|
18
|
+
end
|
19
|
+
def config
|
20
|
+
@config ||= YAML.load(File.read(root.join('pretty_aws.yml')))
|
21
|
+
end
|
22
|
+
def rds
|
23
|
+
@rds ||= Aws::Rds.new(config['aws_access_key'],config['aws_secret_key'])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_aws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Crockett
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-03-11 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: aws
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 6
|
34
|
+
version: 2.2.6
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: thor
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 35
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 13
|
49
|
+
- 4
|
50
|
+
version: 0.13.4
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Pretty AWS
|
54
|
+
email: davy@davcro.com
|
55
|
+
executables:
|
56
|
+
- rds-instances
|
57
|
+
- rds-security-groups
|
58
|
+
- rds-snapshots
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- lib/pretty_aws/ext.rb
|
65
|
+
- lib/pretty_aws/rds_instance.rb
|
66
|
+
- lib/pretty_aws/rds_snapshot.rb
|
67
|
+
- lib/pretty_aws.rb
|
68
|
+
- bin/rds-instances
|
69
|
+
- bin/rds-security-groups
|
70
|
+
- bin/rds-snapshots
|
71
|
+
has_rdoc: true
|
72
|
+
homepage:
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Davcro AWS
|
105
|
+
test_files: []
|
106
|
+
|