OpenStack Dashboard (Horizon)
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.

tables.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  2. # Copyright 2012 Nebula, Inc.
  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. import logging
  16. from django.core.urlresolvers import reverse
  17. from django.utils.translation import ugettext as _
  18. from horizon import api
  19. from horizon import tables
  20. LOG = logging.getLogger(__name__)
  21. class DeleteGroup(tables.DeleteAction):
  22. data_type_singular = _("Security Group")
  23. data_type_plural = _("Security Groups")
  24. def allowed(self, request, security_group=None):
  25. if not security_group:
  26. return True
  27. return security_group.name != 'default'
  28. def delete(self, request, obj_id):
  29. api.security_group_delete(request, obj_id)
  30. class CreateGroup(tables.LinkAction):
  31. name = "create"
  32. verbose_name = _("Create Security Group")
  33. url = "horizon:nova:access_and_security:security_groups:create"
  34. classes = ("ajax-modal",)
  35. class EditRules(tables.LinkAction):
  36. name = "edit_rules"
  37. verbose_name = _("Edit Rules")
  38. url = "horizon:nova:access_and_security:security_groups:edit_rules"
  39. attrs = {"class": "ajax-modal"}
  40. class SecurityGroupsTable(tables.DataTable):
  41. name = tables.Column("name")
  42. description = tables.Column("description")
  43. def sanitize_id(self, obj_id):
  44. return int(obj_id)
  45. class Meta:
  46. name = "security_groups"
  47. verbose_name = _("Security Groups")
  48. table_actions = (CreateGroup, DeleteGroup)
  49. row_actions = (EditRules, DeleteGroup)
  50. class DeleteRule(tables.DeleteAction):
  51. data_type_singular = _("Rule")
  52. data_type_plural = _("Rules")
  53. def delete(self, request, obj_id):
  54. api.security_group_rule_delete(request, obj_id)
  55. def get_success_url(self, request):
  56. return reverse("horizon:nova:access_and_security:index")
  57. def get_cidr(rule):
  58. return rule.ip_range['cidr']
  59. class RulesTable(tables.DataTable):
  60. protocol = tables.Column("ip_protocol",
  61. verbose_name=_("IP Protocol"),
  62. filters=(unicode.upper,))
  63. from_port = tables.Column("from_port", verbose_name=_("From Port"))
  64. to_port = tables.Column("to_port", verbose_name=_("To Port"))
  65. cidr = tables.Column(get_cidr, verbose_name=_("CIDR"))
  66. def sanitize_id(self, obj_id):
  67. return int(obj_id)
  68. def get_object_display(self, rule):
  69. return unicode(rule)
  70. class Meta:
  71. name = "rules"
  72. verbose_name = _("Security Group Rules")
  73. table_actions = (DeleteRule,)
  74. row_actions = (DeleteRule,)