stackmate 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ AWS_ATTRIBS = {'AWS::CloudFormation::WaitCondition' => [ 'Data'],
2
+ 'AWS::CloudFormation::Stack' => ['Outputs.EmbeddedStackOutputName'],
3
+ 'AWS::CloudFront::Distribution' => ['DomainName'],
4
+ 'AWS::EC2::EIP' => ['AllocationId'],
5
+ 'AWS::EC2::Instance' => ['AvailabilityZone', 'PrivateDnsName', 'PublicDnsName', 'PrivateIp', 'PublicIp'],
6
+ 'AWS::EC2::AWS::EC2::SubnetNetworkAclAssociation' => ['AssociationId'],
7
+ 'AWS::ElasticBeanstalk::Environment' => ['EndpointURL'],
8
+ 'AWS::ElasticLoadBalancing::LoadBalancer' => ['CanonicalHostedZoneName', 'CanonicalHostedZoneNameID',
9
+ 'DNSName', 'SourceSecurityGroup.GroupName', 'SourceSecurityGroup.OwnerAlias'],
10
+ 'AWS::IAM::AccessKey' => ['SecretAccessKey'],
11
+ 'AWS::IAM::Group' => ['Arn'],
12
+ 'AWS::IAM::User' => ['Arn'],
13
+ 'AWS::RDS::DBInstance' => ['Endpoint.Address', 'Endpoint.Port'],
14
+ 'AWS::S3::Bucket' => ['DomainName', 'WebsiteURL', 'Arn'],
15
+ 'AWS::SQS::Queue' => ['Arn', 'QueueName']
16
+ }
17
+
@@ -6,7 +6,8 @@ module StackMate
6
6
  'AWS::CloudFormation::WaitConditionHandle' => 'StackMate::WaitConditionHandle',
7
7
  'AWS::CloudFormation::WaitCondition' => 'StackMate::WaitCondition',
8
8
  'AWS::EC2::Instance' => 'StackMate::CloudStackInstance',
9
- 'AWS::EC2::SecurityGroup' => 'StackMate::CloudStackSecurityGroup'
9
+ 'AWS::EC2::SecurityGroup' => 'StackMate::CloudStackSecurityGroup',
10
+ 'Outputs' => 'StackMate::CloudStackOutput'
10
11
  }
11
12
 
12
13
  def StackMate.class_for(cf_resource)
@@ -14,7 +15,11 @@ module StackMate
14
15
  when 'CLOUDSTACK'
15
16
  return CS_CLASS_MAP[cf_resource]
16
17
  when 'NOOP'
17
- return 'StackMate::NoOpResource'
18
+ if cf_resource == 'Outputs'
19
+ 'StackMate::Output'
20
+ else
21
+ 'StackMate::NoOpResource'
22
+ end
18
23
  end
19
24
  end
20
25
 
