Skip to content

Commit 6ade282

Browse files
ShwetaBhosale1adk3798
authored andcommitted
mgr/nfs: Update cluster create command to accept kmip relates params and update export command
Signed-off-by: Shweta Bhosale <[email protected]> (cherry picked from commit 61a56ec) Conflicts: src/pybind/mgr/nfs/cluster.py src/pybind/mgr/nfs/ganesha_conf.py src/pybind/mgr/nfs/module.py Resolves: rhbz#2373703
1 parent eaa935c commit 6ade282

File tree

6 files changed

+83
-23
lines changed

6 files changed

+83
-23
lines changed

src/cephadm/cephadmlib/daemons/nfs.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,23 @@ def create_daemon_dirs(self, data_dir, uid, gid):
172172

173173
# create the ganesha conf dir
174174
config_dir = os.path.join(data_dir, 'etc/ganesha')
175+
kmip_dir = os.path.join(data_dir, 'etc/ganesha/kmip')
175176
makedirs(config_dir, uid, gid, 0o755)
176-
177+
makedirs(kmip_dir, uid, gid, 0o755)
178+
179+
config_files = {
180+
fname: content
181+
for fname, content in self.files.items()
182+
if fname.endswith('.conf')
183+
}
184+
kmip_files = {
185+
fname: content
186+
for fname, content in self.files.items()
187+
if fname.startswith('kmip')
188+
}
177189
# populate files from the config-json
178-
populate_files(config_dir, self.files, uid, gid)
190+
populate_files(config_dir, config_files, uid, gid)
191+
populate_files(kmip_dir, kmip_files, uid, gid)
179192

180193
# write the RGW keyring
181194
if self.rgw:

src/pybind/mgr/cephadm/services/nfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def get_cephadm_config() -> Dict[str, Any]:
183183
'kmip_key',
184184
'kmip_ca_cert',
185185
]:
186-
config['files'][kmip_cert_key_field] = getattr(spec, kmip_cert_key_field)
186+
config['files'][f'{kmip_cert_key_field}.pem'] = getattr(spec, kmip_cert_key_field)
187187
config.update(
188188
self.get_config_and_keyring(
189189
daemon_type, daemon_id,

src/pybind/mgr/nfs/cluster.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ def _call_orch_apply_nfs(
7373
virtual_ip: Optional[str] = None,
7474
ingress_mode: Optional[IngressType] = None,
7575
port: Optional[int] = None,
76-
enable_virtual_server: bool = False
76+
enable_virtual_server: bool = False,
77+
kmip_cert: Optional[str] = None,
78+
kmip_key: Optional[str] = None,
79+
kmip_ca_cert: Optional[str] = None,
80+
kmip_host_list: Optional[List[str]] = None
7781
) -> None:
7882
if not port:
7983
port = 2049 # default nfs port
@@ -101,14 +105,17 @@ def _call_orch_apply_nfs(
101105
keepalive_only = True
102106
ganesha_port = port
103107
frontend_port = None
104-
105108
spec = NFSServiceSpec(service_type='nfs', service_id=cluster_id,
106109
placement=pspec,
107110
# use non-default port so we don't conflict with ingress
108111
port=ganesha_port,
109112
virtual_ip=virtual_ip_for_ganesha,
110113
enable_haproxy_protocol=enable_haproxy_protocol,
111-
enable_virtual_server=enable_virtual_server)
114+
enable_virtual_server=enable_virtual_server,
115+
kmip_cert=kmip_cert,
116+
kmip_key=kmip_key,
117+
kmip_ca_cert=kmip_ca_cert,
118+
kmip_host_list=kmip_host_list)
112119
completion = self.mgr.apply_nfs(spec)
113120
orchestrator.raise_if_exception(completion)
114121
ispec = IngressSpec(service_type='ingress',
@@ -126,7 +133,12 @@ def _call_orch_apply_nfs(
126133
# standalone nfs
127134
spec = NFSServiceSpec(service_type='nfs', service_id=cluster_id,
128135
placement=PlacementSpec.from_string(placement),
129-
port=port, enable_virtual_server=enable_virtual_server)
136+
port=port,
137+
enable_virtual_server=enable_virtual_server,
138+
kmip_cert=kmip_cert,
139+
kmip_key=kmip_key,
140+
kmip_ca_cert=kmip_ca_cert,
141+
kmip_host_list=kmip_host_list)
130142
completion = self.mgr.apply_nfs(spec)
131143
orchestrator.raise_if_exception(completion)
132144
log.debug("Successfully deployed nfs daemons with cluster id %s and placement %s",
@@ -150,7 +162,11 @@ def create_nfs_cluster(
150162
ingress: Optional[bool] = None,
151163
ingress_mode: Optional[IngressType] = None,
152164
port: Optional[int] = None,
153-
enable_virtual_server: bool = False
165+
enable_virtual_server: bool = False,
166+
kmip_cert: Optional[str] = None,
167+
kmip_key: Optional[str] = None,
168+
kmip_ca_cert: Optional[str] = None,
169+
kmip_host_list: Optional[List[str]] = None
154170
) -> None:
155171
try:
156172
if virtual_ip:
@@ -180,6 +196,10 @@ def create_nfs_cluster(
180196
virtual_ip,
181197
ingress_mode,
182198
port,
199+
kmip_cert,
200+
kmip_key,
201+
kmip_ca_cert,
202+
kmip_host_list,
183203
enable_virtual_server
184204
)
185205
return

src/pybind/mgr/nfs/export.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ def create_cephfs_export(self,
698698
clients: list = [],
699699
sectype: Optional[List[str]] = None,
700700
cmount_path: Optional[str] = "/",
701-
earmark_resolver: Optional[CephFSEarmarkResolver] = None
701+
earmark_resolver: Optional[CephFSEarmarkResolver] = None,
702+
kmip_key_id: Optional[str] = None
702703
) -> Dict[str, Any]:
703704

704705
validate_cephfs_path(self.mgr, fs_name, path)
@@ -723,6 +724,7 @@ def create_cephfs_export(self,
723724
},
724725
"clients": clients,
725726
"sectype": sectype,
727+
"kmip_key_id": kmip_key_id
726728
},
727729
earmark_resolver
728730
)
@@ -748,7 +750,8 @@ def create_rgw_export(self,
748750
bucket: Optional[str] = None,
749751
user_id: Optional[str] = None,
750752
clients: list = [],
751-
sectype: Optional[List[str]] = None) -> Dict[str, Any]:
753+
sectype: Optional[List[str]] = None,
754+
kmip_key_id: Optional[str] = None) -> Dict[str, Any]:
752755
pseudo_path = normalize_path(pseudo_path)
753756

754757
if not bucket and not user_id:
@@ -769,6 +772,7 @@ def create_rgw_export(self,
769772
},
770773
"clients": clients,
771774
"sectype": sectype,
775+
"kmip_key_id": kmip_key_id
772776
}
773777
)
774778
log.debug("creating rgw export %s", export)

