diff --git a/lib/backend.py b/lib/backend.py index 1624c57a5d2ec6f2f97ac1db830683b70c5ce33f..3fda9c7d6febd11ec94ce2c42870d0757b97a502 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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) diff --git a/man/ganeti-os-interface.sgml b/man/ganeti-os-interface.sgml index e70224f903e3935a3ddff1ab29591fcb42feaf92..2c6ec60446867086bc771221980eccf2b34aabec 100644 --- a/man/ganeti-os-interface.sgml +++ b/man/ganeti-os-interface.sgml @@ -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>