Ejemplo n.º 1
0
def _parse_driver_info(node):
    """Gets the driver-specific Node deployment info.

    This method validates whether the 'driver_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node to validate.
    :returns: A dict with the driver_info values.
    """

    info = node.get('driver_info', {})
    d_info = {}
    d_info['image_source'] = info.get('pxe_image_source')
    d_info['deploy_kernel'] = info.get('pxe_deploy_kernel')
    d_info['deploy_ramdisk'] = info.get('pxe_deploy_ramdisk')
    d_info['root_gb'] = info.get('pxe_root_gb')

    missing_info = []
    for label in d_info:
        if not d_info[label]:
            missing_info.append("pxe_%s" % label)
    if missing_info:
        raise exception.InvalidParameterValue(_(
                "Can not validate PXE bootloader. The following parameters "
                "were not passed to ironic: %s") % missing_info)

    # Internal use only
    d_info['deploy_key'] = info.get('pxe_deploy_key')

    #TODO(ghe): Should we get rid of swap partition?
    d_info['swap_mb'] = info.get('pxe_swap_mb', 1)
    d_info['ephemeral_gb'] = info.get('pxe_ephemeral_gb', 0)
    d_info['ephemeral_format'] = info.get('pxe_ephemeral_format')

    err_msg_invalid = _("Can not validate PXE bootloader. Invalid parameter "
                        "pxe_%(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(d_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % d_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid %
                                            {'param': param, 'reason': reason})

    if d_info['ephemeral_gb'] and not d_info['ephemeral_format']:
        msg = _("The deploy contains an ephemeral partition, but no "
                "filesystem type was specified by the pxe_ephemeral_format "
                "parameter")
        raise exception.InvalidParameterValue(msg)

    preserve_ephemeral = info.get('pxe_preserve_ephemeral', False)
    try:
        d_info['preserve_ephemeral'] = strutils.bool_from_string(
                                            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid %
                                  {'param': 'preserve_ephemeral', 'reason': e})
    return d_info
Ejemplo n.º 2
0
def _parse_driver_info(node):
    """Gets the driver-specific Node deployment info.

    This method validates whether the 'driver_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node to validate.
    :returns: A dict with the driver_info values.
    """

    info = node.driver_info or {}
    d_info = {}
    d_info['image_source'] = info.get('pxe_image_source')
    d_info['deploy_kernel'] = info.get('pxe_deploy_kernel')
    d_info['deploy_ramdisk'] = info.get('pxe_deploy_ramdisk')
    d_info['root_gb'] = info.get('pxe_root_gb')

    missing_info = []
    for label in d_info:
        if not d_info[label]:
            missing_info.append("pxe_%s" % label)
    if missing_info:
        raise exception.InvalidParameterValue(
            _("Can not validate PXE bootloader. The following parameters "
              "were not passed to ironic: %s") % missing_info)

    # Internal use only
    d_info['deploy_key'] = info.get('pxe_deploy_key')

    d_info['swap_mb'] = info.get('pxe_swap_mb', 0)
    d_info['ephemeral_gb'] = info.get('pxe_ephemeral_gb', 0)
    d_info['ephemeral_format'] = info.get('pxe_ephemeral_format')

    err_msg_invalid = _("Can not validate PXE bootloader. Invalid parameter "
                        "pxe_%(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(d_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % d_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid % {
                'param': param,
                'reason': reason
            })

    if d_info['ephemeral_gb'] and not d_info['ephemeral_format']:
        d_info['ephemeral_format'] = CONF.pxe.default_ephemeral_format

    preserve_ephemeral = info.get('pxe_preserve_ephemeral', False)
    try:
        d_info['preserve_ephemeral'] = strutils.bool_from_string(
            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid % {
            'param': 'preserve_ephemeral',
            'reason': e
        })
    return d_info