src/pybind/mgr/nfs/ganesha_conf.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ def __init__(
356356
fsal: FSAL,
357357
clients: Optional[List[Client]] = None,
358358
sectype: Optional[List[str]] = None,
359-
qos_block: Optional[QOS] = None) -> None:
359+
qos_block: Optional[QOS] = None,
360+
kmip_key_id: Optional[str] = None) -> None:
360361
self.export_id = export_id
361362
self.path = path
362363
self.fsal = fsal
@@ -371,6 +372,7 @@ def __init__(
371372
self.clients: List[Client] = clients or []
372373
self.sectype = sectype
373374
self.qos_block = qos_block
375+
self.kmip_key_id = kmip_key_id
374376

375377
@classmethod
376378
def from_export_block(cls, export_block: RawBlock, cluster_id: str) -> 'Export':
@@ -417,11 +419,17 @@ def from_export_block(cls, export_block: RawBlock, cluster_id: str) -> 'Export':
417419
[Client.from_client_block(client)
418420
for client in client_blocks],
419421
sectype=sectype,
420-
qos_block=qos_block
422+
qos_block=qos_block,
423+
kmip_key_id=export_block.values.get('kmip_key_id')
421424
)
422425

423426
def to_export_block(self) -> RawBlock:
424-
values = {
427+
# if kmip_key_id is present, it should be first line of export block
428+
values: Dict[str, Any] = {}
429+
if self.kmip_key_id:
430+
values['kmip_key_id'] = self.kmip_key_id
431+
432+
values.update({
425433
'export_id': self.export_id,
426434
'path': self.path,
427435
'pseudo': self.pseudo,
@@ -431,7 +439,7 @@ def to_export_block(self) -> RawBlock:
431439
'security_label': self.security_label,
432440
'protocols': self.protocols,
433441
'transports': self.transports,
434-
}
442+
})
435443
if self.sectype:
436444
values['SecType'] = self.sectype
437445
result = RawBlock("EXPORT", values=values)
@@ -463,7 +471,8 @@ def from_dict(cls, export_id: int, ex_dict: Dict[str, Any]) -> 'Export':
463471
FSAL.from_dict(ex_dict.get('fsal', {})),
464472
[Client.from_dict(client) for client in ex_dict.get('clients', [])],
465473
sectype=ex_dict.get("sectype"),
466-
qos_block=qos_block
474+
qos_block=qos_block,
475+
kmip_key_id=ex_dict.get('kmip_key_id')
467476
)
468477

