# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 90
  def create_instance(credentials, image_id, opts=nil)
    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)
    name = (opts[:name] && opts[:name]!='') ? opts[:name] : get_random_instance_name
    safely do
      instance = client.request('grid/server/add', {
        'name' => name,
        'image' => image_id,
        'server.ram' => server_ram,
        'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
      })['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