Revision 2266edb2
b/lib/backend.py | ||
---|---|---|
1273 | 1273 |
rename_script=os_scripts[constants.OS_SCRIPT_RENAME], |
1274 | 1274 |
api_versions=api_versions) |
1275 | 1275 |
|
1276 |
def OSEnvironment(instance, debug=0): |
|
1277 |
"""Calculate the environment for an os script. |
|
1278 |
|
|
1279 |
@type instance: instance object |
|
1280 |
@param instance: target instance for the os script run |
|
1281 |
@type debug: integer |
|
1282 |
@param debug: debug level (0 or 1, for os api 10) |
|
1283 |
@rtype: dict |
|
1284 |
@return: dict of environment variables |
|
1285 |
|
|
1286 |
""" |
|
1287 |
result = {} |
|
1288 |
result['OS_API_VERSION'] = '%d' % constants.OS_API_VERSION |
|
1289 |
result['INSTANCE_NAME'] = instance.name |
|
1290 |
result['HYPERVISOR'] = instance.hypervisor |
|
1291 |
result['DISK_COUNT'] = '%d' % len(instance.disks) |
|
1292 |
result['NIC_COUNT'] = '%d' % len(instance.nics) |
|
1293 |
result['DEBUG_LEVEL'] = '%d' % debug |
|
1294 |
for idx, disk in enumerate(instance.disks): |
|
1295 |
real_disk = _RecursiveFindBD(disk) |
|
1296 |
if real_disk is None: |
|
1297 |
raise errors.BlockDeviceError("Block device '%s' is not set up" % |
|
1298 |
str(disk)) |
|
1299 |
real_disk.Open() |
|
1300 |
result['DISK_%d_PATH' % idx] = real_disk.dev_path |
|
1301 |
# FIXME: When disks will have read-only mode, populate this |
|
1302 |
result['DISK_%d_ACCESS' % idx] = 'W' |
|
1303 |
if constants.HV_DISK_TYPE in instance.hvparams: |
|
1304 |
result['DISK_%d_FRONTEND_TYPE' % idx] = \ |
|
1305 |
instance.hvparams[constants.HV_DISK_TYPE] |
|
1306 |
if disk.dev_type in constants.LDS_BLOCK: |
|
1307 |
result['DISK_%d_BACKEND_TYPE' % idx] = 'block' |
|
1308 |
elif disk.dev_type == constants.LD_FILE: |
|
1309 |
result['DISK_%d_BACKEND_TYPE' % idx] = \ |
|
1310 |
'file:%s' % disk.physical_id[0] |
|
1311 |
for idx, nic in enumerate(instance.nics): |
|
1312 |
result['NIC_%d_MAC' % idx] = nic.mac |
|
1313 |
if nic.ip: |
|
1314 |
result['NIC_%d_IP' % idx] = nic.ip |
|
1315 |
result['NIC_%d_BRIDGE' % idx] = nic.bridge |
|
1316 |
if constants.HV_NIC_TYPE in instance.hvparams: |
|
1317 |
result['NIC_%d_FRONTEND_TYPE' % idx] = \ |
|
1318 |
instance.hvparams[constants.HV_NIC_TYPE] |
|
1319 |
|
|
1320 |
return result |
|
1276 | 1321 |
|
1277 | 1322 |
def GrowBlockDevice(disk, amount): |
1278 | 1323 |
"""Grow a stack of block devices. |
Also available in: Unified diff