@@ -0,0 +1,58 @@
1
+ module StackMate
2
+ module Intrinsic
3
+
4
+ def intrinsic (hash, workitem)
5
+ key = hash.keys[0]
6
+ value = hash[key]
7
+ #logger.debug "Intrinsic: key = #{key}, value = #{value}"
8
+ case key
9
+ when 'Fn::Join'
10
+ fn_join(value, workitem)
11
+ when 'Fn::GetAtt'
12
+ fn_getatt(value, workitem)
13
+ when 'Fn::Select'
14
+ fn_select(value)
15
+ when 'Ref'
16
+ fn_ref(value, workitem)
17
+ end
18
+ end
19
+
20
+ def fn_join(value, workitem)
21
+ delim = value[0]
22
+ v = value[1]
23
+ #logger.debug "Intrinsic: fn_join value = #{v}"
24
+ result = ''
25
+ first_ = true
26
+ v.each do |token|
27
+ case token
28
+ when String
29
+ result = result + (first_ ? "" : delim) + token
30
+ when Hash
31
+ result = result + (first_ ? "" : delim) + intrinsic(token, workitem)
32
+ end
33
+ first_ = false
34
+ end
35
+ result
36
+ end
37
+
38
+ def fn_getatt(array_value, workitem)
39
+ resource = array_value[0]
40
+ attribute = array_value[1]
41
+ #logger.debug "Intrinsic: fn_getatt resource= #{resource} attrib = #{attribute} wi[Resource] = #{workitem[resource]}"
42
+ workitem[resource][attribute]
43
+ end
44
+
45
+ def fn_select(array_value)
46
+ index = array_value[0].to_i #TODO unsafe
47
+ values = array_value[1]
48
+ #logger.debug "Intrinsic: fn_select index= #{index} values = #{values.inspect}"
49
+ values[index]
50
+ end
51
+
52
+ def fn_ref(value, workitem)
53
+ #logger.debug "Intrinsic: fn_ref value = #{value}"
54
+ workitem[value]['physical_id'] #TODO only works with Resources not Params
55
+ end
56
+
57
+ end
58
+ end
@@ -2,6 +2,7 @@ require 'json'
2
2
  require 'cloudstack_ruby_client'
3
3
  require 'yaml'
4
4
  require 'stackmate/logging'
5
+ require 'stackmate/intrinsic_functions'
5
6
 
6
7
  module StackMate
7
8
 
@@ -106,6 +107,12 @@ class CloudStackInstance < CloudStackResource
106
107
 
107
108
  logger.debug("result = #{resultobj.inspect}")
108
109
  workitem[participant_name][:physical_id] = resultobj['virtualmachine']['id']
110
+ workitem[participant_name][:AvailabilityZone] = resultobj['virtualmachine']['zoneid']
111
+ ipaddress = resultobj['virtualmachine']['nic'][0]['ipaddress']
112
+ workitem[participant_name][:PrivateDnsName] = ipaddress
113
+ workitem[participant_name][:PublicDnsName] = ipaddress
114
+ workitem[participant_name][:PrivateIp] = ipaddress
115
+ workitem[participant_name][:PublicIp] = ipaddress
109
116
  reply
110
117
  end
111
118
 
@@ -204,4 +211,23 @@ class CloudStackSecurityGroup < CloudStackResource
204
211
  end
205
212
 
206
213
 
214
+ class CloudStackOutput < Ruote::Participant
215
+ include Logging
216
+ include Intrinsic
217
+
218
+ def on_workitem
219
+ logger.debug "Entering #{participant_name} "
220
+ outputs = workitem.fields['Outputs']
221
+ outputs.each do |key, val|
222
+ v = val['Value']
223
+ constructed_value = intrinsic(v, workitem)
224
+ val['Value'] = constructed_value
225
+ logger.debug "Output: key = #{key}, value = #{constructed_value} descr = #{val['Description']}"
226
+ end
227
+ logger.debug "Output Done"
228
+ reply
229
+ end
230
+
231
+ end
232
+
207
233
  end
@@ -46,7 +46,7 @@ class StackExecutor < StackMate::Stacker
46
46
  @engine.register_participant p, StackMate.class_for(t), @api_opts
47
47
  end
48
48
 
49
- @engine.register_participant 'Output', 'StackMate::Output'
49
+ @engine.register_participant 'Output', StackMate.class_for('Outputs')
50
50
  participants << 'Output'
51
51
  @pdef = Ruote.define @stackname.to_s() do
52
52
  cursor :timeout => '300s' do
@@ -1,3 +1,3 @@
1
1
  module StackMate
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackmate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cloudstack_ruby_client
@@ -114,7 +114,9 @@ executables:
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - lib/stackmate/aws_attribs.rb
117
118
  - lib/stackmate/classmap.rb
119
+ - lib/stackmate/intrinsic_functions.rb
118
120
  - lib/stackmate/logging.rb
119
121
  - lib/stackmate/participants/cloudstack.rb
120
122
  - lib/stackmate/participants/common.rb