summaryrefslogtreecommitdiff
path: root/novaclient/v2/security_group_default_rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/security_group_default_rules.py')
-rw-r--r--novaclient/v2/security_group_default_rules.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/novaclient/v2/security_group_default_rules.py b/novaclient/v2/security_group_default_rules.py
new file mode 100644
index 0000000..d82a1d8
--- /dev/null
+++ b/novaclient/v2/security_group_default_rules.py
@@ -0,0 +1,81 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13"""
14Security group default rules interface.
15"""
16
17from novaclient import base
18from novaclient import exceptions
19from novaclient.i18n import _
20
21
22class SecurityGroupDefaultRule(base.Resource):
23 def __str__(self):
24 return str(self.id)
25
26 def delete(self):
27 self.manager.delete(self)
28
29
30class SecurityGroupDefaultRuleManager(base.Manager):
31 resource_class = SecurityGroupDefaultRule
32
33 def create(self, ip_protocol=None, from_port=None, to_port=None,
34 cidr=None):
35 """
36 Create a security group default rule
37
38 :param ip_protocol: IP protocol, one of 'tcp', 'udp' or 'icmp'
39 :param from_port: Source port
40 :param to_port: Destination port
41 :param cidr: Destination IP address(es) in CIDR notation
42 """
43
44 try:
45 from_port = int(from_port)
46 except (TypeError, ValueError):
47 raise exceptions.CommandError(_("From port must be an integer."))
48 try:
49 to_port = int(to_port)
50 except (TypeError, ValueError):
51 raise exceptions.CommandError(_("To port must be an integer."))
52 if ip_protocol.upper() not in ['TCP', 'UDP', 'ICMP']:
53 raise exceptions.CommandError(_("IP protocol must be 'tcp', 'udp'"
54 ", or 'icmp'."))
55
56 body = {"security_group_default_rule": {
57 "ip_protocol": ip_protocol,
58 "from_port": from_port,
59 "to_port": to_port,
60 "cidr": cidr}}
61
62 return self._create('/os-security-group-default-rules', body,
63 'security_group_default_rule')
64
65 def delete(self, rule):
66 """
67 Delete a security group default rule
68
69 :param rule: The security group default rule to delete (ID or Class)
70 """
71 self._delete('/os-security-group-default-rules/%s' % base.getid(rule))
72
73 def list(self):
74 """
75 Get a list of all security group default rules
76
77 :rtype: list of :class:`SecurityGroupDefaultRule`
78 """
79
80 return self._list('/os-security-group-default-rules',
81 'security_group_default_rules')