               return console.warn "Failed to create VM for ", \
                                    {users, groups, hostnameAlias}
 
-            JVM.createDomains hostnameAliases, hostnameAliases[0]
+            JVM.createDomains account, hostnameAliases, hostnameAliases[0]
 
             group.addVm vm, (err)=>
               return callback err  if err
-              JVM.ensureDomainSettings {vm, type, nickname, groupSlug}
+              JVM.ensureDomainSettings {account, vm, type, nickname, groupSlug}
               if type is 'group'
                 @addVmUsers vm, group, ->
                   callback null, vm

        type            : Boolean
        default         : no

  @createDomains = (domains, hostnameAlias) ->
    JDomain = require './domain'
    domains.forEach (domain) ->
      JDomain.one {domain}, (err, domainData)->
        return  if domainData or err
        (new JDomain
          domain        : domain
          hostnameAlias : [hostnameAlias]
          proxy         : { mode: 'vm' }
          regYears      : 0
        ).save (err)-> console.log err  if err?

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

        requiredDomains.push "#{nickname}.#{domain}"
    else
      requiredDomains = ["#{groupSlug}.#{domain}", "shared.#{groupSlug}.#{domain}"]
    @createDomains account, requiredDomains, vm.hostnameAlias

  @createAliases = ({nickname, type, uid, groupSlug})->
    domain       = 'kd.io'
