1616from ..context import CephadmContext
1717from ..deployment_utils import to_deployment_container
1818from ..exceptions import Error
19- from ..file_utils import make_run_dir , pathify
19+ from ..file_utils import (
20+ make_run_dir ,
21+ pathify ,
22+ populate_files ,
23+ makedirs ,
24+ recursive_chown ,
25+ )
26+ from ..data_utils import dict_get
2027from ..host_facts import HostFacts
2128from ..logging import Highlight
2229from ..net_utils import get_hostname , get_ip_addresses
@@ -298,6 +305,8 @@ def __init__(
298305 self .port = config_json .get ('port' , self .DEFAULT_PORT )
299306 self .prio_limit = config_json .get ('prio-limit' , 5 )
300307 self .stats_period = config_json .get ('stats-period' , 5 )
308+ self .https_enabled : bool = config_json .get ('https_enabled' , False )
309+ self .files = dict_get (config_json , 'files' , {})
301310
302311 @classmethod
303312 def init (
@@ -323,6 +332,15 @@ def get_daemon_args(self) -> List[str]:
323332 f'--prio-limit={ self .prio_limit } ' ,
324333 f'--stats-period={ self .stats_period } ' ,
325334 ]
335+ if self .https_enabled :
336+ args .extend (
337+ [
338+ '--cert-file' ,
339+ '/etc/certs/ceph-exporter.crt' ,
340+ '--key-file' ,
341+ '/etc/certs/ceph-exporter.key' ,
342+ ]
343+ )
326344 return args
327345
328346 def validate (self ) -> None :
@@ -348,6 +366,9 @@ def customize_container_mounts(
348366 ) -> None :
349367 cm = Ceph .get_ceph_mounts (ctx , self .identity )
350368 mounts .update (cm )
369+ if self .https_enabled :
370+ data_dir = self .identity .data_dir (ctx .data_dir )
371+ mounts .update ({os .path .join (data_dir , 'etc/certs' ): '/etc/certs' })
351372
352373 def customize_process_args (
353374 self , ctx : CephadmContext , args : List [str ]
@@ -376,6 +397,23 @@ def prepare_data_dir(self, data_dir: str, uid: int, gid: int) -> None:
376397 # it until now
377398 self .validate ()
378399
400+ def create_daemon_dirs (self , data_dir : str , uid : int , gid : int ) -> None :
401+ """Create files under the container data dir"""
402+ if not os .path .isdir (data_dir ):
403+ raise OSError ('data_dir is not a directory: %s' % (data_dir ))
404+ logger .info ('Writing ceph-exporter config...' )
405+ config_dir = os .path .join (data_dir , 'etc/' )
406+ ssl_dir = os .path .join (data_dir , 'etc/certs' )
407+ for ddir in [config_dir , ssl_dir ]:
408+ makedirs (ddir , uid , gid , 0o755 )
409+ recursive_chown (ddir , uid , gid )
410+ cert_files = {
411+ fname : content
412+ for fname , content in self .files .items ()
413+ if fname .endswith ('.crt' ) or fname .endswith ('.key' )
414+ }
415+ populate_files (ssl_dir , cert_files , uid , gid )
416+
379417
380418def get_ceph_mounts_for_type (
381419 ctx : CephadmContext , fsid : str , daemon_type : str
0 commit comments