예제 #1
0
def _get_instance_image_info(node, ctx):
    """Generate the paths for TFTP files for instance related images.

    This method generates the paths for instance kernel and
    instance ramdisk. This method also updates the node, so caller should
    already have a non-shared lock on the node.

    :param node: a node object
    :param ctx: context
    :returns: a dictionary whose keys are the names of the images (kernel,
        ramdisk) and values are the absolute paths of them. If it's a whole
        disk image, it returns an empty dictionary.
    """
    image_info = {}
    if node.driver_internal_info.get('is_whole_disk_image'):
        return image_info

    root_dir = pxe_utils.get_root_dir()
    i_info = node.instance_info
    labels = ('kernel', 'ramdisk')
    d_info = deploy_utils.get_image_instance_info(node)
    if not (i_info.get('kernel') and i_info.get('ramdisk')):
        glance_service = service.GlanceImageService(version=1, context=ctx)
        iproperties = glance_service.show(d_info['image_source'])['properties']
        for label in labels:
            i_info[label] = str(iproperties[label + '_id'])
        node.instance_info = i_info
        node.save()

    for label in labels:
        image_info[label] = (i_info[label],
                             os.path.join(root_dir, node.uuid, label))

    return image_info
예제 #2
0
def _get_image_info(node, ctx):
    """Generate the paths for tftp files for this instance

    Raises IronicException if
    - instance does not contain kernel_id or ramdisk_id
    - deploy_kernel_id or deploy_ramdisk_id can not be read from
      driver_info and defaults are not set

    """
    d_info = _parse_deploy_info(node)
    image_info = {}
    root_dir = pxe_utils.get_root_dir()

    image_info.update(pxe_utils.get_deploy_kr_info(node.uuid, d_info))

    i_info = node.instance_info
    labels = ('kernel', 'ramdisk')
    if not (i_info.get('kernel') and i_info.get('ramdisk')):
        glance_service = service.Service(version=1, context=ctx)
        iproperties = glance_service.show(d_info['image_source'])['properties']
        for label in labels:
            i_info[label] = str(iproperties[label + '_id']).split('/')[-1]
        node.instance_info = i_info
        node.save()

    for label in labels:
        image_info[label] = (i_info[label],
                             os.path.join(root_dir, node.uuid, label))

    return image_info
예제 #3
0
파일: pxe.py 프로젝트: stendulker/ironic
def _get_image_info(node, ctx):
    """Generate the paths for tftp files for this instance

    Raises IronicException if
    - instance does not contain kernel or ramdisk
    - deploy_kernel or deploy_ramdisk can not be read from
      driver_info and defaults are not set

    """
    d_info = _parse_deploy_info(node)
    image_info = {}
    root_dir = pxe_utils.get_root_dir()

    image_info.update(pxe_utils.get_deploy_kr_info(node.uuid, d_info))

    if node.driver_internal_info.get('is_whole_disk_image'):
        return image_info

    i_info = node.instance_info
    labels = ('kernel', 'ramdisk')
    if not (i_info.get('kernel') and i_info.get('ramdisk')):
        glance_service = service.GlanceImageService(version=1, context=ctx)
        iproperties = glance_service.show(d_info['image_source'])['properties']
        for label in labels:
            i_info[label] = str(iproperties[label + '_id'])
        node.instance_info = i_info
        node.save()

    for label in labels:
        image_info[label] = (
            i_info[label],
            os.path.join(root_dir, node.uuid, label)
        )

    return image_info
예제 #4
0
파일: pxe.py 프로젝트: maratoid/ironic
def _get_instance_image_info(node, ctx):
    """Generate the paths for TFTP files for instance related images.

    This method generates the paths for instance kernel and
    instance ramdisk. This method also updates the node, so caller should
    already have a non-shared lock on the node.

    :param node: a node object
    :param ctx: context
    :returns: a dictionary whose key are the name of the image (kernel,
        ramdisk) and values are the absolute paths of them. If it's a whole
        disk image, it returns an empty dictionary.
    """
    image_info = {}
    if node.driver_internal_info.get("is_whole_disk_image"):
        return image_info

    root_dir = pxe_utils.get_root_dir()
    i_info = node.instance_info
    labels = ("kernel", "ramdisk")
    d_info = _parse_instance_info(node)
    if not (i_info.get("kernel") and i_info.get("ramdisk")):
        glance_service = service.GlanceImageService(version=1, context=ctx)
        iproperties = glance_service.show(d_info["image_source"])["properties"]
        for label in labels:
            i_info[label] = str(iproperties[label + "_id"])
        node.instance_info = i_info
        node.save()

    for label in labels:
        image_info[label] = (i_info[label], os.path.join(root_dir, node.uuid, label))

    return image_info
