stackmate 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGELOG.txt +7 -0
  2. data/README.md +25 -8
  3. data/bin/stackmate.rb +57 -53
  4. data/lib/stackmate/aws_attribs.rb +31 -31
  5. data/lib/stackmate/classmap.rb +33 -25
  6. data/lib/stackmate/client.rb +80 -0
  7. data/lib/stackmate/intrinsic_functions.rb +94 -38
  8. data/lib/stackmate/logging.rb +19 -19
  9. data/lib/stackmate/participants/cloudstack.rb +250 -165
  10. data/lib/stackmate/participants/cloudstack_affinitygroup.rb +122 -0
  11. data/lib/stackmate/participants/cloudstack_autoscalepolicy.rb +113 -0
  12. data/lib/stackmate/participants/cloudstack_autoscalevmgroup.rb +86 -0
  13. data/lib/stackmate/participants/cloudstack_autoscalevmprofile.rb +140 -0
  14. data/lib/stackmate/participants/cloudstack_condition.rb +122 -0
  15. data/lib/stackmate/participants/cloudstack_egressfirewallrule.rb +149 -0
  16. data/lib/stackmate/participants/cloudstack_firewallrule.rb +149 -0
  17. data/lib/stackmate/participants/cloudstack_globalloadbalancerrule.rb +158 -0
  18. data/lib/stackmate/participants/cloudstack_instancegroup.rb +113 -0
  19. data/lib/stackmate/participants/cloudstack_ipaddress.rb +149 -0
  20. data/lib/stackmate/participants/cloudstack_ipforwardingrule.rb +131 -0
  21. data/lib/stackmate/participants/cloudstack_iptonic.rb +95 -0
  22. data/lib/stackmate/participants/cloudstack_iso.rb +95 -0
  23. data/lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb +140 -0
  24. data/lib/stackmate/participants/cloudstack_lbstickinesspolicy.rb +122 -0
  25. data/lib/stackmate/participants/cloudstack_loadbalancer.rb +158 -0
  26. data/lib/stackmate/participants/cloudstack_loadbalancerrule.rb +185 -0
  27. data/lib/stackmate/participants/cloudstack_network.rb +293 -0
  28. data/lib/stackmate/participants/cloudstack_networkacl.rb +176 -0
  29. data/lib/stackmate/participants/cloudstack_networkacllist.rb +104 -0
  30. data/lib/stackmate/participants/cloudstack_nictovirtualmachine.rb +104 -0
  31. data/lib/stackmate/participants/cloudstack_portforwardingrule.rb +176 -0
  32. data/lib/stackmate/participants/cloudstack_project.rb +113 -0
  33. data/lib/stackmate/participants/cloudstack_remoteaccessvpn.rb +122 -0
  34. data/lib/stackmate/participants/cloudstack_securitygroup.rb +122 -0
  35. data/lib/stackmate/participants/cloudstack_securitygroupegress.rb +185 -0
  36. data/lib/stackmate/participants/cloudstack_securitygroupingress.rb +185 -0
  37. data/lib/stackmate/participants/cloudstack_snapshot.rb +113 -0
  38. data/lib/stackmate/participants/cloudstack_snapshotpolicy.rb +122 -0
  39. data/lib/stackmate/participants/cloudstack_sshkeypair.rb +113 -0
  40. data/lib/stackmate/participants/cloudstack_staticnat.rb +113 -0
  41. data/lib/stackmate/participants/cloudstack_staticroute.rb +95 -0
  42. data/lib/stackmate/participants/cloudstack_tags.rb +113 -0
  43. data/lib/stackmate/participants/cloudstack_template.rb +212 -0
  44. data/lib/stackmate/participants/cloudstack_togloballoadbalancerrule.rb +104 -0
  45. data/lib/stackmate/participants/cloudstack_toloadbalancerrule.rb +95 -0
  46. data/lib/stackmate/participants/cloudstack_virtualmachine.rb +348 -0
  47. data/lib/stackmate/participants/cloudstack_virtualmachineops.rb +95 -0
  48. data/lib/stackmate/participants/cloudstack_vmsnapshot.rb +113 -0
  49. data/lib/stackmate/participants/cloudstack_volume.rb +176 -0
  50. data/lib/stackmate/participants/cloudstack_volumeops.rb +111 -0
  51. data/lib/stackmate/participants/cloudstack_vpc.rb +158 -0
  52. data/lib/stackmate/participants/cloudstack_vpnconnection.rb +95 -0
  53. data/lib/stackmate/participants/cloudstack_vpncustomergateway.rb +176 -0
  54. data/lib/stackmate/participants/cloudstack_vpngateway.rb +86 -0
  55. data/lib/stackmate/participants/cloudstack_vpnuser.rb +122 -0
  56. data/lib/stackmate/participants/common.rb +219 -70
  57. data/lib/stackmate/participants/stacknest.rb +6 -0
  58. data/lib/stackmate/resolver.rb +122 -0
  59. data/lib/stackmate/stack.rb +116 -60
  60. data/lib/stackmate/stack_executor.rb +99 -37
  61. data/lib/stackmate/stackpi.rb +46 -0
  62. data/lib/stackmate/version.rb +1 -1
  63. data/lib/stackmate/waitcondition_server.rb +15 -15
  64. data/lib/stackmate.rb +1 -1
  65. data/stackmate.gemspec +2 -4
  66. metadata +70 -19