Ejemplo n.º 3
0
def _parse_instance_info(node):
    """Gets the instance specific Node deployment info.

    This method validates whether the 'instance_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node.
    :returns: A dict with the instance_info values.
    """

    info = node.instance_info
    i_info = {}
    i_info['image_source'] = info.get('image_source')
    i_info['root_gb'] = info.get('root_gb')
    i_info['image_file'] = i_info['image_source']

    _check_for_missing_params(i_info)

    # Internal use only
    i_info['deploy_key'] = info.get('deploy_key')

    i_info['swap_mb'] = info.get('swap_mb', 0)
    i_info['ephemeral_gb'] = info.get('ephemeral_gb', 0)
    i_info['ephemeral_format'] = info.get('ephemeral_format')

    err_msg_invalid = _("Can not validate PXE bootloader. Invalid parameter "
                        "%(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(i_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % i_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid % {
                'param': param,
                'reason': reason
            })

    if i_info['ephemeral_gb'] and not i_info['ephemeral_format']:
        i_info['ephemeral_format'] = CONF.pxe.default_ephemeral_format

    preserve_ephemeral = info.get('preserve_ephemeral', False)
    try:
        i_info['preserve_ephemeral'] = strutils.bool_from_string(
            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid % {
            'param': 'preserve_ephemeral',
            'reason': e
        })
    return i_info
Ejemplo n.º 4
0
def parse_instance_info(node):
    """Gets the instance specific Node deployment info.

    This method validates whether the 'instance_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node.
    :returns: A dict with the instance_info values.
    :raises: MissingParameterValue, if any of the required parameters are
        missing.
    :raises: InvalidParameterValue, if any of the parameters have invalid
        value.
    """
    info = node.instance_info
    i_info = {}
    i_info['image_source'] = info.get('image_source')
    i_info['root_gb'] = info.get('root_gb')

    error_msg = _("Cannot validate iSCSI deploy")
    deploy_utils.check_for_missing_params(i_info, error_msg)

    # Internal use only
    i_info['deploy_key'] = info.get('deploy_key')

    i_info['swap_mb'] = info.get('swap_mb', 0)
    i_info['ephemeral_gb'] = info.get('ephemeral_gb', 0)
    i_info['ephemeral_format'] = info.get('ephemeral_format')

    err_msg_invalid = _("Cannot validate parameter for iSCSI deploy. "
                        "Invalid parameter %(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(i_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % i_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid %
                                            {'param': param, 'reason': reason})

    if i_info['ephemeral_gb'] and not i_info['ephemeral_format']:
        i_info['ephemeral_format'] = CONF.pxe.default_ephemeral_format

    preserve_ephemeral = info.get('preserve_ephemeral', False)
    try:
        i_info['preserve_ephemeral'] = strutils.bool_from_string(
                                            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid %
                                  {'param': 'preserve_ephemeral', 'reason': e})
    return i_info
Ejemplo n.º 5
0
def get_password(max_password_prompts=3):
    """Read password from TTY."""
    verify = strutils.bool_from_string(env("OS_VERIFY_PASSWORD"))
    pw = None
    if hasattr(sys.stdin, "isatty") and sys.stdin.isatty():
        # Check for Ctrl-D
        try:
            for __ in moves.range(max_password_prompts):
                pw1 = getpass.getpass("OS Password: "******"Please verify: ")
                else:
                    pw2 = pw1
                if pw1 == pw2 and pw1:
                    pw = pw1
                    break
        except EOFError:
            pass
    return pw
Ejemplo n.º 6
0
def get_password(max_password_prompts=3):
    """Read password from TTY."""
    verify = strutils.bool_from_string(env("OS_VERIFY_PASSWORD"))
    pw = None
    if hasattr(sys.stdin, "isatty") and sys.stdin.isatty():
        # Check for Ctrl-D
        try:
            for __ in moves.range(max_password_prompts):
                pw1 = getpass.getpass("OS Password: "******"Please verify: ")
                else:
                    pw2 = pw1
                if pw1 == pw2 and pw1:
                    pw = pw1
                    break
        except EOFError:
            pass
    return pw
Ejemplo n.º 7
0
 def validate(value):
     try:
         return strutils.bool_from_string(value, strict=True)
     except ValueError as e:
         # raise Invalid to return 400 (BadRequest) in the API
         raise exception.Invalid(e)
