OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

security_group_rules.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright 2011 OpenStack Foundation
  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. Security group rules interface (1.1 extension).
  17. """
  18. from novaclient import base
  19. class SecurityGroupRule(base.Resource):
  20. def __str__(self):
  21. return str(self.id)
  22. def delete(self):
  23. self.manager.delete(self)
  24. class SecurityGroupRuleManager(base.ManagerWithFind):
  25. resource_class = SecurityGroupRule
  26. def create(self, parent_group_id, ip_protocol=None, from_port=None,
  27. to_port=None, cidr=None, group_id=None):
  28. """
  29. Create a security group
  30. :param ip_protocol: IP protocol, one of 'tcp', 'udp' or 'icmp'
  31. :param from_port: Source port
  32. :param to_port: Destination port
  33. :param cidr: Destination IP address(es) in CIDR notation
  34. :param group_id: Security group id (int)
  35. :param parent_group_id: Parent security group id (int)
  36. """
  37. body = {"security_group_rule": {
  38. "ip_protocol": ip_protocol,
  39. "from_port": from_port,
  40. "to_port": to_port,
  41. "cidr": cidr,
  42. "group_id": group_id,
  43. "parent_group_id": parent_group_id}}
  44. return self._create('/os-security-group-rules', body,
  45. 'security_group_rule')
  46. def delete(self, rule):
  47. """
  48. Delete a security group rule
  49. :param rule: The security group rule to delete (ID or Class)
  50. """
  51. self._delete('/os-security-group-rules/%s' % base.getid(rule))