From f2e78bf2e3009eb67a2e7ef06336371eddee7573 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 May 2021 18:02:25 -0400 Subject: [PATCH] mgr/nfs: move ingress vs virtual_ip check to cluster interface Signed-off-by: Sage Weil --- src/pybind/mgr/nfs/cluster.py | 14 +++++++++++--- src/pybind/mgr/nfs/module.py | 8 +------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 1f9e4db3e5127..aac469412b2f5 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -2,7 +2,7 @@ import logging import socket import json import re -from typing import cast, Dict, List, Any, Union +from typing import cast, Dict, List, Any, Union, Optional from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec, IngressSpec from cephadm.utils import resolve_ip @@ -89,8 +89,16 @@ class NFSCluster: f"{self.pool_ns}") @cluster_setter - def create_nfs_cluster(self, cluster_id, placement, virtual_ip): + def create_nfs_cluster(self, + cluster_id: str, + placement: Optional[str], + virtual_ip: Optional[str], + ingress: Optional[bool] = None): try: + if virtual_ip and not ingress: + raise NFSInvalidOperation('virtual_ip can only be provided with ingress enabled') + if not virtual_ip and ingress: + raise NFSInvalidOperation('ingress currently requires a virtual_ip') invalid_str = re.search('[^A-Za-z0-9-_.]', cluster_id) if invalid_str: raise NFSInvalidOperation(f"cluster id {cluster_id} is invalid. " @@ -143,7 +151,7 @@ class NFSCluster: "ip": cluster.ip or resolve_ip(cluster.hostname), "port": cluster.ports[0] }) - except OrchestratorError: + except orchestrator.OrchestratorError: continue r: Dict[str, Any] = { diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index 164c9f133aa22..5bd1e9260e881 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -70,14 +70,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): ingress: Optional[bool]=None, virtual_ip: Optional[str]=None) -> Tuple[int, str, str]: """Create an NFS Cluster""" - if virtual_ip and not ingress: - return (-errno.EINVAL, '', - '--virtual-ip can only be provided with --ingress') - if ingress and not virtual_ip: - return (-errno.EINVAL, '', - '--ingress current requires --virtual-ip') return self.nfs.create_nfs_cluster(cluster_id=clusterid, placement=placement, - virtual_ip=virtual_ip) + virtual_ip=virtual_ip, ingress=ingress) @CLICommand('nfs cluster rm', perm='rw') def _cmd_nfs_cluster_rm(self, clusterid: str) -> Tuple[int, str, str]: -- 2.39.5