def _attach(self, instance_id): self._check_connection() volume_id = self.id or self._native_vol.id with self.attach_lock: LOG.debug('Attaching CloudStack volume %s', volume_id) taken_before = base.taken_devices() self._conn.attachVolume(volume_id, instance_id) def device_plugged(): # Rescan SCSI bus scsi_host = '/sys/class/scsi_host' for name in os.listdir(scsi_host): with open(scsi_host + '/' + name + '/scan', 'w') as fp: fp.write('- - -') return base.taken_devices() > taken_before util.wait_until( device_plugged, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: %s. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0] LOG.debug('Checking that volume %s is attached', volume_id)
def _attach(self, instance_id): self._check_connection() volume_id = self.id or self._native_vol.id with self.attach_lock: LOG.debug('Attaching CloudStack volume %s', volume_id) taken_before = base.taken_devices() self._conn.attachVolume(volume_id, instance_id) def device_plugged(): # Rescan SCSI bus scsi_host = '/sys/class/scsi_host' for name in os.listdir(scsi_host): with open(scsi_host + '/' + name + '/scan', 'w') as fp: fp.write('- - -') return base.taken_devices() > taken_before util.wait_until(device_plugged, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: %s. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0] LOG.debug('Checking that volume %s is attached', volume_id)
def _attach_volume(self, volume): ebs = self._ebs_volume(volume) with self.attach_lock: device_name = get_free_name() taken_before = base.taken_devices() volume_id = ebs.id LOG.debug('Attaching EBS volume %s (name: %s)', volume_id, device_name) ebs.attach(self._instance_id(), device_name) LOG.debug('Checking that EBS volume %s is attached', volume_id) msg = "EBS volume %s wasn't attached. Timeout reached (%s seconds)" % ( ebs.id, self._global_timeout) util.wait_until( lambda: ebs.update() and ebs.attachment_state() == 'attached', logger=LOG, timeout=self._global_timeout, error_text=msg ) LOG.debug('EBS volume %s attached', volume_id) if not linux.os.windows: util.wait_until(lambda: base.taken_devices() > taken_before, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: {0}. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0], device_name else: return device_name, device_name
def _attach_volume(self, volume): ebs = self._ebs_volume(volume) with self.attach_lock: device_name = get_free_name() taken_before = base.taken_devices() volume_id = ebs.id LOG.debug('Attaching EBS volume %s (name: %s)', volume_id, device_name) ebs.attach(self._instance_id(), device_name) LOG.debug('Checking that EBS volume %s is attached', volume_id) msg = "EBS volume %s wasn't attached. Timeout reached (%s seconds)" % ( ebs.id, self._global_timeout) util.wait_until( lambda: ebs.update() and ebs.attachment_state() == 'attached', logger=LOG, timeout=self._global_timeout, error_text=msg) LOG.debug('EBS volume %s attached', volume_id) if not linux.os.windows: util.wait_until( lambda: base.taken_devices() > taken_before, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: {0}. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0], device_name else: def check_available(): try: wintools.aws_bring_disk_online(device_name) return True except storage2.StorageError: return False util.wait_until( check_available, start_text='Checking that volume %s is available in OS' % volume_id, timeout=self.win_disk_wait_timeout, sleep=self.win_disk_polling_interval, error_text='No Win32_LogicalDisk available for device {}, ' 'although it is online'.format(device_name)) return device_name, device_name
def _attach_volume(self, server_id=None): ''' :rtype: tuple(cloud_device_name, os_device_name) ''' if server_id is None: server_id = self._server_id() volume_id = self.id self._check_nova_connection() ops_delay = 10 with self.attach_lock: for _ in xrange(5): LOG.debug('Attaching Cinder volume %s', volume_id) taken_before = base.taken_devices() try: attachment = self._nova.volumes.create_server_volume(server_id, volume_id, None) except TypeError, e: if "'NoneType' object has no attribute '__getitem__'" not in str(e): # Very often (2/5 times) we got this error on RaxNG, because of incorrect API response raise #waiting for attaching transitional state LOG.debug('Checking that Cinder volume %s is attached', volume_id) new_status = self._wait_status_transition(volume_id) if new_status == 'in-use': LOG.debug('Cinder volume %s attached', volume_id) break elif new_status == 'available': LOG.warn('Volume %s status changed to "available" instead of "in-use"', volume_id) LOG.debug('Will try attach volume again after %d seconds', ops_delay) continue else: msg = 'Unexpected status transition "available" -> "{0}".' \ ' Cinder volume {1}'.format(new_status, volume_id) raise storage2.StorageError(msg) if not linux.os.windows_family: util.wait_until(lambda: base.taken_devices() > taken_before, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: %s. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0] else: return attachment.device
def device_plugged(): # Rescan SCSI bus scsi_host = '/sys/class/scsi_host' for name in os.listdir(scsi_host): with open(scsi_host + '/' + name + '/scan', 'w') as fp: fp.write('- - -') return base.taken_devices() > taken_before
def _attach_volume(self, volume): ebs = self._ebs_volume(volume) with self.attach_lock: device_name = get_free_name() taken_before = base.taken_devices() volume_id = ebs.id LOG.debug('Attaching EBS volume %s (name: %s)', volume_id, device_name) ebs.attach(self._instance_id(), device_name) LOG.debug('Checking that EBS volume %s is attached', volume_id) msg = "EBS volume %s wasn't attached. Timeout reached (%s seconds)" % ( ebs.id, self._global_timeout) util.wait_until( lambda: ebs.update() and ebs.attachment_state() == 'attached', logger=LOG, timeout=self._global_timeout, error_text=msg) LOG.debug('EBS volume %s attached', volume_id) if not linux.os.windows: util.wait_until( lambda: base.taken_devices() > taken_before, start_text='Checking that volume %s is available in OS' % volume_id, timeout=30, sleep=1, error_text='Volume %s attached but not available in OS' % volume_id) devices = list(base.taken_devices() - taken_before) if len(devices) > 1: msg = "While polling for attached device, got multiple new devices: {0}. " \ "Don't know which one to select".format(devices) raise Exception(msg) return devices[0], device_name else: return device_name, device_name
def _attach(self, instance_id): self._check_connection() volume_id = self.id or self._native_vol.id with self.attach_lock: LOG.debug('Attaching CloudStack volume %s', volume_id) taken_before = base.taken_devices() native_vol = self._conn.attachVolume(volume_id, instance_id) if not linux.os.windows: return base.wait_device_plugged(volume_id, taken_before) else: return string.ascii_uppercase[native_vol.deviceid]
def _attach_volume(self, server_id=None): ''' :rtype: tuple(cloud_device_name, os_device_name) ''' if server_id is None: server_id = self._server_id() volume_id = self.id self._check_nova_connection() ops_delay = 10 with self.attach_lock: for _ in xrange(5): LOG.debug('Attaching Cinder volume %s', volume_id) taken_before = base.taken_devices() try: attachment = self._nova.volumes.create_server_volume( server_id, volume_id) except TypeError, e: if "'NoneType' object has no attribute '__getitem__'" not in str( e): # Very often (2/5 times) we got this error on RaxNG, because of incorrect API response raise #waiting for attaching transitional state LOG.debug('Checking that Cinder volume %s is attached', volume_id) new_status = self._wait_status_transition(volume_id) if new_status == 'in-use': LOG.debug('Cinder volume %s attached, device: %s', volume_id, attachment.device) break elif new_status == 'available': LOG.warn( 'Volume %s status changed to "available" instead of "in-use"', volume_id) LOG.debug('Will try attach volume again after %d seconds', ops_delay) continue else: msg = 'Unexpected status transition "available" -> "{0}".' \ ' Cinder volume {1}'.format(new_status, volume_id) raise storage2.StorageError(msg) if not linux.os.windows_family: return base.wait_device_plugged(volume_id, taken_before) else: return attachment.device