Package yakumo :: Package neutron :: Package v2 :: Module security_group_rule
[hide private]
[frames] | no frames]

Source Code for Module yakumo.neutron.v2.security_group_rule

 1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
 2  # All Rights Reserved. 
 3  # 
 4  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
 5  #    not use this file except in compliance with the License. You may obtain 
 6  #    a copy of the License at 
 7  # 
 8  #         http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  #    Unless required by applicable law or agreed to in writing, software 
11  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
12  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
13  #    License for the specific language governing permissions and limitations 
14  #    under the License. 
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   
41 -class Resource(base.Resource):
42 """Resource class for security group rules in Networking V2 API"""
43 44
45 -class Manager(base.SubManager):
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
56 - def create(self, direction=UNDEF, ethertype=UNDEF, 57 port_range_min=UNDEF, port_range_max=UNDEF, 58 protocol=UNDEF, remote_group=UNDEF, remote_ip_prefix=UNDEF):
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
89 - def _find_gen(self, **kwargs):
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