Merge "Kubernetes, VIM label support"

This commit is contained in:
Zuul 2018-11-06 21:27:56 +00:00 committed by Gerrit Code Review
commit 8fbe7aebd6
2 changed files with 74 additions and 0 deletions

View File

@ -12,6 +12,8 @@ from sysinv.api.controllers.v1 import base
from sysinv.api.controllers.v1 import collection
from sysinv.api.controllers.v1 import types
from sysinv.api.controllers.v1 import utils
from sysinv.api.controllers.v1 import vim_api
from sysinv.common import constants
from sysinv.common import exception
from sysinv.common import utils as cutils
from sysinv.openstack.common import excutils
@ -196,6 +198,8 @@ class LabelController(rest.RestController):
LOG.info("patch_data: %s" % body)
host = objects.host.get_by_uuid(pecan.request.context, uuid)
_check_host_locked(host)
try:
pecan.request.rpcapi.update_kubernetes_label(
pecan.request.context,
@ -215,12 +219,24 @@ class LabelController(rest.RestController):
'label_key': key,
'label_value': value
}
try:
new_label = pecan.request.dbapi.label_create(uuid, values)
new_records.append(new_label)
except exception.HostLabelAlreadyExists:
pass
try:
vim_api.vim_host_update(
None,
uuid,
host.hostname,
constants.VIM_DEFAULT_TIMEOUT_IN_SECS)
except Exception as e:
LOG.warn(_("No response vim_api host:%s e=%s" %
(host.hostname, e)))
pass
return LabelCollection.convert_with_links(
new_records, limit=None, url=None, expand=False,
sort_key='id', sort_dir='asc')
@ -236,6 +252,8 @@ class LabelController(rest.RestController):
host = objects.host.get_by_uuid(pecan.request.context, lbl_obj.host_id)
label_dict = {lbl_obj.label_key: None}
_check_host_locked(host)
try:
pecan.request.rpcapi.update_kubernetes_label(
pecan.request.context,
@ -253,3 +271,28 @@ class LabelController(rest.RestController):
msg = _("Delete host label failed: host %s label %s=%s"
% (host.hostname, lbl_obj.label_key, lbl_obj.label_value))
raise wsme.exc.ClientSideError(msg)
try:
vim_api.vim_host_update(
None,
host.uuid,
host.hostname,
constants.VIM_DEFAULT_TIMEOUT_IN_SECS)
except Exception as e:
LOG.warn(_("No response vim_api host:%s e=%s" %
(host.hostname, e)))
pass
###########
# UTILS
###########
def _check_host_locked(host):
# TODO(ksmith):
# turn this on later
return
if (utils.is_aio_simplex_host_unlocked(host) or
host.administrative != constants.ADMIN_LOCKED):
raise wsme.exc.ClientSideError(_("Host must be locked."))

View File

@ -217,3 +217,34 @@ def vim_host_get_instances(token, uuid, hostname, timeout):
response = rest_api_request(token, "GET", api_cmd, api_cmd_headers,
json.dumps(api_cmd_payload), timeout)
return response
def vim_host_update(token, uuid, hostname, timeout):
"""
Inform VIM of host change
"""
api_cmd = None
if token:
api_cmd = token.get_service_url("nfvi", "nfv")
if not api_cmd:
api_cmd = "http://localhost:30001"
api_cmd += "/nfvi-plugins/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['uuid'] = uuid
api_cmd_payload['hostname'] = hostname
response = rest_api_request(token, "PATCH", api_cmd, api_cmd_headers,
json.dumps(api_cmd_payload), timeout)
LOG.debug("vim_host_update api_cmd=%s headers=%s payload=%s" %
(api_cmd, api_cmd_headers, api_cmd_payload))
return response