Add node enquiry API
Provide an API endpoint in Drydock to query the state of nodes in the downstream MAAS service. Change-Id: I7cf4f3cf81e51ef5dc604c778d6a03d7f1208ffa
This commit is contained in:
parent
15e4c96f4e
commit
da84af2d0f
@ -16,6 +16,7 @@ import falcon
|
|||||||
from .designs import *
|
from .designs import *
|
||||||
from .tasks import *
|
from .tasks import *
|
||||||
from .bootdata import *
|
from .bootdata import *
|
||||||
|
from .nodes import NodesResource
|
||||||
|
|
||||||
from .base import DrydockRequest
|
from .base import DrydockRequest
|
||||||
from .middleware import AuthMiddleware, ContextMiddleware, LoggingMiddleware
|
from .middleware import AuthMiddleware, ContextMiddleware, LoggingMiddleware
|
||||||
@ -59,7 +60,10 @@ def start_api(state_manager=None, ingester=None, orchestrator=None):
|
|||||||
|
|
||||||
# API for nodes to discover their bootdata during curtin install
|
# API for nodes to discover their bootdata during curtin install
|
||||||
('/bootdata/{hostname}/{data_key}', BootdataResource(
|
('/bootdata/{hostname}/{data_key}', BootdataResource(
|
||||||
state_manager=state_manager, orchestrator=orchestrator))
|
state_manager=state_manager, orchestrator=orchestrator)),
|
||||||
|
|
||||||
|
# API to list current MaaS nodes
|
||||||
|
('/nodes', NodesResource()),
|
||||||
]
|
]
|
||||||
|
|
||||||
for path, res in v1_0_routes:
|
for path, res in v1_0_routes:
|
||||||
|
48
drydock_provisioner/control/nodes.py
Normal file
48
drydock_provisioner/control/nodes.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright 2017 AT&T Intellectual Property. All other 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 falcon
|
||||||
|
import json
|
||||||
|
|
||||||
|
from drydock_provisioner import policy
|
||||||
|
from drydock_provisioner import config
|
||||||
|
|
||||||
|
from drydock_provisioner.drivers.node.maasdriver.api_client import MaasRequestFactory
|
||||||
|
from drydock_provisioner.drivers.node.maasdriver.models.machine import Machines
|
||||||
|
|
||||||
|
from .base import BaseResource
|
||||||
|
|
||||||
|
|
||||||
|
class NodesResource(BaseResource):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
@policy.ApiEnforcer('physical_provisioner:read_data')
|
||||||
|
def on_get(self, req, resp):
|
||||||
|
try:
|
||||||
|
maas_client = MaasRequestFactory(config.config_mgr.conf.maasdriver.maas_api_url,
|
||||||
|
config.config_mgr.conf.maasdriver.maas_api_key)
|
||||||
|
|
||||||
|
machine_list = Machines(maas_client)
|
||||||
|
machine_list.refresh()
|
||||||
|
|
||||||
|
node_view = list()
|
||||||
|
for m in machine_list:
|
||||||
|
node_view.append(dict(hostname=m.hostname, memory=m.memory, cpu_count=m.cpu_count, status_name=m.status_name, boot_mac=m.boot_mac))
|
||||||
|
|
||||||
|
resp.body = json.dumps(node_view)
|
||||||
|
resp.status = falcon.HTTP_200
|
||||||
|
except Exception as ex:
|
||||||
|
self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
|
||||||
|
self.return_error(
|
||||||
|
resp, falcon.HTTP_500, message="Unknown error", retry=False)
|
Loading…
Reference in New Issue
Block a user