sparkle_formation 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +7 -1
  4. data/bin/generate_sparkle_docs +31 -0
  5. data/lib/sparkle_formation/aws.rb +6 -7
  6. data/lib/sparkle_formation/sparkle_attribute.rb +97 -0
  7. data/lib/sparkle_formation/translation/heat.rb +184 -2
  8. data/lib/sparkle_formation/translation/rackspace.rb +7 -3
  9. data/lib/sparkle_formation/translation.rb +28 -2
  10. data/lib/sparkle_formation/version.rb +1 -1
  11. data/sparkle_formation.gemspec +2 -1
  12. metadata +5 -33
  13. data/CONTRIBUTING.md +0 -25
  14. data/Gemfile +0 -3
  15. data/Gemfile.lock +0 -18
  16. data/bin/aws_resources +0 -85
  17. data/bin/heat_resources +0 -33
  18. data/docs/README.md +0 -177
  19. data/docs/anatomy.md +0 -203
  20. data/docs/building-blocks.md +0 -275
  21. data/docs/examples/cloudformation/components/base.rb +0 -25
  22. data/docs/examples/cloudformation/dynamics/elb.rb +0 -23
  23. data/docs/examples/cloudformation/templates/website.rb +0 -30
  24. data/docs/examples/template_json/website.json +0 -88
  25. data/docs/examples/website.rb +0 -74
  26. data/docs/functions.md +0 -41
  27. data/docs/properties.md +0 -32
  28. data/docs/provisioning.md +0 -82
  29. data/docs/resource-reference.md +0 -49
  30. data/examples/allinone/cloudformation/ec2_example.rb +0 -59
  31. data/examples/allinone/parse.rb +0 -14
  32. data/examples/ami_component/cloudformation/components/ami.rb +0 -21
  33. data/examples/ami_component/cloudformation/ec2_example.rb +0 -39
  34. data/examples/ami_component/parse.rb +0 -14
  35. data/test/spec.rb +0 -6
  36. data/test/specs/attribute.rb +0 -72
  37. data/test/specs/basic.rb +0 -76
  38. data/test/specs/cloudformation/components/ami.rb +0 -14
  39. data/test/specs/cloudformation/dynamics/node.rb +0 -16
  40. data/test/specs/results/base.json +0 -43
  41. data/test/specs/results/base_with_map.json +0 -50
  42. data/test/specs/results/component.json +0 -27
