2015-11-09 16:10:36 +00:00
|
|
|
# (c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
|
2015-07-05 16:04:41 +01:00
|
|
|
#
|
2015-11-09 16:10:36 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2015-07-05 16:04:41 +01:00
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
2015-11-09 16:10:36 +00:00
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2015-07-05 16:04:41 +01:00
|
|
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-05-14 02:18:54 +09:00
|
|
|
from django.urls import reverse
|
2015-07-05 16:04:41 +01:00
|
|
|
|
|
|
|
from horizon import exceptions
|
|
|
|
from horizon import forms
|
|
|
|
from horizon import workflows
|
|
|
|
|
2015-11-09 16:10:36 +00:00
|
|
|
import disaster_recovery.api.api as freezer_api
|
2015-07-05 16:04:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SessionConfigurationAction(workflows.Action):
|
|
|
|
session_id = forms.ChoiceField(
|
|
|
|
help_text=_("Set a session to attach this job"),
|
2017-01-26 23:15:30 +08:00
|
|
|
label=_("Session Name"))
|
2015-07-05 16:04:41 +01:00
|
|
|
|
|
|
|
job_id = forms.CharField(
|
2017-01-26 23:15:30 +08:00
|
|
|
widget=forms.HiddenInput())
|
2015-07-05 16:04:41 +01:00
|
|
|
|
|
|
|
def populate_session_id_choices(self, request, context):
|
|
|
|
sessions = []
|
|
|
|
try:
|
2015-11-09 16:10:36 +00:00
|
|
|
sessions = freezer_api.Session(request).list()
|
2015-07-05 16:04:41 +01:00
|
|
|
except Exception:
|
|
|
|
exceptions.handle(request, _('Error getting session list'))
|
|
|
|
|
|
|
|
sessions = [(s.session_id, s.description) for s in sessions]
|
|
|
|
sessions.insert(0, ('', _('Select A Session')))
|
|
|
|
return sessions
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
name = _("Sessions")
|
|
|
|
slug = "sessions"
|
|
|
|
|
|
|
|
|
|
|
|
class SessionConfiguration(workflows.Step):
|
|
|
|
action_class = SessionConfigurationAction
|
|
|
|
contributes = ('session_id',
|
|
|
|
'job_id')
|
|
|
|
|
|
|
|
|
|
|
|
class AttachJobToSession(workflows.Workflow):
|
|
|
|
slug = "attach_job"
|
|
|
|
name = _("Attach To Session")
|
|
|
|
finalize_button_name = _("Attach")
|
2016-03-01 11:15:47 +00:00
|
|
|
success_message = _('Job attached successfully.')
|
2015-07-05 16:04:41 +01:00
|
|
|
failure_message = _('Unable to attach to session.')
|
2015-11-09 16:10:36 +00:00
|
|
|
success_url = "horizon:disaster_recovery:jobs:index"
|
2015-07-05 16:04:41 +01:00
|
|
|
default_steps = (SessionConfiguration,)
|
|
|
|
|
|
|
|
def handle(self, request, context):
|
|
|
|
try:
|
2015-11-09 16:10:36 +00:00
|
|
|
freezer_api.Session(request).add_job(context['session_id'],
|
|
|
|
context['job_id'])
|
|
|
|
|
|
|
|
return reverse("horizon:disaster_recovery:jobs:index")
|
2015-07-05 16:04:41 +01:00
|
|
|
except Exception:
|
|
|
|
exceptions.handle(request)
|
|
|
|
return False
|