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.
- data/CHANGELOG.txt +7 -0
- data/README.md +25 -8
- data/bin/stackmate.rb +57 -53
- data/lib/stackmate/aws_attribs.rb +31 -31
- data/lib/stackmate/classmap.rb +33 -25
- data/lib/stackmate/client.rb +80 -0
- data/lib/stackmate/intrinsic_functions.rb +94 -38
- data/lib/stackmate/logging.rb +19 -19
- data/lib/stackmate/participants/cloudstack.rb +250 -165
- data/lib/stackmate/participants/cloudstack_affinitygroup.rb +122 -0
- data/lib/stackmate/participants/cloudstack_autoscalepolicy.rb +113 -0
- data/lib/stackmate/participants/cloudstack_autoscalevmgroup.rb +86 -0
- data/lib/stackmate/participants/cloudstack_autoscalevmprofile.rb +140 -0
- data/lib/stackmate/participants/cloudstack_condition.rb +122 -0
- data/lib/stackmate/participants/cloudstack_egressfirewallrule.rb +149 -0
- data/lib/stackmate/participants/cloudstack_firewallrule.rb +149 -0
- data/lib/stackmate/participants/cloudstack_globalloadbalancerrule.rb +158 -0
- data/lib/stackmate/participants/cloudstack_instancegroup.rb +113 -0
- data/lib/stackmate/participants/cloudstack_ipaddress.rb +149 -0
- data/lib/stackmate/participants/cloudstack_ipforwardingrule.rb +131 -0
- data/lib/stackmate/participants/cloudstack_iptonic.rb +95 -0
- data/lib/stackmate/participants/cloudstack_iso.rb +95 -0
- data/lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb +140 -0
- data/lib/stackmate/participants/cloudstack_lbstickinesspolicy.rb +122 -0
- data/lib/stackmate/participants/cloudstack_loadbalancer.rb +158 -0
- data/lib/stackmate/participants/cloudstack_loadbalancerrule.rb +185 -0
- data/lib/stackmate/participants/cloudstack_network.rb +293 -0
- data/lib/stackmate/participants/cloudstack_networkacl.rb +176 -0
- data/lib/stackmate/participants/cloudstack_networkacllist.rb +104 -0
- data/lib/stackmate/participants/cloudstack_nictovirtualmachine.rb +104 -0
- data/lib/stackmate/participants/cloudstack_portforwardingrule.rb +176 -0
- data/lib/stackmate/participants/cloudstack_project.rb +113 -0
- data/lib/stackmate/participants/cloudstack_remoteaccessvpn.rb +122 -0
- data/lib/stackmate/participants/cloudstack_securitygroup.rb +122 -0
- data/lib/stackmate/participants/cloudstack_securitygroupegress.rb +185 -0
- data/lib/stackmate/participants/cloudstack_securitygroupingress.rb +185 -0
- data/lib/stackmate/participants/cloudstack_snapshot.rb +113 -0
- data/lib/stackmate/participants/cloudstack_snapshotpolicy.rb +122 -0
- data/lib/stackmate/participants/cloudstack_sshkeypair.rb +113 -0
- data/lib/stackmate/participants/cloudstack_staticnat.rb +113 -0
- data/lib/stackmate/participants/cloudstack_staticroute.rb +95 -0
- data/lib/stackmate/participants/cloudstack_tags.rb +113 -0
- data/lib/stackmate/participants/cloudstack_template.rb +212 -0
- data/lib/stackmate/participants/cloudstack_togloballoadbalancerrule.rb +104 -0
- data/lib/stackmate/participants/cloudstack_toloadbalancerrule.rb +95 -0
- data/lib/stackmate/participants/cloudstack_virtualmachine.rb +348 -0
- data/lib/stackmate/participants/cloudstack_virtualmachineops.rb +95 -0
- data/lib/stackmate/participants/cloudstack_vmsnapshot.rb +113 -0
- data/lib/stackmate/participants/cloudstack_volume.rb +176 -0
- data/lib/stackmate/participants/cloudstack_volumeops.rb +111 -0
- data/lib/stackmate/participants/cloudstack_vpc.rb +158 -0
- data/lib/stackmate/participants/cloudstack_vpnconnection.rb +95 -0
- data/lib/stackmate/participants/cloudstack_vpncustomergateway.rb +176 -0
- data/lib/stackmate/participants/cloudstack_vpngateway.rb +86 -0
- data/lib/stackmate/participants/cloudstack_vpnuser.rb +122 -0
- data/lib/stackmate/participants/common.rb +219 -70
- data/lib/stackmate/participants/stacknest.rb +6 -0
- data/lib/stackmate/resolver.rb +122 -0
- data/lib/stackmate/stack.rb +116 -60
- data/lib/stackmate/stack_executor.rb +99 -37
- data/lib/stackmate/stackpi.rb +46 -0
- data/lib/stackmate/version.rb +1 -1
- data/lib/stackmate/waitcondition_server.rb +15 -15
- data/lib/stackmate.rb +1 -1
- data/stackmate.gemspec +2 -4
- metadata +70 -19
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackAutoScalePolicy < 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['action'] = get_action
|
16
|
+
args['duration'] = get_duration
|
17
|
+
args['conditionids'] = get_conditionids
|
18
|
+
args['quiettime'] = get_quiettime if @props.has_key?('quiettime')
|
19
|
+
|
20
|
+
logger.info("Creating resource #{@name} with following arguments")
|
21
|
+
p args
|
22
|
+
result_obj = make_async_request('createAutoScalePolicy',args)
|
23
|
+
resource_obj = result_obj['AutoScalePolicy'.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'],"AutoScalePolicy") 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('deleteAutoScalePolicy',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_action
|
81
|
+
resolved_action = get_resolved(@props["action"],workitem)
|
82
|
+
if resolved_action.nil? || !validate_param(resolved_action,"string")
|
83
|
+
raise "Missing mandatory parameter action for resource #{@name}"
|
84
|
+
end
|
85
|
+
resolved_action
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_duration
|
89
|
+
resolved_duration = get_resolved(@props["duration"],workitem)
|
90
|
+
if resolved_duration.nil? || !validate_param(resolved_duration,"integer")
|
91
|
+
raise "Missing mandatory parameter duration for resource #{@name}"
|
92
|
+
end
|
93
|
+
resolved_duration
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_conditionids
|
97
|
+
resolved_conditionids = get_resolved(@props["conditionids"],workitem)
|
98
|
+
if resolved_conditionids.nil? || !validate_param(resolved_conditionids,"list")
|
99
|
+
raise "Missing mandatory parameter conditionids for resource #{@name}"
|
100
|
+
end
|
101
|
+
resolved_conditionids
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_quiettime
|
105
|
+
resolved_quiettime = get_resolved(@props['quiettime'],workitem)
|
106
|
+
if resolved_quiettime.nil? || !validate_param(resolved_quiettime,"integer")
|
107
|
+
raise "Malformed optional parameter quiettime for resource #{@name}"
|
108
|
+
end
|
109
|
+
resolved_quiettime
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackAutoScaleVmGroup < 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
|
+
|
17
|
+
logger.info("Creating resource #{@name} with following arguments")
|
18
|
+
p args
|
19
|
+
result_obj = make_async_request('enableAutoScaleVmGroup',args)
|
20
|
+
resource_obj = result_obj['AutoScaleVmGroup'.downcase]
|
21
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
22
|
+
resource_obj.each_key do |k|
|
23
|
+
val = resource_obj[k]
|
24
|
+
if('id'.eql?(k))
|
25
|
+
k = 'physical_id'
|
26
|
+
end
|
27
|
+
workitem[@name][k] = val
|
28
|
+
end
|
29
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"AutoScaleVmGroup") if @props.has_key?('tags')
|
30
|
+
workitem['ResolvedNames'][@name] = name_cs
|
31
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
32
|
+
|
33
|
+
rescue NoMethodError => nme
|
34
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
35
|
+
raise nme
|
36
|
+
rescue Exception => e
|
37
|
+
logger.error(e.message)
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete
|
44
|
+
logger.debug("Deleting resource #{@name}")
|
45
|
+
begin
|
46
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
47
|
+
if(!physical_id.nil?)
|
48
|
+
args = {'id' => physical_id
|
49
|
+
}
|
50
|
+
result_obj = make_async_request('disableAutoScaleVmGroup',args)
|
51
|
+
if (!(result_obj['error'] == true))
|
52
|
+
logger.info("Successfully deleted resource #{@name}")
|
53
|
+
else
|
54
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
55
|
+
end
|
56
|
+
else
|
57
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
logger.error("Unable to delete resorce #{@name}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def on_workitem
|
65
|
+
@name = workitem.participant_name
|
66
|
+
@props = workitem['Resources'][@name]['Properties']
|
67
|
+
@props.downcase_key
|
68
|
+
@resolved_names = workitem['ResolvedNames']
|
69
|
+
if workitem['params']['operation'] == 'create'
|
70
|
+
create
|
71
|
+
else
|
72
|
+
delete
|
73
|
+
end
|
74
|
+
reply
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_id
|
78
|
+
resolved_id = get_resolved(@props["id"],workitem)
|
79
|
+
if resolved_id.nil? || !validate_param(resolved_id,"uuid")
|
80
|
+
raise "Missing mandatory parameter id for resource #{@name}"
|
81
|
+
end
|
82
|
+
resolved_id
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackAutoScaleVmProfile < 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['zoneid'] = get_zoneid
|
16
|
+
args['serviceofferingid'] = get_serviceofferingid
|
17
|
+
args['templateid'] = get_templateid
|
18
|
+
args['otherdeployparams'] = get_otherdeployparams if @props.has_key?('otherdeployparams')
|
19
|
+
args['destroyvmgraceperiod'] = get_destroyvmgraceperiod if @props.has_key?('destroyvmgraceperiod')
|
20
|
+
args['autoscaleuserid'] = get_autoscaleuserid if @props.has_key?('autoscaleuserid')
|
21
|
+
args['counterparam'] = get_counterparam if @props.has_key?('counterparam')
|
22
|
+
|
23
|
+
logger.info("Creating resource #{@name} with following arguments")
|
24
|
+
p args
|
25
|
+
result_obj = make_async_request('createAutoScaleVmProfile',args)
|
26
|
+
resource_obj = result_obj['AutoScaleVmProfile'.downcase]
|
27
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
28
|
+
resource_obj.each_key do |k|
|
29
|
+
val = resource_obj[k]
|
30
|
+
if('id'.eql?(k))
|
31
|
+
k = 'physical_id'
|
32
|
+
end
|
33
|
+
workitem[@name][k] = val
|
34
|
+
end
|
35
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"AutoScaleVmProfile") if @props.has_key?('tags')
|
36
|
+
workitem['ResolvedNames'][@name] = name_cs
|
37
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
38
|
+
|
39
|
+
rescue NoMethodError => nme
|
40
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
41
|
+
raise nme
|
42
|
+
rescue Exception => e
|
43
|
+
logger.error(e.message)
|
44
|
+
raise e
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete
|
50
|
+
logger.debug("Deleting resource #{@name}")
|
51
|
+
begin
|
52
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
53
|
+
if(!physical_id.nil?)
|
54
|
+
args = {'id' => physical_id
|
55
|
+
}
|
56
|
+
result_obj = make_async_request('deleteAutoScaleVmProfile',args)
|
57
|
+
if (!(result_obj['error'] == true))
|
58
|
+
logger.info("Successfully deleted resource #{@name}")
|
59
|
+
else
|
60
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
61
|
+
end
|
62
|
+
else
|
63
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
64
|
+
end
|
65
|
+
rescue Exception => e
|
66
|
+
logger.error("Unable to delete resorce #{@name}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def on_workitem
|
71
|
+
@name = workitem.participant_name
|
72
|
+
@props = workitem['Resources'][@name]['Properties']
|
73
|
+
@props.downcase_key
|
74
|
+
@resolved_names = workitem['ResolvedNames']
|
75
|
+
if workitem['params']['operation'] == 'create'
|
76
|
+
create
|
77
|
+
else
|
78
|
+
delete
|
79
|
+
end
|
80
|
+
reply
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_zoneid
|
84
|
+
resolved_zoneid = get_resolved(@props["zoneid"],workitem)
|
85
|
+
if resolved_zoneid.nil? || !validate_param(resolved_zoneid,"uuid")
|
86
|
+
raise "Missing mandatory parameter zoneid for resource #{@name}"
|
87
|
+
end
|
88
|
+
resolved_zoneid
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_serviceofferingid
|
92
|
+
resolved_serviceofferingid = get_resolved(@props["serviceofferingid"],workitem)
|
93
|
+
if resolved_serviceofferingid.nil? || !validate_param(resolved_serviceofferingid,"uuid")
|
94
|
+
raise "Missing mandatory parameter serviceofferingid for resource #{@name}"
|
95
|
+
end
|
96
|
+
resolved_serviceofferingid
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_templateid
|
100
|
+
resolved_templateid = get_resolved(@props["templateid"],workitem)
|
101
|
+
if resolved_templateid.nil? || !validate_param(resolved_templateid,"uuid")
|
102
|
+
raise "Missing mandatory parameter templateid for resource #{@name}"
|
103
|
+
end
|
104
|
+
resolved_templateid
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_otherdeployparams
|
108
|
+
resolved_otherdeployparams = get_resolved(@props['otherdeployparams'],workitem)
|
109
|
+
if resolved_otherdeployparams.nil? || !validate_param(resolved_otherdeployparams,"string")
|
110
|
+
raise "Malformed optional parameter otherdeployparams for resource #{@name}"
|
111
|
+
end
|
112
|
+
resolved_otherdeployparams
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_destroyvmgraceperiod
|
116
|
+
resolved_destroyvmgraceperiod = get_resolved(@props['destroyvmgraceperiod'],workitem)
|
117
|
+
if resolved_destroyvmgraceperiod.nil? || !validate_param(resolved_destroyvmgraceperiod,"integer")
|
118
|
+
raise "Malformed optional parameter destroyvmgraceperiod for resource #{@name}"
|
119
|
+
end
|
120
|
+
resolved_destroyvmgraceperiod
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_autoscaleuserid
|
124
|
+
resolved_autoscaleuserid = get_resolved(@props['autoscaleuserid'],workitem)
|
125
|
+
if resolved_autoscaleuserid.nil? || !validate_param(resolved_autoscaleuserid,"uuid")
|
126
|
+
raise "Malformed optional parameter autoscaleuserid for resource #{@name}"
|
127
|
+
end
|
128
|
+
resolved_autoscaleuserid
|
129
|
+
end
|
130
|
+
|
131
|
+
def get_counterparam
|
132
|
+
resolved_counterparam = get_resolved(@props['counterparam'],workitem)
|
133
|
+
if resolved_counterparam.nil? || !validate_param(resolved_counterparam,"map")
|
134
|
+
raise "Malformed optional parameter counterparam for resource #{@name}"
|
135
|
+
end
|
136
|
+
resolved_counterparam
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackCondition < 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['threshold'] = get_threshold
|
16
|
+
args['relationaloperator'] = get_relationaloperator
|
17
|
+
args['counterid'] = get_counterid
|
18
|
+
args['account'] = get_account if @props.has_key?('account')
|
19
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
20
|
+
|
21
|
+
logger.info("Creating resource #{@name} with following arguments")
|
22
|
+
p args
|
23
|
+
result_obj = make_async_request('createCondition',args)
|
24
|
+
resource_obj = result_obj['Condition'.downcase]
|
25
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
26
|
+
resource_obj.each_key do |k|
|
27
|
+
val = resource_obj[k]
|
28
|
+
if('id'.eql?(k))
|
29
|
+
k = 'physical_id'
|
30
|
+
end
|
31
|
+
workitem[@name][k] = val
|
32
|
+
end
|
33
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"Condition") if @props.has_key?('tags')
|
34
|
+
workitem['ResolvedNames'][@name] = name_cs
|
35
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
36
|
+
|
37
|
+
rescue NoMethodError => nme
|
38
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
39
|
+
raise nme
|
40
|
+
rescue Exception => e
|
41
|
+
logger.error(e.message)
|
42
|
+
raise e
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete
|
48
|
+
logger.debug("Deleting resource #{@name}")
|
49
|
+
begin
|
50
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
51
|
+
if(!physical_id.nil?)
|
52
|
+
args = {'id' => physical_id
|
53
|
+
}
|
54
|
+
result_obj = make_async_request('deleteCondition',args)
|
55
|
+
if (!(result_obj['error'] == true))
|
56
|
+
logger.info("Successfully deleted resource #{@name}")
|
57
|
+
else
|
58
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
59
|
+
end
|
60
|
+
else
|
61
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
62
|
+
end
|
63
|
+
rescue Exception => e
|
64
|
+
logger.error("Unable to delete resorce #{@name}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def on_workitem
|
69
|
+
@name = workitem.participant_name
|
70
|
+
@props = workitem['Resources'][@name]['Properties']
|
71
|
+
@props.downcase_key
|
72
|
+
@resolved_names = workitem['ResolvedNames']
|
73
|
+
if workitem['params']['operation'] == 'create'
|
74
|
+
create
|
75
|
+
else
|
76
|
+
delete
|
77
|
+
end
|
78
|
+
reply
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_threshold
|
82
|
+
resolved_threshold = get_resolved(@props["threshold"],workitem)
|
83
|
+
if resolved_threshold.nil? || !validate_param(resolved_threshold,"long")
|
84
|
+
raise "Missing mandatory parameter threshold for resource #{@name}"
|
85
|
+
end
|
86
|
+
resolved_threshold
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_relationaloperator
|
90
|
+
resolved_relationaloperator = get_resolved(@props["relationaloperator"],workitem)
|
91
|
+
if resolved_relationaloperator.nil? || !validate_param(resolved_relationaloperator,"string")
|
92
|
+
raise "Missing mandatory parameter relationaloperator for resource #{@name}"
|
93
|
+
end
|
94
|
+
resolved_relationaloperator
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_counterid
|
98
|
+
resolved_counterid = get_resolved(@props["counterid"],workitem)
|
99
|
+
if resolved_counterid.nil? || !validate_param(resolved_counterid,"uuid")
|
100
|
+
raise "Missing mandatory parameter counterid for resource #{@name}"
|
101
|
+
end
|
102
|
+
resolved_counterid
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_account
|
106
|
+
resolved_account = get_resolved(@props['account'],workitem)
|
107
|
+
if resolved_account.nil? || !validate_param(resolved_account,"string")
|
108
|
+
raise "Malformed optional parameter account for resource #{@name}"
|
109
|
+
end
|
110
|
+
resolved_account
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_domainid
|
114
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
115
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
116
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
117
|
+
end
|
118
|
+
resolved_domainid
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackEgressFirewallRule < 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['networkid'] = get_networkid
|
16
|
+
args['protocol'] = get_protocol
|
17
|
+
args['icmpcode'] = get_icmpcode if @props.has_key?('icmpcode')
|
18
|
+
args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
|
19
|
+
args['type'] = get_type if @props.has_key?('type')
|
20
|
+
args['endport'] = get_endport if @props.has_key?('endport')
|
21
|
+
args['icmptype'] = get_icmptype if @props.has_key?('icmptype')
|
22
|
+
args['startport'] = get_startport if @props.has_key?('startport')
|
23
|
+
|
24
|
+
logger.info("Creating resource #{@name} with following arguments")
|
25
|
+
p args
|
26
|
+
result_obj = make_async_request('createEgressFirewallRule',args)
|
27
|
+
resource_obj = result_obj['EgressFirewallRule'.downcase]
|
28
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
29
|
+
resource_obj.each_key do |k|
|
30
|
+
val = resource_obj[k]
|
31
|
+
if('id'.eql?(k))
|
32
|
+
k = 'physical_id'
|
33
|
+
end
|
34
|
+
workitem[@name][k] = val
|
35
|
+
end
|
36
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"EgressFirewallRule") if @props.has_key?('tags')
|
37
|
+
workitem['ResolvedNames'][@name] = name_cs
|
38
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
39
|
+
|
40
|
+
rescue NoMethodError => nme
|
41
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
42
|
+
raise nme
|
43
|
+
rescue Exception => e
|
44
|
+
logger.error(e.message)
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete
|
51
|
+
logger.debug("Deleting resource #{@name}")
|
52
|
+
begin
|
53
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
54
|
+
if(!physical_id.nil?)
|
55
|
+
args = {'id' => physical_id
|
56
|
+
}
|
57
|
+
result_obj = make_async_request('deleteEgressFirewallRule',args)
|
58
|
+
if (!(result_obj['error'] == true))
|
59
|
+
logger.info("Successfully deleted resource #{@name}")
|
60
|
+
else
|
61
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
62
|
+
end
|
63
|
+
else
|
64
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
65
|
+
end
|
66
|
+
rescue Exception => e
|
67
|
+
logger.error("Unable to delete resorce #{@name}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def on_workitem
|
72
|
+
@name = workitem.participant_name
|
73
|
+
@props = workitem['Resources'][@name]['Properties']
|
74
|
+
@props.downcase_key
|
75
|
+
@resolved_names = workitem['ResolvedNames']
|
76
|
+
if workitem['params']['operation'] == 'create'
|
77
|
+
create
|
78
|
+
else
|
79
|
+
delete
|
80
|
+
end
|
81
|
+
reply
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_networkid
|
85
|
+
resolved_networkid = get_resolved(@props["networkid"],workitem)
|
86
|
+
if resolved_networkid.nil? || !validate_param(resolved_networkid,"uuid")
|
87
|
+
raise "Missing mandatory parameter networkid for resource #{@name}"
|
88
|
+
end
|
89
|
+
resolved_networkid
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_protocol
|
93
|
+
resolved_protocol = get_resolved(@props["protocol"],workitem)
|
94
|
+
if resolved_protocol.nil? || !validate_param(resolved_protocol,"string")
|
95
|
+
raise "Missing mandatory parameter protocol for resource #{@name}"
|
96
|
+
end
|
97
|
+
resolved_protocol
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_icmpcode
|
101
|
+
resolved_icmpcode = get_resolved(@props['icmpcode'],workitem)
|
102
|
+
if resolved_icmpcode.nil? || !validate_param(resolved_icmpcode,"integer")
|
103
|
+
raise "Malformed optional parameter icmpcode for resource #{@name}"
|
104
|
+
end
|
105
|
+
resolved_icmpcode
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_cidrlist
|
109
|
+
resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
|
110
|
+
if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
|
111
|
+
raise "Malformed optional parameter cidrlist for resource #{@name}"
|
112
|
+
end
|
113
|
+
resolved_cidrlist
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_type
|
117
|
+
resolved_type = get_resolved(@props['type'],workitem)
|
118
|
+
if resolved_type.nil? || !validate_param(resolved_type,"string")
|
119
|
+
raise "Malformed optional parameter type for resource #{@name}"
|
120
|
+
end
|
121
|
+
resolved_type
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_endport
|
125
|
+
resolved_endport = get_resolved(@props['endport'],workitem)
|
126
|
+
if resolved_endport.nil? || !validate_param(resolved_endport,"integer")
|
127
|
+
raise "Malformed optional parameter endport for resource #{@name}"
|
128
|
+
end
|
129
|
+
resolved_endport
|
130
|
+
end
|
131
|
+
|
132
|
+
def get_icmptype
|
133
|
+
resolved_icmptype = get_resolved(@props['icmptype'],workitem)
|
134
|
+
if resolved_icmptype.nil? || !validate_param(resolved_icmptype,"integer")
|
135
|
+
raise "Malformed optional parameter icmptype for resource #{@name}"
|
136
|
+
end
|
137
|
+
resolved_icmptype
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_startport
|
141
|
+
resolved_startport = get_resolved(@props['startport'],workitem)
|
142
|
+
if resolved_startport.nil? || !validate_param(resolved_startport,"integer")
|
143
|
+
raise "Malformed optional parameter startport for resource #{@name}"
|
144
|
+
end
|
145
|
+
resolved_startport
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|