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:
parent
d9d50149a1
commit
6cc525c2ec
|
@ -69,16 +69,6 @@ class InvalidConfiguration(ClientException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvalidHosts(ClientException):
|
|
||||||
"""Invalid hosts"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidServices(ClientException):
|
|
||||||
"""Invalid services"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FailedOperation(ClientException):
|
class FailedOperation(ClientException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from kolla_cli.api.exceptions import InvalidHosts
|
|
||||||
from kolla_cli.api.exceptions import InvalidServices
|
|
||||||
from kolla_cli.common.inventory import Inventory
|
from kolla_cli.common.inventory import Inventory
|
||||||
import kolla_cli.i18n as u
|
|
||||||
|
|
||||||
|
|
||||||
def check_kolla_args(hostnames=[], servicenames=[]):
|
def check_kolla_args(hostnames=[], servicenames=[]):
|
||||||
|
@ -25,18 +22,7 @@ def check_kolla_args(hostnames=[], servicenames=[]):
|
||||||
|
|
||||||
inventory = Inventory.load()
|
inventory = Inventory.load()
|
||||||
if hostnames:
|
if hostnames:
|
||||||
all_hosts = inventory.get_hostnames()
|
inventory.validate_hostnames(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:
|
if servicenames:
|
||||||
all_services = [service.name
|
inventory.validate_servicenames(servicenames)
|
||||||
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