This file is indexed.

/usr/lib/python2.7/dist-packages/neutron_dynamic_routing/services/bgp/agent/driver/utils.py is in python-neutron-dynamic-routing 2:9.0.0-1.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
# Copyright 2016 Huawei Technologies India Pvt. Ltd.
#
# 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 six

from neutron_dynamic_routing.services.bgp.agent.driver import exceptions as bgp_driver_exc  # noqa
from neutron_dynamic_routing.services.bgp.common import constants as bgp_consts  # noqa


# Parameter validation functions provided are provided by the base.
def validate_as_num(param, as_num):
    if not isinstance(as_num, six.integer_types):
        raise bgp_driver_exc.InvalidParamType(param=param,
                                              param_type='integer')

    if not (bgp_consts.MIN_ASNUM <= as_num <= bgp_consts.MAX_ASNUM):
        # Must be in [AS_NUM_MIN, AS_NUM_MAX] range.
        allowed_range = ('[' +
                         str(bgp_consts.MIN_ASNUM) + '-' +
                         str(bgp_consts.MAX_ASNUM) +
                         ']')
        raise bgp_driver_exc.InvalidParamRange(param=param,
                                               range=allowed_range)


def validate_auth(auth_type, password):
    validate_string(password)
    if auth_type in bgp_consts.SUPPORTED_AUTH_TYPES:
        if auth_type != 'none' and password is None:
            raise bgp_driver_exc.PasswordNotSpecified(auth_type=auth_type)
        if auth_type == 'none' and password is not None:
            raise bgp_driver_exc.InvaildAuthType(auth_type=auth_type)
    else:
        raise bgp_driver_exc.InvaildAuthType(auth_type=auth_type)


def validate_string(param):
    if param is not None:
        if not isinstance(param, six.string_types):
            raise bgp_driver_exc.InvalidParamType(param=param,
                                                  param_type='string')


class BgpMultiSpeakerCache(object):
    """Class for saving multiple BGP speakers information.

    Version history:
        1.0 - Initial version for caching multiple BGP speaker information.
    """
    def __init__(self):
        self.cache = {}

    def get_hosted_bgp_speakers_count(self):
        return len(self.cache)

    def put_bgp_speaker(self, local_as, speaker):
        self.cache[local_as] = speaker

    def get_bgp_speaker(self, local_as):
        return self.cache.get(local_as)

    def remove_bgp_speaker(self, local_as):
        self.cache.pop(local_as, None)