stackmate 0.0.4 → 0.1.0

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 (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
@@ -0,0 +1,212 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackTemplate < CloudStackResource
5
+
6
+ include Logging
7
+ include Intrinsic
8
+ include Resolver
9
+ def create
10
+ logger.debug("Creating resource #{@name}")
11
+ workitem[@name] = {}
12
+ name_cs = workitem['StackName'] + '-' + @name
13
+ args={}
14
+ begin
15
+ args['displaytext'] = get_displaytext
16
+ args['ostypeid'] = get_ostypeid
17
+ args['name'] = workitem['StackName'] +'-' +get_name
18
+ args['snapshotid'] = get_snapshotid if @props.has_key?('snapshotid')
19
+ args['details'] = get_details if @props.has_key?('details')
20
+ args['virtualmachineid'] = get_virtualmachineid if @props.has_key?('virtualmachineid')
21
+ args['requireshvm'] = get_requireshvm if @props.has_key?('requireshvm')
22
+ args['ispublic'] = get_ispublic if @props.has_key?('ispublic')
23
+ args['volumeid'] = get_volumeid if @props.has_key?('volumeid')
24
+ args['bits'] = get_bits if @props.has_key?('bits')
25
+ args['url'] = get_url if @props.has_key?('url')
26
+ args['templatetag'] = get_templatetag if @props.has_key?('templatetag')
27
+ args['isdynamicallyscalable'] = get_isdynamicallyscalable if @props.has_key?('isdynamicallyscalable')
28
+ args['passwordenabled'] = get_passwordenabled if @props.has_key?('passwordenabled')
29
+ args['isfeatured'] = get_isfeatured if @props.has_key?('isfeatured')
30
+
31
+ logger.info("Creating resource #{@name} with following arguments")
32
+ p args
33
+ result_obj = make_async_request('createTemplate',args)
34
+ resource_obj = result_obj['Template'.downcase]
35
+ #doing it this way since it is easier to change later, rather than cloning whole object
36
+ resource_obj.each_key do |k|
37
+ val = resource_obj[k]
38
+ if('id'.eql?(k))
39
+ k = 'physical_id'
40
+ end
41
+ workitem[@name][k] = val
42
+ end
43
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"Template") if @props.has_key?('tags')
44
+ workitem['ResolvedNames'][@name] = name_cs
45
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
46
+
47
+ rescue NoMethodError => nme
48
+ logger.error("Create request failed for resource . Cleaning up the stack")
49
+ raise nme
50
+ rescue Exception => e
51
+ logger.error(e.message)
52
+ raise e
53
+ end
54
+
55
+ end
56
+
57
+ def delete
58
+ logger.debug("Deleting resource #{@name}")
59
+ begin
60
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
61
+ if(!physical_id.nil?)
62
+ args = {'id' => physical_id
63
+ }
64
+ result_obj = make_async_request('deleteTemplate',args)
65
+ if (!(result_obj['error'] == true))
66
+ logger.info("Successfully deleted resource #{@name}")
67
+ else
68
+ logger.info("CloudStack error while deleting resource #{@name}")
69
+ end
70
+ else
71
+ logger.info("Resource not created in CloudStack. Skipping delete...")
72
+ end
73
+ rescue Exception => e
74
+ logger.error("Unable to delete resorce #{@name}")
75
+ end
76
+ end
77
+
78
+ def on_workitem
79
+ @name = workitem.participant_name
80
+ @props = workitem['Resources'][@name]['Properties']
81
+ @props.downcase_key
82
+ @resolved_names = workitem['ResolvedNames']
83
+ if workitem['params']['operation'] == 'create'
84
+ create
85
+ else
86
+ delete
87
+ end
88
+ reply
89
+ end
90
+
91
+ def get_displaytext
92
+ resolved_displaytext = get_resolved(@props["displaytext"],workitem)
93
+ if resolved_displaytext.nil? || !validate_param(resolved_displaytext,"string")
94
+ raise "Missing mandatory parameter displaytext for resource #{@name}"
95
+ end
96
+ resolved_displaytext
97
+ end
98
+
99
+ def get_ostypeid
100
+ resolved_ostypeid = get_resolved(@props["ostypeid"],workitem)
101
+ if resolved_ostypeid.nil? || !validate_param(resolved_ostypeid,"uuid")
102
+ raise "Missing mandatory parameter ostypeid for resource #{@name}"
103
+ end
104
+ resolved_ostypeid
105
+ end
106
+
107
+ def get_name
108
+ resolved_name = get_resolved(@props["name"],workitem)
109
+ if resolved_name.nil? || !validate_param(resolved_name,"string")
110
+ raise "Missing mandatory parameter name for resource #{@name}"
111
+ end
112
+ resolved_name
113
+ end
114
+
115
+ def get_snapshotid
116
+ resolved_snapshotid = get_resolved(@props['snapshotid'],workitem)
117
+ if resolved_snapshotid.nil? || !validate_param(resolved_snapshotid,"uuid")
118
+ raise "Malformed optional parameter snapshotid for resource #{@name}"
119
+ end
120
+ resolved_snapshotid
121
+ end
122
+
123
+ def get_details
124
+ resolved_details = get_resolved(@props['details'],workitem)
125
+ if resolved_details.nil? || !validate_param(resolved_details,"map")
126
+ raise "Malformed optional parameter details for resource #{@name}"
127
+ end
128
+ resolved_details
129
+ end
130
+
131
+ def get_virtualmachineid
132
+ resolved_virtualmachineid = get_resolved(@props['virtualmachineid'],workitem)
133
+ if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
134
+ raise "Malformed optional parameter virtualmachineid for resource #{@name}"
135
+ end
136
+ resolved_virtualmachineid
137
+ end
138
+
139
+ def get_requireshvm
140
+ resolved_requireshvm = get_resolved(@props['requireshvm'],workitem)
141
+ if resolved_requireshvm.nil? || !validate_param(resolved_requireshvm,"boolean")
142
+ raise "Malformed optional parameter requireshvm for resource #{@name}"
143
+ end
144
+ resolved_requireshvm
145
+ end
146
+
147
+ def get_ispublic
148
+ resolved_ispublic = get_resolved(@props['ispublic'],workitem)
149
+ if resolved_ispublic.nil? || !validate_param(resolved_ispublic,"boolean")
150
+ raise "Malformed optional parameter ispublic for resource #{@name}"
151
+ end
152
+ resolved_ispublic
153
+ end
154
+
155
+ def get_volumeid
156
+ resolved_volumeid = get_resolved(@props['volumeid'],workitem)
157
+ if resolved_volumeid.nil? || !validate_param(resolved_volumeid,"uuid")
158
+ raise "Malformed optional parameter volumeid for resource #{@name}"
159
+ end
160
+ resolved_volumeid
161
+ end
162
+
163
+ def get_bits
164
+ resolved_bits = get_resolved(@props['bits'],workitem)
165
+ if resolved_bits.nil? || !validate_param(resolved_bits,"integer")
166
+ raise "Malformed optional parameter bits for resource #{@name}"
167
+ end
168
+ resolved_bits
169
+ end
170
+
171
+ def get_url
172
+ resolved_url = get_resolved(@props['url'],workitem)
173
+ if resolved_url.nil? || !validate_param(resolved_url,"string")
174
+ raise "Malformed optional parameter url for resource #{@name}"
175
+ end
176
+ resolved_url
177
+ end
178
+
179
+ def get_templatetag
180
+ resolved_templatetag = get_resolved(@props['templatetag'],workitem)
181
+ if resolved_templatetag.nil? || !validate_param(resolved_templatetag,"string")
182
+ raise "Malformed optional parameter templatetag for resource #{@name}"
183
+ end
184
+ resolved_templatetag
185
+ end
186
+
187
+ def get_isdynamicallyscalable
188
+ resolved_isdynamicallyscalable = get_resolved(@props['isdynamicallyscalable'],workitem)
189
+ if resolved_isdynamicallyscalable.nil? || !validate_param(resolved_isdynamicallyscalable,"boolean")
190
+ raise "Malformed optional parameter isdynamicallyscalable for resource #{@name}"
191
+ end
192
+ resolved_isdynamicallyscalable
193
+ end
194
+
195
+ def get_passwordenabled
196
+ resolved_passwordenabled = get_resolved(@props['passwordenabled'],workitem)
197
+ if resolved_passwordenabled.nil? || !validate_param(resolved_passwordenabled,"boolean")
198
+ raise "Malformed optional parameter passwordenabled for resource #{@name}"
199
+ end
200
+ resolved_passwordenabled
201
+ end
202
+
203
+ def get_isfeatured
204
+ resolved_isfeatured = get_resolved(@props['isfeatured'],workitem)
205
+ if resolved_isfeatured.nil? || !validate_param(resolved_isfeatured,"boolean")
206
+ raise "Malformed optional parameter isfeatured for resource #{@name}"
207
+ end
208
+ resolved_isfeatured
209
+ end
210
+ end
211
+ end
212
+
@@ -0,0 +1,104 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackToGlobalLoadBalancerRule < CloudStackResource
5
+
6
+ include Logging
7
+ include Intrinsic
8
+ include Resolver
9
+ def create
10
+ logger.debug("Creating resource #{@name}")
11
+ workitem[@name] = {}
12
+ name_cs = workitem['StackName'] + '-' + @name
13
+ args={}
14
+ begin
15
+ args['id'] = get_id
16
+ args['loadbalancerrulelist'] = get_loadbalancerrulelist
17
+ args['gslblbruleweightsmap'] = get_gslblbruleweightsmap if @props.has_key?('gslblbruleweightsmap')
18
+
19
+ logger.info("Creating resource #{@name} with following arguments")
20
+ p args
21
+ result_obj = make_async_request('assignToGlobalLoadBalancerRule',args)
22
+ resource_obj = result_obj['ToGlobalLoadBalancerRule'.downcase]
23
+ #doing it this way since it is easier to change later, rather than cloning whole object
24
+ resource_obj.each_key do |k|
25
+ val = resource_obj[k]
26
+ if('id'.eql?(k))
27
+ k = 'physical_id'
28
+ end
29
+ workitem[@name][k] = val
30
+ end
31
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"ToGlobalLoadBalancerRule") if @props.has_key?('tags')
32
+ workitem['ResolvedNames'][@name] = name_cs
33
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
34
+
35
+ rescue NoMethodError => nme
36
+ logger.error("Create request failed for resource . Cleaning up the stack")
37
+ raise nme
38
+ rescue Exception => e
39
+ logger.error(e.message)
40
+ raise e
41
+ end
42
+
43
+ end
44
+
45
+ def delete
46
+ logger.debug("Deleting resource #{@name}")
47
+ begin
48
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
49
+ if(!physical_id.nil?)
50
+ args = {'loadbalancerrulelist' => physical_id
51
+ }
52
+ result_obj = make_async_request('removeToGlobalLoadBalancerRule',args)
53
+ if (!(result_obj['error'] == true))
54
+ logger.info("Successfully deleted resource #{@name}")
55
+ else
56
+ logger.info("CloudStack error while deleting resource #{@name}")
57
+ end
58
+ else
59
+ logger.info("Resource not created in CloudStack. Skipping delete...")
60
+ end
61
+ rescue Exception => e
62
+ logger.error("Unable to delete resorce #{@name}")
63
+ end
64
+ end
65
+
66
+ def on_workitem
67
+ @name = workitem.participant_name
68
+ @props = workitem['Resources'][@name]['Properties']
69
+ @props.downcase_key
70
+ @resolved_names = workitem['ResolvedNames']
71
+ if workitem['params']['operation'] == 'create'
72
+ create
73
+ else
74
+ delete
75
+ end
76
+ reply
77
+ end
78
+
79
+ def get_id
80
+ resolved_id = get_resolved(@props["id"],workitem)
81
+ if resolved_id.nil? || !validate_param(resolved_id,"uuid")
82
+ raise "Missing mandatory parameter id for resource #{@name}"
83
+ end
84
+ resolved_id
85
+ end
86
+
87
+ def get_loadbalancerrulelist
88
+ resolved_loadbalancerrulelist = get_resolved(@props["loadbalancerrulelist"],workitem)
89
+ if resolved_loadbalancerrulelist.nil? || !validate_param(resolved_loadbalancerrulelist,"list")
90
+ raise "Missing mandatory parameter loadbalancerrulelist for resource #{@name}"
91
+ end
92
+ resolved_loadbalancerrulelist
93
+ end
94
+
95
+ def get_gslblbruleweightsmap
96
+ resolved_gslblbruleweightsmap = get_resolved(@props['gslblbruleweightsmap'],workitem)
97
+ if resolved_gslblbruleweightsmap.nil? || !validate_param(resolved_gslblbruleweightsmap,"map")
98
+ raise "Malformed optional parameter gslblbruleweightsmap for resource #{@name}"
99
+ end
100
+ resolved_gslblbruleweightsmap
101
+ end
102
+ end
103
+ end
104
+
@@ -0,0 +1,95 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackToLoadBalancerRule < CloudStackResource
5
+
6
+ include Logging
7
+ include Intrinsic
8
+ include Resolver
9
+ def create
10
+ logger.debug("Creating resource #{@name}")
11
+ workitem[@name] = {}
12
+ name_cs = workitem['StackName'] + '-' + @name
13
+ args={}
14
+ begin
15
+ args['id'] = get_id
16
+ args['virtualmachineids'] = get_virtualmachineids
17
+
18
+ logger.info("Creating resource #{@name} with following arguments")
19
+ p args
20
+ result_obj = make_async_request('assignToLoadBalancerRule',args)
21
+ resource_obj = result_obj['ToLoadBalancerRule'.downcase]
22
+ #doing it this way since it is easier to change later, rather than cloning whole object
23
+ resource_obj.each_key do |k|
24
+ val = resource_obj[k]
25
+ if('id'.eql?(k))
26
+ k = 'physical_id'
27
+ end
28
+ workitem[@name][k] = val
29
+ end
30
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"ToLoadBalancerRule") if @props.has_key?('tags')
31
+ workitem['ResolvedNames'][@name] = name_cs
32
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
33
+
34
+ rescue NoMethodError => nme
35
+ logger.error("Create request failed for resource . Cleaning up the stack")
36
+ raise nme
37
+ rescue Exception => e
38
+ logger.error(e.message)
39
+ raise e
40
+ end
41
+
42
+ end
43
+
44
+ def delete
45
+ logger.debug("Deleting resource #{@name}")
46
+ begin
47
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
48
+ if(!physical_id.nil?)
49
+ args = {'virtualmachineids' => physical_id
50
+ }
51
+ result_obj = make_async_request('removeToLoadBalancerRule',args)
52
+ if (!(result_obj['error'] == true))
53
+ logger.info("Successfully deleted resource #{@name}")
54
+ else
55
+ logger.info("CloudStack error while deleting resource #{@name}")
56
+ end
57
+ else
58
+ logger.info("Resource not created in CloudStack. Skipping delete...")
59
+ end
60
+ rescue Exception => e
61
+ logger.error("Unable to delete resorce #{@name}")
62
+ end
63
+ end
64
+
65
+ def on_workitem
66
+ @name = workitem.participant_name
67
+ @props = workitem['Resources'][@name]['Properties']
68
+ @props.downcase_key
69
+ @resolved_names = workitem['ResolvedNames']
70
+ if workitem['params']['operation'] == 'create'
71
+ create
72
+ else
73
+ delete
74
+ end
75
+ reply
76
+ end
77
+
78
+ def get_id
79
+ resolved_id = get_resolved(@props["id"],workitem)
80
+ if resolved_id.nil? || !validate_param(resolved_id,"uuid")
81
+ raise "Missing mandatory parameter id for resource #{@name}"
82
+ end
83
+ resolved_id
84
+ end
85
+
86
+ def get_virtualmachineids
87
+ resolved_virtualmachineids = get_resolved(@props["virtualmachineids"],workitem)
88
+ if resolved_virtualmachineids.nil? || !validate_param(resolved_virtualmachineids,"list")
89
+ raise "Missing mandatory parameter virtualmachineids for resource #{@name}"
90
+ end
91
+ resolved_virtualmachineids
92
+ end
93
+ end
94
+ end
95
+