469478
def to_dict(self) -> Dict[str, Any]:
@@ -484,6 +493,8 @@ def to_dict(self) -> Dict[str, Any]:
484493
values['sectype'] = self.sectype
485494
if self.qos_block:
486495
values['qos_block'] = self.qos_block.to_dict()
496+
if self.kmip_key_id:
497+
values['kmip_key_id'] = self.kmip_key_id
487498
return values
488499

489500
def validate(self, mgr: 'Module') -> None:
@@ -535,14 +546,15 @@ def __eq__(self, other: Any) -> bool:
535546

536547
def _format_block_body(block: RawBlock, depth: int = 0) -> str:
537548
conf_str = ""
538-
for blo in block.blocks:
539-
conf_str += format_block(blo, depth)
540-
541549
for key, val in block.values.items():
542550
if val is not None:
543551
conf_str += _indentation(depth)
544552
fval = _format_val(block.block_name, key, val)
545553
conf_str += '{} = {};\n'.format(key, fval)
554+
555+
for blo in block.blocks:
556+
conf_str += format_block(blo, depth)
557+
546558
return conf_str
547559

548560

src/pybind/mgr/nfs/module.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def _cmd_nfs_export_create_cephfs(
4141
squash: str = 'none',
4242
sectype: Optional[List[str]] = None,
4343
cmount_path: Optional[str] = "/",
44-
skip_notify_nfs_server: bool = False
44+
skip_notify_nfs_server: bool = False,
45+
kmip_key_id: Optional[str] = None
4546
) -> Dict[str, Any]:
4647
"""Create a CephFS export"""
4748
self.export_mgr.skip_notify_nfs_server = skip_notify_nfs_server
@@ -57,7 +58,8 @@ def _cmd_nfs_export_create_cephfs(
5758
addr=client_addr,
5859
sectype=sectype,
5960
cmount_path=cmount_path,
60-
earmark_resolver=earmark_resolver
61+
earmark_resolver=earmark_resolver,
62+
kmip_key_id=kmip_key_id
6163
)
6264

6365
@CLICommand('nfs export create rgw', perm='rw')
@@ -72,7 +74,8 @@ def _cmd_nfs_export_create_rgw(
7274
client_addr: Optional[List[str]] = None,
7375
squash: str = 'none',
7476
sectype: Optional[List[str]] = None,
75-
skip_notify_nfs_server: bool = False
77+
skip_notify_nfs_server: bool = False,
78+
kmip_key_id: Optional[str] = None
7679
) -> Dict[str, Any]:
7780
"""Create an RGW export"""
7881
self.export_mgr.skip_notify_nfs_server = skip_notify_nfs_server
@@ -86,6 +89,7 @@ def _cmd_nfs_export_create_rgw(
8689
squash=squash,
8790
addr=client_addr,
8891
sectype=sectype,
92+
kmip_key_id=kmip_key_id
8993
)
9094

9195
@CLICommand('nfs export rm', perm='rw')
@@ -148,12 +152,19 @@ def _cmd_nfs_cluster_create(self,
148152
virtual_ip: Optional[str] = None,
149153
ingress_mode: Optional[IngressType] = None,
150154
port: Optional[int] = None,
151-
enable_virtual_server: bool = False) -> None:
155+
enable_virtual_server: bool = False,
156+
kmip_cert: Optional[str] = None,
157+
kmip_key: Optional[str] = None,
158+
kmip_ca_cert: Optional[str] = None,
159+
kmip_host_list: Optional[List[str]] = None,
160+
) -> None:
152161
"""Create an NFS Cluster"""
153162
return self.nfs.create_nfs_cluster(cluster_id=cluster_id, placement=placement,
154163
virtual_ip=virtual_ip, ingress=ingress,
155164
ingress_mode=ingress_mode, port=port,
156-
enable_virtual_server=enable_virtual_server)
165+
enable_virtual_server=enable_virtual_server,
166+
kmip_cert=kmip_cert, kmip_key=kmip_key,
167+
kmip_ca_cert=kmip_ca_cert, kmip_host_list=kmip_host_list)
157168

158169
@CLICommand('nfs cluster rm', perm='rw')
159170
@object_format.EmptyResponder()

0 commit comments

Comments
 (0)