]>
Commit | Line | Data |
---|---|---|
b3b6e05e TL |
1 | import logging |
2 | import threading | |
a4b75251 | 3 | from typing import Tuple, Optional, List, Dict, Any |
b3b6e05e | 4 | |
522d829b | 5 | from mgr_module import MgrModule, CLICommand, Option, CLICheckNonemptyFileInput |
1e59de90 | 6 | import object_format |
b3b6e05e | 7 | import orchestrator |
1e59de90 | 8 | from orchestrator.module import IngressType |
b3b6e05e | 9 | |
1e59de90 | 10 | from .export import ExportMgr, AppliedExportResults |
b3b6e05e | 11 | from .cluster import NFSCluster |
a4b75251 | 12 | from .utils import available_clusters |
b3b6e05e TL |
13 | |
14 | log = logging.getLogger(__name__) | |
15 | ||
16 | ||
17 | class Module(orchestrator.OrchestratorClientMixin, MgrModule): | |
18 | MODULE_OPTIONS: List[Option] = [] | |
19 | ||
a4b75251 | 20 | def __init__(self, *args: str, **kwargs: Any) -> None: |
b3b6e05e TL |
21 | self.inited = False |
22 | self.lock = threading.Lock() | |
23 | super(Module, self).__init__(*args, **kwargs) | |
24 | with self.lock: | |
25 | self.export_mgr = ExportMgr(self) | |
26 | self.nfs = NFSCluster(self) | |
27 | self.inited = True | |
28 | ||
29 | @CLICommand('nfs export create cephfs', perm='rw') | |
1e59de90 | 30 | @object_format.Responder() |
a4b75251 TL |
31 | def _cmd_nfs_export_create_cephfs( |
32 | self, | |
33 | cluster_id: str, | |
34 | pseudo_path: str, | |
35 | fsname: str, | |
36 | path: Optional[str] = '/', | |
37 | readonly: Optional[bool] = False, | |
38 | client_addr: Optional[List[str]] = None, | |
39 | squash: str = 'none', | |
39ae355f | 40 | sectype: Optional[List[str]] = None, |
1e59de90 | 41 | ) -> Dict[str, Any]: |
a4b75251 | 42 | """Create a CephFS export""" |
39ae355f TL |
43 | return self.export_mgr.create_export( |
44 | fsal_type='cephfs', | |
45 | fs_name=fsname, | |
46 | cluster_id=cluster_id, | |
47 | pseudo_path=pseudo_path, | |
48 | read_only=readonly, | |
49 | path=path, | |
50 | squash=squash, | |
51 | addr=client_addr, | |
52 | sectype=sectype, | |
53 | ) | |
a4b75251 TL |
54 | |
55 | @CLICommand('nfs export create rgw', perm='rw') | |
1e59de90 | 56 | @object_format.Responder() |
a4b75251 TL |
57 | def _cmd_nfs_export_create_rgw( |
58 | self, | |
59 | cluster_id: str, | |
60 | pseudo_path: str, | |
61 | bucket: Optional[str] = None, | |
62 | user_id: Optional[str] = None, | |
63 | readonly: Optional[bool] = False, | |
64 | client_addr: Optional[List[str]] = None, | |
65 | squash: str = 'none', | |
39ae355f | 66 | sectype: Optional[List[str]] = None, |
1e59de90 | 67 | ) -> Dict[str, Any]: |
a4b75251 | 68 | """Create an RGW export""" |
39ae355f TL |
69 | return self.export_mgr.create_export( |
70 | fsal_type='rgw', | |
71 | bucket=bucket, | |
72 | user_id=user_id, | |
73 | cluster_id=cluster_id, | |
74 | pseudo_path=pseudo_path, | |
75 | read_only=readonly, | |
76 | squash=squash, | |
77 | addr=client_addr, | |
78 | sectype=sectype, | |
79 | ) | |
b3b6e05e TL |
80 | |
81 | @CLICommand('nfs export rm', perm='rw') | |
1e59de90 TL |
82 | @object_format.EmptyResponder() |
83 | def _cmd_nfs_export_rm(self, cluster_id: str, pseudo_path: str) -> None: | |
b3b6e05e | 84 | """Remove a cephfs export""" |
a4b75251 | 85 | return self.export_mgr.delete_export(cluster_id=cluster_id, pseudo_path=pseudo_path) |
b3b6e05e TL |
86 | |
87 | @CLICommand('nfs export delete', perm='rw') | |
1e59de90 TL |
88 | @object_format.EmptyResponder() |
89 | def _cmd_nfs_export_delete(self, cluster_id: str, pseudo_path: str) -> None: | |
b3b6e05e | 90 | """Delete a cephfs export (DEPRECATED)""" |
a4b75251 | 91 | return self.export_mgr.delete_export(cluster_id=cluster_id, pseudo_path=pseudo_path) |
b3b6e05e TL |
92 | |
93 | @CLICommand('nfs export ls', perm='r') | |
1e59de90 TL |
94 | @object_format.Responder() |
95 | def _cmd_nfs_export_ls(self, cluster_id: str, detailed: bool = False) -> List[Any]: | |
b3b6e05e | 96 | """List exports of a NFS cluster""" |
a4b75251 | 97 | return self.export_mgr.list_exports(cluster_id=cluster_id, detailed=detailed) |
b3b6e05e | 98 | |
a4b75251 | 99 | @CLICommand('nfs export info', perm='r') |
1e59de90 TL |
100 | @object_format.Responder() |
101 | def _cmd_nfs_export_info(self, cluster_id: str, pseudo_path: str) -> Dict[str, Any]: | |
b3b6e05e | 102 | """Fetch a export of a NFS cluster given the pseudo path/binding""" |
a4b75251 TL |
103 | return self.export_mgr.get_export(cluster_id=cluster_id, pseudo_path=pseudo_path) |
104 | ||
105 | @CLICommand('nfs export get', perm='r') | |
1e59de90 TL |
106 | @object_format.Responder() |
107 | def _cmd_nfs_export_get(self, cluster_id: str, pseudo_path: str) -> Dict[str, Any]: | |
a4b75251 TL |
108 | """Fetch a export of a NFS cluster given the pseudo path/binding (DEPRECATED)""" |
109 | return self.export_mgr.get_export(cluster_id=cluster_id, pseudo_path=pseudo_path) | |
b3b6e05e | 110 | |
a4b75251 TL |
111 | @CLICommand('nfs export apply', perm='rw') |
112 | @CLICheckNonemptyFileInput(desc='Export JSON or Ganesha EXPORT specification') | |
1e59de90 TL |
113 | @object_format.Responder() |
114 | def _cmd_nfs_export_apply(self, cluster_id: str, inbuf: str) -> AppliedExportResults: | |
a4b75251 TL |
115 | """Create or update an export by `-i <json_or_ganesha_export_file>`""" |
116 | return self.export_mgr.apply_export(cluster_id, export_config=inbuf) | |
b3b6e05e TL |
117 | |
118 | @CLICommand('nfs cluster create', perm='rw') | |
1e59de90 | 119 | @object_format.EmptyResponder() |
b3b6e05e | 120 | def _cmd_nfs_cluster_create(self, |
a4b75251 TL |
121 | cluster_id: str, |
122 | placement: Optional[str] = None, | |
123 | ingress: Optional[bool] = None, | |
124 | virtual_ip: Optional[str] = None, | |
1e59de90 TL |
125 | ingress_mode: Optional[IngressType] = None, |
126 | port: Optional[int] = None) -> None: | |
b3b6e05e | 127 | """Create an NFS Cluster""" |
a4b75251 TL |
128 | return self.nfs.create_nfs_cluster(cluster_id=cluster_id, placement=placement, |
129 | virtual_ip=virtual_ip, ingress=ingress, | |
1e59de90 | 130 | ingress_mode=ingress_mode, port=port) |
b3b6e05e TL |
131 | |
132 | @CLICommand('nfs cluster rm', perm='rw') | |
1e59de90 TL |
133 | @object_format.EmptyResponder() |
134 | def _cmd_nfs_cluster_rm(self, cluster_id: str) -> None: | |
b3b6e05e | 135 | """Removes an NFS Cluster""" |
a4b75251 | 136 | return self.nfs.delete_nfs_cluster(cluster_id=cluster_id) |
b3b6e05e TL |
137 | |
138 | @CLICommand('nfs cluster delete', perm='rw') | |
1e59de90 TL |
139 | @object_format.EmptyResponder() |
140 | def _cmd_nfs_cluster_delete(self, cluster_id: str) -> None: | |
b3b6e05e | 141 | """Removes an NFS Cluster (DEPRECATED)""" |
a4b75251 | 142 | return self.nfs.delete_nfs_cluster(cluster_id=cluster_id) |
b3b6e05e TL |
143 | |
144 | @CLICommand('nfs cluster ls', perm='r') | |
1e59de90 TL |
145 | @object_format.Responder() |
146 | def _cmd_nfs_cluster_ls(self) -> List[str]: | |
b3b6e05e TL |
147 | """List NFS Clusters""" |
148 | return self.nfs.list_nfs_cluster() | |
149 | ||
150 | @CLICommand('nfs cluster info', perm='r') | |
1e59de90 TL |
151 | @object_format.Responder() |
152 | def _cmd_nfs_cluster_info(self, cluster_id: Optional[str] = None) -> Dict[str, Any]: | |
b3b6e05e | 153 | """Displays NFS Cluster info""" |
a4b75251 TL |
154 | return self.nfs.show_nfs_cluster_info(cluster_id=cluster_id) |
155 | ||
156 | @CLICommand('nfs cluster config get', perm='r') | |
1e59de90 | 157 | @object_format.ErrorResponseHandler() |
a4b75251 TL |
158 | def _cmd_nfs_cluster_config_get(self, cluster_id: str) -> Tuple[int, str, str]: |
159 | """Fetch NFS-Ganesha config""" | |
1e59de90 TL |
160 | conf = self.nfs.get_nfs_cluster_config(cluster_id=cluster_id) |
161 | return 0, conf, "" | |
b3b6e05e TL |
162 | |
163 | @CLICommand('nfs cluster config set', perm='rw') | |
522d829b | 164 | @CLICheckNonemptyFileInput(desc='NFS-Ganesha Configuration') |
1e59de90 TL |
165 | @object_format.EmptyResponder() |
166 | def _cmd_nfs_cluster_config_set(self, cluster_id: str, inbuf: str) -> None: | |
b3b6e05e | 167 | """Set NFS-Ganesha config by `-i <config_file>`""" |
a4b75251 | 168 | return self.nfs.set_nfs_cluster_config(cluster_id=cluster_id, nfs_config=inbuf) |
b3b6e05e TL |
169 | |
170 | @CLICommand('nfs cluster config reset', perm='rw') | |
1e59de90 TL |
171 | @object_format.EmptyResponder() |
172 | def _cmd_nfs_cluster_config_reset(self, cluster_id: str) -> None: | |
b3b6e05e | 173 | """Reset NFS-Ganesha Config to default""" |
a4b75251 TL |
174 | return self.nfs.reset_nfs_cluster_config(cluster_id=cluster_id) |
175 | ||
176 | def fetch_nfs_export_obj(self) -> ExportMgr: | |
177 | return self.export_mgr | |
178 | ||
179 | def export_ls(self) -> List[Dict[Any, Any]]: | |
180 | return self.export_mgr.list_all_exports() | |
181 | ||
182 | def export_get(self, cluster_id: str, export_id: int) -> Optional[Dict[str, Any]]: | |
183 | return self.export_mgr.get_export_by_id(cluster_id, export_id) | |
184 | ||
185 | def export_rm(self, cluster_id: str, pseudo: str) -> None: | |
186 | self.export_mgr.delete_export(cluster_id=cluster_id, pseudo_path=pseudo) | |
187 | ||
188 | def cluster_ls(self) -> List[str]: | |
189 | return available_clusters(self) |