Add service and host check for API
now, the action will run even though the service or the host are invaild, this PS to check them before the action executed. Change-Id: I764599673d44c33ce6622bf97988f372a7a26285
This commit is contained in:
parent
6b63c00967
commit
679824b687
|
@ -14,6 +14,7 @@
|
|||
|
||||
from kolla_cli.api.job import Job
|
||||
from kolla_cli.common.ansible.actions import KollaAction
|
||||
from kolla_cli.common.ansible.utils import check_kolla_args
|
||||
from kolla_cli.common.inventory import Inventory
|
||||
from kolla_cli.common.utils import check_arg
|
||||
from kolla_cli.common.utils import safe_decode
|
||||
|
@ -79,6 +80,9 @@ class ControlPlaneApi(object):
|
|||
check_arg(servicenames, u._('Service names'), list,
|
||||
empty_ok=True, none_ok=True)
|
||||
|
||||
check_kolla_args(hostnames=hostnames,
|
||||
servicenames=servicenames)
|
||||
|
||||
hostnames = safe_decode(hostnames)
|
||||
servicenames = safe_decode(servicenames)
|
||||
aciton = KollaAction(verbose_level=verbose_level,
|
||||
|
|
|
@ -69,6 +69,16 @@ class InvalidConfiguration(ClientException):
|
|||
pass
|
||||
|
||||
|
||||
class InvalidHosts(ClientException):
|
||||
"""Invalid hosts"""
|
||||
pass
|
||||
|
||||
|
||||
class InvalidServices(ClientException):
|
||||
"""Invalid services"""
|
||||
pass
|
||||
|
||||
|
||||
class FailedOperation(ClientException):
|
||||
pass
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright(c) 2019, caoyuan. 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.
|
||||
|
||||
from kolla_cli.api.exceptions import InvalidHosts
|
||||
from kolla_cli.api.exceptions import InvalidServices
|
||||
from kolla_cli.common.inventory import Inventory
|
||||
import kolla_cli.i18n as u
|
||||
|
||||
|
||||
def check_kolla_args(hostnames=[], servicenames=[]):
|
||||
|
||||
if not any([hostnames, servicenames]):
|
||||
return
|
||||
|
||||
inventory = Inventory.load()
|
||||
if hostnames:
|
||||
all_hosts = inventory.get_hostnames()
|
||||
invalid_hosts = list(set(hostnames) - set(all_hosts))
|
||||
if invalid_hosts:
|
||||
raise InvalidHosts(
|
||||
u._('Hosts {hosts} are not valid.').format(
|
||||
hosts=invalid_hosts))
|
||||
|
||||
if servicenames:
|
||||
all_services = [service.name
|
||||
for service in inventory.get_services()]
|
||||
invalid_services = list(set(servicenames) - set(all_services))
|
||||
if invalid_services:
|
||||
raise InvalidServices(
|
||||
u._('Services {services} are not valid.').format(
|
||||
services=invalid_services))
|
Loading…
Reference in New Issue