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
@@ -0,0 +1,176 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackNetworkACL < 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['protocol'] = get_protocol
16
+ args['networkid'] = get_networkid if @props.has_key?('networkid')
17
+ args['endport'] = get_endport if @props.has_key?('endport')
18
+ args['action'] = get_action if @props.has_key?('action')
19
+ args['startport'] = get_startport if @props.has_key?('startport')
20
+ args['traffictype'] = get_traffictype if @props.has_key?('traffictype')
21
+ args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
22
+ args['icmpcode'] = get_icmpcode if @props.has_key?('icmpcode')
23
+ args['aclid'] = get_aclid if @props.has_key?('aclid')
24
+ args['number'] = get_number if @props.has_key?('number')
25
+ args['icmptype'] = get_icmptype if @props.has_key?('icmptype')
26
+
27
+ logger.info("Creating resource #{@name} with following arguments")
28
+ p args
29
+ result_obj = make_async_request('createNetworkACL',args)
30
+ resource_obj = result_obj['NetworkACL'.downcase]
31
+ #doing it this way since it is easier to change later, rather than cloning whole object
32
+ resource_obj.each_key do |k|
33
+ val = resource_obj[k]
34
+ if('id'.eql?(k))
35
+ k = 'physical_id'
36
+ end
37
+ workitem[@name][k] = val
38
+ end
39
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"NetworkACL") if @props.has_key?('tags')
40
+ workitem['ResolvedNames'][@name] = name_cs
41
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
42
+
43
+ rescue NoMethodError => nme
44
+ logger.error("Create request failed for resource . Cleaning up the stack")
45
+ raise nme
46
+ rescue Exception => e
47
+ logger.error(e.message)
48
+ raise e
49
+ end
50
+
51
+ end
52
+
53
+ def delete
54
+ logger.debug("Deleting resource #{@name}")
55
+ begin
56
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
57
+ if(!physical_id.nil?)
58
+ args = {'id' => physical_id
59
+ }
60
+ result_obj = make_async_request('deleteNetworkACL',args)
61
+ if (!(result_obj['error'] == true))
62
+ logger.info("Successfully deleted resource #{@name}")
63
+ else
64
+ logger.info("CloudStack error while deleting resource #{@name}")
65
+ end
66
+ else
67
+ logger.info("Resource not created in CloudStack. Skipping delete...")
68
+ end
69
+ rescue Exception => e
70
+ logger.error("Unable to delete resorce #{@name}")
71
+ end
72
+ end
73
+
74
+ def on_workitem
75
+ @name = workitem.participant_name
76
+ @props = workitem['Resources'][@name]['Properties']
77
+ @props.downcase_key
78
+ @resolved_names = workitem['ResolvedNames']
79
+ if workitem['params']['operation'] == 'create'
80
+ create
81
+ else
82
+ delete
83
+ end
84
+ reply
85
+ end
86
+
87
+ def get_protocol
88
+ resolved_protocol = get_resolved(@props["protocol"],workitem)
89
+ if resolved_protocol.nil? || !validate_param(resolved_protocol,"string")
90
+ raise "Missing mandatory parameter protocol for resource #{@name}"
91
+ end
92
+ resolved_protocol
93
+ end
94
+
95
+ def get_networkid
96
+ resolved_networkid = get_resolved(@props['networkid'],workitem)
97
+ if resolved_networkid.nil? || !validate_param(resolved_networkid,"uuid")
98
+ raise "Malformed optional parameter networkid for resource #{@name}"
99
+ end
100
+ resolved_networkid
101
+ end
102
+
103
+ def get_endport
104
+ resolved_endport = get_resolved(@props['endport'],workitem)
105
+ if resolved_endport.nil? || !validate_param(resolved_endport,"integer")
106
+ raise "Malformed optional parameter endport for resource #{@name}"
107
+ end
108
+ resolved_endport
109
+ end
110
+
111
+ def get_action
112
+ resolved_action = get_resolved(@props['action'],workitem)
113
+ if resolved_action.nil? || !validate_param(resolved_action,"string")
114
+ raise "Malformed optional parameter action for resource #{@name}"
115
+ end
116
+ resolved_action
117
+ end
118
+
119
+ def get_startport
120
+ resolved_startport = get_resolved(@props['startport'],workitem)
121
+ if resolved_startport.nil? || !validate_param(resolved_startport,"integer")
122
+ raise "Malformed optional parameter startport for resource #{@name}"
123
+ end
124
+ resolved_startport
125
+ end
126
+
127
+ def get_traffictype
128
+ resolved_traffictype = get_resolved(@props['traffictype'],workitem)
129
+ if resolved_traffictype.nil? || !validate_param(resolved_traffictype,"string")
130
+ raise "Malformed optional parameter traffictype for resource #{@name}"
131
+ end
132
+ resolved_traffictype
133
+ end
134
+
135
+ def get_cidrlist
136
+ resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
137
+ if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
138
+ raise "Malformed optional parameter cidrlist for resource #{@name}"
139
+ end
140
+ resolved_cidrlist
141
+ end
142
+
143
+ def get_icmpcode
144
+ resolved_icmpcode = get_resolved(@props['icmpcode'],workitem)
145
+ if resolved_icmpcode.nil? || !validate_param(resolved_icmpcode,"integer")
146
+ raise "Malformed optional parameter icmpcode for resource #{@name}"
147
+ end
148
+ resolved_icmpcode
149
+ end
150
+
151
+ def get_aclid
152
+ resolved_aclid = get_resolved(@props['aclid'],workitem)
153
+ if resolved_aclid.nil? || !validate_param(resolved_aclid,"uuid")
154
+ raise "Malformed optional parameter aclid for resource #{@name}"
155
+ end
156
+ resolved_aclid
157
+ end
158
+
159
+ def get_number
160
+ resolved_number = get_resolved(@props['number'],workitem)
161
+ if resolved_number.nil? || !validate_param(resolved_number,"integer")
162
+ raise "Malformed optional parameter number for resource #{@name}"
163
+ end
164
+ resolved_number
165
+ end
166
+
167
+ def get_icmptype
168
+ resolved_icmptype = get_resolved(@props['icmptype'],workitem)
169
+ if resolved_icmptype.nil? || !validate_param(resolved_icmptype,"integer")
170
+ raise "Malformed optional parameter icmptype for resource #{@name}"
171
+ end
172
+ resolved_icmptype
173
+ end
174
+ end
175
+ end
176
+
@@ -0,0 +1,104 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackNetworkACLList < 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['vpcid'] = get_vpcid
16
+ args['name'] = workitem['StackName'] +'-' +get_name
17
+ args['description'] = get_description if @props.has_key?('description')
18
+
19
+ logger.info("Creating resource #{@name} with following arguments")
20
+ p args
21
+ result_obj = make_async_request('createNetworkACLList',args)
22
+ resource_obj = result_obj['NetworkACLList'.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'],"NetworkACLList") 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 = {'id' => physical_id
51
+ }
52
+ result_obj = make_async_request('deleteNetworkACLList',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_vpcid
80
+ resolved_vpcid = get_resolved(@props["vpcid"],workitem)
81
+ if resolved_vpcid.nil? || !validate_param(resolved_vpcid,"uuid")
82
+ raise "Missing mandatory parameter vpcid for resource #{@name}"
83
+ end
84
+ resolved_vpcid
85
+ end
86
+
87
+ def get_name
88
+ resolved_name = get_resolved(@props["name"],workitem)
89
+ if resolved_name.nil? || !validate_param(resolved_name,"string")
90
+ raise "Missing mandatory parameter name for resource #{@name}"
91
+ end
92
+ resolved_name
93
+ end
94
+
95
+ def get_description
96
+ resolved_description = get_resolved(@props['description'],workitem)
97
+ if resolved_description.nil? || !validate_param(resolved_description,"string")
98
+ raise "Malformed optional parameter description for resource #{@name}"
99
+ end
100
+ resolved_description
101
+ end
102
+ end
103
+ end
104
+
@@ -0,0 +1,104 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackNicToVirtualMachine < 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['virtualmachineid'] = get_virtualmachineid
16
+ args['networkid'] = get_networkid
17
+ args['ipaddress'] = get_ipaddress if @props.has_key?('ipaddress')
18
+
19
+ logger.info("Creating resource #{@name} with following arguments")
20
+ p args
21
+ result_obj = make_async_request('addNicToVirtualMachine',args)
22
+ resource_obj = result_obj['NicToVirtualMachine'.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'],"NicToVirtualMachine") 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 = {'virtualmachineid' => physical_id
51
+ }
52
+ result_obj = make_async_request('removeNicToVirtualMachine',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_virtualmachineid
80
+ resolved_virtualmachineid = get_resolved(@props["virtualmachineid"],workitem)
81
+ if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
82
+ raise "Missing mandatory parameter virtualmachineid for resource #{@name}"
83
+ end
84
+ resolved_virtualmachineid
85
+ end
86
+
87
+ def get_networkid
88
+ resolved_networkid = get_resolved(@props["networkid"],workitem)
89
+ if resolved_networkid.nil? || !validate_param(resolved_networkid,"uuid")
90
+ raise "Missing mandatory parameter networkid for resource #{@name}"
91
+ end
92
+ resolved_networkid
93
+ end
94
+
95
+ def get_ipaddress
96
+ resolved_ipaddress = get_resolved(@props['ipaddress'],workitem)
97
+ if resolved_ipaddress.nil? || !validate_param(resolved_ipaddress,"string")
98
+ raise "Malformed optional parameter ipaddress for resource #{@name}"
99
+ end
100
+ resolved_ipaddress
101
+ end
102
+ end
103
+ end
104
+
@@ -0,0 +1,176 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackPortForwardingRule < 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['privateport'] = get_privateport
16
+ args['protocol'] = get_protocol
17
+ args['ipaddressid'] = get_ipaddressid
18
+ args['virtualmachineid'] = get_virtualmachineid
19
+ args['publicport'] = get_publicport
20
+ args['privateendport'] = get_privateendport if @props.has_key?('privateendport')
21
+ args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
22
+ args['vmguestip'] = get_vmguestip if @props.has_key?('vmguestip')
23
+ args['networkid'] = get_networkid if @props.has_key?('networkid')
24
+ args['publicendport'] = get_publicendport if @props.has_key?('publicendport')
25
+ args['openfirewall'] = get_openfirewall if @props.has_key?('openfirewall')
26
+
27
+ logger.info("Creating resource #{@name} with following arguments")
28
+ p args
29
+ result_obj = make_async_request('createPortForwardingRule',args)
30
+ resource_obj = result_obj['PortForwardingRule'.downcase]
31
+ #doing it this way since it is easier to change later, rather than cloning whole object
32
+ resource_obj.each_key do |k|
33
+ val = resource_obj[k]
34
+ if('id'.eql?(k))
35
+ k = 'physical_id'
36
+ end
37
+ workitem[@name][k] = val
38
+ end
39
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"PortForwardingRule") if @props.has_key?('tags')
40
+ workitem['ResolvedNames'][@name] = name_cs
41
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
42
+
43
+ rescue NoMethodError => nme
44
+ logger.error("Create request failed for resource . Cleaning up the stack")
45
+ raise nme
46
+ rescue Exception => e
47
+ logger.error(e.message)
48
+ raise e
49
+ end
50
+
51
+ end
52
+
53
+ def delete
54
+ logger.debug("Deleting resource #{@name}")
55
+ begin
56
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
57
+ if(!physical_id.nil?)
58
+ args = {'id' => physical_id
59
+ }
60
+ result_obj = make_async_request('deletePortForwardingRule',args)
61
+ if (!(result_obj['error'] == true))
62
+ logger.info("Successfully deleted resource #{@name}")
63
+ else
64
+ logger.info("CloudStack error while deleting resource #{@name}")
65
+ end
66
+ else
67
+ logger.info("Resource not created in CloudStack. Skipping delete...")
68
+ end
69
+ rescue Exception => e
70
+ logger.error("Unable to delete resorce #{@name}")
71
+ end
72
+ end
73
+
74
+ def on_workitem
75
+ @name = workitem.participant_name
76
+ @props = workitem['Resources'][@name]['Properties']
77
+ @props.downcase_key
78
+ @resolved_names = workitem['ResolvedNames']
79
+ if workitem['params']['operation'] == 'create'
80
+ create
81
+ else
82
+ delete
83
+ end
84
+ reply
85
+ end
86
+
87
+ def get_privateport
88
+ resolved_privateport = get_resolved(@props["privateport"],workitem)
89
+ if resolved_privateport.nil? || !validate_param(resolved_privateport,"integer")
90
+ raise "Missing mandatory parameter privateport for resource #{@name}"
91
+ end
92
+ resolved_privateport
93
+ end
94
+
95
+ def get_protocol
96
+ resolved_protocol = get_resolved(@props["protocol"],workitem)
97
+ if resolved_protocol.nil? || !validate_param(resolved_protocol,"string")
98
+ raise "Missing mandatory parameter protocol for resource #{@name}"
99
+ end
100
+ resolved_protocol
101
+ end
102
+
103
+ def get_ipaddressid
104
+ resolved_ipaddressid = get_resolved(@props["ipaddressid"],workitem)
105
+ if resolved_ipaddressid.nil? || !validate_param(resolved_ipaddressid,"uuid")
106
+ raise "Missing mandatory parameter ipaddressid for resource #{@name}"
107
+ end
108
+ resolved_ipaddressid
109
+ end
110
+
111
+ def get_virtualmachineid
112
+ resolved_virtualmachineid = get_resolved(@props["virtualmachineid"],workitem)
113
+ if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
114
+ raise "Missing mandatory parameter virtualmachineid for resource #{@name}"
115
+ end
116
+ resolved_virtualmachineid
117
+ end
118
+
119
+ def get_publicport
120
+ resolved_publicport = get_resolved(@props["publicport"],workitem)
121
+ if resolved_publicport.nil? || !validate_param(resolved_publicport,"integer")
122
+ raise "Missing mandatory parameter publicport for resource #{@name}"
123
+ end
124
+ resolved_publicport
125
+ end
126
+
127
+ def get_privateendport
128
+ resolved_privateendport = get_resolved(@props['privateendport'],workitem)
129
+ if resolved_privateendport.nil? || !validate_param(resolved_privateendport,"integer")
130
+ raise "Malformed optional parameter privateendport for resource #{@name}"
131
+ end
132
+ resolved_privateendport
133
+ end
134
+
135
+ def get_cidrlist
136
+ resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
137
+ if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
138
+ raise "Malformed optional parameter cidrlist for resource #{@name}"
139
+ end
140
+ resolved_cidrlist
141
+ end
142
+
143
+ def get_vmguestip
144
+ resolved_vmguestip = get_resolved(@props['vmguestip'],workitem)
145
+ if resolved_vmguestip.nil? || !validate_param(resolved_vmguestip,"string")
146
+ raise "Malformed optional parameter vmguestip for resource #{@name}"
147
+ end
148
+ resolved_vmguestip
149
+ end
150
+
151
+ def get_networkid
152
+ resolved_networkid = get_resolved(@props['networkid'],workitem)
153
+ if resolved_networkid.nil? || !validate_param(resolved_networkid,"uuid")
154
+ raise "Malformed optional parameter networkid for resource #{@name}"
155
+ end
156
+ resolved_networkid
157
+ end
158
+
159
+ def get_publicendport
160
+ resolved_publicendport = get_resolved(@props['publicendport'],workitem)
161
+ if resolved_publicendport.nil? || !validate_param(resolved_publicendport,"integer")
162
+ raise "Malformed optional parameter publicendport for resource #{@name}"
163
+ end
164
+ resolved_publicendport
165
+ end
166
+
167
+ def get_openfirewall
168
+ resolved_openfirewall = get_resolved(@props['openfirewall'],workitem)
169
+ if resolved_openfirewall.nil? || !validate_param(resolved_openfirewall,"boolean")
170
+ raise "Malformed optional parameter openfirewall for resource #{@name}"
171
+ end
172
+ resolved_openfirewall
173
+ end
174
+ end
175
+ end
176
+
@@ -0,0 +1,113 @@
1
+ require 'stackmate/participants/cloudstack'
2
+
3
+ module StackMate
4
+ class CloudStackProject < 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['name'] = workitem['StackName'] +'-' +get_name
16
+ args['displaytext'] = get_displaytext
17
+ args['account'] = get_account if @props.has_key?('account')
18
+ args['domainid'] = get_domainid if @props.has_key?('domainid')
19
+
20
+ logger.info("Creating resource #{@name} with following arguments")
21
+ p args
22
+ result_obj = make_async_request('createProject',args)
23
+ resource_obj = result_obj['Project'.downcase]
24
+ #doing it this way since it is easier to change later, rather than cloning whole object
25
+ resource_obj.each_key do |k|
26
+ val = resource_obj[k]
27
+ if('id'.eql?(k))
28
+ k = 'physical_id'
29
+ end
30
+ workitem[@name][k] = val
31
+ end
32
+ set_tags(@props['tags'],workitem[@name]['physical_id'],"Project") if @props.has_key?('tags')
33
+ workitem['ResolvedNames'][@name] = name_cs
34
+ workitem['IdMap'][workitem[@name]['physical_id']] = @name
35
+
36
+ rescue NoMethodError => nme
37
+ logger.error("Create request failed for resource . Cleaning up the stack")
38
+ raise nme
39
+ rescue Exception => e
40
+ logger.error(e.message)
41
+ raise e
42
+ end
43
+
44
+ end
45
+
46
+ def delete
47
+ logger.debug("Deleting resource #{@name}")
48
+ begin
49
+ physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
50
+ if(!physical_id.nil?)
51
+ args = {'id' => physical_id
52
+ }
53
+ result_obj = make_async_request('deleteProject',args)
54
+ if (!(result_obj['error'] == true))
55
+ logger.info("Successfully deleted resource #{@name}")
56
+ else
57
+ logger.info("CloudStack error while deleting resource #{@name}")
58
+ end
59
+ else
60
+ logger.info("Resource not created in CloudStack. Skipping delete...")
61
+ end
62
+ rescue Exception => e
63
+ logger.error("Unable to delete resorce #{@name}")
64
+ end
65
+ end
66
+
67
+ def on_workitem
68
+ @name = workitem.participant_name
69
+ @props = workitem['Resources'][@name]['Properties']
70
+ @props.downcase_key
71
+ @resolved_names = workitem['ResolvedNames']
72
+ if workitem['params']['operation'] == 'create'
73
+ create
74
+ else
75
+ delete
76
+ end
77
+ reply
78
+ end
79
+
80
+ def get_name
81
+ resolved_name = get_resolved(@props["name"],workitem)
82
+ if resolved_name.nil? || !validate_param(resolved_name,"string")
83
+ raise "Missing mandatory parameter name for resource #{@name}"
84
+ end
85
+ resolved_name
86
+ end
87
+
88
+ def get_displaytext
89
+ resolved_displaytext = get_resolved(@props["displaytext"],workitem)
90
+ if resolved_displaytext.nil? || !validate_param(resolved_displaytext,"string")
91
+ raise "Missing mandatory parameter displaytext for resource #{@name}"
92
+ end
93
+ resolved_displaytext
94
+ end
95
+
96
+ def get_account
97
+ resolved_account = get_resolved(@props['account'],workitem)
98
+ if resolved_account.nil? || !validate_param(resolved_account,"string")
99
+ raise "Malformed optional parameter account for resource #{@name}"
100
+ end
101
+ resolved_account
102
+ end
103
+
104
+ def get_domainid
105
+ resolved_domainid = get_resolved(@props['domainid'],workitem)
106
+ if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
107
+ raise "Malformed optional parameter domainid for resource #{@name}"
108
+ end
109
+ resolved_domainid
110
+ end
111
+ end
112
+ end
113
+