Beispiel #1
0
 def attach_volume(self, instance_name, device_path, mountpoint):
     """Attach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.NotFound(
             _('Instance %s not found') % instance_name)
     # NOTE: No Resource Pool concept so far
     LOG.debug(
         _("Attach_volume: %(instance_name)s, %(device_path)s,"
           " %(mountpoint)s") % locals())
     # Create the iSCSI SR, and the PDB through which hosts access SRs.
     # But first, retrieve target info, like Host, IQN, LUN and SCSIID
     vol_rec = VolumeHelper.parse_volume_info(device_path, mountpoint)
     label = 'SR-%s' % vol_rec['volumeId']
     description = 'Disk-for:%s' % instance_name
     # Create SR
     sr_ref = VolumeHelper.create_iscsi_storage(self._session, vol_rec,
                                                label, description)
     # Introduce VDI  and attach VBD to VM
     try:
         vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
     except StorageError, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(
             _('Unable to create VDI on SR %(sr_ref)s for'
               ' instance %(instance_name)s') % locals())
Beispiel #2
0
 def attach_volume(self, instance_name, device_path, mountpoint):
     """Attach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.NotFound(_('Instance %s not found')
                                   % instance_name)
     # NOTE: No Resource Pool concept so far
     LOG.debug(_("Attach_volume: %(instance_name)s, %(device_path)s,"
             " %(mountpoint)s") % locals())
     # Create the iSCSI SR, and the PDB through which hosts access SRs.
     # But first, retrieve target info, like Host, IQN, LUN and SCSIID
     vol_rec = VolumeHelper.parse_volume_info(device_path, mountpoint)
     label = 'SR-%s' % vol_rec['volumeId']
     description = 'Disk-for:%s' % instance_name
     # Create SR
     sr_ref = VolumeHelper.create_iscsi_storage(self._session,
                                                      vol_rec,
                                                      label,
                                                      description)
     # Introduce VDI  and attach VBD to VM
     try:
         vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
     except StorageError, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(_('Unable to create VDI on SR %(sr_ref)s for'
                 ' instance %(instance_name)s') % locals())
Beispiel #3
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        data = connection_info['data']
        if 'name_label' not in data:
            label = 'tempSR-%s' % data['volume_id']
        else:
            label = data['name_label']
            del data['name_label']

        if 'name_description' not in data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in data:
            sr_params = VolumeHelper.parse_volume_info(connection_info,
                                                       mountpoint)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = data['sr_uuid']
            for k in data['introduce_sr_keys']:
                sr_params[k] = data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))
Beispiel #4
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # NOTE: No Resource Pool concept so far
        LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s,"
                " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        data = connection_info['data']
        if 'name_label' not in data:
            label = 'tempSR-%s' % data['volume_id']
        else:
            label = data['name_label']
            del data['name_label']

        if 'name_description' not in data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in data:
            sr_params = VolumeHelper.parse_volume_info(connection_info,
                                                       mountpoint)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = data['sr_uuid']
            for k in data['introduce_sr_keys']:
                sr_params[k] = data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))