Exemple #1
0
def get_tftp_image_info(instance):
    """Generate the paths for tftp files for this instance.

    Raises NovaException if
    - instance does not contain kernel_id
    """
    image_info = {
            'kernel': [None, None],
            }
    try:
        image_info['kernel'][0] = str(instance['kernel_id'])
    except KeyError:
        pass

    missing_labels = []
    for label in image_info.keys():
        (uuid, path) = image_info[label]
        if not uuid:
            missing_labels.append(label)
        else:
            image_info[label][1] = os.path.join(CONF.tftp_root,
                            instance['uuid'], label)
    if missing_labels:
        raise exception.NovaException(_(
            "Can not activate Tilera bootloader. "
            "The following boot parameters "
            "were not passed to baremetal driver: %s") % missing_labels)
    return image_info
Exemple #2
0
    def attach_volume(self, connection_info, instance, mountpoint):
        node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
        ctx = nova_context.get_admin_context()
        pxe_ip = db.bm_pxe_ip_get_by_bm_node_id(ctx, node['id'])
        if not pxe_ip:
            if not CONF.use_unsafe_iscsi:
                raise exception.NovaException(
                    _('No fixed PXE IP is associated to %s') %
                    instance['uuid'])

        mount_device = mountpoint.rpartition("/")[2]
        self._volume_driver_method('connect_volume', connection_info,
                                   mount_device)
        device_path = connection_info['data']['device_path']
        iqn = _get_iqn(instance['name'], mountpoint)
        tid = _get_next_tid()
        _create_iscsi_export_tgtadm(device_path, tid, iqn)

        if pxe_ip:
            _allow_iscsi_tgtadm(tid, pxe_ip['address'])
        else:
            # NOTE(NTTdocomo): Since nova-compute does not know the
            # instance's initiator ip, it allows any initiators
            # to connect to the volume. This means other bare-metal
            # instances that are not attached the volume can connect
            # to the volume. Do not set CONF.use_unsafe_iscsi
            # out of dev/test environments.
            # TODO(NTTdocomo): support CHAP
            _allow_iscsi_tgtadm(tid, 'ALL')
Exemple #3
0
    def plug(self, instance, vif):
        LOG.debug(
            _("plug: instance_uuid=%(uuid)s vif=%(vif)s") % {
                'uuid': instance['uuid'],
                'vif': vif
            })
        network, mapping = vif
        vif_uuid = mapping['vif_uuid']
        ctx = nova_context.get_admin_context()
        node = db.bm_node_get_by_instance_uuid(ctx, instance['uuid'])

        # TODO(deva): optimize this database query
        #             this is just searching for a free physical interface
        pifs = db.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
        for pif in pifs:
            if not pif['vif_uuid']:
                db.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
                LOG.debug(
                    _("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)") % {
                        'id': pif['id'],
                        'vif_uuid': vif_uuid
                    })
                self._after_plug(instance, network, mapping, pif)
                return

        # NOTE(deva): should this really be raising an exception
        #             when there are no physical interfaces left?
        raise exception.NovaException(
            _("Baremetal node: %(id)s has no available physical interface"
              " for virtual interface %(vif_uuid)s") % {
                  'id': node['id'],
                  'vif_uuid': vif_uuid
              })
Exemple #4
0
def _delete_iscsi_export_tgtadm(tid):
    try:
        utils.execute('tgtadm',
                      '--lld',
                      'iscsi',
                      '--mode',
                      'logicalunit',
                      '--op',
                      'delete',
                      '--tid',
                      tid,
                      '--lun',
                      '1',
                      run_as_root=True)
    except exception.ProcessExecutionError:
        pass
    try:
        utils.execute('tgtadm',
                      '--lld',
                      'iscsi',
                      '--mode',
                      'target',
                      '--op',
                      'delete',
                      '--tid',
                      tid,
                      run_as_root=True)
    except exception.ProcessExecutionError:
        pass
    # Check if the tid is deleted, that is, check the tid no longer exists.
    # If the tid dose not exist, tgtadm returns with exit_code 22.
    # utils.execute() can check the exit_code if check_exit_code parameter is
    # passed. But, regardless of whether check_exit_code contains 0 or not,
    # if the exit_code is 0, the function dose not report errors. So we have to
    # catch a ProcessExecutionError and test its exit_code is 22.
    try:
        utils.execute('tgtadm',
                      '--lld',
                      'iscsi',
                      '--mode',
                      'target',
                      '--op',
                      'show',
                      '--tid',
                      tid,
                      run_as_root=True)
    except exception.ProcessExecutionError as e:
        if e.exit_code == 22:
            # OK, the tid is deleted
            return
        raise
    raise exception.NovaException(
        _('baremetal driver was unable to delete tid %s') % tid)
