Class: DrawCloud::Base

Inherits:
Object
  • Object
show all
Includes:
Locations, Utilities
Defined in:
lib/draw_cloud/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Locations

#arn_s3

Methods included from Utilities

#desplice, #fnbase64, #fngetatt, #fnjoin, #hash_to_tag_array, #region, #resource_style, #splice, #stack_name

Constructor Details

#initialize(options = {}, &block) ⇒ Base

Returns a new instance of Base.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/draw_cloud/base.rb', line 57

def initialize(options={}, &block)
  @mappings = {}
  @parameters = {}
  @resources = {}
  @outputs = {}

  @subnets = []
  @route_tables = []
  @network_acls = []
  @security_groups = []
  @iam_users = []
  @iam_policies = []
  @iam_access_keys = []
  @gateways = []
  @rdses = []
  @ec2_instances = []
  @as_launch_configurations = []
  @as_groups = []
  @elastic_ips = []
  @network_interfaces = []
  @wait_handles = []
  @vpcs = []
  @sns_topics = []

  @parent = options.fetch(:parent, nil)

  self.instance_exec(self, &block) if block
end

Instance Attribute Details

#as_groupsObject

Returns the value of attribute as_groups.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def as_groups
  @as_groups
end

#as_launch_configurationsObject

Returns the value of attribute as_launch_configurations.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def as_launch_configurations
  @as_launch_configurations
end

#deletion_policyObject

Returns the value of attribute deletion_policy.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def deletion_policy
  @deletion_policy
end

#depends_onObject

Returns the value of attribute depends_on.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def depends_on
  @depends_on
end

#ec2_instancesObject

Returns the value of attribute ec2_instances.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def ec2_instances
  @ec2_instances
end

#elastic_ipsObject

Returns the value of attribute elastic_ips.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def elastic_ips
  @elastic_ips
end

#gatewaysObject

Returns the value of attribute gateways.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def gateways
  @gateways
end

#iam_access_keysObject

Returns the value of attribute iam_access_keys.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def iam_access_keys
  @iam_access_keys
end

#iam_policiesObject

Returns the value of attribute iam_policies.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def iam_policies
  @iam_policies
end

#iam_usersObject

Returns the value of attribute iam_users.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def iam_users
  @iam_users
end

#mappingsObject

Returns the value of attribute mappings.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def mappings
  @mappings
end

#metadataObject

Returns the value of attribute metadata.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def 
  @metadata
end

#network_aclsObject

Returns the value of attribute network_acls.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def network_acls
  @network_acls
end

#network_interfacesObject

Returns the value of attribute network_interfaces.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def network_interfaces
  @network_interfaces
end

#outputsObject

Returns the value of attribute outputs.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def outputs
  @outputs
end

#parametersObject

Returns the value of attribute parameters.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def parameters
  @parameters
end

#parentObject

Returns the value of attribute parent.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def parent
  @parent
end

#rdsesObject

Returns the value of attribute rdses.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def rdses
  @rdses
end

#resourcesObject

Returns the value of attribute resources.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def resources
  @resources
end

#route_tablesObject

Returns the value of attribute route_tables.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def route_tables
  @route_tables
end

#security_groupsObject

Returns the value of attribute security_groups.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def security_groups
  @security_groups
end

#sns_topicsObject

Returns the value of attribute sns_topics.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def sns_topics
  @sns_topics
end

#subnetsObject

Returns the value of attribute subnets.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def subnets
  @subnets
end

#vpcsObject

Returns the value of attribute vpcs.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def vpcs
  @vpcs
end

#wait_handlesObject

Returns the value of attribute wait_handles.



28
29
30
# File 'lib/draw_cloud/base.rb', line 28

def wait_handles
  @wait_handles
end

Instance Method Details

#[](attribute) ⇒ Object



112
113
114
# File 'lib/draw_cloud/base.rb', line 112

def [](attribute)
  fngetatt(self, attribute)
end

#accessorObject

Accessors (list below so grep works) def elastic_ip def internet_gateway def network_acl def rds def route_table def security_group def subnet def vpc



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/draw_cloud/base.rb', line 250

