Esempio n. 1
0
 def prepare_scripts(self, host, is_server):
     if self.scripts_prepared_for_host.get(host, False):
         return
     gateway_host = SshConn.get_gateway_host(host)
     # copy scripts to host
     scripts_dir = os.path.join(self.env_monitoring_config['app_path'],
                                self.APP_SCRIPTS_FOLDER)
     script_files = [f for f in os.listdir(scripts_dir)
                     if os.path.isfile(os.path.join(scripts_dir, f))]
     script_mode = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | \
         stat.S_IROTH | stat.S_IXOTH
     target_host = host if is_server else gateway_host
     self.make_remote_dir(target_host, self.REMOTE_SCRIPTS_FOLDER)
     for file_name in script_files:
         remote_path = os.path.join(self.REMOTE_SCRIPTS_FOLDER, file_name)
         local_path = os.path.join(scripts_dir, file_name)
         if not os.path.isfile(local_path):
             continue
         if is_server:
             ssh = self.get_ssh(target_host, for_sftp=True)
             ssh.copy_file(local_path, remote_path, mode=script_mode)
         else:
             self.copy_to_remote_host(target_host, local_path, remote_path,
                                      mode=script_mode,
                                      make_remote_dir=False)
     self.scripts_prepared_for_host[host] = True
Esempio n. 2
0
 def deploy_ssl_files(self, hosts: list):
     try:
         monitoring_server = self.env_monitoring_config['server_ip']
         gateway_host = SshConn.get_gateway_host(hosts[0])
         temp_dir = tempfile.TemporaryDirectory()
         for file_path in self.fetch_ssl_files:
             # copy SSL files from the monitoring server
             file_name = os.path.basename(file_path)
             local_path = os.path.join(temp_dir.name, file_name)
             self.get_file(monitoring_server, file_path, local_path)
             #  first copy the files to the gateway
             self.write_to_remote_host(gateway_host, local_path,
                                       remote_path=file_path)
         ssl_path = os.path.commonprefix(self.fetch_ssl_files)
         for host in hosts:
             self.copy_from_gateway_to_host(host, ssl_path, ssl_path)
     except SshError:
         self.had_errors = True