Files
distcloud/distributedcloud/dcorch/api/controllers/v1/root.py
Hugo Brito 56e359bf8a Apply black formatter to dcorch/api
This commit applies the Black format to the `dcorch/api`
files to ensure that it adheres to the Black code style guidelines.

Test Plan:
PASS: Success in stx-distcloud-tox-black

Story: 2011149
Task: 50445

Change-Id: I9e5bd8ca9dd33a7cdd2ce36e8dcbd4be65c436d7
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
2024-06-28 13:42:16 +00:00

48 lines
1.6 KiB
Python

# Copyright (c) 2017 Ericsson AB.
# Copyright (c) 2024 Wind River Systems, 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 pecan
from dcorch.api.controllers.v1 import subcloud_manager
class Controller(object):
def _get_resource_controller(self, tenant_id, remainder):
if not remainder:
pecan.abort(404)
return
minor_version = remainder[-1]
remainder = remainder[:-1]
sub_controllers = dict()
if minor_version == "0":
sub_controllers["subclouds"] = subcloud_manager.SubcloudController
for name, ctrl in sub_controllers.items():
setattr(self, name, ctrl)
resource = remainder[0]
if resource not in sub_controllers:
pecan.abort(404)
return
# Pass the tenant_id for verification
remainder = (tenant_id,) + remainder[1:]
return sub_controllers[resource](), remainder
@pecan.expose()
def _lookup(self, tenant_id, *remainder):
return self._get_resource_controller(tenant_id, remainder)