topo-provision 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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +100 -0
  4. data/bin/topo-provision +23 -0
  5. data/lib/topo/converter.rb +80 -0
  6. data/lib/topo/converter/cloudformation/converter.rb +219 -0
  7. data/lib/topo/exporter.rb +15 -0
  8. data/lib/topo/loader.rb +31 -0
  9. data/lib/topo/provision.rb +3 -0
  10. data/lib/topo/provision/aws/generator.rb +55 -0
  11. data/lib/topo/provision/aws/generators/aws_auto_scaling_group.rb +61 -0
  12. data/lib/topo/provision/aws/generators/aws_launch_configuration.rb +65 -0
  13. data/lib/topo/provision/aws/generators/context.rb +33 -0
  14. data/lib/topo/provision/aws/generators/load_balancer.rb +47 -0
  15. data/lib/topo/provision/aws/generators/machine.rb +36 -0
  16. data/lib/topo/provision/aws/generators/machine_image.rb +38 -0
  17. data/lib/topo/provision/aws/generators/node_group.rb +64 -0
  18. data/lib/topo/provision/cli.rb +95 -0
  19. data/lib/topo/provision/generator.rb +185 -0
  20. data/lib/topo/provision/generators/chef_node.rb +35 -0
  21. data/lib/topo/provision/generators/context.rb +70 -0
  22. data/lib/topo/provision/generators/load_balancer.rb +40 -0
  23. data/lib/topo/provision/generators/machine.rb +50 -0
  24. data/lib/topo/provision/generators/machine_image.rb +43 -0
  25. data/lib/topo/provision/generators/node_group.rb +74 -0
  26. data/lib/topo/provision/generators/resource.rb +91 -0
  27. data/lib/topo/provision/generators/templates/context.erb +8 -0
  28. data/lib/topo/provision/generators/templates/machine_deploy.erb +11 -0
  29. data/lib/topo/provision/generators/templates/machine_stop.erb +5 -0
  30. data/lib/topo/provision/generators/templates/node_group_action.erb +6 -0
  31. data/lib/topo/provision/generators/templates/node_group_deploy.erb +5 -0
  32. data/lib/topo/provision/generators/templates/resource_deploy.erb +5 -0
  33. data/lib/topo/provision/generators/templates/resource_undeploy.erb +5 -0
  34. data/lib/topo/provision/topology_generator.rb +84 -0
  35. data/lib/topo/provision/vagrant/generator.rb +33 -0
  36. data/lib/topo/provision/version.rb +5 -0
  37. data/lib/topo/topology.rb +61 -0
  38. data/lib/topo/utils/output.rb +31 -0
  39. data/lib/topo/utils/parsegen.rb +101 -0
  40. metadata +126 -0
