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,122 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackRemoteAccessVpn < 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['publicipid'] = get_publicipid
|
16
|
+
args['account'] = get_account if @props.has_key?('account')
|
17
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
18
|
+
args['openfirewall'] = get_openfirewall if @props.has_key?('openfirewall')
|
19
|
+
args['iprange'] = get_iprange if @props.has_key?('iprange')
|
20
|
+
|
21
|
+
logger.info("Creating resource #{@name} with following arguments")
|
22
|
+
p args
|
23
|
+
result_obj = make_async_request('createRemoteAccessVpn',args)
|
24
|
+
resource_obj = result_obj['RemoteAccessVpn'.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'],"RemoteAccessVpn") 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 = {'publicipid' => physical_id
|
53
|
+
}
|
54
|
+
result_obj = make_async_request('deleteRemoteAccessVpn',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_publicipid
|
82
|
+
resolved_publicipid = get_resolved(@props["publicipid"],workitem)
|
83
|
+
if resolved_publicipid.nil? || !validate_param(resolved_publicipid,"uuid")
|
84
|
+
raise "Missing mandatory parameter publicipid for resource #{@name}"
|
85
|
+
end
|
86
|
+
resolved_publicipid
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_account
|
90
|
+
resolved_account = get_resolved(@props['account'],workitem)
|
91
|
+
if resolved_account.nil? || !validate_param(resolved_account,"string")
|
92
|
+
raise "Malformed optional parameter account for resource #{@name}"
|
93
|
+
end
|
94
|
+
resolved_account
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_domainid
|
98
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
99
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
100
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
101
|
+
end
|
102
|
+
resolved_domainid
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_openfirewall
|
106
|
+
resolved_openfirewall = get_resolved(@props['openfirewall'],workitem)
|
107
|
+
if resolved_openfirewall.nil? || !validate_param(resolved_openfirewall,"boolean")
|
108
|
+
raise "Malformed optional parameter openfirewall for resource #{@name}"
|
109
|
+
end
|
110
|
+
resolved_openfirewall
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_iprange
|
114
|
+
resolved_iprange = get_resolved(@props['iprange'],workitem)
|
115
|
+
if resolved_iprange.nil? || !validate_param(resolved_iprange,"string")
|
116
|
+
raise "Malformed optional parameter iprange for resource #{@name}"
|
117
|
+
end
|
118
|
+
resolved_iprange
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackSecurityGroup < 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['description'] = get_description if @props.has_key?('description')
|
17
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
18
|
+
args['account'] = get_account if @props.has_key?('account')
|
19
|
+
args['projectid'] = get_projectid if @props.has_key?('projectid')
|
20
|
+
|
21
|
+
logger.info("Creating resource #{@name} with following arguments")
|
22
|
+
p args
|
23
|
+
result_obj = make_sync_request('createSecurityGroup',args)
|
24
|
+
resource_obj = result_obj['SecurityGroup'.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'],"SecurityGroup") 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_sync_request('deleteSecurityGroup',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_name
|
82
|
+
resolved_name = get_resolved(@props["name"],workitem)
|
83
|
+
if resolved_name.nil? || !validate_param(resolved_name,"string")
|
84
|
+
raise "Missing mandatory parameter name for resource #{@name}"
|
85
|
+
end
|
86
|
+
resolved_name
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_description
|
90
|
+
resolved_description = get_resolved(@props['description'],workitem)
|
91
|
+
if resolved_description.nil? || !validate_param(resolved_description,"string")
|
92
|
+
raise "Malformed optional parameter description for resource #{@name}"
|
93
|
+
end
|
94
|
+
resolved_description
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_domainid
|
98
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
99
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
100
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
101
|
+
end
|
102
|
+
resolved_domainid
|
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_projectid
|
114
|
+
resolved_projectid = get_resolved(@props['projectid'],workitem)
|
115
|
+
if resolved_projectid.nil? || !validate_param(resolved_projectid,"uuid")
|
116
|
+
raise "Malformed optional parameter projectid for resource #{@name}"
|
117
|
+
end
|
118
|
+
resolved_projectid
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackSecurityGroupEgress < 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['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
|
16
|
+
args['securitygroupname'] = get_securitygroupname if @props.has_key?('securitygroupname')
|
17
|
+
args['account'] = get_account if @props.has_key?('account')
|
18
|
+
args['endport'] = get_endport if @props.has_key?('endport')
|
19
|
+
args['usersecuritygrouplist'] = get_usersecuritygrouplist if @props.has_key?('usersecuritygrouplist')
|
20
|
+
args['protocol'] = get_protocol if @props.has_key?('protocol')
|
21
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
22
|
+
args['icmptype'] = get_icmptype if @props.has_key?('icmptype')
|
23
|
+
args['startport'] = get_startport if @props.has_key?('startport')
|
24
|
+
args['icmpcode'] = get_icmpcode if @props.has_key?('icmpcode')
|
25
|
+
args['projectid'] = get_projectid if @props.has_key?('projectid')
|
26
|
+
args['securitygroupid'] = get_securitygroupid if @props.has_key?('securitygroupid')
|
27
|
+
|
28
|
+
logger.info("Creating resource #{@name} with following arguments")
|
29
|
+
p args
|
30
|
+
result_obj = make_async_request('authorizeSecurityGroupEgress',args)
|
31
|
+
resource_obj = result_obj['securitygroup']['egressrule'.downcase][0]
|
32
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
33
|
+
resource_obj.each_key do |k|
|
34
|
+
val = resource_obj[k]
|
35
|
+
if('ruleid'.eql?(k))
|
36
|
+
k = 'physical_id'
|
37
|
+
end
|
38
|
+
workitem[@name][k] = val
|
39
|
+
end
|
40
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"SecurityGroupEgress") if @props.has_key?('tags')
|
41
|
+
workitem['ResolvedNames'][@name] = name_cs
|
42
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
43
|
+
|
44
|
+
rescue NoMethodError => nme
|
45
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
46
|
+
raise nme
|
47
|
+
rescue Exception => e
|
48
|
+
logger.error(e.message)
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete
|
55
|
+
logger.debug("Deleting resource #{@name}")
|
56
|
+
begin
|
57
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
58
|
+
if(!physical_id.nil?)
|
59
|
+
args = {'id' => physical_id
|
60
|
+
}
|
61
|
+
result_obj = make_async_request('revokeSecurityGroupEgress',args)
|
62
|
+
if (!(result_obj['error'] == true))
|
63
|
+
logger.info("Successfully deleted resource #{@name}")
|
64
|
+
else
|
65
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
66
|
+
end
|
67
|
+
else
|
68
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
69
|
+
end
|
70
|
+
rescue Exception => e
|
71
|
+
logger.error("Unable to delete resorce #{@name}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_workitem
|
76
|
+
@name = workitem.participant_name
|
77
|
+
@props = workitem['Resources'][@name]['Properties']
|
78
|
+
@props.downcase_key
|
79
|
+
@resolved_names = workitem['ResolvedNames']
|
80
|
+
if workitem['params']['operation'] == 'create'
|
81
|
+
create
|
82
|
+
else
|
83
|
+
delete
|
84
|
+
end
|
85
|
+
reply
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_cidrlist
|
89
|
+
resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
|
90
|
+
if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
|
91
|
+
raise "Malformed optional parameter cidrlist for resource #{@name}"
|
92
|
+
end
|
93
|
+
resolved_cidrlist
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_securitygroupname
|
97
|
+
resolved_securitygroupname = get_resolved(@props['securitygroupname'],workitem)
|
98
|
+
if resolved_securitygroupname.nil? || !validate_param(resolved_securitygroupname,"string")
|
99
|
+
raise "Malformed optional parameter securitygroupname for resource #{@name}"
|
100
|
+
end
|
101
|
+
resolved_securitygroupname
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_account
|
105
|
+
resolved_account = get_resolved(@props['account'],workitem)
|
106
|
+
if resolved_account.nil? || !validate_param(resolved_account,"string")
|
107
|
+
raise "Malformed optional parameter account for resource #{@name}"
|
108
|
+
end
|
109
|
+
resolved_account
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_endport
|
113
|
+
resolved_endport = get_resolved(@props['endport'],workitem)
|
114
|
+
if resolved_endport.nil? || !validate_param(resolved_endport,"integer")
|
115
|
+
raise "Malformed optional parameter endport for resource #{@name}"
|
116
|
+
end
|
117
|
+
resolved_endport
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_usersecuritygrouplist
|
121
|
+
resolved_usersecuritygrouplist = get_resolved(@props['usersecuritygrouplist'],workitem)
|
122
|
+
if resolved_usersecuritygrouplist.nil? || !validate_param(resolved_usersecuritygrouplist,"map")
|
123
|
+
raise "Malformed optional parameter usersecuritygrouplist for resource #{@name}"
|
124
|
+
end
|
125
|
+
resolved_usersecuritygrouplist
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_protocol
|
129
|
+
resolved_protocol = get_resolved(@props['protocol'],workitem)
|
130
|
+
if resolved_protocol.nil? || !validate_param(resolved_protocol,"string")
|
131
|
+
raise "Malformed optional parameter protocol for resource #{@name}"
|
132
|
+
end
|
133
|
+
resolved_protocol
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_domainid
|
137
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
138
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
139
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
140
|
+
end
|
141
|
+
resolved_domainid
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_icmptype
|
145
|
+
resolved_icmptype = get_resolved(@props['icmptype'],workitem)
|
146
|
+
if resolved_icmptype.nil? || !validate_param(resolved_icmptype,"integer")
|
147
|
+
raise "Malformed optional parameter icmptype for resource #{@name}"
|
148
|
+
end
|
149
|
+
resolved_icmptype
|
150
|
+
end
|
151
|
+
|
152
|
+
def get_startport
|
153
|
+
resolved_startport = get_resolved(@props['startport'],workitem)
|
154
|
+
if resolved_startport.nil? || !validate_param(resolved_startport,"integer")
|
155
|
+
raise "Malformed optional parameter startport for resource #{@name}"
|
156
|
+
end
|
157
|
+
resolved_startport
|
158
|
+
end
|
159
|
+
|
160
|
+
def get_icmpcode
|
161
|
+
resolved_icmpcode = get_resolved(@props['icmpcode'],workitem)
|
162
|
+
if resolved_icmpcode.nil? || !validate_param(resolved_icmpcode,"integer")
|
163
|
+
raise "Malformed optional parameter icmpcode for resource #{@name}"
|
164
|
+
end
|
165
|
+
resolved_icmpcode
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_projectid
|
169
|
+
resolved_projectid = get_resolved(@props['projectid'],workitem)
|
170
|
+
if resolved_projectid.nil? || !validate_param(resolved_projectid,"uuid")
|
171
|
+
raise "Malformed optional parameter projectid for resource #{@name}"
|
172
|
+
end
|
173
|
+
resolved_projectid
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_securitygroupid
|
177
|
+
resolved_securitygroupid = get_resolved(@props['securitygroupid'],workitem)
|
178
|
+
if resolved_securitygroupid.nil? || !validate_param(resolved_securitygroupid,"uuid")
|
179
|
+
raise "Malformed optional parameter securitygroupid for resource #{@name}"
|
180
|
+
end
|
181
|
+
resolved_securitygroupid
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackSecurityGroupIngress < 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['endport'] = get_endport if @props.has_key?('endport')
|
16
|
+
args['securitygroupid'] = get_securitygroupid if @props.has_key?('securitygroupid')
|
17
|
+
args['protocol'] = get_protocol if @props.has_key?('protocol')
|
18
|
+
args['icmpcode'] = get_icmpcode if @props.has_key?('icmpcode')
|
19
|
+
args['startport'] = get_startport if @props.has_key?('startport')
|
20
|
+
args['projectid'] = get_projectid if @props.has_key?('projectid')
|
21
|
+
args['usersecuritygrouplist'] = get_usersecuritygrouplist if @props.has_key?('usersecuritygrouplist')
|
22
|
+
args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
|
23
|
+
args['securitygroupname'] = get_securitygroupname if @props.has_key?('securitygroupname')
|
24
|
+
args['icmptype'] = get_icmptype if @props.has_key?('icmptype')
|
25
|
+
args['account'] = get_account if @props.has_key?('account')
|
26
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
27
|
+
|
28
|
+
logger.info("Creating resource #{@name} with following arguments")
|
29
|
+
p args
|
30
|
+
result_obj = make_async_request('authorizeSecurityGroupIngress',args)
|
31
|
+
resource_obj = result_obj['securitygroup']['ingressrule'.downcase][0]
|
32
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
33
|
+
resource_obj.each_key do |k|
|
34
|
+
val = resource_obj[k]
|
35
|
+
if('ruleid'.eql?(k))
|
36
|
+
k = 'physical_id'
|
37
|
+
end
|
38
|
+
workitem[@name][k] = val
|
39
|
+
end
|
40
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"SecurityGroupIngress") if @props.has_key?('tags')
|
41
|
+
workitem['ResolvedNames'][@name] = name_cs
|
42
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
43
|
+
|
44
|
+
rescue NoMethodError => nme
|
45
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
46
|
+
raise nme
|
47
|
+
rescue Exception => e
|
48
|
+
logger.error(e.message)
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete
|
55
|
+
logger.debug("Deleting resource #{@name}")
|
56
|
+
begin
|
57
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
58
|
+
if(!physical_id.nil?)
|
59
|
+
args = {'id' => physical_id
|
60
|
+
}
|
61
|
+
result_obj = make_async_request('revokeSecurityGroupIngress',args)
|
62
|
+
if (!(result_obj['error'] == true))
|
63
|
+
logger.info("Successfully deleted resource #{@name}")
|
64
|
+
else
|
65
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
66
|
+
end
|
67
|
+
else
|
68
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
69
|
+
end
|
70
|
+
rescue Exception => e
|
71
|
+
logger.error("Unable to delete resorce #{@name}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_workitem
|
76
|
+
@name = workitem.participant_name
|
77
|
+
@props = workitem['Resources'][@name]['Properties']
|
78
|
+
@props.downcase_key
|
79
|
+
@resolved_names = workitem['ResolvedNames']
|
80
|
+
if workitem['params']['operation'] == 'create'
|
81
|
+
create
|
82
|
+
else
|
83
|
+
delete
|
84
|
+
end
|
85
|
+
reply
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_endport
|
89
|
+
resolved_endport = get_resolved(@props['endport'],workitem)
|
90
|
+
if resolved_endport.nil? || !validate_param(resolved_endport,"integer")
|
91
|
+
raise "Malformed optional parameter endport for resource #{@name}"
|
92
|
+
end
|
93
|
+
resolved_endport
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_securitygroupid
|
97
|
+
resolved_securitygroupid = get_resolved(@props['securitygroupid'],workitem)
|
98
|
+
if resolved_securitygroupid.nil? || !validate_param(resolved_securitygroupid,"uuid")
|
99
|
+
raise "Malformed optional parameter securitygroupid for resource #{@name}"
|
100
|
+
end
|
101
|
+
resolved_securitygroupid
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_protocol
|
105
|
+
resolved_protocol = get_resolved(@props['protocol'],workitem)
|
106
|
+
if resolved_protocol.nil? || !validate_param(resolved_protocol,"string")
|
107
|
+
raise "Malformed optional parameter protocol for resource #{@name}"
|
108
|
+
end
|
109
|
+
resolved_protocol
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_icmpcode
|
113
|
+
resolved_icmpcode = get_resolved(@props['icmpcode'],workitem)
|
114
|
+
if resolved_icmpcode.nil? || !validate_param(resolved_icmpcode,"integer")
|
115
|
+
raise "Malformed optional parameter icmpcode for resource #{@name}"
|
116
|
+
end
|
117
|
+
resolved_icmpcode
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_startport
|
121
|
+
resolved_startport = get_resolved(@props['startport'],workitem)
|
122
|
+
if resolved_startport.nil? || !validate_param(resolved_startport,"integer")
|
123
|
+
raise "Malformed optional parameter startport for resource #{@name}"
|
124
|
+
end
|
125
|
+
resolved_startport
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_projectid
|
129
|
+
resolved_projectid = get_resolved(@props['projectid'],workitem)
|
130
|
+
if resolved_projectid.nil? || !validate_param(resolved_projectid,"uuid")
|
131
|
+
raise "Malformed optional parameter projectid for resource #{@name}"
|
132
|
+
end
|
133
|
+
resolved_projectid
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_usersecuritygrouplist
|
137
|
+
resolved_usersecuritygrouplist = get_resolved(@props['usersecuritygrouplist'],workitem)
|
138
|
+
if resolved_usersecuritygrouplist.nil? || !validate_param(resolved_usersecuritygrouplist,"map")
|
139
|
+
raise "Malformed optional parameter usersecuritygrouplist for resource #{@name}"
|
140
|
+
end
|
141
|
+
resolved_usersecuritygrouplist
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_cidrlist
|
145
|
+
resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
|
146
|
+
if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
|
147
|
+
raise "Malformed optional parameter cidrlist for resource #{@name}"
|
148
|
+
end
|
149
|
+
resolved_cidrlist
|
150
|
+
end
|
151
|
+
|
152
|
+
def get_securitygroupname
|
153
|
+
resolved_securitygroupname = get_resolved(@props['securitygroupname'],workitem)
|
154
|
+
if resolved_securitygroupname.nil? || !validate_param(resolved_securitygroupname,"string")
|
155
|
+
raise "Malformed optional parameter securitygroupname for resource #{@name}"
|
156
|
+
end
|
157
|
+
resolved_securitygroupname
|
158
|
+
end
|
159
|
+
|
160
|
+
def get_icmptype
|
161
|
+
resolved_icmptype = get_resolved(@props['icmptype'],workitem)
|
162
|
+
if resolved_icmptype.nil? || !validate_param(resolved_icmptype,"integer")
|
163
|
+
raise "Malformed optional parameter icmptype for resource #{@name}"
|
164
|
+
end
|
165
|
+
resolved_icmptype
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_account
|
169
|
+
resolved_account = get_resolved(@props['account'],workitem)
|
170
|
+
if resolved_account.nil? || !validate_param(resolved_account,"string")
|
171
|
+
raise "Malformed optional parameter account for resource #{@name}"
|
172
|
+
end
|
173
|
+
resolved_account
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_domainid
|
177
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
178
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
179
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
180
|
+
end
|
181
|
+
resolved_domainid
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|