Commit efaa9b06 authored by Iustin Pop's avatar Iustin Pop
Browse files

Split the core-OS and instance-specific env



Since we'll need to be able to generate the OS-specific environment
separately from the instance one, we move it to a separate function. We
also add a new OS_NAME env. var which is identical to the INSTANCE_OS
one (which won't exist for OS-only environments).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 73e0328b
......@@ -1911,11 +1911,9 @@ def OSFromDisk(name, base_dir=None):
return payload
def OSEnvironment(instance, inst_os, debug=0):
"""Calculate the environment for an os script.
def OSCoreEnv(inst_os, debug=0):
"""Calculate the basic environment for an os script.
@type instance: L{objects.Instance}
@param instance: target instance for the os script run
@type inst_os: L{objects.OS}
@param inst_os: operating system for which the environment is being built
@type debug: integer
......@@ -1930,18 +1928,44 @@ def OSEnvironment(instance, inst_os, debug=0):
api_version = \
max(constants.OS_API_VERSIONS.intersection(inst_os.api_versions))
result['OS_API_VERSION'] = '%d' % api_version
result['INSTANCE_NAME'] = instance.name
result['INSTANCE_OS'] = instance.os
result['HYPERVISOR'] = instance.hypervisor
result['DISK_COUNT'] = '%d' % len(instance.disks)
result['NIC_COUNT'] = '%d' % len(instance.nics)
result['OS_NAME'] = inst_os.name
result['DEBUG_LEVEL'] = '%d' % debug
# OS variants
if api_version >= constants.OS_API_V15:
try:
variant = instance.os.split('+', 1)[1]
variant = inst_os.name.split('+', 1)[1]
except IndexError:
variant = inst_os.supported_variants[0]
result['OS_VARIANT'] = variant
return result
def OSEnvironment(instance, inst_os, debug=0):
"""Calculate the environment for an os script.
@type instance: L{objects.Instance}
@param instance: target instance for the os script run
@type inst_os: L{objects.OS}
@param inst_os: operating system for which the environment is being built
@type debug: integer
@param debug: debug level (0 or 1, for OS Api 10)
@rtype: dict
@return: dict of environment variables
@raise errors.BlockDeviceError: if the block device
cannot be found
"""
result = OSCoreEnv(inst_os, debug)
result['INSTANCE_NAME'] = instance.name
result['INSTANCE_OS'] = instance.os
result['HYPERVISOR'] = instance.hypervisor
result['DISK_COUNT'] = '%d' % len(instance.disks)
result['NIC_COUNT'] = '%d' % len(instance.nics)
# Disks
for idx, disk in enumerate(instance.disks):
real_disk = _OpenRealBD(disk)
result['DISK_%d_PATH' % idx] = real_disk.dev_path
......@@ -1954,6 +1978,8 @@ def OSEnvironment(instance, inst_os, debug=0):
elif disk.dev_type == constants.LD_FILE:
result['DISK_%d_BACKEND_TYPE' % idx] = \
'file:%s' % disk.physical_id[0]
# NICs
for idx, nic in enumerate(instance.nics):
result['NIC_%d_MAC' % idx] = nic.mac
if nic.ip:
......@@ -1967,6 +1993,7 @@ def OSEnvironment(instance, inst_os, debug=0):
result['NIC_%d_FRONTEND_TYPE' % idx] = \
instance.hvparams[constants.HV_NIC_TYPE]
# HV/BE params
for source, kind in [(instance.beparams, "BE"), (instance.hvparams, "HV")]:
for key, value in source.items():
result["INSTANCE_%s_%s" % (kind, key)] = str(value)
......
......@@ -86,14 +86,15 @@
</varlistentry>
<varlistentry>
<term>INSTANCE_OS</term>
<term>OS_NAME</term>
<listitem>
<simpara>The name of the instance's OS as Ganeti knows
it. This can simplify the OS scripts by providing the same
scripts under multiple names, and then the scripts can use
this name to alter their behaviour.</simpara>
<simpara>With OS API 15 changing the script behavior based
on this variable is deprecated: OS_VARIANT should be used
instead (see below).</simpara>
<simpara>Both names point to the name of the instance's OS
as Ganeti knows it. This can simplify the OS scripts by
providing the same scripts under multiple names, and then
the scripts can use this name to alter their
behaviour.</simpara> <simpara>With OS API 15 changing the
script behavior based on this variable is deprecated:
OS_VARIANT should be used instead (see below).</simpara>
</listitem>
</varlistentry>
<varlistentry>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment