Use inventory object to validate the hosts and services

inventory complete the hosts and services check, we should use it
rather than complete it again[1]

[1]: https://review.opendev.org/#/c/673537/

Change-Id: Iad1e78be8cba0e378a623d17ad408b3e43a48daf
This commit is contained in:
gujin 2019-08-09 15:16:51 +08:00
parent d9d50149a1
commit 6cc525c2ec
2 changed files with 2 additions and 26 deletions

View File

@ -69,16 +69,6 @@ class InvalidConfiguration(ClientException):
pass
class InvalidHosts(ClientException):
"""Invalid hosts"""
pass
class InvalidServices(ClientException):
"""Invalid services"""
pass
class FailedOperation(ClientException):
pass

View File

@ -12,10 +12,7 @@
# 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=[]):
@ -25,18 +22,7 @@ def check_kolla_args(hostnames=[], servicenames=[]):
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))
inventory.validate_hostnames(hostnames)
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))
inventory.validate_servicenames(servicenames)