[:elastic_ip, :network_interface, :ec2_instance, :as_launch_configuration, :as_group,
 :internet_gateway, :network_acl, :rds, :route_table, :security_group,
 :subnet, :vpc, :iam_user, :iam_policy, :iam_access_key].each do |accessor|
  self.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
    def #{accessor}()
      if parent
        parent.#{accessor}
      else
        nil
      end
    end
  RUBY_EVAL
end

#add_standard_properties(hash) ⇒ Object



101
102
103
104
105
106
# File 'lib/draw_cloud/base.rb', line 101

def add_standard_properties(hash)
  hash["DependsOn"] = DrawCloud.resource_name(depends_on) if depends_on
  hash["DeletionPolicy"] = DrawCloud.resource_style(deletion_policy) if deletion_policy
  hash["Metadata"] = DrawCloud.ref() unless .nil?
  hash
end

#create_as_group(name, options = {}, &block) ⇒ Object



217
218
219
220
221
# File 'lib/draw_cloud/base.rb', line 217

def create_as_group(name, options={}, &block)
  asg = ASGroup.new(name, options.merge(:parent => self), &block)
  as_groups << asg
  asg
end

#create_as_launch_configuration(name, options = {}, &block) ⇒ Object



211
212
213
214
215
# File 'lib/draw_cloud/base.rb', line 211

def create_as_launch_configuration(name, options={}, &block)
  lc = ASLaunchConfiguration.new(name, options.merge(:parent => self), &block)
  as_launch_configurations << lc
  lc
end

#create_ec2_instance(name, options = {}, &block) ⇒ Object



205
206
207
208
209
# File 'lib/draw_cloud/base.rb', line 205

def create_ec2_instance(name, options={}, &block)
  e = EC2Instance.new(name, options.merge(:parent => self), &block)
  ec2_instances << e
  e
end

#create_ec2_instance_template(name, options = {}, &block) ⇒ Object



201
202
203
# File 'lib/draw_cloud/base.rb', line 201

def create_ec2_instance_template(name, options={}, &block)
  EC2InstanceTemplate.new(name, options.merge(:parent => self), &block)
end

#create_elastic_ip(name, options = {}, &block) ⇒ Object



229
230
231
232
233
# File 'lib/draw_cloud/base.rb', line 229

def create_elastic_ip(name, options={}, &block)
  eip = ElasticIp.new(name, options.merge(:parent => self), &block)
  elastic_ips << eip
  eip
end

#create_iam_access_key(name, options = {}, &block) ⇒ Object



189
190
191
192
193
# File 'lib/draw_cloud/base.rb', line 189

def create_iam_access_key(name, options={}, &block)
  a = IAMAccessKey.new(name, options.merge(:parent => self), &block)
  iam_access_keys << a
  a
end

#create_iam_policy(name, options = {}, &block) ⇒ Object



183
184
185
186
187
# File 'lib/draw_cloud/base.rb', line 183

def create_iam_policy(name, options={}, &block)
  p = IAMPolicy.new(name, options.merge(:parent => self), &block)
  iam_policies << p
  p
end

#create_iam_user(name, options = {}, &block) ⇒ Object



177
178
179
180
181
# File 'lib/draw_cloud/base.rb', line 177

def create_iam_user(name, options={}, &block)
  u = IAMUser.new(name, options.merge(:parent => self), &block)
  iam_users << u
  u
end

#create_mapping(name, map_by_function, values = {}) ⇒ Object

Definers



118
119
120
121
122
# File 'lib/draw_cloud/base.rb', line 118

def create_mapping(name, map_by_function, values={})
  m = Map.new(name, map_by_function, {:parent => self}, values)
  mappings[m.resource_name] = m
  m
end

#create_network_acl(name, options = {}, &block) ⇒ Object



165
166
167
168
169
# File 'lib/draw_cloud/base.rb', line 165

def create_network_acl(name, options={}, &block)
  a = NetworkAcl.new(name, options.merge(:parent => self), &block)
  network_acls << a
  a
end

#create_network_interface(name, options = {}, &block) ⇒ Object



235
236
237
238
239
# File 'lib/draw_cloud/base.rb', line 235

