275
275
forget_sr(session, sr_rec['uuid'])
278
def parse_volume_info(connection_info, mountpoint):
278
def get_device_number(mountpoint):
279
device_number = mountpoint_to_number(mountpoint)
280
if device_number < 0:
281
raise StorageError(_('Unable to obtain target information'
282
' %(mountpoint)s') % locals())
286
def parse_volume_info(connection_data):
280
288
Parse device_path and mountpoint as they can be used by XenAPI.
281
289
In particular, the mountpoint (e.g. /dev/sdc) must be translated
288
296
db in the iscsi_target table with the necessary info and modify
289
297
the iscsi driver to set them.
291
device_number = mountpoint_to_number(mountpoint)
292
data = connection_info['data']
293
volume_id = data['volume_id']
294
target_portal = data['target_portal']
299
volume_id = connection_data['volume_id']
300
target_portal = connection_data['target_portal']
295
301
target_host = _get_target_host(target_portal)
296
302
target_port = _get_target_port(target_portal)
297
target_iqn = data['target_iqn']
303
target_iqn = connection_data['target_iqn']
298
304
LOG.debug('(vol_id,number,host,port,iqn): (%s,%s,%s,%s)',
299
305
volume_id, target_host, target_port, target_iqn)
300
if (device_number < 0 or
306
if (volume_id is None or
302
307
target_host is None or
303
308
target_iqn is None):
304
309
raise StorageError(_('Unable to obtain target information'
305
' %(data)s, %(mountpoint)s') % locals())
310
' %(connection_data)s') % locals())
307
312
volume_info['id'] = volume_id
308
313
volume_info['target'] = target_host
309
314
volume_info['port'] = target_port
310
315
volume_info['targetIQN'] = target_iqn
311
if ('auth_method' in connection_info and
312
connection_info['auth_method'] == 'CHAP'):
313
volume_info['chapuser'] = connection_info['auth_username']
314
volume_info['chappassword'] = connection_info['auth_password']
316
if ('auth_method' in connection_data and
317
connection_data['auth_method'] == 'CHAP'):
318
volume_info['chapuser'] = connection_data['auth_username']
319
volume_info['chappassword'] = connection_data['auth_password']
316
321
return volume_info
354
359
"""Retrieve target host"""
356
361
return iscsi_string[0:iscsi_string.find(':')]
357
elif iscsi_string is None or FLAGS.target_host:
358
return FLAGS.target_host
362
elif iscsi_string is None or CONF.target_host:
363
return CONF.target_host
361
366
def _get_target_port(iscsi_string):
362
367
"""Retrieve target port"""
364
369
return iscsi_string[iscsi_string.find(':') + 1:]
365
elif iscsi_string is None or FLAGS.target_port:
366
return FLAGS.target_port
370
elif iscsi_string is None or CONF.target_port:
371
return CONF.target_port
369
374
def _get_iqn(iscsi_string, id):
370
375
"""Retrieve target IQN"""
372
377
return iscsi_string
373
elif iscsi_string is None or FLAGS.iqn_prefix:
378
elif iscsi_string is None or CONF.iqn_prefix:
374
379
volume_id = _get_volume_id(id)
375
return '%s:%s' % (FLAGS.iqn_prefix, volume_id)
380
return '%s:%s' % (CONF.iqn_prefix, volume_id)