akashi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +9 -1
- data/README.md +1 -27
- data/akashi.gemspec +1 -0
- data/lib/akashi/builder.rb +117 -0
- data/lib/akashi/elb/load_balancer.rb +12 -2
- data/lib/akashi/version.rb +1 -1
- data/lib/akashi/vpc/elastic_ip.rb +22 -0
- data/lib/akashi/vpc/monkey_patch.rb +7 -0
- data/lib/akashi/vpc/security_group/elb.rb +5 -1
- data/lib/akashi/vpc.rb +2 -0
- data/lib/akashi.rb +2 -60
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749f6513d50475d95503f1e6deaf545893fb2a22
|
4
|
+
data.tar.gz: a2d8f02a64d1ff5c17429e88c7e19cef43952b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 457867906d2214162998f21d53a0ef32807a8bd803dc918b855b4ff414108be7ccac17a9dfd1a5ab8d0c8a91d2bdc6cf88bec7173c68b723736a350a37c4c700
|
7
|
+
data.tar.gz: 6341de6d3fa94655bd176f09eda10b670827ffc67e39d864decacd6d32c0dfac5c9449029de6ff06a3ce21fabc1bd17c1e74a6915af9f29c88bf476a7fae1092
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
akashi (0.0.
|
4
|
+
akashi (0.0.2)
|
5
5
|
activesupport
|
6
6
|
aws-sdk
|
7
7
|
hashie
|
@@ -18,14 +18,21 @@ GEM
|
|
18
18
|
aws-sdk (1.43.1)
|
19
19
|
json (~> 1.4)
|
20
20
|
nokogiri (>= 1.4.4)
|
21
|
+
coderay (1.1.0)
|
21
22
|
hashie (3.0.0)
|
22
23
|
i18n (0.6.9)
|
23
24
|
json (1.8.1)
|
25
|
+
method_source (0.8.2)
|
24
26
|
mini_portile (0.6.0)
|
25
27
|
minitest (5.3.4)
|
26
28
|
nokogiri (1.6.2.1)
|
27
29
|
mini_portile (= 0.6.0)
|
30
|
+
pry (0.10.0)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.8.1)
|
33
|
+
slop (~> 3.4)
|
28
34
|
rake (10.3.2)
|
35
|
+
slop (3.5.0)
|
29
36
|
thread_safe (0.3.4)
|
30
37
|
tzinfo (1.2.1)
|
31
38
|
thread_safe (~> 0.1)
|
@@ -36,4 +43,5 @@ PLATFORMS
|
|
36
43
|
DEPENDENCIES
|
37
44
|
akashi!
|
38
45
|
bundler (~> 1.3)
|
46
|
+
pry
|
39
47
|
rake
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
require "yaml"
|
23
23
|
require "akashi"
|
24
24
|
|
25
|
-
Akashi::Aws.config = YAML.load_file("aws.yml")
|
25
|
+
Akashi::Aws.config = YAML.load_file("aws.yml")
|
26
26
|
|
27
27
|
Akashi.application = application
|
28
28
|
Akashi.environment = environment
|
@@ -31,32 +31,6 @@ Akashi.manifest = YAML.load_file("#{Akashi.name(separator: "_")}.yml")
|
|
31
31
|
Akashi.send(action.intern)
|
32
32
|
```
|
33
33
|
|
34
|
-
## Configurations
|
35
|
-
### VPC
|
36
|
-
Cidr block is 10.0.0.0/16.
|
37
|
-
|
38
|
-
### Roles
|
39
|
-
|Role|Cidr block
|
40
|
-
|---|---|
|
41
|
-
|ELB|10.0.0.0/19|
|
42
|
-
|SSH Gateway|10.0.32.0/19|
|
43
|
-
|RDS|10.0.64.0/19|
|
44
|
-
|Web Server|10.0.96.0/19|
|
45
|
-
|
46
|
-
#### Allowed input
|
47
|
-
|Role|Protocol|Port|Source|
|
48
|
-
|---|---|---|---|
|
49
|
-
|ELB|TCP|443|0.0.0.0/0|
|
50
|
-
|SSH Gateway|TCP|9922|0.0.0.0/0|
|
51
|
-
||ICMP|-|0.0.0.0/0|
|
52
|
-
|RDS|TCP|3306|10.0.96.0/19|
|
53
|
-
|Web Server|TCP|80|10.0.0.0/19|
|
54
|
-
||TCP|9922|10.0.32.0/19|
|
55
|
-
||ICMP|-|10.0.32.0/19|
|
56
|
-
|
57
|
-
### Subnets
|
58
|
-
Cidr is 24. Create subnet from cidr block of role each availability zone.
|
59
|
-
Example of ELB: 10.0.0.0/24, 10.0.1.0/24, 10.0.2.0/24...
|
60
34
|
## Contributing
|
61
35
|
|
62
36
|
1. Fork it
|
data/akashi.gemspec
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
module Akashi
|
2
|
+
class Builder
|
3
|
+
def build
|
4
|
+
create_vpc
|
5
|
+
create_internet_gateway
|
6
|
+
create_subnets
|
7
|
+
create_security_groups
|
8
|
+
create_key_pair
|
9
|
+
create_ssl_certificate
|
10
|
+
create_ec2_instances
|
11
|
+
create_subnet_group
|
12
|
+
create_db_instance
|
13
|
+
create_load_balancer
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create_vpc
|
19
|
+
@vpc = Akashi::Vpc::Instance.create
|
20
|
+
|
21
|
+
@route_table = Akashi::Vpc::RouteTable.find_by(vpc_id: @vpc.id)
|
22
|
+
@route_table.name = Akashi.name
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_internet_gateway
|
26
|
+
@internet_gateway = Akashi::Vpc::InternetGateway.create
|
27
|
+
|
28
|
+
@vpc.attach_internet_gateway(@internet_gateway)
|
29
|
+
@route_table.create_route(internet_gateway: @internet_gateway)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_subnets
|
33
|
+
Akashi.manifest.role.each do |role_name, role|
|
34
|
+
role.subnets.each do |subnet|
|
35
|
+
subnets[role_name] << Akashi.klass(:vpc, :subnet, role_name).
|
36
|
+
create(vpc: @vpc, availability_zone: subnet.availability_zone)
|
37
|
+
end
|
38
|
+
|
39
|
+
if !!role.internet_connection
|
40
|
+
subnets[role_name].each { |subnet| subnet.route_table = @route_table }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_security_groups
|
46
|
+
Akashi.manifest.role.each do |role_name, role|
|
47
|
+
security_group[role_name] = Akashi.klass(:vpc, :security_group, role_name).create(vpc: @vpc)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_key_pair
|
52
|
+
Akashi::Ec2::KeyPair.create
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_ec2_instances
|
56
|
+
Akashi.manifest.role.each do |role_name, role|
|
57
|
+
role.subnets.zip(subnets[role_name]).each do |subnet, _subnet|
|
58
|
+
if !!subnet.instance
|
59
|
+
ami = Akashi::Ec2::Ami.find(subnet.instance.ami_id)
|
60
|
+
|
61
|
+
(subnet.instance.number_of_instances || 1).times do
|
62
|
+
ec2_instances[role_name] << Akashi::Ec2::Instance.create(
|
63
|
+
ami: ami,
|
64
|
+
instance_class: subnet.instance.instance_class,
|
65
|
+
security_group: security_group[role_name],
|
66
|
+
subnet: _subnet,
|
67
|
+
allocated_storage: subnet.instance.allocated_storage || 8,
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
ec2_instances[:gateway].each do |ec2_instance|
|
75
|
+
eip = Akashi::Vpc::ElasticIp.create
|
76
|
+
eip.associate(instance: ec2_instance)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_subnet_group
|
81
|
+
@subnet_group = Akashi::Rds::SubnetGroup.create(subnets: subnets[:rds])
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_db_instance
|
85
|
+
@db_instance = Akashi::Rds::DbInstance.create(security_group: security_group[:rds])
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_ssl_certificate
|
89
|
+
@ssl_certificate = Akashi::Elb::SslCertificate.create
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_load_balancer
|
93
|
+
@load_balancer = Akashi::Elb::LoadBalancer.create(
|
94
|
+
security_group: security_group[:elb],
|
95
|
+
subnets: subnets[:elb],
|
96
|
+
ssl_certificate: @ssl_certificate,
|
97
|
+
)
|
98
|
+
@load_balancer.register_instances(ec2_instances[:web])
|
99
|
+
end
|
100
|
+
|
101
|
+
def ec2_instances
|
102
|
+
@ec2_instances ||= Hashie::Mash.new.tap do |_ec2_instances|
|
103
|
+
Akashi.role_names.each { |role_name| _ec2_instances[role_name] = [] }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def security_group
|
108
|
+
@security_group ||= Hashie::Mash.new
|
109
|
+
end
|
110
|
+
|
111
|
+
def subnets
|
112
|
+
@subnets ||= Hashie::Mash.new.tap do |_subnets|
|
113
|
+
Akashi.role_names.each { |role_name| _subnets[role_name] = [] }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -8,6 +8,10 @@ module Akashi
|
|
8
8
|
modify_load_balancer_attributes(options.merge({ load_balancer_name: name }))
|
9
9
|
end
|
10
10
|
|
11
|
+
def register_instances(instances)
|
12
|
+
@object.instances.register(Array.wrap(instances).map(&:id))
|
13
|
+
end
|
14
|
+
|
11
15
|
class << self
|
12
16
|
def create(security_group:, subnets:, ssl_certificate:)
|
13
17
|
Akashi::Aws.elb.client.create_load_balancer(
|
@@ -21,7 +25,13 @@ module Akashi
|
|
21
25
|
instance_protocol: "HTTP",
|
22
26
|
instance_port: 80,
|
23
27
|
ssl_certificate_id: ssl_certificate.arn,
|
24
|
-
}
|
28
|
+
},
|
29
|
+
{
|
30
|
+
protocol: "HTTP",
|
31
|
+
load_balancer_port: 80,
|
32
|
+
instance_protocol: "HTTP",
|
33
|
+
instance_port: 80,
|
34
|
+
},
|
25
35
|
],
|
26
36
|
)
|
27
37
|
|
@@ -44,7 +54,7 @@ module Akashi
|
|
44
54
|
unhealthy_threshold: 2,
|
45
55
|
healthy_threshold: 2,
|
46
56
|
)
|
47
|
-
puts "Created a LoadBalancer(#{instance.name})."
|
57
|
+
puts "Created a LoadBalancer (#{instance.name})."
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
data/lib/akashi/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Akashi
|
2
|
+
class Vpc
|
3
|
+
class ElasticIp < Akashi::Vpc::Base
|
4
|
+
def_delegators :@object, :public_ip, :associate
|
5
|
+
|
6
|
+
def associate(instance:)
|
7
|
+
@object.associate(instance: instance.id)
|
8
|
+
puts "An Elastic IP (#{public_ip}) associated with an EC2 Instance (#{instance.id})."
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def create
|
13
|
+
response = Akashi::Aws.ec2.client.allocate_address(domain: "vpc")
|
14
|
+
|
15
|
+
new(response[:public_ip]).tap do |instance|
|
16
|
+
puts "Created an Elastic IP (#{instance.public_ip})."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/akashi/vpc.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "akashi/vpc/base"
|
2
|
+
require "akashi/vpc/elastic_ip"
|
2
3
|
require "akashi/vpc/instance"
|
3
4
|
require "akashi/vpc/internet_gateway"
|
5
|
+
require "akashi/vpc/monkey_patch"
|
4
6
|
require "akashi/vpc/route_table"
|
5
7
|
require "akashi/vpc/security_group"
|
6
8
|
require "akashi/vpc/subnet"
|
data/lib/akashi.rb
CHANGED
@@ -2,6 +2,7 @@ require "active_support/core_ext"
|
|
2
2
|
require "hashie/mash"
|
3
3
|
require "akashi/aws"
|
4
4
|
require "akashi/base"
|
5
|
+
require "akashi/builder"
|
5
6
|
require "akashi/ec2"
|
6
7
|
require "akashi/elb"
|
7
8
|
require "akashi/rds"
|
@@ -21,58 +22,7 @@ module Akashi
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def build
|
24
|
-
|
25
|
-
|
26
|
-
route_table = Akashi::Vpc::RouteTable.find_by(vpc_id: vpc.id)
|
27
|
-
route_table.name = Akashi.name
|
28
|
-
|
29
|
-
internet_gateway = Akashi::Vpc::InternetGateway.create
|
30
|
-
vpc.attach_internet_gateway(internet_gateway)
|
31
|
-
route_table.create_route(internet_gateway: internet_gateway)
|
32
|
-
|
33
|
-
ssl_certificate = Akashi::Elb::SslCertificate.create
|
34
|
-
|
35
|
-
Akashi::Ec2::KeyPair.create
|
36
|
-
|
37
|
-
manifest.role.each do |role_name, role|
|
38
|
-
subnets[role_name] = []
|
39
|
-
subnet_class = klass(:vpc, :subnet, role_name)
|
40
|
-
security_group_class = klass(:vpc, :security_group, role_name)
|
41
|
-
|
42
|
-
security_group[role_name] = security_group_class.create(vpc: vpc)
|
43
|
-
|
44
|
-
role.subnets.each do |subnet|
|
45
|
-
_subnet = subnet_class.create(vpc: vpc, availability_zone: subnet.availability_zone)
|
46
|
-
subnets[role_name] << _subnet
|
47
|
-
|
48
|
-
if !!subnet.instance
|
49
|
-
ami = Akashi::Ec2::Ami.find(subnet.instance.ami_id)
|
50
|
-
|
51
|
-
(subnet.instance.number_of_instances || 1).times do
|
52
|
-
Akashi::Ec2::Instance.create(
|
53
|
-
ami: ami,
|
54
|
-
instance_class: subnet.instance.instance_class,
|
55
|
-
security_group: security_group[role_name],
|
56
|
-
subnet: _subnet,
|
57
|
-
allocated_storage: subnet.instance.allocated_storage,
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
if !!role.internet_connection
|
64
|
-
subnets[role_name].each { |subnet| subnet.route_table = route_table }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Akashi::Rds::SubnetGroup.create(subnets: subnets[:rds])
|
69
|
-
Akashi::Rds::DbInstance.create(security_group: security_group[:rds])
|
70
|
-
|
71
|
-
Akashi::Elb::LoadBalancer.create(
|
72
|
-
security_group: security_group[:elb],
|
73
|
-
subnets: subnets[:elb],
|
74
|
-
ssl_certificate: ssl_certificate,
|
75
|
-
)
|
25
|
+
Akashi::Builder.new.build
|
76
26
|
end
|
77
27
|
|
78
28
|
def destroy
|
@@ -90,14 +40,6 @@ module Akashi
|
|
90
40
|
context.constantize
|
91
41
|
end
|
92
42
|
|
93
|
-
def subnets
|
94
|
-
@subnets ||= Hashie::Mash.new
|
95
|
-
end
|
96
|
-
|
97
|
-
def security_group
|
98
|
-
@security_group ||= Hashie::Mash.new
|
99
|
-
end
|
100
|
-
|
101
43
|
def role_names
|
102
44
|
@role_names ||= [
|
103
45
|
:elb,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akashi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- asonas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: pry
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Wrapping aws-sdk
|
85
99
|
email:
|
86
100
|
- hzw1258@gmail.com
|
@@ -101,6 +115,7 @@ files:
|
|
101
115
|
- lib/akashi.rb
|
102
116
|
- lib/akashi/aws.rb
|
103
117
|
- lib/akashi/base.rb
|
118
|
+
- lib/akashi/builder.rb
|
104
119
|
- lib/akashi/ec2.rb
|
105
120
|
- lib/akashi/ec2/ami.rb
|
106
121
|
- lib/akashi/ec2/base.rb
|
@@ -118,8 +133,10 @@ files:
|
|
118
133
|
- lib/akashi/version.rb
|
119
134
|
- lib/akashi/vpc.rb
|
120
135
|
- lib/akashi/vpc/base.rb
|
136
|
+
- lib/akashi/vpc/elastic_ip.rb
|
121
137
|
- lib/akashi/vpc/instance.rb
|
122
138
|
- lib/akashi/vpc/internet_gateway.rb
|
139
|
+
- lib/akashi/vpc/monkey_patch.rb
|
123
140
|
- lib/akashi/vpc/route_table.rb
|
124
141
|
- lib/akashi/vpc/security_group.rb
|
125
142
|
- lib/akashi/vpc/security_group/base.rb
|