This file is indexed.

/usr/lib/python3/dist-packages/jujubundlelib/models.py is in python3-jujubundlelib 0.4.1-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
# Copyright 2015 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.

from __future__ import unicode_literals

from collections import namedtuple


VALID_CONTAINERS = (
    'lxc',
    'kvm',
)


# Define a tuple holding a specific unit placement.
UnitPlacement = namedtuple(
    'UnitPlacement', [
        'container_type',
        'machine',
        'service',
        'unit',
    ]
)

# Define a relation object.
Relation = namedtuple('Relation', ['name', 'interface'])


def parse_v3_unit_placement(placement_str):
    """Return a UnitPlacement for bundles version 3, given a placement string.

    See https://github.com/juju/charmstore/blob/v4/docs/bundles.md
    Raise a ValueError if the placement is not valid.
    """
    placement = placement_str
    container = machine = service = unit = ''
    if ':' in placement:
        try:
            container, placement = placement_str.split(':')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if '=' in placement:
        try:
            placement, unit = placement.split('=')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if placement.isdigit():
        machine = placement
    else:
        service = placement
    if (container and container not in VALID_CONTAINERS):
        msg = 'invalid container {} for placement {}'.format(
            container, placement_str)
        raise ValueError(msg.encode('utf-8'))
    unit = _parse_unit(unit, placement_str)
    if machine and machine != '0':
        raise ValueError(b'legacy bundles may not place units on machines '
                         b'other than 0')
    return UnitPlacement(container, machine, service, unit)


def parse_v4_unit_placement(placement_str):
    """Return a UnitPlacement for bundles version 4, given a placement string.

    See https://github.com/juju/charmstore/blob/v4/docs/bundles.md
    Raise a ValueError if the placement is not valid.
    """
    placement = placement_str
    container = machine = service = unit = ''
    if ':' in placement:
        try:
            container, placement = placement_str.split(':')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if '/' in placement:
        try:
            placement, unit = placement.split('/')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if placement.isdigit() or placement == 'new':
        machine = placement
    else:
        service = placement
    if (container and container not in VALID_CONTAINERS):
        msg = 'invalid container {} for placement {}'.format(
            container, placement_str)
        raise ValueError(msg.encode('utf-8'))
    unit = _parse_unit(unit, placement_str)
    return UnitPlacement(container, machine, service, unit)


def _parse_unit(unit, placement_str):
    """Parse a unit as part of the unit placement.

    Return the unit as an integer or None.
    Raise a ValueError if the unit is specified but it is not a digit.
    """
    if not unit:
        return None
    try:
        return int(unit)
    except (TypeError, ValueError):
        msg = 'unit in placement {} must be digit'.format(placement_str)
        raise ValueError(msg.encode('utf-8'))