     memory: { type: 'integer', optional: true }
   }
 
+  # Current user must be an administrator.
+  @checkPermission 'admin'
+
   try
     VM = @getObject params.id
   catch

{
  each: $each
} = require 'underscore'

$js2xml = do ->

  xapi = @getXAPI VM

  # Some settings can only be changed when the VM is halted.
  if VM.power_state isnt 'Halted'
    for param in ['memory']
      if param of params
        @throw(
          'INVALID_PARAMS'
          "cannot change #{param} when the VM is not halted"
        )

  for param, fields of {
    CPUs:
      if VM.power_state is 'Halted'
        ['VCPUs_max', 'VCPUs_at_startup']
      else
        'VCPUs_number_live'
    memory: 'memory_static_max'
    'name_label'
    'name_description'
  }
    continue unless param of params

    fields = [fields] unless $isArray fields
    xapi.call "VM.set_#{field}", VM.ref, "#{params[param]}" for field in fields
