     JGroup  = require './group'
     JUser   = require './user'
 
-    addVm = ({ target, user, sudo, groups, groupSlug
+    addVm = ({ account, target, user, sudo, groups, groupSlug
                type, planCode, planOwner, webHome })->
 
       uid = 0

              return console.warn "Failed to create VM for ", \
                                   {users, groups, hostnameAlias}

            JVM.createDomains hostnameAliases, hostnameAliases[0]

            group.addVm vm, (err)=>
              return callback err  if err
              JVM.ensureDomainSettings {vm, type, nickname, groupSlug}
              if type is 'group'
                @addVmUsers vm, group, ->
                  callback null, vm

        type            : Boolean
        default         : no

  @createDomains = (account, domains, hostnameAlias)->
    JDomain = require './domain'
    console.log "creating domains for ", account, domains, hostnameAlias
    domains.forEach (domain) ->
      domainObj = new JDomain
        domain        : domain
        hostnameAlias : [hostnameAlias]
        proxy         : { mode: 'vm' }
        regYears      : 0
      domainObj.save (err)->
        console.log err  if err?
        unless err
          account.addDomain domainObj, (err)->
            console.log err  if err?

  @ensureDomainSettings = ({account, vm, type, nickname, groupSlug})->
    domain = 'kd.io'
    if type is 'user'
      requiredDomains = ["#{nickname}.#{groupSlug}.#{domain}"]
