This file is indexed.

/usr/lib/python2.7/dist-packages/manila_ui/dashboards/project/shares/replicas/views.py is in python-manila-ui 2.5.1-0.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright (c) 2015 Mirantis, Inc.
# All rights reserved.
#
#    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.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
from horizon import forms
from horizon import tables
from horizon import tabs
from horizon.utils import memoized

from manila_ui.api import manila
from manila_ui.dashboards.project.shares.replicas import (
    forms as replicas_forms)
from manila_ui.dashboards.project.shares.replicas import (
    tables as replicas_tables)
from manila_ui.dashboards.project.shares.replicas import tabs as replicas_tabs


class ManageReplicasView(tables.DataTableView):
    table_class = replicas_tables.ReplicasTable
    template_name = 'project/shares/replicas/manage_replicas.html'
    _redirect_url = 'horizon:project:shares:index'

    def get_context_data(self, **kwargs):
        context = super(ManageReplicasView, self).get_context_data(**kwargs)
        try:
            share = manila.share_get(self.request, self.kwargs["share_id"])
        except Exception:
            redirect = reverse(self._redirect_url)
            exceptions.handle(
                self.request,
                _('Unable to retrieve share. %s') % self.kwargs["share_id"],
                redirect=redirect)
        context["share_display_name"] = share.name or share.id
        context["share"] = self.get_data()
        context["page_title"] = _(
            "Share Replicas: %(share_display_name)s") % {
                "share_display_name": context["share_display_name"]}
        return context

    @memoized.memoized_method
    def get_data(self):
        try:
            share_id = self.kwargs['share_id']
            return manila.share_replica_list(self.request, share_id)
        except Exception:
            redirect = reverse(self._redirect_url)
            exceptions.handle(
                self.request,
                _('Unable to retrieve share replicas.'),
                redirect=redirect)


class DetailReplicaView(tabs.TabView):
    tab_group_class = replicas_tabs.ReplicaDetailTabs
    template_name = 'project/shares/replicas/detail.html'
    _redirect_url = 'horizon:project:shares:index'

    def _calculate_size_of_longest_export_location(self, export_locations):
        size = 40
        for export_location in export_locations:
            current_size = len(export_location["path"])
            if current_size > size:
                size = current_size
        return size

    def get_context_data(self, **kwargs):
        context = super(DetailReplicaView, self).get_context_data(**kwargs)
        replica = self.get_data()
        replica_display_name = replica.id
        context["replica"] = replica
        context["replica_display_name"] = replica_display_name
        context["page_title"] = _(
            "Replica Details: %(replica_display_name)s") % {
                "replica_display_name": replica_display_name}
        return context

    @memoized.memoized_method
    def get_data(self):
        try:
            replica_id = self.kwargs['replica_id']
            replica = manila.share_replica_get(self.request, replica_id)
            replica.export_locations = (
                manila.share_instance_export_location_list(
                    self.request, replica_id))
            replica.el_size = self._calculate_size_of_longest_export_location(
                replica.export_locations)
        except Exception:
            redirect = reverse(self._redirect_url)
            exceptions.handle(
                self.request,
                _('Unable to retrieve replica %sdetails.') % replica_id,
                redirect=redirect)
        return replica

    def get_tabs(self, request, *args, **kwargs):
        replica = self.get_data()
        return self.tab_group_class(request, replica=replica, **kwargs)


class CreateReplicaView(forms.ModalFormView):
    form_class = replicas_forms.CreateReplicaForm
    form_id = "create_replica"
    template_name = 'project/shares/replicas/create_replica.html'
    modal_header = _("Create Replica")
    modal_id = "create_replica_modal"
    submit_label = _("Create")
    submit_url = "horizon:project:shares:create_replica"
    success_url = 'horizon:project:shares:manage_replicas'
    page_title = _("Create Replica")

    def get_context_data(self, **kwargs):
        context = super(CreateReplicaView, self).get_context_data(**kwargs)
        context['share_id'] = self.kwargs['share_id']
        args = (context['share_id'],)
        context['submit_url'] = reverse(self.submit_url, args=args)
        return context

    def get_initial(self):
        return {'share_id': self.kwargs["share_id"]}

    def get_success_url(self):
        return reverse(self.success_url, args=[self.kwargs['share_id']])


class SetReplicaAsActiveView(forms.ModalFormView):
    form_class = replicas_forms.SetReplicaAsActiveForm
    form_id = "set_replica_as_active"
    template_name = "project/shares/replicas/set_replica_as_active.html"
    modal_header = _("Set Replica as Active")
    modal_id = "set_replica_as_active_modal"
    submit_label = _("Set as Active")
    submit_url = "horizon:project:shares:set_replica_as_active"
    success_url = "horizon:project:shares:manage_replicas"
    page_title = _("Set Replica as Active")

    def get_success_url(self):
        return reverse(self.success_url, args=[self.get_object().share_id])

    def get_object(self):
        if not hasattr(self, "_object"):
            replica_id = self.kwargs["replica_id"]
            try:
                self._object = manila.share_replica_get(
                    self.request, replica_id)
            except Exception:
                msg = _("Unable to retrieve replica '%s'.") % replica_id
                url = reverse("horizon:project:shares:index")
                exceptions.handle(self.request, msg, redirect=url)
        return self._object

    def get_context_data(self, **kwargs):
        context = super(SetReplicaAsActiveView, self).get_context_data(
            **kwargs)
        context["replica_id"] = self.kwargs["replica_id"]
        args = (context["replica_id"],)
        context["submit_url"] = reverse(self.submit_url, args=args)
        return context

    def get_initial(self):
        return {"replica_id": self.kwargs["replica_id"]}