This file is indexed.

/usr/lib/python2.7/dist-packages/neutronclient/osc/v2/sfc/sfc_port_pair.py is in python-neutronclient 1:6.7.0-0ubuntu1.

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Copyright (c) 2017 Huawei Technologies India Pvt.Limited.
# 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 logging

from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils

from neutronclient._i18n import _
from neutronclient.osc import utils as nc_osc_utils

LOG = logging.getLogger(__name__)

resource = 'port_pair'

_attr_map = (
    ('id', 'ID', nc_osc_utils.LIST_BOTH),
    ('name', 'Name', nc_osc_utils.LIST_BOTH),
    ('ingress', 'Ingress Logical Port', nc_osc_utils.LIST_BOTH),
    ('egress', 'Egress Logical Port', nc_osc_utils.LIST_BOTH),
    ('service_function_parameters', 'Service Function Parameters',
     nc_osc_utils.LIST_LONG_ONLY),
    ('description', 'Description', nc_osc_utils.LIST_LONG_ONLY),
    ('project_id', 'Project', nc_osc_utils.LIST_LONG_ONLY),
)


class CreateSfcPortPair(command.ShowOne):
    _description = _("Create a port pair")

    def get_parser(self, prog_name):
        parser = super(CreateSfcPortPair, self).get_parser(prog_name)
        parser.add_argument(
            'name',
            metavar='<name>',
            help=_('Name of the port pair'))
        parser.add_argument(
            '--description',
            metavar='<description>',
            help=_('Description for the port pair'))
        parser.add_argument(
            '--service-function-parameters',
            metavar='correlation=<correlation-type>,weight=<weight>',
            action=parseractions.MultiKeyValueAction,
            optional_keys=['correlation', 'weight'],
            help=_('Dictionary of service function parameters. '
                   'Currently, correlation=(None|mpls|nsh) and weight '
                   'are supported. Weight is an integer that influences '
                   'the selection of a port pair within a port pair group '
                   'for a flow. The higher the weight, the more flows will '
                   'hash to the port pair. The default weight is 1.'))
        parser.add_argument(
            '--ingress',
            metavar='<ingress>',
            required=True,
            help=_('Ingress neutron port (name or ID)'))
        parser.add_argument(
            '--egress',
            metavar='<egress>',
            required=True,
            help=_('Egress neutron port (name or ID)'))
        return parser

    def take_action(self, parsed_args):
        client = self.app.client_manager.neutronclient
        attrs = _get_common_attrs(self.app.client_manager, parsed_args)
        body = {resource: attrs}
        obj = client.create_sfc_port_pair(body)[resource]
        columns, display_columns = nc_osc_utils.get_columns(obj, _attr_map)
        data = utils.get_dict_properties(obj, columns)
        return display_columns, data


class DeleteSfcPortPair(command.Command):
    _description = _("Delete a given port pair")

    def get_parser(self, prog_name):
        parser = super(DeleteSfcPortPair, self).get_parser(prog_name)
        parser.add_argument(
            'port_pair',
            metavar="<port-pair>",
            help=_("Port pair to delete (name or ID)")
        )
        return parser

    def take_action(self, parsed_args):
        # TODO(mohan): Add support for deleting multiple resources.
        client = self.app.client_manager.neutronclient
        port_pair_id = _get_id(client, parsed_args.port_pair, resource)
        try:
            client.delete_sfc_port_pair(port_pair_id)
        except Exception as e:
            msg = (_("Failed to delete port pair with name "
                     "or ID '%(port_pair)s': %(e)s")
                   % {'port_pair': parsed_args.port_pair, 'e': e})
            raise exceptions.CommandError(msg)


class ListSfcPortPair(command.Lister):
    _description = _("List port pairs")

    def get_parser(self, prog_name):
        parser = super(ListSfcPortPair, self).get_parser(prog_name)
        parser.add_argument(
            '--long',
            action='store_true',
            help=_("List additional fields in output")
        )
        return parser

    def take_action(self, parsed_args):
        client = self.app.client_manager.neutronclient
        data = client.list_sfc_port_pairs()
        headers, columns = nc_osc_utils.get_column_definitions(
            _attr_map, long_listing=parsed_args.long)
        return (headers,
                (utils.get_dict_properties(
                    s, columns,
                ) for s in data['port_pairs']))


class SetSfcPortPair(command.Command):
    _description = _("Set port pair properties")

    def get_parser(self, prog_name):
        parser = super(SetSfcPortPair, self).get_parser(prog_name)
        parser.add_argument(
            '--name',
            metavar='<name>',
            help=_('Name of the port pair'))
        parser.add_argument(
            '--description',
            metavar='<description>',
            help=_('Description for the port pair'))
        parser.add_argument(
            'port_pair',
            metavar='<port-pair>',
            help=_("Port pair to modify (name or ID)")
        )
        return parser

    def take_action(self, parsed_args):
        client = self.app.client_manager.neutronclient
        port_pair_id = _get_id(client, parsed_args.port_pair, resource)
        attrs = _get_common_attrs(self.app.client_manager, parsed_args,
                                  is_create=False)
        body = {resource: attrs}
        try:
            client.update_sfc_port_pair(port_pair_id, body)
        except Exception as e:
            msg = (_("Failed to update port pair '%(port_pair)s': %(e)s")
                   % {'port_pair': parsed_args.port_pair, 'e': e})
            raise exceptions.CommandError(msg)


class ShowSfcPortPair(command.ShowOne):
    _description = _("Display port pair details")

    def get_parser(self, prog_name):
        parser = super(ShowSfcPortPair, self).get_parser(prog_name)
        parser.add_argument(
            'port_pair',
            metavar='<port-pair>',
            help=_("Port pair to display (name or ID)")
        )
        return parser

    def take_action(self, parsed_args):
        client = self.app.client_manager.neutronclient
        port_pair_id = _get_id(client, parsed_args.port_pair, resource)
        obj = client.show_sfc_port_pair(port_pair_id)[resource]
        columns, display_columns = nc_osc_utils.get_columns(obj, _attr_map)
        data = utils.get_dict_properties(obj, columns)
        return display_columns, data


def _get_common_attrs(client_manager, parsed_args, is_create=True):
    attrs = {}
    if parsed_args.name is not None:
        attrs['name'] = parsed_args.name
    if parsed_args.description is not None:
        attrs['description'] = parsed_args.description
    if is_create:
        _get_attrs(client_manager, attrs, parsed_args)
    return attrs


def _get_attrs(client_manager, attrs, parsed_args):
    if parsed_args.ingress is not None:
        attrs['ingress'] = _get_id(client_manager.neutronclient,
                                   parsed_args.ingress, 'port')
    if parsed_args.egress is not None:
        attrs['egress'] = _get_id(client_manager.neutronclient,
                                  parsed_args.egress, 'port')
    if parsed_args.service_function_parameters is not None:
        attrs['service_function_parameters'] = _get_service_function_params(
            parsed_args.service_function_parameters)


def _get_service_function_params(sf_params):
    attrs = {}
    for sf_param in sf_params:
        if 'correlation' in sf_param:
            if sf_param['correlation'] == 'None':
                attrs['correlation'] = None
            else:
                attrs['correlation'] = sf_param['correlation']
        if 'weight' in sf_param:
            attrs['weight'] = sf_param['weight']
    return attrs


def _get_id(client, id_or_name, resource):
    return client.find_resource(resource, id_or_name)['id']