def _dhcp_option_file_or_url(task, urlboot=False, ip_version=None): """Returns the appropriate file or URL. :param task: A TaskManager object. :param url_boot: Boolean value default False to indicate if a URL should be returned to the file as opposed to a file. :param ip_version: Integer representing the version of IP of to return options for DHCP. Possible options are 4, and 6. """ try: if task.driver.boot.ipxe_enabled: boot_file = deploy_utils.get_ipxe_boot_file(task.node) else: boot_file = deploy_utils.get_pxe_boot_file(task.node) except AttributeError: # Support boot interfaces that lack an explicit ipxe_enabled # attribute flag. boot_file = deploy_utils.get_pxe_boot_file(task.node) # NOTE(TheJulia): There are additional cases as we add new # features, so the logic below is in the form of if/elif/elif if not urlboot: return boot_file elif urlboot: if CONF.my_ipv6 and ip_version == 6: host = utils.wrap_ipv6(CONF.my_ipv6) else: host = utils.wrap_ipv6(CONF.pxe.tftp_server) return "tftp://{host}/{boot_file}".format(host=host, boot_file=boot_file)
def get_socat_console_url(port): """Get a URL to access the console via socat. :param port: the terminal port (integer) for the node :return: an access URL to the socat console of the node """ console_host = utils.wrap_ipv6(CONF.console.socat_address) return 'tcp://%(host)s:%(port)s' % {'host': console_host, 'port': port}
def discovery(portal_address, portal_port): """Do iSCSI discovery on portal.""" utils.execute('iscsiadm', '-m', 'discovery', '-t', 'st', '-p', '%s:%s' % (utils.wrap_ipv6(portal_address), portal_port), run_as_root=True, check_exit_code=[0], attempts=5, delay_on_retry=True)
def logout_iscsi(portal_address, portal_port, target_iqn): """Logout from an iSCSI target.""" utils.execute('iscsiadm', '-m', 'node', '-p', '%s:%s' % (utils.wrap_ipv6(portal_address), portal_port), '-T', target_iqn, '--logout', run_as_root=True, check_exit_code=[0], attempts=5, delay_on_retry=True)
def get_shellinabox_console_url(port): """Get a url to access the console via shellinaboxd. :param port: the terminal port for the node. """ console_host = utils.wrap_ipv6(CONF.my_ip) scheme = 'https' if CONF.console.terminal_cert_dir else 'http' return '%(scheme)s://%(host)s:%(port)s' % { 'scheme': scheme, 'host': console_host, 'port': port }
def delete_iscsi(portal_address, portal_port, target_iqn): """Delete the iSCSI target.""" # Retry delete until it succeeds (exit code 0) or until there is # no longer a target to delete (exit code 21). utils.execute('iscsiadm', '-m', 'node', '-p', '%s:%s' % (utils.wrap_ipv6(portal_address), portal_port), '-T', target_iqn, '-o', 'delete', run_as_root=True, check_exit_code=[0, 21], attempts=5, delay_on_retry=True)
def _dhcp_option_file_or_url(task, urlboot=False): """Returns the appropriate file or URL. :param task: A TaskManager object. :param url_boot: Boolean value default False to indicate if a URL should be returned to the file as opposed to a file. """ boot_file = deploy_utils.get_pxe_boot_file(task.node) # NOTE(TheJulia): There are additional cases as we add new # features, so the logic below is in the form of if/elif/elif if not urlboot: return boot_file elif urlboot: host = utils.wrap_ipv6(CONF.pxe.tftp_server) return "tftp://{host}/{boot_file}".format(host=host, boot_file=boot_file)
def login_iscsi(portal_address, portal_port, target_iqn): """Login to an iSCSI target.""" utils.execute('iscsiadm', '-m', 'node', '-p', '%s:%s' % (utils.wrap_ipv6(portal_address), portal_port), '-T', target_iqn, '--login', run_as_root=True, check_exit_code=[0], attempts=5, delay_on_retry=True) error_occurred = False try: # Ensure the login complete verify_iscsi_connection(target_iqn) # force iSCSI initiator to re-read luns force_iscsi_lun_update(target_iqn) # ensure file system sees the block device check_file_system_for_iscsi_device(portal_address, portal_port, target_iqn) except (exception.InstanceDeployFailure, processutils.ProcessExecutionError) as e: with excutils.save_and_reraise_exception(): error_occurred = True LOG.error("Failed to login to an iSCSI target due to %s", e) finally: if error_occurred: try: logout_iscsi(portal_address, portal_port, target_iqn) delete_iscsi(portal_address, portal_port, target_iqn) except processutils.ProcessExecutionError as e: LOG.warning( "An error occurred when trying to cleanup " "failed ISCSI session error %s", e)