mitchellh/vagrant-google

Should requests return an operation?

Temikus opened this issue · 1 comments

I think if requests are uncomfortable enough that we have to have this in tests:
https://github.com/fog/fog-google/blob/23878b2d33ea1aecb54fa7d4652b1c77b3e51530/test/helpers/client_helper.rb#L43

 def wait_until_complete
    result = yield

    case result.kind
    when "compute#operation"
      region = result.region
      zone = result.zone
      Fog.wait_for { operation_finished?(result) }
      if zone.nil?
        client.get_region_operation(region, result.name)
      else
        client.get_zone_operation(zone, result.name)
      end
    when "sql#operation"
      Fog.wait_for { sql_operation_finished?(result) }
      client.get_operation(result.name)
    else
      result
    end
  end

, we should just make requests return an operation object we can just use .wait_for on.

So instead of:

    request = @client.insert_backup_run(instance.name, data)
    operation = @operations.new(:service => service).get(request.name)
    operation.wait_for { ready? }

, we should have something like:

    operation = @client.insert_backup_run(instance.name, data)
    operation.wait_for { ready? }

@icco WDYT? Or am I missing something?

Wrong repo, this goes upstream: fog/fog-google#340