Ejemplo n.º 8
0
Archivo: pxe.py Proyecto: nkaul/ironic
def _parse_driver_info(node):
    """Gets the driver-specific Node deployment info.

    This method validates whether the 'driver_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node to validate.
    :returns: A dict with the driver_info values.
    """

    info = node.driver_info or {}
    d_info = {}
    d_info['image_source'] = info.get('pxe_image_source')
    d_info['deploy_kernel'] = info.get('pxe_deploy_kernel')
    d_info['deploy_ramdisk'] = info.get('pxe_deploy_ramdisk')
    d_info['root_gb'] = info.get('pxe_root_gb')

    missing_info = []
    for label in d_info:
        if not d_info[label]:
            missing_info.append("pxe_%s" % label)
    if missing_info:
        raise exception.InvalidParameterValue(_(
                "Can not validate PXE bootloader. The following parameters "
                "were not passed to ironic: %s") % missing_info)

    # Internal use only
    d_info['deploy_key'] = info.get('pxe_deploy_key')

    # TODO(ghe): Should we get rid of swap partition?
    d_info['swap_mb'] = info.get('pxe_swap_mb', 0)
    d_info['ephemeral_gb'] = info.get('pxe_ephemeral_gb', 0)
    d_info['ephemeral_format'] = info.get('pxe_ephemeral_format')

    err_msg_invalid = _("Can not validate PXE bootloader. Invalid parameter "
                        "pxe_%(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(d_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % d_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid %
                                            {'param': param, 'reason': reason})

    # NOTE(lucasagomes): For simpler code paths on the deployment side,
    #                    we always create a swap partition. if the size is
    #                    <= 0 we default to 1MB
    if int(d_info['swap_mb']) <= 0:
        d_info['swap_mb'] = 1

    if d_info['ephemeral_gb'] and not d_info['ephemeral_format']:
        d_info['ephemeral_format'] = CONF.pxe.default_ephemeral_format

    preserve_ephemeral = info.get('pxe_preserve_ephemeral', False)
    try:
        d_info['preserve_ephemeral'] = strutils.bool_from_string(
                                            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid %
                                  {'param': 'preserve_ephemeral', 'reason': e})
    return d_info
Ejemplo n.º 9
0
def _parse_driver_info(node):
    """Gets the driver-specific Node deployment info.

    This method validates whether the 'driver_info' property of the
    supplied node contains the required information for this driver to
    deploy images to the node.

    :param node: a single Node to validate.
    :returns: A dict with the driver_info values.
    """

    info = node.get('driver_info', {})
    d_info = {}
    d_info['image_source'] = info.get('pxe_image_source')
    d_info['deploy_kernel'] = info.get('pxe_deploy_kernel')
    d_info['deploy_ramdisk'] = info.get('pxe_deploy_ramdisk')
    d_info['root_gb'] = info.get('pxe_root_gb')

    missing_info = []
    for label in d_info:
        if not d_info[label]:
            missing_info.append("pxe_%s" % label)
    if missing_info:
        raise exception.InvalidParameterValue(
            _("Can not validate PXE bootloader. The following parameters "
              "were not passed to ironic: %s") % missing_info)

    # Internal use only
    d_info['deploy_key'] = info.get('pxe_deploy_key')

    # TODO(ghe): Should we get rid of swap partition?
    d_info['swap_mb'] = info.get('pxe_swap_mb', 0)
    d_info['ephemeral_gb'] = info.get('pxe_ephemeral_gb', 0)
    d_info['ephemeral_format'] = info.get('pxe_ephemeral_format')

    err_msg_invalid = _("Can not validate PXE bootloader. Invalid parameter "
                        "pxe_%(param)s. Reason: %(reason)s")
    for param in ('root_gb', 'swap_mb', 'ephemeral_gb'):
        try:
            int(d_info[param])
        except ValueError:
            reason = _("'%s' is not an integer value.") % d_info[param]
            raise exception.InvalidParameterValue(err_msg_invalid % {
                'param': param,
                'reason': reason
            })

    # NOTE(lucasagomes): For simpler code paths on the deployment side,
    #                    we always create a swap partition. if the size is
    #                    <= 0 we default to 1MB
    if int(d_info['swap_mb']) <= 0:
        d_info['swap_mb'] = 1

    if d_info['ephemeral_gb'] and not d_info['ephemeral_format']:
        msg = _("The deploy contains an ephemeral partition, but no "
                "filesystem type was specified by the pxe_ephemeral_format "
                "parameter")
        raise exception.InvalidParameterValue(msg)

    preserve_ephemeral = info.get('pxe_preserve_ephemeral', False)
    try:
        d_info['preserve_ephemeral'] = strutils.bool_from_string(
            preserve_ephemeral, strict=True)
    except ValueError as e:
        raise exception.InvalidParameterValue(err_msg_invalid % {
            'param': 'preserve_ephemeral',
            'reason': e
        })
    return d_info
Ejemplo n.º 10
0
 def validate(value):
     try:
         return strutils.bool_from_string(value, strict=True)
     except ValueError as e:
         # raise Invalid to return 400 (BadRequest) in the API
         raise exception.Invalid(e)