diff options
Diffstat (limited to 'openstack_dashboard/dashboards/project/instances/workflows/update_instance.py')
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/workflows/update_instance.py | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py b/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py deleted file mode 100644 index f4cc5b9b..00000000 --- a/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py +++ /dev/null @@ -1,148 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Copyright 2012 Nebula, Inc. -# -# 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 -# -# Unless required by applicable law or agreed to in writing, software -# 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. - - -from django.utils.translation import ugettext_lazy as _ - -from horizon import exceptions -from horizon import forms -from horizon import workflows - -from openstack_dashboard import api -from openstack_dashboard.utils.filters import get_int_or_uuid - - -INDEX_URL = "horizon:projects:instances:index" -ADD_USER_URL = "horizon:projects:instances:create_user" - - -class UpdateInstanceSecurityGroupsAction(workflows.Action): - default_role = forms.CharField(required=False) - role_member = forms.MultipleChoiceField(required=False) - - def __init__(self, request, *args, **kwargs): - super(UpdateInstanceSecurityGroupsAction, self).__init__(request, - *args, - **kwargs) - err_msg = _('Unable to retrieve security group list. ' - 'Please try again later.') - context = args[0] - instance_id = context.get('instance_id', '') - - self.fields['default_role'].initial = 'member' - - # Get list of available security groups - all_groups = [] - try: - all_groups = api.network.security_group_list(request) - except: - exceptions.handle(request, err_msg) - groups_list = [(group.id, group.name) for group in all_groups] - - instance_groups = [] - try: - instance_groups = api.network.server_security_groups(request, - instance_id) - except Exception: - exceptions.handle(request, err_msg) - self.fields['role_member'].choices = groups_list - self.fields['role_member'].initial = [group.id - for group in instance_groups] - - def handle(self, request, data): - instance_id = data['instance_id'] - wanted_groups = map(get_int_or_uuid, data['wanted_groups']) - try: - api.network.server_update_security_groups(request, instance_id, - wanted_groups) - except Exception as e: - exceptions.handle(request, e.message) - return False - return True - - class Meta: - name = _("Security Groups") - slug = "update_security_groups" - - -class UpdateInstanceSecurityGroups(workflows.UpdateMembersStep): - action_class = UpdateInstanceSecurityGroupsAction - help_text = _("From here you can add and remove security groups to " - "this project from the list of available security groups.") - available_list_title = _("All Security Groups") - members_list_title = _("Instance Security Groups") - no_available_text = _("No security groups found.") - no_members_text = _("No security groups enabled.") - show_roles = False - depends_on = ("instance_id",) - contributes = ("wanted_groups",) - - def contribute(self, data, context): - request = self.workflow.request - if data: - context["wanted_groups"] = request.POST.getlist("role_member") - return context - - -class UpdateInstanceInfoAction(workflows.Action): - name = forms.CharField(required=True) - - def handle(self, request, data): - try: - api.nova.server_update(request, - data['instance_id'], - data['name']) - except: - exceptions.handle(request, ignore=True) - return False - return True - - class Meta: - name = _("Info") - slug = 'instance_info' - help_text = _("From here you can edit the instance details.") - - -class UpdateInstanceInfo(workflows.Step): - action_class = UpdateInstanceInfoAction - depends_on = ("instance_id",) - contributes = ("name",) - - -class UpdateInstance(workflows.Workflow): - slug = "update_instance" - name = _("Edit Instance") - finalize_button_name = _("Save") - success_message = _('Modified instance "%s".') - failure_message = _('Unable to modify instance "%s".') - success_url = "horizon:project:instances:index" - default_steps = (UpdateInstanceInfo, - UpdateInstanceSecurityGroups) - - def format_status_message(self, message): - return message % self.context.get('name', 'unknown instance') - - -# NOTE(kspear): nova doesn't support instance security group management -# by an admin. This isn't really the place for this code, -# but the other ways of special-casing this are even messier. -class AdminUpdateInstance(UpdateInstance): - success_url = "horizon:admin:instances:index" - default_steps = (UpdateInstanceInfo,) |