Update Rack and Systems controller to be generic
This commit updates the rack and systems to use controller interface Partially-Implements blueprint add-vendor-extensible-framework Change-Id: I8a33b0b924e1a688ab75cccc8bc7ca6185515d43
This commit is contained in:
parent
1afb9f0cbf
commit
d0a5d9ad7e
|
@ -19,7 +19,7 @@ import flask_restful
|
|||
from six.moves import http_client
|
||||
|
||||
from valence.common import utils
|
||||
from valence.redfish import redfish
|
||||
from valence.controller import racks
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -27,12 +27,18 @@ LOG = logging.getLogger(__name__)
|
|||
class RackList(flask_restful.Resource):
|
||||
|
||||
def get(self):
|
||||
req = request.get_json()
|
||||
filters = request.args.to_dict()
|
||||
|
||||
return utils.make_response(
|
||||
http_client.OK, redfish.list_racks(request.get_json()))
|
||||
http_client.OK,
|
||||
racks.Rack(req['podm_id']).list_racks(req, filters))
|
||||
|
||||
|
||||
class Rack(flask_restful.Resource):
|
||||
|
||||
def get(self, rack_id):
|
||||
req = request.get_json()
|
||||
return utils.make_response(
|
||||
http_client.OK, redfish.show_rack(rack_id))
|
||||
http_client.OK,
|
||||
racks.Rack(req['podm_id']).show_rack(rack_id))
|
||||
|
|
|
@ -19,7 +19,7 @@ from flask_restful import Resource
|
|||
from six.moves import http_client
|
||||
|
||||
from valence.common import utils
|
||||
from valence.redfish import redfish
|
||||
from valence.controller import systems
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -27,12 +27,17 @@ LOG = logging.getLogger(__name__)
|
|||
class SystemsList(Resource):
|
||||
|
||||
def get(self):
|
||||
return utils.make_response(http_client.OK,
|
||||
redfish.systems_list(request.args))
|
||||
req = request.get_json()
|
||||
filters = request.args.to_dict()
|
||||
return utils.make_response(
|
||||
http_client.OK,
|
||||
systems.System(req['podm_id']).list_systems(filters))
|
||||
|
||||
|
||||
class Systems(Resource):
|
||||
|
||||
def get(self, systemid):
|
||||
return utils.make_response(http_client.OK,
|
||||
redfish.get_systembyid(systemid))
|
||||
req = request.get_json()
|
||||
return utils.make_response(
|
||||
http_client.OK,
|
||||
systems.System(req['podm_id']).get_system_by_id(systemid))
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2016 Intel, 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 logging
|
||||
|
||||
from valence.podmanagers import manager
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Rack(object):
|
||||
|
||||
def __init__(self, podm_id):
|
||||
self.connection = manager.get_connection(podm_id)
|
||||
|
||||
def list_racks(self, request_body, filters={}):
|
||||
"""List racks
|
||||
|
||||
:param filters: filter params
|
||||
:param show_detail: True, to show detail info
|
||||
:return: rack list
|
||||
"""
|
||||
return self.connection.list_racks(filters, request_body['show_detail'])
|
||||
|
||||
def show_rack(self, rack_id):
|
||||
"""Show rack
|
||||
|
||||
:param rack_id: Rack ID
|
||||
:return: rack info
|
||||
"""
|
||||
return self.connection.show_rack(rack_id)
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2017 NEC, Corp.
|
||||
#
|
||||
# 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 logging
|
||||
|
||||
from valence.podmanagers import manager
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class System(object):
|
||||
|
||||
def __init__(self, podm_id):
|
||||
self.connection = manager.get_connection(podm_id)
|
||||
|
||||
def list_systems(self, filters={}):
|
||||
"""List racks
|
||||
|
||||
:param filters: filter params
|
||||
:param show_detail: True, to show detail info
|
||||
:return: rack list
|
||||
"""
|
||||
return self.connection.systems_list(filters)
|
||||
|
||||
def get_system_by_id(self, system_id):
|
||||
"""Show rack
|
||||
|
||||
:param rack_id: Rack ID
|
||||
:return: rack info
|
||||
"""
|
||||
return self.connection.get_system_by_id(system_id)
|
|
@ -38,6 +38,22 @@ class PodManagerBase(object):
|
|||
def node_action(self, index, request_body):
|
||||
pass
|
||||
|
||||
# TODO(): use rsd_lib here
|
||||
def list_racks(self, filters={}, show_detail=False):
|
||||
pass
|
||||
|
||||
# TODO(): use rsd_lib here
|
||||
def show_rack(self, rack_id):
|
||||
pass
|
||||
|
||||
# TODO(): use rsd_lib here
|
||||
def systems_list(self, filters={}):
|
||||
pass
|
||||
|
||||
# TODO(): use rsd_lib here
|
||||
def get_system_by_id(self, system_id):
|
||||
pass
|
||||
|
||||
def get_resource_info_by_url(self, resource_url):
|
||||
return self.driver.get_resources_by_url(resource_url)
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
# copyright (c) 2017 NEC, Corp.
|
||||
#
|
||||
# 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 unittest
|
||||
|
||||
import mock
|
||||
|
||||
from valence.controller import systems
|
||||
from valence.podmanagers import podm_base
|
||||
|
||||
|
||||
class TestAPISystems(unittest.TestCase):
|
||||
|
||||
@mock.patch('valence.podmanagers.manager.get_connection')
|
||||
@mock.patch('valence.redfish.sushy.sushy_instance.RedfishInstance')
|
||||
def setUp(self, mock_redfish, mock_connection):
|
||||
self.system_controller = systems.System(podm_id='test-podm-1')
|
||||
self.system_controller.connection = podm_base.PodManagerBase(
|
||||
'fake', 'fake-pass', 'http://fake-url')
|
||||
|
||||
@mock.patch("valence.podmanagers.podm_base.PodManagerBase.systems_list")
|
||||
def test_system_list(self, mock_redfish):
|
||||
response = [{
|
||||
'uuid': 'fake_system_uuid',
|
||||
'name': 'fake-system-name',
|
||||
'power_state': 'on',
|
||||
'links': 'system/1'
|
||||
}]
|
||||
mock_redfish.return_value = response
|
||||
result = self.system_controller.list_systems()
|
||||
self.assertEqual(response, result)
|
||||
mock_redfish.assert_called_once_with({})
|
||||
|
||||
@mock.patch.object(podm_base.PodManagerBase, "get_system_by_id")
|
||||
def test_get_system_by_id(self, mock_redfish):
|
||||
|
||||
response = {
|
||||
'uuid': 'fake_system_id',
|
||||
'name': 'fake-system-name',
|
||||
'power_state': 'on',
|
||||
'health': 'ok',
|
||||
'chassis_id': 'c-id',
|
||||
'links': 'system/1'
|
||||
}
|
||||
mock_redfish.return_value = response
|
||||
result = self.system_controller.get_system_by_id('fake_system_id')
|
||||
mock_redfish.assert_called_once_with('fake_system_id')
|
||||
self.assertEqual(response, result)
|
Loading…
Reference in New Issue