code: def _apply_memory_config(config_spec, memory):
      '''
      Sets memory size to the given value
  
      config_spec
          vm.ConfigSpec object
  
      memory
          Memory size and unit
      '''
      log.trace('Configuring virtual machine memory '
                'settings memory=%s', memory)
      if 'size' in memory and 'unit' in memory:
          try:
              if memory['unit'].lower() == 'kb':
                  memory_mb = memory['size'] / 1024
              elif memory['unit'].lower() == 'mb':
                  memory_mb = memory['size']
              elif memory['unit'].lower() == 'gb':
                  memory_mb = int(float(memory['size']) * 1024)
          except (TypeError, ValueError):
              memory_mb = int(memory['size'])
          config_spec.memoryMB = memory_mb
      if 'reservation_max' in memory:
          config_spec.memoryReservationLockedToMax = memory['reservation_max']
      if 'hotadd' in memory:
          config_spec.memoryHotAddEnabled = memory['hotadd'f _apply_memory_config(config_spec, memory):
      '''
      Sets memory size to the given value
  
      config_spec
          vm.ConfigSpec object
  
      memory
          Memory size and unit
      '''
      log.trace('Configuring virtual machine memory '
                'settings memory=%s', memory)
      if 'size' in memory and 'unit' in memory:
          try:
              if memory['unit'].lower() == 'kb':
                  memory_mb = memory['size'] / 1024
              elif memory['unit'].lower() == 'mb':
                  memory_mb = memory['size']
              elif memory['unit'].lower() == 'gb':
                  memory_mb = int(float(memory['size']) * 1024)
          except (TypeError, ValueError):
              memory_mb = int(memory['size'])
          config_spec.memoryMB = memory_mb
      if 'reservation_max' in memory:
          config_spec.memoryReservationLockedToMax = memory['reservation_max']
      if 'hotadd' in memory:
          config_spec.memoryHotAddEnabled = memory['hotadd']
docs: Sets memory size to the given value
  
      config_spec
          vm.ConfigSpec object
  
      memory
          Memory size and unit