def TransformMachineType(r): """Return the formatted name for a machine type. Args: r: JSON-serializable object. Returns: The formatted name for a machine type. """ if not isinstance(r, basestring): return r custom_cpu, custom_ram = instance_utils.GetCpuRamFromCustomName(r) if not custom_cpu or not custom_ram: return r # Restricting output to 2 decimal places custom_ram_gb = '{0:.2f}'.format(float(custom_ram) / (2**10)) return 'custom ({0} vCPU, {1} GiB)'.format(custom_cpu, custom_ram_gb)
def _FormatCustomMachineTypeName(mt): """Checks for custom machine type and modifies output. Args: mt: machine type to be formatted Returns: If mt was a custom type, then it will be formatted into the desired custom machine type output. Otherwise, it is returned unchanged. Helper function for _MachineTypeNameToCell """ custom_cpu, custom_ram = instance_utils.GetCpuRamFromCustomName(mt) if custom_cpu and custom_ram: # Restricting output to 2 decimal places custom_ram_gb = '{0:.2f}'.format(float(custom_ram) / (2 ** 10)) mt = 'custom ({0} vCPU, {1} GiB)'.format(custom_cpu, custom_ram_gb) return mt
def TransformMachineType(r, undefined=''): """Return the formatted name for a machine type. Args: r: JSON-serializable object. undefined: Returns this value if the resource cannot be formatted. Returns: The formatted name for a machine type. """ if not isinstance(r, six.string_types): return undefined custom_cpu, custom_ram = instance_utils.GetCpuRamFromCustomName(r) if not custom_cpu or not custom_ram: return r # Restricting output to 2 decimal places custom_ram_gb = '{0:.2f}'.format(float(custom_ram) / (2**10)) return 'custom ({0} vCPU, {1} GiB)'.format(custom_cpu, custom_ram_gb)