@@ -0,0 +1,15 @@
1
+
2
+ module Topo
3
+ class Exporter
4
+
5
+
6
+ def self.to_file(file, topo)
7
+
8
+ begin
9
+ File.open(file, 'w') { |f| f.write(JSON.pretty_generate(topo)) }
10
+ rescue
11
+ STDERR.puts "ERROR: Cannot write to topology export file #{f}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require "topo/converter"
2
+ require "topo/topology"
3
+
4
+ module Topo
5
+ class Loader
6
+
7
+
8
+ def self.from_file(file, format='default')
9
+
10
+ unless File.file?(file)
11
+ STDERR.puts "ERROR: #{file} is not the name of a valid file."
12
+ exit(-1)
13
+ end
14
+
15
+ begin
16
+ data = JSON.parse(File.read(file))
17
+ filename = File.basename(file)
18
+ index = filename.rindex('.') || -1
19
+ index -= 1 unless index == -1
20
+ data['name'] = filename[0..index] unless data['name']
21
+ rescue JSON::ParserError => e
22
+ STDERR.puts e.message
23
+ STDERR.puts "ERROR: Parsing error in #{file}."
24
+ exit(-1)
25
+ end
26
+
27
+ Topo::Topology.new(Topo::Converter.convert(data, format))
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ require "topo/provision/version"
2
+ require "topo/loader"
3
+ require "topo/provision/generator"
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generator'
20
+
21
+ # load the resource generators
22
+ %w[aws_auto_scaling_group aws_launch_configuration load_balancer machine machine_image context node_group].each do |gen|
23
+ require_relative 'generators/' + gen
24
+ end
25
+
26
+ module Topo
27
+ module Provision
28
+ class AwsGenerator < Topo::Provision::Generator
29
+
30
+ self.register_generator("aws", self.name)
31
+
32
+ def context()
33
+ @context ||= Topo::Provision::AwsContextGenerator.new(@topology.provisioning, @topology.driver)
34
+ end
35
+
36
+ def node(data)
37
+ if (data['provisioning'])
38
+ if(data['provisioning']['node_group'])
39
+ node = Topo::Provision::AwsNodeGroupGenerator.new(data)
40
+ else
41
+ node = Topo::Provision::AwsMachineGenerator.new(data)
42
+ end
43
+ else
44
+ node = Topo::Provision::ChefNodeGenerator.new(data)
45
+ end
46
+ node
47
+ end
48
+
49
+ def load_balancer(data)
50
+ Topo::Provision::AwsLoadBalancerGenerator.new(data)
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,61 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ module Topo
22
+ module Provision
23
+ class AwsAutoScalingGroupGenerator < Topo::Provision::ResourceGenerator
24
+ extend Topo::ParseGen
25
+
26
+ def initialize(data)
27
+ @resource_type ||= "aws_auto_scaling_group"
28
+ super
29
+ %w[launch_configuration max_size min_size desired_capacity availability_zones load_balancers options].each do |key|
30
+ @resource_attributes[key] = data[key] if data.key? key
31
+ end
32
+ end
33
+
34
+ def self.from_node(node)
35
+ auto_scaling = value_from_path(node, %w[provisioning node_group auto_scaling]) || {}
36
+
37
+ group_data = {
38
+ "name" => auto_scaling['group_name'] || node['name'] + "_group",
39
+ "launch_configuration" => auto_scaling['launch_configuration'] || node['name'] + "_config"
40
+ }
41
+
42
+ %w[max_size min_size desired_capacity availability_zones load_balancers].each do |key|
43
+ group_data[key] = auto_scaling[key] if auto_scaling.key? key
44
+ end
45
+
46
+ options = auto_scaling['group_options']
47
+ if options
48
+ # we also need to convert some of the field values in options, and then all of the keys
49
+ %w[health_check_type].each do |key|
50
+ options[key] = options[key].to_sym if options.key? key
51
+ end
52
+ group_data['options'] = convert_keys_to_sym_deep(options)
53
+ end
54
+
55
+ self.new(group_data)
56
+ end
57
+
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ module Topo
22
+ module Provision
23
+ class AwsLaunchConfigurationGenerator < Topo::Provision::ResourceGenerator
24
+ extend Topo::ParseGen
25
+
26
+ def initialize(data, image_id=nil)
27
+ @resource_type ||= "aws_launch_configuration"
28
+ super(data)
29
+ @image_id = image_id || value_from_path(data, %w[options image_id])
30
+
31
+ %w[image instance_type options].each do |key|
32
+ @resource_attributes[key] = data[key] if data.key? key
33
+ end
34
+ end
35
+
36
+ def needs_image?
37
+ @image_id.nil?
38
+ end
39
+
40
+ def self.from_node(node)
41
+ auto_scaling = value_from_path(node, %w[provisioning node_group auto_scaling]) || {}
42
+ options = auto_scaling['launch_configuration_options']
43
+ bootstrap_options = value_from_path(node, %w[provisioning machine_options bootstrap_options])
44
+ options ||= bootstrap_options
45
+ image_id = options['image_id']
46
+ options.delete('image_id')
47
+
48
+ lc_data = {
49
+ "name" => auto_scaling['launch_configuration_name'] || node['name'] + "_config",
50
+ "image" => image_id || auto_scaling['image'] || node['name'] + "_image"
51
+ }
52
+
53
+ %w[instance_type].each do |key|
54
+ lc_data[key] = auto_scaling[key] if auto_scaling.key? key
55
+ end
56
+
57
+ if options
58
+ lc_data['options'] = convert_keys_to_sym_deep(options)
59
+ end
60
+
61
+ self.new(lc_data, image_id)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/context'
20
+
21
+
22
+ module Topo
23
+ module Provision
24
+
25
+ class AwsContextGenerator < Topo::Provision::ContextGenerator
26
+ def initialize(data, default_driver)
27
+ super
28
+ @machine_options = convert_keys_to_sym_deep(@machine_options) if @machine_options
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ module Topo
22
+ module Provision
23
+
24
+ class AwsLoadBalancerGenerator < Topo::Provision::LoadBalancerGenerator
25
+
26
+ def initialize(data)
27
+ super
28
+ @undeploy_action = "destroy"
29
+ %w[machines].each do |key|
30
+ @resource_attributes[key] = data['provisioning'][key] if data['provisioning'].key? key
31
+ end
32
+
33
+ lbopts = (data['provisioning']|| {})['load_balancer_options']
34
+ if(lbopts)
35
+ lbopts = convert_keys_to_sym_deep(lbopts)
36
+ if (lbopts[:listeners])
37
+ lbopts[:listeners].each_with_index do |listener, index|
38
+ lbopts[:listeners][index] = convert_keys_to_sym(listener)
39
+ end
40
+ end
41
+ @resource_attributes['load_balancer_options'] = lbopts
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ #
22
+ # The ResourceGenerator class generates the recipe resources
23
+ #
24
+
25
+ module Topo
26
+ module Provision
27
+ class AwsMachineGenerator < Topo::Provision::MachineGenerator
28
+
29
+ def initialize(data)
30
+ super
31
+ @machine_options = convert_keys_to_sym_deep(@machine_options) if @machine_options
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ #
22
+ # The ResourceGenerator class generates the recipe resources
23
+ #
24
+
25
+ module Topo
26
+ module Provision
27
+ class AwsMachineImageGenerator < Topo::Provision::MachineImageGenerator
28
+
29
+ def initialize(data)
30
+ super
31
+ opts = @resource_attributes['image_options']
32
+ @resource_attributes['image_options'] = convert_keys_to_sym_deep(opts) if opts
33
+ @machine_options = convert_keys_to_sym_deep(@machine_options) if @machine_options
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
3
+ # Copyright:: Copyright (c) 2015 ThirdWave Insights LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'topo/provision/generators/resource'
20
+
21
+ #
22
+ # The NodeGroupGenerator class generates multiple resources depending on the node data
23
+ #
24
+
25
+ module Topo
26
+ module Provision
27
+ class AwsNodeGroupGenerator < Topo::Provision::ResourceGenerator
28
+
29
+ def initialize(data)
30
+ super
31
+ @resources=[]
32
+ launch_config = Topo::Provision::AwsLaunchConfigurationGenerator.from_node(data)
33
+ @resources << Topo::Provision::AwsMachineImageGenerator.new(data) if launch_config.needs_image?
34
+ @resources << launch_config
35
+ @resources << Topo::Provision::AwsAutoScalingGroupGenerator.from_node(data)
36
+ end
37
+
38
+ def deploy()
39
+ @resources.each do |resource|
40
+ resource.do_action("deploy")
41
+ end
42
+ end
43
+
44
+ def undeploy()
45
+ @resources.reverse.each do |resource|
46
+ resource.do_action("undeploy")
47
+ end
48
+ end
49
+
50
+ def stop()
51
+ @resources.reverse.each do |resource|
52
+ resource.do_action("stop")
53
+ end
54
+ end
55
+
56
+ def default_action(action)
57
+ @resources.each do |resource|
58
+ resource.do_action(action)
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end