This file is indexed.

/usr/lib/python2.7/dist-packages/neutronclient/neutron/v2_0/qos/policy.py is in python-neutronclient 1:6.0.0-2.

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
# Copyright 2015 Huawei Technologies India Pvt Ltd, 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.
#

import os

from neutronclient._i18n import _
from neutronclient.neutron import v2_0 as neutronv20


def get_qos_policy_id(client, policy_id_or_name):
    _policy_id = neutronv20.find_resourceid_by_name_or_id(
        client, 'policy', policy_id_or_name, cmd_resource='qos_policy')
    return _policy_id


class CreateQosPolicyMixin(object):
    def add_arguments_qos_policy(self, parser):
        qos_policy_args = parser.add_mutually_exclusive_group()
        qos_policy_args.add_argument(
            '--qos-policy',
            help=_('ID or name of the QoS policy that should'
                   'be attached to the resource.'))
        return qos_policy_args

    def args2body_qos_policy(self, parsed_args, resource):
        if parsed_args.qos_policy:
            _policy_id = get_qos_policy_id(self.get_client(),
                                           parsed_args.qos_policy)
            resource['qos_policy_id'] = _policy_id


class UpdateQosPolicyMixin(CreateQosPolicyMixin):
    def add_arguments_qos_policy(self, parser):
        qos_policy_args = (super(UpdateQosPolicyMixin, self).
                           add_arguments_qos_policy(parser))
        qos_policy_args.add_argument(
            '--no-qos-policy',
            action='store_true',
            help=_('Detach QoS policy from the resource.'))
        return qos_policy_args

    def args2body_qos_policy(self, parsed_args, resource):
        super(UpdateQosPolicyMixin, self).args2body_qos_policy(parsed_args,
                                                               resource)
        if parsed_args.no_qos_policy:
            resource['qos_policy_id'] = None


class ListQoSPolicy(neutronv20.ListCommand):
    """List QoS policies that belong to a given tenant connection."""

    resource = 'policy'
    shadow_resource = 'qos_policy'
    list_columns = ['id', 'name']
    pagination_support = True
    sorting_support = True


class ShowQoSPolicy(neutronv20.ShowCommand):
    """Show information of a given qos policy."""

    resource = 'policy'
    shadow_resource = 'qos_policy'

    def format_output_data(self, data):
        rules = []
        for rule in data['policy'].get('rules', []):
            rules.append("%s (type: %s)" % (rule['id'], rule['type']))
        data['policy']['rules'] = os.linesep.join(rules)

        super(ShowQoSPolicy, self).format_output_data(data)


class CreateQoSPolicy(neutronv20.CreateCommand):
    """Create a qos policy."""

    resource = 'policy'
    shadow_resource = 'qos_policy'

    def add_known_arguments(self, parser):
        parser.add_argument(
            'name', metavar='NAME',
            help=_('Name of the QoS policy to be created.'))
        parser.add_argument(
            '--description',
            help=_('Description of the QoS policy to be created.'))
        parser.add_argument(
            '--shared',
            action='store_true',
            help=_('Accessible by other tenants. '
                   'Set shared to True (default is False).'))

    def args2body(self, parsed_args):
        body = {'name': parsed_args.name}
        if parsed_args.description:
            body['description'] = parsed_args.description
        if parsed_args.shared:
            body['shared'] = parsed_args.shared
        if parsed_args.tenant_id:
            body['tenant_id'] = parsed_args.tenant_id
        return {self.resource: body}


class UpdateQoSPolicy(neutronv20.UpdateCommand):
    """Update a given qos policy."""

    resource = 'policy'
    shadow_resource = 'qos_policy'

    def add_known_arguments(self, parser):
        parser.add_argument(
            '--name',
            help=_('Name of the QoS policy.'))
        parser.add_argument(
            '--description',
            help=_('Description of the QoS policy.'))
        shared_group = parser.add_mutually_exclusive_group()
        shared_group.add_argument(
            '--shared',
            action='store_true',
            help=_('Accessible by other tenants. '
                   'Set shared to True (default is False).'))
        shared_group.add_argument(
            '--no-shared',
            action='store_true',
            help=_('Not accessible by other tenants. '
                   'Set shared to False.'))

    def args2body(self, parsed_args):
        body = {}
        if parsed_args.name:
            body['name'] = parsed_args.name
        if parsed_args.description:
            body['description'] = parsed_args.description
        if parsed_args.shared:
            body['shared'] = True
        if parsed_args.no_shared:
            body['shared'] = False

        return {self.resource: body}


class DeleteQoSPolicy(neutronv20.DeleteCommand):
    """Delete a given qos policy."""

    resource = 'policy'
    shadow_resource = 'qos_policy'