bd998017d5
Create host inventory services (api, conductor and agent) and python-inventoryclient. The inventory service collects the host resources and provides a REST API and client to expose the host resources. Create plugin for integration with system configuration (sysinv) service. This is the initial inventory service infratructure commit. Puppet configuration, SM integration and host integration with sysinv(systemconfig) changes are pending and planned to be delivered in future commits. Tests Performed: Verify the changes are inert on config_controller installation and provisioning. Puppet and spec changes are required in order to create keystone, database and activate inventory services. Unit tests performed (when puppet configuration for keystone, database is applied): Trigger host configure_check, configure signals into systemconfig(sysinv). Verify python-inventoryclient and api service: Disks and related storage resources are pending. inventory host-cpu-list/show inventory host-device-list/show/modify inventory host-ethernetport-list/show inventory host-lldp-neighbor-list inventory host-lldp-agent-list/show inventory host-memory-list/show inventory host-node-list/show inventory host-port-list/show Tox Unit tests: inventory: pep8 python-inventoryclient: py27, pep8, cover, pylint Change-Id: I744ac0de098608c55b9356abf180cc36601cfb8d Story: 2002950 Task: 22952 Signed-off-by: John Kung <john.kung@windriver.com>
103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
#
|
|
# Copyright (c) 2015-2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
from inventory.common import exception as si_exception
|
|
import json
|
|
from oslo_log import log
|
|
from rest_api import rest_api_request
|
|
import time
|
|
|
|
LOG = log.getLogger(__name__)
|
|
|
|
|
|
def host_add(token, address, port, ihost_mtce, timeout):
|
|
"""
|
|
Sends a Host Add command to maintenance.
|
|
"""
|
|
|
|
# api_cmd = "http://localhost:2112"
|
|
api_cmd = "http://%s:%s" % (address, port)
|
|
api_cmd += "/v1/hosts/"
|
|
|
|
api_cmd_headers = dict()
|
|
api_cmd_headers['Content-type'] = "application/json"
|
|
api_cmd_headers['User-Agent'] = "sysinv/1.0"
|
|
|
|
api_cmd_payload = dict()
|
|
api_cmd_payload = ihost_mtce
|
|
|
|
LOG.info("host_add for %s cmd=%s hdr=%s payload=%s" %
|
|
(ihost_mtce['hostname'],
|
|
api_cmd, api_cmd_headers, api_cmd_payload))
|
|
|
|
response = rest_api_request(token, "POST", api_cmd, api_cmd_headers,
|
|
json.dumps(api_cmd_payload), timeout)
|
|
|
|
return response
|
|
|
|
|
|
def host_modify(token, address, port, ihost_mtce, timeout, max_retries=1):
|
|
"""
|
|
Sends a Host Modify command to maintenance.
|
|
"""
|
|
|
|
# api_cmd = "http://localhost:2112"
|
|
api_cmd = "http://%s:%s" % (address, port)
|
|
api_cmd += "/v1/hosts/%s" % ihost_mtce['uuid']
|
|
|
|
api_cmd_headers = dict()
|
|
api_cmd_headers['Content-type'] = "application/json"
|
|
api_cmd_headers['User-Agent'] = "sysinv/1.0"
|
|
|
|
api_cmd_payload = dict()
|
|
api_cmd_payload = ihost_mtce
|
|
|
|
LOG.debug("host_modify for %s cmd=%s hdr=%s payload=%s" %
|
|
(ihost_mtce['hostname'],
|
|
api_cmd, api_cmd_headers, api_cmd_payload))
|
|
|
|
num_of_try = 0
|
|
response = None
|
|
while num_of_try < max_retries and response is None:
|
|
try:
|
|
num_of_try = num_of_try + 1
|
|
LOG.info("number of calls to rest_api_request=%d (max_retry=%d)" %
|
|
(num_of_try, max_retries))
|
|
response = rest_api_request(
|
|
token, "PATCH", api_cmd, api_cmd_headers,
|
|
json.dumps(api_cmd_payload), timeout)
|
|
if response is None:
|
|
time.sleep(3)
|
|
except si_exception.SysInvSignalTimeout as e:
|
|
LOG.warn("WARNING rest_api_request Timeout Error e=%s" % (e))
|
|
raise si_exception.SysInvSignalTimeout
|
|
except si_exception.InventoryException as e:
|
|
LOG.warn("WARNING rest_api_request Unexpected Error e=%s" % (e))
|
|
|
|
return response
|
|
|
|
|
|
def host_delete(token, address, port, ihost_mtce, timeout):
|
|
"""
|
|
Sends a Host Delete command to maintenance.
|
|
"""
|
|
|
|
api_cmd = "http://%s:%s" % (address, port)
|
|
api_cmd += "/v1/hosts/%s" % ihost_mtce['uuid']
|
|
|
|
api_cmd_headers = dict()
|
|
api_cmd_headers['Content-type'] = "application/json"
|
|
api_cmd_headers['User-Agent'] = "sysinv/1.0"
|
|
|
|
api_cmd_payload = None
|
|
|
|
LOG.info("host_delete for %s cmd=%s hdr=%s payload=%s" %
|
|
(ihost_mtce['uuid'], api_cmd, api_cmd_headers, api_cmd_payload))
|
|
|
|
response = rest_api_request(token, "DELETE", api_cmd, api_cmd_headers,
|
|
json.dumps(api_cmd_payload), timeout)
|
|
|
|
return response
|