@@ -6,60 +6,122 @@ require 'stackmate/classmap'
6
6
  require 'stackmate/participants/cloudstack'
7
7
  require 'stackmate/participants/common'
8
8
 
9
+ Dir[File.dirname(__FILE__) + "/participants/*.rb"].each do |participant|
10
+ if(participant.include?("cloudstack_"))
11
+ require participant
12
+ end
13
+ end
14
+
9
15
  module StackMate
10
16
 
11
- class StackExecutor < StackMate::Stacker
17
+ class StackExecutor < StackMate::Stacker
12
18
  include Logging
13
19
 
14
- def initialize(templatefile, stackname, params, engine, create_wait_conditions, api_opts)
15
- stackstr = File.read(templatefile)
16
- super(stackstr, stackname, resolve_param_refs(params, stackname))
17
- @engine = engine
18
- @create_wait_conditions = create_wait_conditions
19
- @api_opts = api_opts
20
+ def initialize(templatefile, stackname, params, engine, create_wait_conditions, api_opts, plugins=nil)
21
+ stackstr = File.read(templatefile)
22
+ super(stackstr, stackname, resolve_param_refs(params, stackname))
23
+ @engine = engine
24
+ @create_wait_conditions = create_wait_conditions
25
+ @api_opts = api_opts
26
+ load_plugins(plugins)
20
27
  end
21
28
 
29
+ def load_plugins(plugins)
30
+ if !plugins.nil?
31
+ dirs = plugins.split(",")
32
+ dirs.each do |dir|
33
+ if(File.directory?(dir))
34
+ Dir[dir+"/*.rb"].each do |file|
35
+ begin
36
+ existing_classes = ObjectSpace.each_object(Class).to_a
37
+ require file
38
+ new_classes = ObjectSpace.each_object(Class).to_a
39
+ added_classes = new_classes - existing_classes
40
+ added_classes.each do |plugin_class|
41
+ if(plugin_class.class_variable_defined?(:@@stackmate_participant) && plugin_class.class_variable_get(:@@stackmate_participant) == true)
42
+ if(not(plugin_class.method_defined?(:consume_workitem) && plugin_class.ancestors.include?(Ruote::Participant)))
43
+ #http://stackoverflow.com/questions/1901884/loading-unloading-updating-class-in-ruby
44
+ #recursively get class name
45
+ namespace = plugin_class.name.split('::')[0..-2]
46
+ klass = plugin_class.name.split('::')[-1]
47
+ parent = Object
48
+ namespace.each do |p|
49
+ parent = parent.const_get(p.to_sym)
50
+ end
51
+ logger.debug("Removing bad participant defninition #{plugin_class} from #{parent}")
52
+ parent.send(:remove_const,klass.to_sym)
53
+ else
54
+ logger.debug("Adding method on_workitem to class #{plugin_class}")
55
+ plugin_class.class_eval do
56
+ def on_workitem
57
+ consume_workitem
58
+ reply
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ rescue Exception => e
65
+ logger.error("Unable to load plugin #{file}. Dangling classes may exist!!")
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
22
72
  def resolve_param_refs(params, stackname)
23
- resolved_params = {}
73
+ resolved_params = {}
74
+ begin
24
75
  params.split(';').each do |p|
25
- i = p.split('=')
26
- resolved_params[i[0]] = i[1]
76
+ i = p.split('=')
77
+ resolved_params[i[0]] = i[1]
27
78
  end
