# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 89
  def create_instance(credentials, image_id, opts={})
    server_ram = nil
    if opts[:hwp_memory]
      mem = opts[:hwp_memory].to_i
      server_ram = (mem == 512) ? "512MB" : "#{mem / 1024}GB"
    else
      server_ram = "512MB"
    end
    client = new_client(credentials)
    params = {
      'name' => opts[:name] || get_random_instance_name,
      'image' => image_id,
      'server.ram' => server_ram,
      'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
    }
    params.merge!('isSandbox' => 'true') if opts[:sandbox] 
    safely do
      instance = client.request('grid/server/add', params)['list'].first
      if instance
        login_data = get_login_data(client, instance[:id])
        if login_data['username'] and login_data['password']
          instance['username'] = login_data['username']
          instance['password'] = login_data['password']
          inst = convert_instance(instance, credentials.user)
        else
          inst = convert_instance(instance, credentials.user)
          inst.authn_error = "Unable to fetch password"
        end
        return inst
      else
        return nil
      end
    end
  end