data/bin/aws_resources DELETED
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'json'
4
- require 'nokogiri'
5
- require 'fileutils'
6
-
7
- STORE = '/tmp/aws-cfn-docs'
8
-
9
- unless(File.directory?(STORE))
10
- FileUtils.mkdir_p(STORE)
11
- Dir.chdir(STORE) do
12
- unless(system('wget -q -r -l 1 -A "aws-*" "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html"'))
13
- puts "FAILED: Documentation fetching failed!"
14
- exit -1
15
- end
16
- end
17
- end
18
-
19
- aws_resources = {}
20
-
21
- Dir.glob(File.join(STORE, '**/*.html')).each do |path|
22
- resource = nil
23
- begin
24
- file = Nokogiri::HTML(File.open(path, 'r'))
25
- type = file.css('h1.topictitle').text.strip
26
- if(type.include?(' '))
27
- next
28
- end
29
- resource = file.css('div.variablelist').first
30
- if(resource)
31
- names = resource.css('dt').css('span').map(&:text).map(&:strip)
32
- types = resource.css('dd p').map(&:text).find_all do |x|
33
- x.include?('Type')
34
- end.map do |x|
35
- if(x.downcase.match(/(\s|^)list(\s|$)/))
36
- 'Array'
37
- elsif(x.include?('Type: String'))
38
- 'String'
39
- elsif(x.include?('Type: Boolean'))
40
- 'Boolean'
41
- elsif(x.include?('Type: Integer'))
42
- 'Number'
43
- elsif(x.include?('Type:') && x.include?('JSON') && x.include?('document'))
44
- 'JSON'
45
- else
46
- 'Unknown'
47
- end
48
- end
49
- requires = resource.css('dd p').map(&:text).find_all do |x|
50
- x.include?('Required:')
51
- end.map do |x|
52
- x.include?('No') ? false : true
53
- end
54
- descriptions = resource.css('dd').map do |dd|
55
- dd.css('p').first.text.strip
56
- end.map do |string|
57
- string.split("\n").map(&:strip).join(' ')
58
- end
59
- property_hashes = names.size.times.map do |i|
60
- [names[i], {:description => descriptions[i], :required => requires[i], :type => types[i]}]
61
- end
62
- aws_resources[type] = {
63
- :properties => names,
64
- :full_properties => Hash[property_hashes]
65
- }
66
- else
67
- resource = file.css('div.informaltable')
68
- if(resource)
69
- aws_resources[type] = {
70
- :properties => resource.css('tr').map{|tr|
71
- item = tr.css('td').first
72
- item ? item.text.strip : nil
73
- }.compact
74
- }
75
- else
76
- next
77
- end
78
- end
79
- aws_resources[type][:path] = File.basename(path)
80
- end
81
- end
82
-
83
- require 'pp'
84
-
85
- pp aws_resources
data/bin/heat_resources DELETED
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'json'
4
- require 'nokogiri'
5
- require 'fileutils'
6
-
7
- STORE = '/tmp/openstack-heat-docs'
8
-
9
- unless(File.directory?(STORE))
10
- FileUtils.mkdir_p(STORE)
11
- Dir.chdir(STORE) do
12
- unless(system('wget -q "http://docs.openstack.org/developer/heat/template_guide/openstack.html"'))
13
- puts "FAILED: Documentation fetching failed!"
14
- exit -1
15
- end
16
- end
17
- end
18
-
19
- file = Nokogiri::HTML(File.open(File.join(STORE, 'openstack.html'), 'r'))
20
-
21
- resources = Hash[
22
- file.css('div.section[id*="json"]').css('pre.literal-block').map do |node|
23
- [
24
- node.text.scan(/Type":.*"(.+?)"/).flatten.first,
25
- node.text.scan(/Properties.*?\{(.+)$/m).flatten.first.
26
- strip.split("\n").map{|z| z.split(' ')}.flatten.find_all{|z| !z.scan(/^[A-Za-z0-9_"]+:$/).empty?}.map{|z| z.tr('":', '')}
27
- ]
28
- end
29
- ]
30
-
31
- require 'pp'
32
-
33
- pp resources
data/docs/README.md DELETED
@@ -1,177 +0,0 @@
1
- ## Overview
2
- SparkleFormation is a Ruby DSL for programatically composing
3
- [AWS Cloudformation][cloudformation], [OpenStack Heat][heat]
4
- provisioning templates for the purpose of interacting with cloud
5
- infrastructure orchestration APIs.
6
-
7
- SparkleFormation templates describe the creation and configuration of
8
- collections of cloud resources (a stack) as code, allowing you to
9
- provision stacks in a predictable and repeatable manner. Stacks can be
10
- managed as single unit, allowing you to create, modify, or delete
11
- collections of resources via a single API call.
12
-
13
- SparkleFormation composes templates in the native cloud orchestration
14
- formats for AWS, Rackspace, Google Compute, and similar services.
15
-
16
- ## Table of Contents
17
-
18
- - [Getting Started](#getting-started)
19
- - [What It Looks Like](#what-it-looks-like)
20
- - [Building Blocks](building-blocks.md)
21
- - [Components](building-blocks.md#components)
22
- - [Dynamics](building-blocks.md#dynamics)
23
- - [Registries](building-blocks.md#registries)
24
- - [Template Anatomy](anatomy.md)
25
- - [Parameters](anatomy.md#parameters)
26
- - [Resources](anatomy.md#resources)
27
- - [Mappings](anatomy.md#mappings)
28
- - [Outputs](anatomy.md#outputs)
29
- - [Intrinsic Functions](functions.md)
30
- - [Ref](functions.md#ref)
31
- - [Attr](functions.md#attr)
32
- - [Join](functions.md#join)
33
- - [Universal Properties](properties.md)
34
- - [Tags](properties.md#tags)
35
-
36
- ## Getting Started
37
- ### Gemfile
38
- SparkleFormation is in active development. To access all the features
39
- detailed in the documentation (using the knife plugin CLI), you should
40
- install the plugin and supporting libraries from git:
41
-
42
- ```ruby
43
- gem 'fog', :git => 'https://github.com/chrisroberts/fog.git', :ref => 'feature/orchestration'
44
- gem 'fog-core', :git => 'https://github.com/chrisroberts/fog-core.git', :ref => 'feature/orchestration'
45
- gem 'knife-cloudformation', :git => 'https://github.com/heavywater/knife-cloudformation.git', :ref => 'feature/fog-model'
46
- ```
47
-
48
- The Knife Cloudformation gem is only needed for stack provisioning via
49
- knife. You could also upload SparkleFormation generated templates to AWS via the WebUI.
50
-
51
- ### Knife Config
52
- To use Knife for provisioning, you will need to add the following to
53
- your `knife.rb` file:
54
-
55
- ```ruby
56
- knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
57
- knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
58
-
59
- [:cloudformation, :options].inject(knife){ |m,k| m[k] ||= Mash.new }
60
- knife[:cloudformation][:options][:disable_rollback] = ENV['AWS_CFN_DISABLE_ROLLBACK'].to_s.downcase == 'true'
61
- knife[:cloudformation][:options][:capabilities] = ['CAPABILITY_IAM']
62
- knife[:cloudformation][:processing] = true
63
- knife[:cloudformation][:credentials] = {
64
- :aws_access_key_id => knife[:aws_access_key_id],
65
- :aws_secret_access_key => knife[:aws_secret_access_key]
66
- }
67
- ```
68
-
69
- | Attribute | Function |
70
- |--------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
71
- | `[:cloudformation][:options][:disable_rollback]` | Disables rollback if stack is unsuccessful. Useful for debugging. |
72
- | `[:cloudformation][:credentials]` | Credentials for a user that is allowed to create stacks. |
73
- | `[:cloudformation][:options][:capabilities]` | Enables IAM creation (AWS only). Options are `nil` or `['CAPABILITY_IAM']` |
74
- | `[:cloudformation][:processing]` | Enables processing SparkleFormation templates (otherwise knife cloudformation will expect a JSON CFN template. |
75
-
76
- ## What it Looks Like
77
- Below is a basic SparkleFormation template which would provision an
78
- elastic load balancer forwarding port 80 to an autoscaling group of
79
- ec2 instances.
80
-
81
- ```ruby
82
- SparkleFormation.new('website') do
83
-
84
- set!('AWSTemplateFormatVersion', '2010-09-09')
85
-
86
- description 'Supercool Website'
87
-
88
- resources.cfn_user do
89
- type 'AWS::IAM::User'
90
- properties.path '/'
91
- properties.policies _array(
92
- -> {
93
- policy_name 'cfn_access'
94
- policy_document.statement _array(
95
- -> {
96
- effect 'Allow'
97
- action 'cloudformation:DescribeStackResource'
98
- resource '*'
99
- }
100
- )
101
- }
102
- )
103
- end
104
-
105
- resources.cfn_keys do
106
- type 'AWS::IAM::AccessKey'
107
- properties.user_name ref!(:cfn_user)
108
- end
109
-
110
- parameters.web_nodes do
111
- type 'Number'
112
- description 'Number of web nodes for ASG.'
113
- default 2
114
- end
115
-
116
- resources.website_autoscale do
117
- type 'AWS::AutoScaling::AutoScalingGroup'
118
- properties do
119
- availability_zones({'Fn::GetAZs' => ''})
120
- launch_configuration_name ref!(:website_launch_config)
121
- min_size ref!(:web_nodes)
122
- max_size ref!(:web_nodes)
123
- end
124
- end
125
-
126
- resources.website_launch_config do
127
- type 'AWS::AutoScaling::LaunchConfiguration'
128
- properties do
129
- image_id 'ami-123456'
130
- instance_type 'm3.medium'
131
- end
132
- end
133
-
134
- resources.website_elb do
135
- type 'AWS::ElasticLoadBalancing::LoadBalancer'
136
- properties do
137
- availability_zones._set('Fn::GetAZs', '')
138
- listeners _array(
139
- -> {
140
- load_balancer_port '80'
141
- protocol 'HTTP'
142
- instance_port '80'
143
- instance_protocol 'HTTP'
144
- }
145
- )
146
- health_check do
147
- target 'HTTP:80/'
148
- healthy_threshold '3'
149
- unhealthy_threshold '3'
150
- interval '5'
151
- timeout '15'
152
- end
153
- end
154
- end
155
- end
156
- ```
157
-
158
- This template is 74 lines long (with generous spacing for
159
- readability). The [json template this
160
- renders](examples/template_json/website.json) is 88 lines, without
161
- spacing). This can be improved, though. SparkleFormation allows you to
162
- create resusable files such that the above template can become :
163
-
164
- ```ruby
165
- SparkleFormation.new(:website).load(:base).overrides do
166
-
167
- description 'Supercool Website'
168
-
169
- dynamic!(:autoscale, 'website', :nodes => 2)
170
- dynamic!(:launch_config, 'website', :image_id => 'ami-123456', :instance_type => 'm3.medium')
171
- dynamic!(:elb, 'website')
172
-
173
- end
174
- ```
175
-
176
- [cloudformation]: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html
177
- [heat]: http://docs.openstack.org/developer/heat/template_guide/index.html
data/docs/anatomy.md DELETED
@@ -1,203 +0,0 @@
1
- ## Template Anatomy
2
-
3
- ### Parameters
4
- Parameters are prompts for stack specific values. A default may be
5
- specified, but is not required. Every parameter must have a value at runtime.
6
-
7
- In the Getting Started example we had one parameter, `web_nodes` which
8
- set the min and max for the autoscaling group:
9
-
10
- ```ruby
11
- parameters.web_nodes do
12
- type 'Number'
13
- description 'Number of web nodes for ASG.'
14
- default 2
15
- end
16
- ```
17
-
18
- Every parameter must have a type and a description. Available types are `String`,
19
- `Number` (an integer), and `CommaDelimitedList` (an array of
20
- strings, as-in: `['alpha', 'beta', '1', 2']`). The descriptions is a
21
- string describing the resource.
22
-
23
- Parameters support optional default values, declared as
24
- above. An array of accepted values may be set, as well:
25
-
26
- ```ruby
27
- parameters.web_nodes do
28
- type 'Number'
29
- description 'Number of web nodes for ASG.'
30
- default 2
31
- allowed_values [1, 2, 3, 5]
32
- end
33
- ```
34
-
35
- ### Resources
36
- Resources are the infrastructure resources that are provisioned with
37
- the stack. Every resource must have a type that corresponds to a
38
- supported cloud resource. Resources typically have a properties hash
39
- that configures the resource. Some resources also have metadata. For
40
- the complete list of required and optional options, see the
41
- individual resource documentation.
42
-
43
- Resource availability is not consistent across
44
- providers. SparkleFormation's resources support is based on AWS, and
45
- not all resources will be available on other platforms. See the
46
- [resource reference](resource-reference.md) table for more information.
47
-
48
- The prior example included the following resources:
49
- - cfn_user: The IAM user for the stack, which will be used to
50
- provision stack resources.
51
-
52
- ```ruby
53
- resources.cfn_user do
54
- type 'AWS::IAM::User'
55
- properties.path '/'
56
- properties.policies _array(
57
- -> {
58
- policy_name 'cfn_access'
59
- policy_document.statement _array(
60
- -> {
61
- effect 'Allow'
62
- action 'cloudformation:DescribeStackResource'
63
- resource '*'
64
- }
65
- )
66
- }
67
- )
68
- end
69
- ```
70
-
71
- - cfn_key: The IAM keys for the stack IAM user.
72
-
73
- ```ruby
74
- resources.cfn_keys do
75
- type 'AWS::IAM::AccessKey'
76
- properties.user_name ref!(:cfn_user)
77
- end
78
- ```
79
-
80
- - website_asg: The autoscaling group containing website nodes. The
81
- size of the autoscaling group is set to the value of the web_nodes
82
- parameter.
83
-
84
- ```ruby
85
- resources.website_autoscale do
86
- type 'AWS::AutoScaling::AutoScalingGroup'
87
- properties do
88
- availability_zones({'Fn::GetAZs' => ''})
89
- launch_configuration_name ref!(:website_launch_config)
90
- min_size ref!(:web_nodes)
91
- max_size ref!(:web_nodes)
92
- end
93
- end
94
- ```
95
-
96
- - website_launch_configuration: The launch configuration for
97
- website_asg nodes. The AMI image ID and instance type (size) are
98
- required.
99
-
100
- ```ruby
101
- resources.website_launch_config do
102
- type 'AWS::AutoScaling::LaunchConfiguration'
103
- properties do
104
- image_id 'ami-123456'
105
- instance_type 'm3.medium'
106
- end
107
- end
108
- ```
109
-
110
- - website_elb: The elastic load balancer for the website. The
111
- listeners array configures port forwarding. The health check
112
- configures the load balancer health check target and thresholds.
113
-
114
- ```ruby
115
- resources.website_elb do
116
- type 'AWS::ElasticLoadBalancing::LoadBalancer'
117
- properties do
118
- availability_zones._set('Fn::GetAZs', '')
119
- listeners _array(
120
- -> {
121
- load_balancer_port '80'
122
- protocol 'HTTP'
123
- instance_port '80'
124
- instance_protocol 'HTTP'
125
- }
126
- )
127
- health_check do
128
- target 'HTTP:80/'
129
- healthy_threshold '3'
130
- unhealthy_threshold '3'
131
- interval '5'
132
- timeout '15'
133
- end
134
- end
135
- end
136
- ```
137
-
138
- ### Mappings
139
- Mappings allow you to create key/value pairs which can be referenced
140
- at runtime. This is useful for things like an image id that differs
141
- by region or environment.
142
-
143
- Mappings for the 2014.09 Amazon Linux PV Instance Store 64-bit AMIs
144
- for each US region:
145
-
146
- ```ruby
147
- mappings.region_map do
148
- set!('us-east-1', :ami => 'ami-8e852ce6')
149
- set!('us-west-1', :ami => 'ami-03a8a146')
150
- set!('us-west-2', :ami => 'ami-f786c6c7')
151
- end
152
- ```
153
-
154
- These can be referenced, in turn, with the following:
155
-
156
- ```ruby
157
- map!(:region_map, ref!('AWS::Region'), :ami)
158
- ```
159
-
160
- 'AWS::Region' is a psuedo parameter. We could also perform a lookup
161
- based on a parameter we provide, e.g. an instance size based on the environment:
162
-
163
- ```ruby
164
- parameters.environment do
165
- type 'String'
166
- allowed_values ['development', 'staging', 'production']
167
- end
168
-
169
- mappings.instance_size do
170
- set!('development', :instance => 'm3.small')
171
- set!('staging', :instance => 'm3.medium')
172
- set!('production', :instance => 'm3.large')
173
- end
174
-
175
- resources.website_launch_config do
176
- type 'AWS::AutoScaling::LaunchConfiguration'
177
- properties do
178
- image_id map!(:region_map, 'AWS::Region', :ami)
179
- instance_type map!(:instance_size, ref!(:environment), :instance)
180
- end
181
- end
182
- ```
183
-
184
- ### Outputs
185
- Outputs provide metadata for the stack, as key/value pairs within an
186
- outputs block. Note that this block lives outside the resource
187
- blocks. This will retrieve the DNSName attribute for our load
188
- balancer, and provide it as a value for an 'Elb Dns' output:
189
-
190
- ```ruby
191
- outputs do
192
- elb_dns do
193
- value attr!(:website_elb, 'DNSName')
194
- description "Website ELB DNS name"
195
- end
196
- end
197
- ```
198
-
199
- Outputs are not simply informational. You can interact with them
200
- during [provisioning](provisioning.md#knife-cloudformation) using the [knife-cloudformation
201
- plugin](https://rubygems.org/gems/knife-cloudformation).
202
-
203
-