28
- resolved_params['AWS::Region'] = 'us-east-1' #TODO handle this better
29
- resolved_params['AWS::StackName'] = stackname
30
- resolved_params['AWS::StackId'] = stackname
31
- resolved_params
79
+ rescue
80
+ #minimum parameters??
81
+ end
82
+ resolved_params['AWS::Region'] = 'us-east-1' #TODO handle this better
83
+ resolved_params['AWS::StackName'] = stackname
84
+ resolved_params['AWS::StackId'] = stackname
85
+ resolved_params
32
86
  end
33
87
 
34
88
  def pdef
35
- participants = self.strongly_connected_components.flatten
36
- #if we want to skip creating wait conditions (useful for automated tests)
37
- participants = participants.select { |p|
38
- StackMate.class_for(@templ['Resources'][p]['Type']) != 'StackMate::WaitCondition'
39
- } if !@create_wait_conditions
89
+ begin
90
+ #participants = self.strongly_connected_components.flatten
91
+ participants = self.tsort
92
+ rescue Exception => e
93
+ raise "ERROR: Cyclic Dependency detected! " + e.message
94
+ end
95
+ #if we want to skip creating wait conditions (useful for automated tests)
96
+ participants = participants.select { |p|
97
+ StackMate.class_for(@templ['Resources'][p]['Type']) != 'StackMate::WaitCondition'
98
+ } if !@create_wait_conditions
40
99
 
41
- logger.info("Ordered list of participants: #{participants}")
100
+ logger.info("Ordered list of participants: #{participants}")
42
101
 
43
- participants.each do |p|
44
- t = @templ['Resources'][p]['Type']
45
- throw :unknown, t if !StackMate.class_for(t)
46
- @engine.register_participant p, StackMate.class_for(t), @api_opts
47
- end
102
+ participants.each do |p|
103
+ t = @templ['Resources'][p]['Type']
104
+ throw :unknown, t if !StackMate.class_for(t)
105
+ @engine.register_participant p, StackMate.class_for(t), @api_opts
106
+ end
48
107
 
49
- @engine.register_participant 'Output', StackMate.class_for('Outputs')
50
- participants << 'Output'
51
- @pdef = Ruote.define @stackname.to_s() do
52
- cursor :timeout => '300s' do
53
- participants.collect{ |name| __send__(name) }
54
- end
108
+ @engine.register_participant 'Output', StackMate.class_for('Outputs')
109
+ @pdef = Ruote.define @stackname.to_s() do
110
+ cursor :timeout => '300s', :on_error => 'rollback', :on_timeout => 'rollback' do
111
+ participants.collect{ |name| __send__(name, :operation => :create) }
112
+ __send__('Output')
113
+ end
114
+ define 'rollback', :timeout => '300s' do
115
+ participants.reverse_each.collect {|name| __send__(name, :operation => :rollback) }
55
116
  end
117
+ end
56
118
  end
57
-
119
+
58
120
  def launch
59
- wfid = @engine.launch( pdef, @templ)
60
- @engine.wait_for(wfid)
61
- logger.error { "engine error : #{@engine.errors.first.message}"} if @engine.errors.first
121
+ wfid = @engine.launch( pdef, @templ)
122
+ @engine.wait_for(wfid, :timeout => 600)
123
+ logger.error { "engine error : #{@engine.errors.first.message}"} if @engine.errors.first
62
124
  end
63
- end
125
+ end
64
126
 
