1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Resource class and its manager for security group rules in Networking V2 API
18 """
19
20 from yakumo import base
21 from yakumo.constant import UNDEF
22 from yakumo import mapper
23
24
25 ATTRIBUTE_MAPPING = [
26 ('id', 'id', mapper.Noop),
27 ('direction', 'direction', mapper.Noop),
28 ('ethertype', 'ethertype', mapper.Noop),
29 ('remote_ip_prefix', 'remote_ip_prefix', mapper.Noop),
30 ('port_range_max', 'port_range_max', mapper.Noop),
31 ('port_range_min', 'port_range_min', mapper.Noop),
32 ('protocol', 'protocol', mapper.Noop),
33 ('security_group', 'security_group_id',
34 mapper.Resource('neutron.security_group')),
35 ('remote_group', 'remote_group_id',
36 mapper.Resource('neutron.security_group')),
37 ('project', 'tenant_id', mapper.Resource('project')),
38 ]
39
40
42 """Resource class for security group rules in Networking V2 API"""
43
44
46 """Manager class for security group rules in Networking V2 API"""
47
48 resource_class = Resource
49 service_type = 'network'
50 _attr_mapping = ATTRIBUTE_MAPPING
51 _hidden_methods = ["update"]
52 _json_resource_key = 'security_group_rule'
53 _json_resources_key = 'security_group_rules'
54 _url_resource_path = '/v2.0/security-group-rules'
55
59 """
60 Register a rule of a security group
61
62 @keyword direction: Direction (ingress or egress)
63 @type direction: str
64 @keyword ethertype: Ether type
65 @typt ethertype: str
66 @keyword port_range_min: Minimum number of the port range
67 @type port_range_min: int
68 @keyword port_range_max: Maximum number of the port range
69 @type port_range_max: int
70 @keyword protocol: Protocol (tcp, udp or icmp)
71 @type protocol: str
72 @keyword remote_group: Remote group
73 @type remote_group:
74 @keyword remote_ip_prefix: Remote IP address prefix
75 @type remote_ip_prefix: str
76 @return: Created rule
77 @rtype: yakumo.neutron.v2.security_group_rule.Resource
78 """
79 security_group = self.parent_resource
80 return super(Manager, self).create(direction=direction,
81 ethertype=ethertype,
82 security_group=security_group,
83 port_range_min=port_range_min,
84 port_range_max=port_range_max,
85 protocol=protocol,
86 remote_group=remote_group,
87 remote_ip_prefix=remote_ip_prefix)
88
90 """
91 Find a security group rule
92
93 :param key=value: search condition
94 """
95 kwargs['security_group'] = self.parent_resource
96 return super(Manager, self)._find_gen(**kwargs)
97