|
1
|
|
|
from lib import actions |
|
2
|
|
|
from libcloud.compute.drivers.dimensiondata import ( |
|
3
|
|
|
DimensionDataFirewallRule, |
|
4
|
|
|
DimensionDataFirewallAddress) |
|
5
|
|
|
|
|
6
|
|
|
__all__ = [ |
|
7
|
|
|
'CreateFirewallRuleAction', |
|
8
|
|
|
] |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class CreateFirewallRuleAction(actions.BaseAction): |
|
12
|
|
|
|
|
13
|
|
|
def run(self, **kwargs): |
|
14
|
|
|
network_domain_id = kwargs['network_domain_id'] |
|
15
|
|
|
del kwargs['network_domain_id'] |
|
16
|
|
|
action = kwargs['action'] |
|
17
|
|
|
del kwargs['action'] |
|
18
|
|
|
region = kwargs['region'] |
|
19
|
|
|
del kwargs['region'] |
|
20
|
|
|
driver = self._get_compute_driver(region) |
|
21
|
|
|
network_domain = driver.ex_get_network_domain(network_domain_id) |
|
22
|
|
|
kwargs['network_domain'] = network_domain |
|
23
|
|
|
any_source = kwargs['any_source'] |
|
24
|
|
|
del kwargs['any_source'] |
|
25
|
|
|
any_destination = kwargs['any_destination'] |
|
26
|
|
|
del kwargs['any_destination'] |
|
27
|
|
|
if any_source: |
|
28
|
|
|
source = DimensionDataFirewallAddress( |
|
29
|
|
|
any_ip=True, |
|
30
|
|
|
ip_address=None, |
|
31
|
|
|
port_begin=None, |
|
32
|
|
|
port_end=None, |
|
33
|
|
|
ip_prefix_size=None |
|
34
|
|
|
) |
|
35
|
|
|
else: |
|
36
|
|
|
source = DimensionDataFirewallAddress( |
|
37
|
|
|
any_ip=True, |
|
38
|
|
|
ip_address=kwargs['source_ip'], |
|
39
|
|
|
port_begin=kwargs['source_port_begin'], |
|
40
|
|
|
port_end=['source_port_end'], |
|
41
|
|
|
ip_prefix_size=['source_ip_prefix_size'] |
|
42
|
|
|
) |
|
43
|
|
|
if any_destination: |
|
44
|
|
|
destination = DimensionDataFirewallAddress( |
|
45
|
|
|
any_ip=True, |
|
46
|
|
|
ip_address=None, |
|
47
|
|
|
port_begin=None, |
|
48
|
|
|
port_end=None, |
|
49
|
|
|
ip_prefix_size=None |
|
50
|
|
|
) |
|
51
|
|
|
else: |
|
52
|
|
|
destination = DimensionDataFirewallAddress( |
|
53
|
|
|
any_ip=True, |
|
54
|
|
|
ip_address=kwargs['destination_ip'], |
|
55
|
|
|
port_begin=kwargs['destination_port_begin'], |
|
56
|
|
|
port_end=['destination_port_end'], |
|
57
|
|
|
ip_prefix_size=['destination_ip_prefix_size'] |
|
58
|
|
|
) |
|
59
|
|
|
# setup the rule |
|
60
|
|
|
rule = DimensionDataFirewallRule( |
|
61
|
|
|
id=None, |
|
62
|
|
|
location=network_domain.location, |
|
63
|
|
|
status=None, |
|
64
|
|
|
network_domain=network_domain, |
|
65
|
|
|
enabled=True, |
|
66
|
|
|
source=source, |
|
67
|
|
|
destination=destination, |
|
68
|
|
|
protocol=kwargs['protocol'], |
|
69
|
|
|
name=kwargs['name'], |
|
70
|
|
|
action=kwargs['fw_action'], |
|
71
|
|
|
ip_version=kwargs['ip_version'] |
|
72
|
|
|
) |
|
73
|
|
|
kwargs['rule'] = rule |
|
74
|
|
|
del kwargs['name'] |
|
75
|
|
|
del kwargs['fw_action'] |
|
76
|
|
|
del kwargs['ip_version'] |
|
77
|
|
|
del kwargs['protocol'] |
|
78
|
|
|
del kwargs['source_ip'] |
|
79
|
|
|
del kwargs['source_port_begin'] |
|
80
|
|
|
del kwargs['source_port_end'] |
|
81
|
|
|
del kwargs['source_ip_prefix_size'] |
|
82
|
|
|
del kwargs['destination_ip'] |
|
83
|
|
|
del kwargs['destination_port_begin'] |
|
84
|
|
|
del kwargs['destination_port_end'] |
|
85
|
|
|
del kwargs['destination_ip_prefix_size'] |
|
86
|
|
|
return self._do_function(driver, action, **kwargs) |
|
87
|
|
|
|