65
- end
127
+ end
@@ -0,0 +1,46 @@
1
+ require 'ruote'
2
+ require 'ruote/storage/hash_storage'
3
+ require 'optparse'
4
+ require 'stackmate'
5
+ require 'stackmate/classmap'
6
+ require 'stackmate/waitcondition_server'
7
+ #require 'stackmate/logging'
8
+ #API for creating stack
9
+ #TODO clean up repeated code
10
+
11
+ module StackMate
12
+ module StackPi
13
+ #class Create
14
+ #include Logging
15
+ def self.create_stack(file,stack_name,params,wait_conditions)
16
+ # Thread.new do
17
+ # StackMate::WaitConditionServer.run!
18
+ # end
19
+ engine = Ruote::Dashboard.new(
20
+ Ruote::Worker.new(
21
+ Ruote::HashStorage.new))
22
+ engine.noisy = ENV['NOISY'] == 'true'
23
+ engine.configure('wait_logger_timeout', 600)
24
+ # engine.on_error = Ruote.process_definition do
25
+ # p("Error : StackPi create stack for #{stack_name} failed!")
26
+ # end
27
+ unknown = nil
28
+ unresolved = catch(:unresolved) do
29
+ unknown = catch(:unknown) do
30
+ api_opts = {:APIKEY => "#{ENV['APIKEY']}", :SECKEY => "#{ENV['SECKEY']}", :URL => "#{ENV['URL']}" }
31
+ p = StackMate::StackExecutor.new(file,stack_name,params,engine,wait_conditions,api_opts)
32
+ p.launch()
33
+ nil
34
+ end
35
+ nil
36
+ end
37
+ puts 'Failed to resolve parameters ' + unresolved.to_s if unresolved
38
+ print "Sorry, I don't know how to create resources of type: ", unknown, "\n" if unknown
39
+ end
40
+
41
+ def self.delete_stack(file,stack_name,params,wait_conditions)
42
+
43
+ end
44
+ #end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module StackMate
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,26 +7,26 @@ require 'stackmate/participants/common'
7
7
 
8
8
  module StackMate
9
9
 
10
- class WaitConditionServer < Sinatra::Base
11
- set :static, false
12
- set :run, true
10
+ class WaitConditionServer < Sinatra::Base
11
+ set :static, false
12
+ set :run, true
13
13
 
14
- def initialize()
14
+ def initialize()
15
15
  super
16
- end
17
-
18
- put '/waitcondition/:wfeid/:waithandle' do
19
- #print "Got PUT of " , params[:wfeid], ", name = ", params[:waithandle], "\n"
20
- WaitCondition.get_conditions.each do |w|
21
- w.set_handle(params[:waithandle].to_s)
22
16
  end
23
- 'success
17
+
18
+ put '/waitcondition/:wfeid/:waithandle' do
19
+ #print "Got PUT of " , params[:wfeid], ", name = ", params[:waithandle], "\n"
20
+ WaitCondition.get_conditions.each do |w|
21
+ w.set_handle(params[:waithandle].to_s)
22
+ end
23
+ 'success
24
24
  '
25
- end
25
+ end
26
26
 
27
27
 
28
- run! if app_file == $0
28
+ run! if app_file == $0
29
29
 
30
- end
30
+ end
31
31
 
32
- end
32
+ end
data/lib/stackmate.rb CHANGED
@@ -2,4 +2,4 @@ require 'stackmate/stack'
2
2
  require 'stackmate/stack_executor'
3
3
  require 'stackmate/participants/common.rb'
4
4
  require 'stackmate/participants/cloudstack.rb'
5
- require 'stackmate/aws_attribs.rb'
5
+ require 'stackmate/aws_attribs.rb'
data/stackmate.gemspec CHANGED
@@ -19,14 +19,12 @@ Gem::Specification.new do |s|
19
19
  'https://github.com/chiradeep/stackmate'
20
20
  s.platform = Gem::Platform::RUBY
21
21
 
22
- #s.add_runtime_dependency 'ruby_parser', '~> 2.3'
23
- s.add_runtime_dependency 'cloudstack_ruby_client', '>= 0.0.4'
24
22
  s.add_runtime_dependency 'json'
25
23
  s.add_runtime_dependency 'ruote', '>= 2.3.0'
26
24
  s.add_runtime_dependency 'sinatra', '~> 1.3.6'
27
25
  s.add_runtime_dependency 'yajl-ruby', '= 1.1.0'
26
+ s.add_runtime_dependency 'netaddr'
28
27
 
29
- s.add_development_dependency 'json'
30
-
28
+ s.add_development_dependency 'rspec'
31
29
  s.require_path = 'lib'
32
30
  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.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: cloudstack_ruby_client
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 0.0.4
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 0.0.4
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: json
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +76,23 @@ dependencies:
92
76
  - !ruby/object:Gem::Version
93
77
  version: 1.1.0
94
78
  - !ruby/object:Gem::Dependency
95
- name: json
79
+ name: netaddr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -116,18 +116,69 @@ extra_rdoc_files: []
116
116
  files:
117
117
  - lib/stackmate/aws_attribs.rb
118
118
  - lib/stackmate/classmap.rb
119
+ - lib/stackmate/client.rb
119
120
  - lib/stackmate/intrinsic_functions.rb
120
121
  - lib/stackmate/logging.rb
121
122
  - lib/stackmate/participants/cloudstack.rb
