def get_ssh_client(self): """ Creates an ssh client against the VM only if the Instance is the master """ if self.public: if not self.ssh_client or self.ssh_client.ip_address != self.public_ip: self.ssh_client = SSHClient(self.public_ip, self.ssh_credentials) else: if not self.ssh_client or self.ssh_client.ip_address != self.private_ip: self.ssh_client = SSHClient(self.private_ip, self.ssh_credentials) return self.ssh_client
def __init__(self, standalone_config): self.config = standalone_config self.backend_name = self.config['backend'] self.runtime = self.config['runtime'] self.is_lithops_worker = is_lithops_worker() self.start_timeout = self.config.get('start_timeout', 300) self.auto_dismantle = self.config.get('auto_dismantle') self.hard_dismantle_timeout = self.config.get('hard_dismantle_timeout') self.soft_dismantle_timeout = self.config.get('soft_dismantle_timeout') try: module_location = 'lithops.standalone.backends.{}'.format( self.backend_name) sb_module = importlib.import_module(module_location) StandaloneBackend = getattr(sb_module, 'StandaloneBackend') self.backend = StandaloneBackend(self.config[self.backend_name]) except Exception as e: logger.error("There was an error trying to create the " "{} standalone backend".format(self.backend_name)) raise e self.log_monitors = {} self.ssh_credentials = self.backend.get_ssh_credentials() self.ip_address = self.backend.get_ip_address() from lithops.util.ssh_client import SSHClient self.ssh_client = SSHClient(self.ssh_credentials) logger.debug("Standalone handler created successfully")
def get_ssh_client(self): """ Creates an ssh client against the VM only if the Instance is the master """ if self.ip_address: if not self.ssh_client: self.ssh_client = SSHClient(self.ip_address, self.ssh_credentials) return self.ssh_client
def run_job_on_worker(worker_info, call_ids_range, job_payload): """ Install all the Lithops dependencies into the worker. Runs the job """ instance_name, ip_address, instance_id = worker_info logger.info('Going to setup {}, IP address {}'.format( instance_name, ip_address)) ssh_client = SSHClient(ip_address, STANDALONE_SSH_CREDNTIALS) wait_instance_ready(ssh_client) # upload zip lithops package logger.info('Uploading lithops files to VM instance {}'.format(ip_address)) ssh_client.upload_local_file('/opt/lithops/lithops_standalone.zip', '/tmp/lithops_standalone.zip') logger.info( 'Executing lithops installation process on VM instance {}'.format( ip_address)) vm_data = { 'instance_name': instance_name, 'ip_address': ip_address, 'instance_id': instance_id } script = get_worker_setup_script(STANDALONE_CONFIG, vm_data) ssh_client.run_remote_command(script, run_async=True) ssh_client.close() # Wait until the proxy is ready wait_proxy_ready(ip_address) dbr = job_payload['data_byte_ranges'] job_payload['call_ids'] = call_ids_range job_payload['data_byte_ranges'] = [ dbr[int(call_id)] for call_id in call_ids_range ] url = "http://{}:{}/run".format(ip_address, STANDALONE_SERVICE_PORT) r = requests.post(url, data=json.dumps(job_payload)) response = r.json() if 'activationId' in response: logger.info('Calls {} invoked. Activation ID: {}'.format( ', '.join(call_ids_range), response['activationId'])) else: logger.error('calls {} failed invocation: {}'.format( ', '.join(call_ids_range), response['error']))
def get_ssh_client(self): """ Creates an ssh client against the VM only if the Instance is the master """ if not self.validated and self.public and self.instance_id: # validate that private ssh key in ssh_credentials is a pair of public key on instance key_filename = self.ssh_credentials['key_filename'] key_filename = os.path.abspath(os.path.expanduser(key_filename)) if not os.path.exists(key_filename): raise LithopsValidationError( f"Private key file {key_filename} doesn't exist") initialization_data = self.ibm_vpc_client.get_instance_initialization( self.instance_id).get_result() private_res = paramiko.RSAKey(filename=key_filename).get_base64() key = None names = [] for k in initialization_data['keys']: public_res = self.ibm_vpc_client.get_key( k['id']).get_result()['public_key'].split(' ')[1] if public_res == private_res: self.validated = True break else: names.append(k['name']) if not self.validated: raise LithopsValidationError( f"No public key from keys: {names} on master {self} not a pair for private ssh key {key_filename}" ) if self.private_ip or self.public_ip: if not self.ssh_client: self.ssh_client = SSHClient(self.public_ip or self.private_ip, self.ssh_credentials) return self.ssh_client