Exemple #5
0
    def _require_node(self, instance):
        """Get a node's uuid out of a manager instance dict.

        The compute manager is meant to know the node uuid, so missing uuid
        a significant issue - it may mean we've been passed someone elses data.
        """
        node_uuid = instance.get('node')
        if not node_uuid:
            raise exception.NovaException(
                _("Baremetal node id not supplied to driver for %r") %
                instance['uuid'])
        return node_uuid
    def _get_conn(self):
        if not CONF.virtual_power_ssh_host:
            raise exception.NovaException(
                _('virtual_power_ssh_host not defined. Can not Start'))

        if not CONF.virtual_power_host_user:
            raise exception.NovaException(
                _('virtual_power_host_user not defined. Can not Start'))

        if not CONF.virtual_power_host_pass:
            # it is ok to not have a password if you have a keyfile
            if CONF.virtual_power_host_key is None:
                raise exception.NovaException(
                    _('virtual_power_host_pass/key not set. Can not Start'))

        _conn = connection.Connection(
            CONF.virtual_power_ssh_host,
            CONF.virtual_power_host_user,
            CONF.virtual_power_host_pass,
            CONF.virtual_power_ssh_port,
            CONF.virtual_power_host_key)
        return _conn
Exemple #7
0
    def activate_node(self, context, node, instance):
        """Wait for Tilera deployment to complete."""

        locals = {'error': '', 'started': False}

        try:
            row = db.bm_node_get(context, node['id'])
            if instance['uuid'] != row.get('instance_uuid'):
                locals['error'] = _("Node associated with another instance"
                                    " while waiting for deploy of %s")

            status = row.get('task_state')
            if (status == states.DEPLOYING and
                locals['started'] is False):
                LOG.info(_('Tilera deploy started for instance %s')
                           % instance['uuid'])
                locals['started'] = True
            elif status in (states.DEPLOYDONE,
                            states.BUILDING,
                            states.ACTIVE):
                LOG.info(_("Tilera deploy completed for instance %s")
                           % instance['uuid'])
                node_ip = node['pm_address']
                user_data = instance['user_data']
                try:
                    self._iptables_set(node_ip, user_data)
                except Exception:
                    self.deactivate_bootloader(context, node, instance)
                    raise exception.NovaException(_("Node is "
                          "unknown error state."))
            elif status == states.DEPLOYFAIL:
                locals['error'] = _("Tilera deploy failed for instance %s")
        except exception.NodeNotFound:
                locals['error'] = _("Baremetal node deleted while waiting "
                                "for deployment of instance %s")

        if locals['error']:
            raise exception.InstanceDeployFailure(
                    locals['error'] % instance['uuid'])
Exemple #8
0
def get_tftp_image_info(instance, instance_type):
    """Generate the paths for tftp files for this instance

    Raises NovaException if
    - instance does not contain kernel_id or ramdisk_id
    - deploy_kernel_id or deploy_ramdisk_id can not be read from
      instance_type['extra_specs'] and defaults are not set

    """
    image_info = {
        'kernel': [None, None],
        'ramdisk': [None, None],
        'deploy_kernel': [None, None],
        'deploy_ramdisk': [None, None],
    }
    try:
        image_info['kernel'][0] = str(instance['kernel_id'])
        image_info['ramdisk'][0] = str(instance['ramdisk_id'])
        image_info['deploy_kernel'][0] = get_deploy_aki_id(instance_type)
        image_info['deploy_ramdisk'][0] = get_deploy_ari_id(instance_type)
    except KeyError:
        pass

    missing_labels = []
    for label in image_info.keys():
        (uuid, path) = image_info[label]
        if not uuid:
            missing_labels.append(label)
        else:
            image_info[label][1] = os.path.join(CONF.tftp_root,
                                                instance['uuid'], label)
    if missing_labels:
        raise exception.NovaException(
            _("Can not activate PXE bootloader. The following boot parameters "
              "were not passed to baremetal driver: %s") % missing_labels)
    return image_info