def _wait_execution(mutable, channel): try: stdout_data = channel.recv(1048576) except Exception: LOG.debug('No data from SSH stdout.') else: LOG.debug('Got %d from SSH stdout.', len(stdout_data)) stdout_io.write(stdout_data) try: stderr_data = channel.recv_stderr(1048576) except Exception: LOG.debug('No data from SSH stderr.') else: LOG.debug('Got %d from SSH stderr.', len(stderr_data)) stderr_io.write(stderr_data) if channel.exit_status_ready(): raise loopingcall.LoopingCallDone() try: ssh = utils.ssh_connect(ssh_params) except exception.SSHConnectFailed: mutable['error'] = True raise loopingcall.LoopingCallDone() else: ssh.close()
def _get_connection(node): """Returns an SSH client connected to a node. :param node: the Node. :returns: paramiko.SSHClient, an active ssh connection. """ return utils.ssh_connect(_parse_driver_info(node))
def pass_deploy_info(self, task, **kwargs): """Continues the deployment of baremetal node.""" node = task.node task.process_event('resume') err_msg = _('Failed to continue deployment with Fuel Agent.') agent_status = kwargs.get('status') if agent_status != 'ready': LOG.error(_LE('Deploy failed for node %(node)s. Fuel Agent is not ' 'in ready state, error: %(error)s'), {'node': node.uuid, 'error': kwargs.get('error_message')}) deploy_utils.set_failed_state(task, err_msg) return params = _parse_driver_info(node) params['host'] = kwargs.get('address') cmd = ('%s --data_driver ironic --config-file ' '/etc/fuel-agent/fuel-agent.conf' % params.pop('script')) if CONF.debug: cmd += ' --debug' instance_info = node.instance_info try: deploy_data = _get_deploy_data(task.context, instance_info['image_source']) image_data = {"/": {"uri": instance_info['image_url'], "format": "raw", "container": "raw"}} deploy_data['ks_meta']['image_data'] = image_data ssh = utils.ssh_connect(params) sftp = ssh.open_sftp() _sftp_upload(sftp, json.dumps(deploy_data), '/tmp/provision.json') # swift configdrive store should be disabled configdrive = instance_info.get('configdrive') if configdrive is not None: _sftp_upload(sftp, configdrive, '/tmp/config-drive.img') _ssh_execute(ssh, cmd, params) LOG.info(_LI('Fuel Agent pass on node %s'), node.uuid) manager_utils.node_set_boot_device(task, boot_devices.DISK, persistent=True) manager_utils.node_power_action(task, states.REBOOT) except Exception as e: msg = (_('Deploy failed for node %(node)s. Error: %(error)s') % {'node': node.uuid, 'error': e}) LOG.error(msg) deploy_utils.set_failed_state(task, msg) else: task.process_event('done') LOG.info(_LI('Deployment to node %s done'), task.node.uuid)
def get_ssh_connection(task, **kwargs): ssh = utils.ssh_connect(kwargs) # Note(oberezovskyi): this is required to prevent printing private_key to # the conductor log if kwargs.get('key_contents'): kwargs['key_contents'] = '*****' LOG.debug("SSH with params:") LOG.debug(kwargs) return ssh
def _get_connection(node): return utils.ssh_connect(_parse_driver_info(node))
def heartbeat(self, task, callback_url): """Continues the deployment of baremetal node.""" node = task.node # NOTE(pas-ha) this driver does not support cleaning, # so the only valid state to continue on heartbeat is DEPLOYWAIT if node.provision_state != states.DEPLOYWAIT: LOG.warning( _LW('Call back from %(node)s in invalid provision ' 'state %(state)s'), { 'node': node.uuid, 'state': node.provision_state }) return task.upgrade_lock(purpose='deploy') task.process_event('resume') params = _parse_driver_info(node) params['host'] = urlparse.urlparse(callback_url).netloc.split(':')[0] cmd = ('%s --data_driver ironic --config-file ' '/etc/fuel-agent/fuel-agent.conf' % params.pop('script')) if CONF.debug: cmd += ' --debug' instance_info = node.instance_info try: deploy_data = _get_deploy_data(task.context, instance_info['image_source']) image_data = { "/": { "uri": instance_info['image_url'], "format": "raw", "container": "raw" } } deploy_data['ks_meta']['image_data'] = image_data ssh = utils.ssh_connect(params) sftp = ssh.open_sftp() _sftp_upload(sftp, json.dumps(deploy_data), '/tmp/provision.json') # swift configdrive store should be disabled configdrive = instance_info.get('configdrive') if configdrive is not None: _sftp_upload(sftp, configdrive, '/tmp/config-drive.img') _ssh_execute(ssh, cmd, params) LOG.info(_LI('Fuel Agent pass on node %s'), node.uuid) manager_utils.node_set_boot_device(task, boot_devices.DISK, persistent=True) manager_utils.node_power_action(task, states.POWER_OFF) task.driver.network.remove_provisioning_network(task) task.driver.network.configure_tenant_networks(task) manager_utils.node_power_action(task, states.POWER_ON) except Exception as e: msg = (_('Deploy failed for node %(node)s. Error: %(error)s') % { 'node': node.uuid, 'error': e }) LOG.error(msg) deploy_utils.set_failed_state(task, msg, collect_logs=False) else: task.process_event('done') LOG.info(_LI('Deployment to node %s done'), task.node.uuid)
def pass_deploy_info(self, task, **kwargs): """Continues the deployment of baremetal node.""" node = task.node task.process_event('resume') err_msg = _('Failed to continue deployment with Fuel Agent.') agent_status = kwargs.get('status') if agent_status != 'ready': LOG.error( _LE('Deploy failed for node %(node)s. Fuel Agent is not ' 'in ready state, error: %(error)s'), { 'node': node.uuid, 'error': kwargs.get('error_message') }) deploy_utils.set_failed_state(task, err_msg) return params = _parse_driver_info(node) params['host'] = kwargs.get('address') cmd = ('%s --data_driver ironic --config-file ' '/etc/fuel-agent/fuel-agent.conf' % params.pop('script')) if CONF.debug: cmd += ' --debug' instance_info = node.instance_info try: deploy_data = _get_deploy_data(task.context, instance_info['image_source']) image_data = { "/": { "uri": instance_info['image_url'], "format": "raw", "container": "raw" } } deploy_data['ks_meta']['image_data'] = image_data ssh = utils.ssh_connect(params) sftp = ssh.open_sftp() _sftp_upload(sftp, json.dumps(deploy_data), '/tmp/provision.json') # swift configdrive store should be disabled configdrive = instance_info.get('configdrive') if configdrive is not None: _sftp_upload(sftp, configdrive, '/tmp/config-drive.img') _ssh_execute(ssh, cmd, params) LOG.info(_LI('Fuel Agent pass on node %s'), node.uuid) manager_utils.node_set_boot_device(task, boot_devices.DISK, persistent=True) manager_utils.node_power_action(task, states.REBOOT) except Exception as e: msg = (_('Deploy failed for node %(node)s. Error: %(error)s') % { 'node': node.uuid, 'error': e }) LOG.error(msg) deploy_utils.set_failed_state(task, msg) else: task.process_event('done') LOG.info(_LI('Deployment to node %s done'), task.node.uuid)