<commit_before># -*- coding: utf-8 -*-

#    Copyright 2015 Mirantis, Inc.
#
#    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 pecan
from pecan import rest

from bareon_api.common import utils
from bareon_api import models


LOG = utils.getLogger(__name__)


def get_or_404(model, obj_id):
    try:
        return model[obj_id]
    except (IndexError, KeyError):
        pecan.abort(404)


class DisksController(rest.RestController):

    @pecan.expose(template='json')
    def get_one(self, node_id, disk_id):
        node_id = int(node_id)
        # NOTE(prmtl): since this is just a list, lets not
        # force to use ids starting with 0
        disk_id = int(disk_id) - 1
        node_disks = get_or_404(models.DISKS, node_id)
        return get_or_404(node_disks, disk_id)

    @pecan.expose(template='json')
    def get_all(self, node_id):
        node_id = int(node_id)
        return get_or_404(models.DISKS, node_id)


class NodesController(rest.RestController):

    disks = DisksController()

    @pecan.expose(template='json')
    def get_one(self, node_id):
        node_id = int(node_id)
        return get_or_404(models.NODES, node_id)

    @pecan.expose(template='json')
    def put(self, node_id):
        node_id = int(node_id)
        models.NODES[node_id] = pecan.request.json
        return models.NODES[node_id]

    @pecan.expose(template='json')
    def get_all(self):
        return models.NODES.values()<commit_msg>Add API to return full partitioning data<commit_after># -*- coding: utf-8 -*-

#    Copyright 2015 Mirantis, Inc.
#
#    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 pecan
from pecan import rest

from bareon_api.common import utils
from bareon_api import models


LOG = utils.getLogger(__name__)


def get_or_404(model, obj_id):
    try:
        return model[obj_id]
    except (IndexError, KeyError):
        pecan.abort(404)


class PartitioningCotroller(rest.RestController):

    @pecan.expose(template='json')
    def get(self, node_id):
        node_id = int(node_id)
        data = {
            'fss': [
                {
                    'device': '/dev/kurnik/kogut',
                    'fs_label': 'kogut',
                    'fs_type': 'ext2',
                    'mount': '/tmp/kogutek',
                },
            ],
            "lvs": [
                {
                    "name": "kogut",
                    "size": 96,
                    "vgname": "kurnik"
                },
                {
                    "name": "kura",
                    "size": 69,
                    "vgname": "kurnik"
                }
            ],
            'parteds': [
                {
                    'label': 'gpt',
                    'name': '/dev/vdc',
                    'partitions': [
                        {
                            'begin': 1,
                            'configdrive': False,
                            'count': 1,
                            'device': '/dev/vdc',
                            'end': 20000,
                            'flags': ['bios_grub'],
                            'guid': None,
                            'name': '/dev/vdc1',
                            'partition_type': 'primary',
                        },
                    ],
                },
            ],
            'pvs': [
                {
                    'metadatacopies': 2,
                    'metadatasize': 28,
                    'name': '/dev/vdc1',
                },
            ],
            'vgs': [
                {
                    'name': 'kurnik',
                    'pvnames': [
                        '/dev/vdc1',
                    ],
                },
            ],
        }
        return data


class DisksController(rest.RestController):

    @pecan.expose(template='json')
    def get_one(self, node_id, disk_id):
        node_id = int(node_id)
        # NOTE(prmtl): since this is just a list, lets not
        # force to use ids starting with 0
        disk_id = int(disk_id) - 1
        node_disks = get_or_404(models.DISKS, node_id)
        return get_or_404(node_disks, disk_id)

    @pecan.expose(template='json')
    def get_all(self, node_id):
        node_id = int(node_id)
        return get_or_404(models.DISKS, node_id)


class NodesController(rest.RestController):

    disks = DisksController()
    partitioning = PartitioningCotroller()

    @pecan.expose(template='json')
    def get_one(self, node_id):
        node_id = int(node_id)
        return get_or_404(models.NODES, node_id)

    @pecan.expose(template='json')
    def put(self, node_id):
        node_id = int(node_id)
        models.NODES[node_id] = pecan.request.json
        return models.NODES[node_id]

    @pecan.expose(template='json')
    def get_all(self):
        return models.NODES.values()
{'fraction_non_alphanumeric': 0.10390052801907682, 'fraction_numerical': 0.012944983818770227, 'mean_word_length': 1.7097369635440702, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '401162', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1728, 'n_words': 440}