예제 #5
0
파일: pxe.py 프로젝트: ader1990/ironic
def _cache_ramdisk_kernel(ctx, node, pxe_info):
    """Fetch the necessary kernels and ramdisks for the instance."""
    fileutils.ensure_tree(
        os.path.join(pxe_utils.get_root_dir(), node.uuid))
    LOG.debug("Fetching kernel and ramdisk for node %s",
              node.uuid)
    deploy_utils.fetch_images(ctx, TFTPImageCache(), pxe_info.values())
예제 #6
0
 def _build_pxe_options(self, node):
     pxe_info = {}
     root_dir = pxe_utils.get_root_dir()
     for label in ('user_kernel', 'user_ramdisk'):
         pxe_info[label] = \
             os.path.join(root_dir, node.instance_info.get(label))
     return pxe_info
예제 #7
0
def _cache_ramdisk_kernel(ctx, node, pxe_info):
    """Fetch the necessary kernels and ramdisks for the instance."""
    fileutils.ensure_tree(
        os.path.join(pxe_utils.get_root_dir(), node.uuid))
    LOG.debug("Fetching kernel and ramdisk for node %s",
              node.uuid)
    deploy_utils.fetch_images(ctx, TFTPImageCache(), pxe_info.values())
예제 #8
0
    def _get_pxe_mac_path(self, mac, delimiter='-', client_id=None):
        """Convert a MAC address into a PXE config file name.

        :param mac: A MAC address string in the format xx:xx:xx:xx:xx:xx.
        :param delimiter: The MAC address delimiter. Defaults to dash ('-').
        :param client_id: client_id indicate InfiniBand port.
                          Defaults is None (Ethernet)
        :returns: the path to the config file.

        """
        mac_file_name = mac.replace(':', delimiter).lower()
        if not CONF.pxe.ipxe_enabled:
            hw_type = '01-'
            if client_id:
                hw_type = '20-'
            mac_file_name = hw_type + mac_file_name

        return os.path.join(get_root_dir(), PXE_CFG_DIR_NAME, mac_file_name)
예제 #9
0
파일: pxe.py 프로젝트: Tehsmash/ironic
def _get_instance_image_info(node, ctx):
    """Generate the paths for TFTP files for instance related images.

    This method generates the paths for instance kernel and
    instance ramdisk. This method also updates the node, so caller should
    already have a non-shared lock on the node.

    :param node: a node object
    :param ctx: context
    :returns: a dictionary whose keys are the names of the images (kernel,
        ramdisk) and values are the absolute paths of them. If it's a whole
        disk image or node is configured for localboot,
        it returns an empty dictionary.
    """
    image_info = {}
    # NOTE(pas-ha) do not report image kernel and ramdisk for
    # local boot or whole disk images so that they are not cached
    if (node.driver_internal_info.get('is_whole_disk_image') or
        deploy_utils.get_boot_option(node) == 'local'):
            return image_info

    root_dir = pxe_utils.get_root_dir()
    i_info = node.instance_info
    labels = ('kernel', 'ramdisk')
    d_info = deploy_utils.get_image_instance_info(node)
    if not (i_info.get('kernel') and i_info.get('ramdisk')):
        glance_service = service.GlanceImageService(
            version=CONF.glance.glance_api_version, context=ctx)
        iproperties = glance_service.show(d_info['image_source'])['properties']
        for label in labels:
            i_info[label] = str(iproperties[label + '_id'])
        node.instance_info = i_info
        node.save()

    for label in labels:
        image_info[label] = (
            i_info[label],
            os.path.join(root_dir, node.uuid, label)
        )

    return image_info
예제 #10
0
 def test_get_root_dir_ipxe(self):
     expected_dir = '/httpboot'
     self.config(ipxe_enabled=True, group='pxe')
     self.config(http_root=expected_dir, group='deploy')
     self.assertEqual(expected_dir, pxe_utils.get_root_dir())
예제 #11
0
 def test_get_root_dir(self):
     expected_dir = '/tftproot'
     self.config(ipxe_enabled=False, group='pxe')
     self.config(tftp_root=expected_dir, group='pxe')
     self.assertEqual(expected_dir, pxe_utils.get_root_dir())
 def test_get_root_dir_ipxe(self):
     expected_dir = '/httpboot'
     self.config(ipxe_enabled=True, group='pxe')
     self.config(http_root=expected_dir, group='pxe')
     self.assertEqual(expected_dir, pxe_utils.get_root_dir())
 def test_get_root_dir(self):
     expected_dir = '/tftproot'
     self.config(ipxe_enabled=False, group='pxe')
     self.config(tftp_root=expected_dir, group='pxe')
     self.assertEqual(expected_dir, pxe_utils.get_root_dir())