draw_cloud 0.0.1
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.
- data/README.md +22 -0
- data/lib/draw_cloud.rb +75 -0
- data/lib/draw_cloud/as_group.rb +104 -0
- data/lib/draw_cloud/as_group.rb~ +54 -0
- data/lib/draw_cloud/as_launch_configuration.rb +71 -0
- data/lib/draw_cloud/as_launch_configuration.rb~ +50 -0
- data/lib/draw_cloud/base.rb +264 -0
- data/lib/draw_cloud/base64_func.rb +30 -0
- data/lib/draw_cloud/configuration.rb +61 -0
- data/lib/draw_cloud/configuration.rb~ +64 -0
- data/lib/draw_cloud/ec2_instance.rb +141 -0
- data/lib/draw_cloud/ec2_instance.rb~ +78 -0
- data/lib/draw_cloud/ec2_instance_template.rb +29 -0
- data/lib/draw_cloud/ec2_instance_template.rb~ +36 -0
- data/lib/draw_cloud/elastic_ip.rb +97 -0
- data/lib/draw_cloud/elastic_ip.rb~ +19 -0
- data/lib/draw_cloud/get_att_func.rb +31 -0
- data/lib/draw_cloud/get_att_func.rb~ +19 -0
- data/lib/draw_cloud/iam_access_key.rb +53 -0
- data/lib/draw_cloud/iam_access_key.rb~ +43 -0
- data/lib/draw_cloud/iam_policy.rb +71 -0
- data/lib/draw_cloud/iam_policy.rb~ +41 -0
- data/lib/draw_cloud/iam_user.rb +53 -0
- data/lib/draw_cloud/iam_user.rb~ +44 -0
- data/lib/draw_cloud/internet_gateway.rb +66 -0
- data/lib/draw_cloud/join_func.rb +31 -0
- data/lib/draw_cloud/join_func.rb~ +24 -0
- data/lib/draw_cloud/locations.rb +25 -0
- data/lib/draw_cloud/locations.rb~ +53 -0
- data/lib/draw_cloud/map.rb +65 -0
- data/lib/draw_cloud/network_acl.rb +91 -0
- data/lib/draw_cloud/network_acl.rb~ +36 -0
- data/lib/draw_cloud/network_acl_entry.rb +110 -0
- data/lib/draw_cloud/network_acl_entry.rb~ +36 -0
- data/lib/draw_cloud/network_interface.rb +71 -0
- data/lib/draw_cloud/network_interface.rb~ +46 -0
- data/lib/draw_cloud/output.rb +38 -0
- data/lib/draw_cloud/output.rb~ +39 -0
- data/lib/draw_cloud/parameter.rb +58 -0
- data/lib/draw_cloud/parameter.rb~ +30 -0
- data/lib/draw_cloud/rds_instance.rb +117 -0
- data/lib/draw_cloud/rds_security_group.rb +57 -0
- data/lib/draw_cloud/route_table.rb +56 -0
- data/lib/draw_cloud/route_table_entry.rb +59 -0
- data/lib/draw_cloud/route_table_entry.rb~ +33 -0
- data/lib/draw_cloud/s3_bucket.rb~ +41 -0
- data/lib/draw_cloud/security_group.rb +85 -0
- data/lib/draw_cloud/security_group.rb~ +71 -0
- data/lib/draw_cloud/service.rb~ +75 -0
- data/lib/draw_cloud/simple_ref.rb +30 -0
- data/lib/draw_cloud/simple_ref.rb~ +17 -0
- data/lib/draw_cloud/sns_topic.rb +58 -0
- data/lib/draw_cloud/sns_topic.rb~ +39 -0
- data/lib/draw_cloud/subnet.rb +104 -0
- data/lib/draw_cloud/subnet.rb~ +56 -0
- data/lib/draw_cloud/utilities.rb +65 -0
- data/lib/draw_cloud/version.rb +3 -0
- data/lib/draw_cloud/vpc.rb +57 -0
- data/lib/draw_cloud/vpc.rb~ +55 -0
- data/lib/draw_cloud/wait_handle.rb +78 -0
- data/lib/draw_cloud/wait_handle.rb~ +10 -0
- metadata +195 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this work except in compliance with the License. You may
|
7
|
+
# obtain a copy of the License in the LICENSE file, or at:
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
|
17
|
+
#
|
18
|
+
|
19
|
+
module DrawCloud
|
20
|
+
class Base64Func
|
21
|
+
attr_accessor :arg
|
22
|
+
def initialize(arg=nil)
|
23
|
+
@arg = arg
|
24
|
+
end
|
25
|
+
|
26
|
+
def ref
|
27
|
+
{"Fn::Base64" => DrawCloud.ref(arg) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this work except in compliance with the License. You may
|
7
|
+
# obtain a copy of the License in the LICENSE file, or at:
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
|
17
|
+
#
|
18
|
+
|
19
|
+
module DrawCloud
|
20
|
+
class Configuration < Base
|
21
|
+
attr_accessor :description
|
22
|
+
def self.draw(&block)
|
23
|
+
c = Configuration.new
|
24
|
+
c.instance_exec(c, &block)
|
25
|
+
puts JSON.pretty_generate(c.to_cf)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(options={}, &block)
|
29
|
+
super(options, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_cf
|
33
|
+
h = {"AWSTemplateFormatVersion" => "2010-09-09"}
|
34
|
+
h["Description"] = description if description
|
35
|
+
|
36
|
+
c = Configuration.new
|
37
|
+
self.load_into_config(c)
|
38
|
+
|
39
|
+
{ "Mappings" => c.mappings,
|
40
|
+
"Parameters" => c.parameters,
|
41
|
+
"Resources" => c.resources,
|
42
|
+
"Outputs" => c.outputs }.each do |(key, values)|
|
43
|
+
h[key] = Hash[*values.collect {|k,v| [k, v.to_h]}.flatten] unless values.empty?
|
44
|
+
end
|
45
|
+
h
|
46
|
+
end
|
47
|
+
|
48
|
+
def cf_add_mapping(name, map)
|
49
|
+
mappings[name] = map
|
50
|
+
end
|
51
|
+
def cf_add_parameter(name, param)
|
52
|
+
parameters[name] = param
|
53
|
+
end
|
54
|
+
def cf_add_resource(name, res)
|
55
|
+
resources[name] = res
|
56
|
+
end
|
57
|
+
def cf_add_output(name, out)
|
58
|
+
outputs[name] = out
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module DrawCloud
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :mappings, :parameters, :resources, :outputs, :vpcs
|
4
|
+
def self.draw(&block)
|
5
|
+
c = Configuration.new
|
6
|
+
c.instance_exec(c, &block)
|
7
|
+
puts JSON.pretty_generate(c.to_cf)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@mappings = {}
|
12
|
+
@parameters = {}
|
13
|
+
@resources = {}
|
14
|
+
@outputs = {}
|
15
|
+
|
16
|
+
@vpcs = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def description(s)
|
20
|
+
@description = s
|
21
|
+
end
|
22
|
+
|
23
|
+
def mapping(name, map_by_function, values={})
|
24
|
+
m = Map.new(name, map_by_function, values)
|
25
|
+
@mappings[m.resource_name] = m
|
26
|
+
m
|
27
|
+
end
|
28
|
+
|
29
|
+
def vpc(name, cidr, &block)
|
30
|
+
v = Vpc.new(name, cidr, &block)
|
31
|
+
@vpcs << v
|
32
|
+
v
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_cf
|
36
|
+
h = {"AWSTemplateFormatVersion" => "2010-09-09"}
|
37
|
+
h["Description"] = @description if @description
|
38
|
+
|
39
|
+
c = Configuration.new
|
40
|
+
[@mappings, @parameters, @resources, @outputs].each {|i| i.each {|k,v| v.load_into_config(c) } }
|
41
|
+
@vpcs.each {|v| v.load_into_config(c) }
|
42
|
+
{ "Mappings" => c.mappings,
|
43
|
+
"Parameters" => c.parameters,
|
44
|
+
"Resources" => c.resources,
|
45
|
+
"Outputs" => c.outputs }.each do |(key, values)|
|
46
|
+
h[key] = Hash[*values.collect {|k,v| [k, v.to_h]}.flatten] unless values.empty?
|
47
|
+
end
|
48
|
+
h
|
49
|
+
end
|
50
|
+
|
51
|
+
def cf_add_mapping(name, map)
|
52
|
+
mappings[name] = map
|
53
|
+
end
|
54
|
+
def cf_add_parameter(name, param)
|
55
|
+
parameters[name] = param
|
56
|
+
end
|
57
|
+
def cf_add_resource(name, res)
|
58
|
+
resources[name] = res
|
59
|
+
end
|
60
|
+
def cf_add_output(name, out)
|
61
|
+
outputs[name] = out
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this work except in compliance with the License. You may
|
7
|
+
# obtain a copy of the License in the LICENSE file, or at:
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
|
17
|
+
#
|
18
|
+
|
19
|
+
module DrawCloud
|
20
|
+
class EC2Instance < Base
|
21
|
+
attr_accessor(:name,
|
22
|
+
:availability_zone,
|
23
|
+
:disable_api_termination,
|
24
|
+
:image_id,
|
25
|
+
:instance_type,
|
26
|
+
:key_name,
|
27
|
+
:monitoring,
|
28
|
+
:placement_group_name,
|
29
|
+
:private_ip_address,
|
30
|
+
:source_dest_check,
|
31
|
+
:subnet_id,
|
32
|
+
:tags,
|
33
|
+
:user_data,
|
34
|
+
:metadata,
|
35
|
+
:template,
|
36
|
+
:eip_name)
|
37
|
+
alias :instance_class :instance_type
|
38
|
+
alias :instance_class= :instance_type=
|
39
|
+
alias :instance_monitoring :monitoring
|
40
|
+
alias :instance_monitoring= :monitoring=
|
41
|
+
alias :ami :image_id
|
42
|
+
alias :ami= :image_id=
|
43
|
+
alias :subnet :subnet_id
|
44
|
+
alias :subnet= :subnet_id=
|
45
|
+
def initialize(name, options={}, &block)
|
46
|
+
@name = name
|
47
|
+
@tags = {}
|
48
|
+
@template = options.fetch(:template, nil)
|
49
|
+
super(options, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
def ec2_instance
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def elastic_ip=(eip)
|
57
|
+
case eip
|
58
|
+
when DrawCloud::ElasticIp
|
59
|
+
eip.instance_id = self
|
60
|
+
self.eip_name = nil
|
61
|
+
else
|
62
|
+
self.eip_name = eip
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def elastic_ip_association
|
67
|
+
DrawCloud::ElasticIp::ElasticIpAssociation.new(eip_name, self, vpc)
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_into_config(config)
|
71
|
+
config.cf_add_resource resource_name, self
|
72
|
+
config.cf_add_resource(elastic_ip_association.resource_name, elastic_ip_association) if eip_name
|
73
|
+
super(config)
|
74
|
+
end
|
75
|
+
|
76
|
+
def resource_name
|
77
|
+
resource_style(name) + "EC2"
|
78
|
+
end
|
79
|
+
|
80
|
+
def fetchmergeprop(name)
|
81
|
+
s = {}
|
82
|
+
s.deep_merge!(template.fetchmergeprop(name)) if template
|
83
|
+
s.deep_merge!(self.send(name))
|
84
|
+
s
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetchprop(name)
|
88
|
+
s = self.send(name)
|
89
|
+
return s unless s.nil?
|
90
|
+
return template.fetchprop(name) unless template.nil?
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def fetchunionprop(name)
|
95
|
+
if template
|
96
|
+
p = template.fetchunionprop(name).clone
|
97
|
+
p.concat self.send(name)
|
98
|
+
p.uniq
|
99
|
+
else
|
100
|
+
self.send(name)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def default_tags
|
105
|
+
{"Name" => resource_style(name)}
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_h
|
109
|
+
h = {
|
110
|
+
"Type" => "AWS::EC2::Instance",
|
111
|
+
"Properties" => {
|
112
|
+
"ImageId" => DrawCloud.ref(fetchprop :image_id),
|
113
|
+
"InstanceType" => DrawCloud.ref(fetchprop :instance_type),
|
114
|
+
}
|
115
|
+
}
|
116
|
+
p = h["Properties"]
|
117
|
+
%w(availability_zone disable_api_termination key_name
|
118
|
+
monitoring placement_group_name private_ip_address
|
119
|
+
source_dest_check subnet_id user_data).each do |prop_str|
|
120
|
+
prop = prop_str.intern
|
121
|
+
p[resource_style(prop)] = DrawCloud.ref(fetchprop(prop)) unless fetchprop(prop).nil?
|
122
|
+
end
|
123
|
+
p["Tags"] = hash_to_tag_array(default_tags.merge(fetchmergeprop(:tags)))
|
124
|
+
h["DependsOn"] = DrawCloud.resource_name(fetchprop(:depends_on)) unless fetchprop(:depends_on).nil?
|
125
|
+
h["Metadata"] = DrawCloud.ref(fetchmergeprop(:metadata)) unless fetchmergeprop(:metadata).empty?
|
126
|
+
|
127
|
+
enis = fetchunionprop(:network_interfaces)
|
128
|
+
p["NetworkInterfaces"] = enis.enum_for(:each_with_index).collect do |e, i|
|
129
|
+
{ "NetworkInterfaceId" => DrawCloud.ref(e),
|
130
|
+
"DeviceIndex" => (i+1).to_s }
|
131
|
+
end unless enis.empty?
|
132
|
+
|
133
|
+
security_groups = fetchunionprop(:security_groups)
|
134
|
+
vpc_security_groups = security_groups.find_all(&:vpc)
|
135
|
+
regular_security_groups = security_groups.reject(&:vpc)
|
136
|
+
p["SecurityGroups"] = regular_security_groups.collect {|s| DrawCloud.ref(s) } unless regular_security_groups.empty?
|
137
|
+
p["SecurityGroupIds"] = vpc_security_groups.collect {|s| DrawCloud.ref(s) } unless vpc_security_groups.empty?
|
138
|
+
h
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
# License:: All rights reserved
|
5
|
+
#
|
6
|
+
|
7
|
+
module DrawCloud
|
8
|
+
class EC2Instance
|
9
|
+
include Base
|
10
|
+
|
11
|
+
attr_accessor(:availability_zone,
|
12
|
+
:disable_api_termination,
|
13
|
+
:image_id,
|
14
|
+
:instance_type,
|
15
|
+
:key_name,
|
16
|
+
:monitoring,
|
17
|
+
:placement_group_name,
|
18
|
+
:private_ip_address,
|
19
|
+
:security_groups,
|
20
|
+
:security_group_ids,
|
21
|
+
:source_dest_check,
|
22
|
+
:subnet_id,
|
23
|
+
:tags,
|
24
|
+
:template)
|
25
|
+
def initialize(name, options={}, &block)
|
26
|
+
@name = name
|
27
|
+
@security_groups = []
|
28
|
+
@security_group_ids = []
|
29
|
+
@tags = []
|
30
|
+
@template = options.fetch(:template, nil)
|
31
|
+
self.instance_exec(self, &block) if block
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_into_config(config)
|
35
|
+
config.cf_add_resource resource_name, self
|
36
|
+
end
|
37
|
+
|
38
|
+
def resource_name
|
39
|
+
resource_style(name) + "EC2"
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetchprop(name)
|
43
|
+
s = self.send(name)
|
44
|
+
return s unless s.nil?
|
45
|
+
return template.fetchprop(name) unless template.nil?
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetchunionprop(name)
|
50
|
+
if template
|
51
|
+
p = template.send(name).clone
|
52
|
+
p.concat self.send(name)
|
53
|
+
else
|
54
|
+
self.send(name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_h
|
59
|
+
h = {
|
60
|
+
"Type" => "AWS::EC2::Instance",
|
61
|
+
"Properties" => {
|
62
|
+
"ImageId" => DrawCloud.ref(fetchprop :image_id),
|
63
|
+
"InstanceType" => DrawCloud.ref(fetchprop :instance_type),
|
64
|
+
}
|
65
|
+
}
|
66
|
+
p = h["Properties"]
|
67
|
+
%s(availability_zone disable_api_termination key_name
|
68
|
+
monitoring placement_group_name private_ip_address
|
69
|
+
source_dest_check subnet_id).each do |prop|
|
70
|
+
p[resource_style(prop)] = DrawCloud.ref(fetchprop(prop)) unless fetchprop(prop).nil?
|
71
|
+
end
|
72
|
+
p["Tags"] = fetchunionprop(:tags) unless fetchunionprop(:tags).empty?
|
73
|
+
p["SecurityGroups"] = fetchunionprop(:security_groups).collect {|s| DrawCloud.ref(s) } unless fetchunionprop(:security_groups).empty?
|
74
|
+
p["SecurityGroupIds"] = fetchunionprop(:security_group_ids).collect {|s| DrawCloud.ref(s) } unless fetchunionprop(:security_group_ids).empty?
|
75
|
+
h
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this work except in compliance with the License. You may
|
7
|
+
# obtain a copy of the License in the LICENSE file, or at:
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
|
17
|
+
#
|
18
|
+
|
19
|
+
module DrawCloud
|
20
|
+
class EC2InstanceTemplate < EC2Instance
|
21
|
+
def initialize(name, options={}, &block)
|
22
|
+
super(name, options, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_into_config(config)
|
26
|
+
# template - do NOT add to config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
# License:: All rights reserved
|
5
|
+
#
|
6
|
+
|
7
|
+
module DrawCloud
|
8
|
+
class EC2Instance
|
9
|
+
include Base
|
10
|
+
|
11
|
+
attr_accessor(:availability_zone,
|
12
|
+
:disable_api_termination,
|
13
|
+
:image_id,
|
14
|
+
:instance_type,
|
15
|
+
:key_name,
|
16
|
+
:monitoring,
|
17
|
+
:placement_group_name,
|
18
|
+
:private_ip_address,
|
19
|
+
:security_groups,
|
20
|
+
:security_group_ids,
|
21
|
+
:source_dest_check,
|
22
|
+
:subnet_id,
|
23
|
+
:tags)
|
24
|
+
def initialize(name, options={}, &block)
|
25
|
+
@name = name
|
26
|
+
@security_groups = []
|
27
|
+
@security_group_ids = []
|
28
|
+
@tags
|
29
|
+
self.instance_exec(self, &block) if block
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_into_config(config)
|
33
|
+
# template!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this work except in compliance with the License. You may
|
7
|
+
# obtain a copy of the License in the LICENSE file, or at:
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
|
17
|
+
#
|
18
|
+
|
19
|
+
module DrawCloud
|
20
|
+
class ElasticIp < Base
|
21
|
+
class ElasticIpAssociation
|
22
|
+
attr_accessor(:elastic_ip, :instance, :vpc)
|
23
|
+
def initialize(elastic_ip, instance, vpc)
|
24
|
+
@elastic_ip = elastic_ip
|
25
|
+
@instance = instance
|
26
|
+
@vpc = vpc
|
27
|
+
end
|
28
|
+
|
29
|
+
def resource_name
|
30
|
+
elastic_ip.resource_name + "Association"
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
h = {
|
35
|
+
"Type" => "AWS::EC2::EIPAssociation",
|
36
|
+
"Properties" => { },
|
37
|
+
}
|
38
|
+
if instance.ec2_instance
|
39
|
+
h["Properties"]["InstanceId"] = DrawCloud.ref(instance)
|
40
|
+
elsif instance.network_interface
|
41
|
+
h["Properties"]["NetworkInterfaceId"] = DrawCloud.ref(instance)
|
42
|
+
else
|
43
|
+
raise ArgumentError, "Unknown instance or network interface type #{instance.inspect}"
|
44
|
+
end
|
45
|
+
|
46
|
+
if vpc
|
47
|
+
case elastic_ip
|
48
|
+
when DrawCloud::ElasticIp
|
49
|
+
h["Properties"]["AllocationId"] = DrawCloud.ref(elastic_ip[:allocation_id])
|
50
|
+
else
|
51
|
+
h["Properties"]["AllocationId"] = DrawCloud.ref(elastic_ip)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
h["Properties"]["EIP"] = DrawCloud.ref(elastic_ip)
|
55
|
+
end
|
56
|
+
h
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor(:name, :instance_id, :domain)
|
61
|
+
def initialize(name, options={}, &block)
|
62
|
+
@name = name
|
63
|
+
@domain = options.fetch(:domain, nil)
|
64
|
+
@instance_id = options.fetch(:instance_id, nil)
|
65
|
+
super(options, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def elastic_ip
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def association
|
73
|
+
ElasticIpAssociation.new(self, instance_id, vpc)
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_into_config(config)
|
77
|
+
config.cf_add_resource resource_name, self
|
78
|
+
config.cf_add_resource(association.resource_name, association) if instance_id
|
79
|
+
super(config)
|
80
|
+
end
|
81
|
+
|
82
|
+
def resource_name
|
83
|
+
resource_style(name) + "EIP"
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_h
|
87
|
+
h = {
|
88
|
+
"Type" => "AWS::EC2::EIP",
|
89
|
+
"Properties" => {}
|
90
|
+
}
|
91
|
+
h["Properties"]["Domain"] = domain unless domain.nil?
|
92
|
+
h["Properties"]["Domain"] = "vpc" if (domain.nil? && vpc)
|
93
|
+
add_standard_properties(h)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|