VM-side agent for Murano
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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. # Copyright (c) 2013 Mirantis Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. # implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import logging
  16. import re
  17. from django.utils.translation import ugettext_lazy as _
  18. from horizon import messages
  19. from horizon import tables
  20. from glazierdashboard.tabula import api
  21. LOG = logging.getLogger(__name__)
  22. class CreateService(tables.LinkAction):
  23. name = 'CreateService'
  24. verbose_name = _('Create Service')
  25. url = 'horizon:project:tabula:create'
  26. classes = ('btn-launch', 'ajax-modal')
  27. def allowed(self, request, datum):
  28. return True
  29. def action(self, request, service):
  30. api.service_create(request, service)
  31. class CreateEnvironment(tables.LinkAction):
  32. name = 'CreateEnvironment'
  33. verbose_name = _('Create Environment')
  34. url = 'horizon:project:tabula:create_dc'
  35. classes = ('btn-launch', 'ajax-modal')
  36. def allowed(self, request, datum):
  37. return True
  38. def action(self, request, environment):
  39. api.environment_create(request, environment)
  40. class DeleteEnvironment(tables.BatchAction):
  41. name = 'delete'
  42. action_present = _('Delete')
  43. action_past = _('Delete')
  44. data_type_singular = _('Environment')
  45. data_type_plural = _('Environment')
  46. classes = ('btn-danger', 'btn-terminate')
  47. def allowed(self, request, datum):
  48. return True
  49. def action(self, request, environment_id):
  50. api.environment_delete(request, environment_id)
  51. class DeleteService(tables.BatchAction):
  52. name = 'delete'
  53. action_present = _('Delete')
  54. action_past = _('Delete')
  55. data_type_singular = _('Service')
  56. data_type_plural = _('Service')
  57. classes = ('btn-danger', 'btn-terminate')
  58. def allowed(self, request, datum):
  59. return True
  60. def action(self, request, service_id):
  61. link = request.__dict__['META']['HTTP_REFERER']
  62. datacenter_id = re.search('tabula/(\S+)', link).group(0)[6:-1]
  63. try:
  64. api.service_delete(request, datacenter_id, service_id)
  65. except:
  66. messages.error(request, _('Sorry, you can not delete this '
  67. 'service right now.'))
  68. class DeployEnvironment(tables.BatchAction):
  69. name = 'deploy'
  70. action_present = _('Deploy')
  71. action_past = _('Deploy')
  72. data_type_singular = _('Environment')
  73. data_type_plural = _('Environment')
  74. classes = 'btn-launch'
  75. def allowed(self, request, datum):
  76. return True
  77. def action(self, request, environment_id):
  78. return api.environment_deploy(request, environment_id)
  79. class ShowDataCenterServices(tables.LinkAction):
  80. name = 'edit'
  81. verbose_name = _('Services')
  82. url = 'horizon:project:tabula:services'
  83. def allowed(self, request, instance):
  84. return True
  85. class UpdateDCRow(tables.Row):
  86. ajax = True
  87. def get_data(self, request, environment_id):
  88. return api.environment_get(request, environment_id)
  89. class UpdateServiceRow(tables.Row):
  90. ajax = True
  91. def get_data(self, request, service_id):
  92. link = request.__dict__['META']['HTTP_REFERER']
  93. environment_id = re.search('tabula/(\S+)', link).group(0)[6:-1]
  94. service = api.service_get(request, environment_id, service_id)
  95. return service
  96. STATUS_DISPLAY_CHOICES = (
  97. ('draft', 'Ready to deploy'),
  98. ('pending', 'Wait for configuration'),
  99. ('inprogress', 'Deploy in progress'),
  100. ('finished', 'Active')
  101. )
  102. class DCTable(tables.DataTable):
  103. STATUS_CHOICES = (
  104. (None, True),
  105. ('Ready to deploy', True),
  106. ('Active', True)
  107. )
  108. name = tables.Column('name',
  109. link=('horizon:project:tabula:services'),
  110. verbose_name=_('Name'))
  111. status = tables.Column('status', verbose_name=_('Status'),
  112. status=True,
  113. status_choices=STATUS_CHOICES,
  114. display_choices=STATUS_DISPLAY_CHOICES)
  115. class Meta:
  116. name = 'tabula'
  117. verbose_name = _('Environment')
  118. row_class = UpdateDCRow
  119. status_columns = ['status']
  120. table_actions = (CreateDataCenter,)
  121. row_actions = (ShowDataCenterServices, DeleteDataCenter,
  122. DeployDataCenter)
  123. class ServicesTable(tables.DataTable):
  124. STATUS_CHOICES = (
  125. (None, True),
  126. ('Ready to deploy', True),
  127. ('Active', True)
  128. )
  129. name = tables.Column('name', verbose_name=_('Name'),
  130. link=('horizon:project:tabula:service_details'))
  131. _type = tables.Column('service_type', verbose_name=_('Type'))
  132. status = tables.Column('status', verbose_name=_('Status'),
  133. status=True,
  134. status_choices=STATUS_CHOICES,
  135. display_choices=STATUS_DISPLAY_CHOICES)
  136. operation = tables.Column('operation', verbose_name=_('Operation'))
  137. class Meta:
  138. name = 'services'
  139. verbose_name = _('Services')
  140. row_class = UpdateServiceRow
  141. status_columns = ['status']
  142. table_actions = (CreateService,)