Add "Edit evironment".

Change-Id: I42bb058b6785dc55b48b0ea63145a1e14b042e80
This commit is contained in:
Ekaterina Fedorova 2013-06-05 18:11:33 +04:00
parent c03e0efede
commit 0be3d0bb5a
7 changed files with 119 additions and 23 deletions

View File

@ -136,6 +136,10 @@ def environment_deploy(request, environment_id):
return env
def environment_update(request, environment_id, name):
return muranoclient(request).environments.update(environment_id, name)
def get_service_client(request, service_type):
if service_type == 'Active Directory':
return muranoclient(request).activeDirectories

View File

@ -14,11 +14,12 @@
import logging
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from horizon import exceptions
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from muranodashboard.panel import api
LOG = logging.getLogger(__name__)
@ -78,8 +79,8 @@ class CreateEnvironment(tables.LinkAction):
class DeleteEnvironment(tables.DeleteAction):
data_type_singular = _("Environment")
data_type_plural = _("Environments")
data_type_singular = _('Environment')
data_type_plural = _('Environments')
def allowed(self, request, environment):
return True
@ -92,13 +93,28 @@ class DeleteEnvironment(tables.DeleteAction):
exceptions.handle(request, msg)
class EditEnvironment(tables.LinkAction):
name = 'edit'
verbose_name = _('Edit Environment')
url = 'horizon:project:murano:update_environment'
classes = ('ajax-modal', 'btn-edit')
def allowed(self, request, environment):
status = getattr(environment, 'status', None)
if status not in [STATUS_ID_DEPLOYING]:
return True
else:
return False
class DeleteService(tables.DeleteAction):
data_type_singular = _('Service')
data_type_plural = _('Services')
def allowed(self, request, environment):
status = getattr(environment, 'status', None)
if status not in [STATUS_ID_DEPLOYING]:
#TODO: Change this when services deletion on deployed env fixed
if status in [STATUS_ID_PENDING]:
return True
return False
@ -132,13 +148,13 @@ class DeployEnvironment(tables.BatchAction):
api.environment_deploy(request, environment_id)
except:
msg = _('Unable to deploy. Maybe this environment \
is already deploying by someone else. Try again later')
is already deploying. Try again later')
redirect = reverse("horizon:project:murano:index")
exceptions.handle(request, msg, redirect=redirect)
class ShowEnvironmentServices(tables.LinkAction):
name = 'edit'
name = 'show'
verbose_name = _('Services')
url = 'horizon:project:murano:services'
@ -181,7 +197,7 @@ class EnvironmentsTable(tables.DataTable):
status_columns = ['status']
table_actions = (CreateEnvironment, DeleteEnvironment)
row_actions = (ShowEnvironmentServices, DeployEnvironment,
DeleteEnvironment)
EditEnvironment, DeleteEnvironment)
class ServicesTable(tables.DataTable):

View File

@ -15,7 +15,7 @@
from django.conf.urls.defaults import patterns, url
from views import IndexView, Services, CreateEnvironmentView, DetailServiceView
from views import Wizard
from views import Wizard, EditEnvironmentView
from forms import WizardFormServiceType, WizardFormConfiguration
VIEW_MOD = 'openstack_dashboard.dashboards.project.murano.views'
@ -28,6 +28,9 @@ urlpatterns = patterns(
name='create'),
url(r'^create_environment$', CreateEnvironmentView.as_view(),
name='create_environment'),
url(r'^(?P<environment_id>[^/]+)/update_environment$',
EditEnvironmentView.as_view(),
name='update_environment'),
url(r'^(?P<environment_id>[^/]+)/services$', Services.as_view(),
name='services'),
url(r'^services/(?P<service_id>[^/]+)$', DetailServiceView.as_view(),

View File

@ -17,7 +17,7 @@ from muranoclient.common.exceptions import CommunicationError
import re
from django.views import generic
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.contrib.formtools.wizard.views import SessionWizardView
@ -30,7 +30,7 @@ from horizon.forms.views import ModalFormMixin
from muranodashboard.panel import api
from tables import EnvironmentsTable, ServicesTable
from workflows import CreateEnvironment
from workflows import CreateEnvironment, UpdateEnvironment
from tabs import ServicesTabs
from forms import WizardFormADConfiguration
from forms import WizardFormIISConfiguration
@ -224,3 +224,32 @@ class CreateEnvironmentView(workflows.WorkflowView):
initial['project_id'] = self.request.user.tenant_id
initial['user_id'] = self.request.user.id
return initial
class EditEnvironmentView(workflows.WorkflowView):
workflow_class = UpdateEnvironment
template_name = 'update_env.html'
success_url = reverse_lazy("horizon:project:murano:index")
def get_context_data(self, **kwargs):
context = super(EditEnvironmentView, self).get_context_data(**kwargs)
context["environment_id"] = self.kwargs['environment_id']
return context
def get_object(self, *args, **kwargs):
if not hasattr(self, "_object"):
environment_id = self.kwargs['environment_id']
try:
self._object = \
api.environment_get(self.request, environment_id)
except:
redirect = reverse("horizon:project:murano:index")
msg = _('Unable to retrieve environment details.')
exceptions.handle(self.request, msg, redirect=redirect)
return self._object
def get_initial(self):
initial = super(EditEnvironmentView, self).get_initial()
initial.update({'environment_id': self.kwargs['environment_id'],
'name': getattr(self.get_object(), 'name', '')})
return initial

View File

@ -62,7 +62,7 @@ class ConfigureEnvironmentAction(workflows.Action):
class ConfigureEnvironment(workflows.Step):
action_class = ConfigureEnvironmentAction
contibutes = ('name',)
contributes = ('name',)
def contribute(self, data, context):
if data:
@ -90,3 +90,47 @@ class CreateEnvironment(workflows.Workflow):
except:
exceptions.handle(request)
return False
class UpdateEnvironmentInfoAction(workflows.Action):
name = forms.CharField(required=True)
def handle(self, request, data):
try:
api.environment_update(request,
data['environment_id'],
data['name'])
except:
exceptions.handle(request, ignore=True)
return False
return True
class Meta:
name = _("Environment Info")
slug = 'environment_info'
help_text = _("From here you can edit the environment details.")
class UpdateEnvironmentInfo(workflows.Step):
action_class = UpdateEnvironmentInfoAction
depends_on = ('environment_id',)
contributes = ('name',)
def contribute(self, data, context):
if data:
context['name'] = data.get('name', '')
return context
class UpdateEnvironment(workflows.Workflow):
slug = "update_environment"
name = _("Edit Environment")
finalize_button_name = _("Save")
success_message = _('Modified environment "%s".')
failure_message = _('Unable to modify environment "%s".')
success_url = "horizon:project:murano:index"
default_steps = (UpdateEnvironmentInfo,)
def format_status_message(self, message):
return message % self.context.get('name', 'unknown environment')

View File

@ -1,11 +0,0 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Update Instance" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Update Instance") %}
{% endblock page_header %}
{% block main %}
{% include 'project/instances/_update.html' %}
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Edit Environment" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Edit Environment") %}
{% endblock page_header %}
{% block main %}
{% include 'horizon/common/_workflow.html' %}
{% endblock %}