def create_network_interface(name, options={}, &block)
  eni = NetworkInterface.new(name, options.merge(:parent => self), &block)
  network_interfaces << eni
  eni
end

#create_output(name, options = {}, &block) ⇒ Object



124
125
126
127
128
# File 'lib/draw_cloud/base.rb', line 124

def create_output(name, options={}, &block)
  o = Output.new(name, options.merge(:parent => self), &block)
  outputs[o.resource_name] = o
  o
end

#create_parameter(name, type, options = {}, &block) ⇒ Object



130
131
132
133
134
# File 'lib/draw_cloud/base.rb', line 130

def create_parameter(name, type, options={}, &block)
  p = Parameter.new(name, type, options.merge(:parent => self), &block)
  parameters[p.resource_name] = p
  p
end

#create_rds(name, options = {}, &block) ⇒ Object



195
196
197
198
199
# File 'lib/draw_cloud/base.rb', line 195

def create_rds(name, options={}, &block)
  r = RDSInstance.new(name, options.merge(:parent => self), &block)
  rdses << r
  r
end

#create_route_table(name, options = {}, &block) ⇒ Object



159
160
161
162
163
# File 'lib/draw_cloud/base.rb', line 159

def create_route_table(name, options={}, &block)
  r = RouteTable.new(name, options.merge(:parent => self), &block)
  route_tables << r
  r
end

#create_security_group(name, description = nil, options = {}, &block) ⇒ Object



171
172
173
174
175
# File 'lib/draw_cloud/base.rb', line 171

def create_security_group(name, description=nil, options={}, &block)
  g = SecurityGroup.new(name, description, options.merge(:parent => self), &block)
  security_groups << g
  g
end

#create_service(name, options = {}, &block) ⇒ Object



136
137
138
# File 'lib/draw_cloud/base.rb', line 136

def create_service(name, options={}, &block)
  # NOOP
end

#create_sns_topic(name, options = {}, &block) ⇒ Object



146
147
148
149
150
# File 'lib/draw_cloud/base.rb', line 146

def create_sns_topic(name, options={}, &block)
  s = SNSTopic.new(name, options.merge(:parent => self), &block)
  sns_topics << s
  s
end

#create_subnet(name, cidr, options = {}, &block) ⇒ Object



152
153
154
155
156
157
# File 'lib/draw_cloud/base.rb', line 152

def create_subnet(name, cidr, options={}, &block)
  # collisioncheck
  s = Subnet.new(name, cidr, options.merge(:parent => self), &block)
  subnets << s
  s
end

#create_vpc(name, cidr, options = {}, &block) ⇒ Object



140
141
142
143
144
# File 'lib/draw_cloud/base.rb', line 140

def create_vpc(name, cidr, options={}, &block)
  v = Vpc.new(name, cidr, options.merge(:parent => self), &block)
  vpcs << v
  v
end

#create_wait_handle(name, timeout = nil, options = {}, &block) ⇒ Object



223
224
225
226
227
# File 'lib/draw_cloud/base.rb', line 223

def create_wait_handle(name, timeout=nil, options={}, &block)
  h = WaitHandle.new(name, timeout, options.merge(:parent => self), &block)
  wait_handles << h
  h
end

#load_into_config(config) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/draw_cloud/base.rb', line 86

def load_into_config(config)
  [@mappings, @parameters, @resources, @outputs].each do |i|
    i.each {|k,v| v.load_into_config(config)}
  end

  [@gateways, @subnets, @route_tables, @network_acls, @security_groups, @iam_users, @iam_policies, @iam_access_keys,
   @rdses, @ec2_instances, @as_launch_configurations, @as_groups, @elastic_ips, @network_interfaces, @wait_handles, @vpcs, @sns_topics].each do |a|
    a.each {|g| g.load_into_config(config) }
  end
end

#refObject



108
109
110
# File 'lib/draw_cloud/base.rb', line 108

def ref
  {"Ref" => resource_name}
end

#resource_nameObject



97
98
99
# File 'lib/draw_cloud/base.rb', line 97

def resource_name
  resource_style(name)
end