123
+ - lib/stackmate/participants/cloudstack_affinitygroup.rb
124
+ - lib/stackmate/participants/cloudstack_autoscalepolicy.rb
125
+ - lib/stackmate/participants/cloudstack_autoscalevmgroup.rb
126
+ - lib/stackmate/participants/cloudstack_autoscalevmprofile.rb
127
+ - lib/stackmate/participants/cloudstack_condition.rb
128
+ - lib/stackmate/participants/cloudstack_egressfirewallrule.rb
129
+ - lib/stackmate/participants/cloudstack_firewallrule.rb
130
+ - lib/stackmate/participants/cloudstack_globalloadbalancerrule.rb
131
+ - lib/stackmate/participants/cloudstack_instancegroup.rb
132
+ - lib/stackmate/participants/cloudstack_ipaddress.rb
133
+ - lib/stackmate/participants/cloudstack_ipforwardingrule.rb
134
+ - lib/stackmate/participants/cloudstack_iptonic.rb
135
+ - lib/stackmate/participants/cloudstack_iso.rb
136
+ - lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb
137
+ - lib/stackmate/participants/cloudstack_lbstickinesspolicy.rb
138
+ - lib/stackmate/participants/cloudstack_loadbalancer.rb
139
+ - lib/stackmate/participants/cloudstack_loadbalancerrule.rb
140
+ - lib/stackmate/participants/cloudstack_network.rb
141
+ - lib/stackmate/participants/cloudstack_networkacl.rb
142
+ - lib/stackmate/participants/cloudstack_networkacllist.rb
143
+ - lib/stackmate/participants/cloudstack_nictovirtualmachine.rb
144
+ - lib/stackmate/participants/cloudstack_portforwardingrule.rb
145
+ - lib/stackmate/participants/cloudstack_project.rb
146
+ - lib/stackmate/participants/cloudstack_remoteaccessvpn.rb
147
+ - lib/stackmate/participants/cloudstack_securitygroup.rb
148
+ - lib/stackmate/participants/cloudstack_securitygroupegress.rb
149
+ - lib/stackmate/participants/cloudstack_securitygroupingress.rb
150
+ - lib/stackmate/participants/cloudstack_snapshot.rb
151
+ - lib/stackmate/participants/cloudstack_snapshotpolicy.rb
152
+ - lib/stackmate/participants/cloudstack_sshkeypair.rb
153
+ - lib/stackmate/participants/cloudstack_staticnat.rb
154
+ - lib/stackmate/participants/cloudstack_staticroute.rb
155
+ - lib/stackmate/participants/cloudstack_tags.rb
156
+ - lib/stackmate/participants/cloudstack_template.rb
157
+ - lib/stackmate/participants/cloudstack_togloballoadbalancerrule.rb
158
+ - lib/stackmate/participants/cloudstack_toloadbalancerrule.rb
159
+ - lib/stackmate/participants/cloudstack_virtualmachine.rb
160
+ - lib/stackmate/participants/cloudstack_virtualmachineops.rb
161
+ - lib/stackmate/participants/cloudstack_vmsnapshot.rb
162
+ - lib/stackmate/participants/cloudstack_volume.rb
163
+ - lib/stackmate/participants/cloudstack_volumeops.rb
164
+ - lib/stackmate/participants/cloudstack_vpc.rb
165
+ - lib/stackmate/participants/cloudstack_vpnconnection.rb
166
+ - lib/stackmate/participants/cloudstack_vpncustomergateway.rb
167
+ - lib/stackmate/participants/cloudstack_vpngateway.rb
168
+ - lib/stackmate/participants/cloudstack_vpnuser.rb
122
169
  - lib/stackmate/participants/common.rb
170
+ - lib/stackmate/participants/stacknest.rb
171
+ - lib/stackmate/resolver.rb
123
172
  - lib/stackmate/stack.rb
124
173
  - lib/stackmate/stack_executor.rb
174
+ - lib/stackmate/stackpi.rb
125
175
  - lib/stackmate/version.rb
126
176
  - lib/stackmate/waitcondition_server.rb
127
177
  - lib/stackmate.rb
128
178
  - bin/stackmate
129
179
  - bin/stackmate.rb
130
180
  - stackmate.gemspec
181
+ - CHANGELOG.txt
131
182
  - LICENSE.txt
132
183
  - README.md
133
184
  homepage: https://github.com/chiradeep/stackmate