>From my use of the GoGrid API, it seems there is a problem searching for newly created instances. In particular, trying to do a grid/server/get on them doesn't actually work until they are more initialized in the backend. Deal with this by falling back to a full listing in the case we get a Bad Request from the backend.
Signed-off-by: Chris Lalancette <[email protected]> --- .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 31 +++++++++++++++---- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb index ec14348..d7f0841 100644 --- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb @@ -125,12 +125,24 @@ class GogridDriver < Deltacloud::BaseDriver end end + def list_instances(credentials, id) + instances = [] + safely do + new_client(credentials).request('grid/server/list')['list'].collect do |instance| + if id.nil? or instance['name'] == id + instances << convert_instance(instance, credentials.user) + end + end + end + instances + end + def instances(credentials, opts=nil) instances = [] if opts and opts[:id] - safely do + begin client = new_client(credentials) - instance = client.request('grid/server/get', { 'id' => opts[:id] })['list'].first + instance = client.request('grid/server/get', { 'name' => opts[:id] })['list'].first login_data = get_login_data(client, instance['id']) if login_data['username'] and login_data['password'] instance['username'] = login_data['username'] @@ -141,13 +153,18 @@ class GogridDriver < Deltacloud::BaseDriver inst.authn_error = "Unable to fetch password" end instances = [inst] - end - else - safely do - instances = new_client(credentials).request('grid/server/list')['list'].collect do |instance| - convert_instance(instance, credentials.user) + rescue Exception => e + if e.message == "400 Bad Request" + # in the case of a VM that we just made, the grid/server/get method + # throws a "400 Bad Request error". In this case we try again by + # getting a full listing a filtering on the id. This could + # potentially take a long time, but I don't see another way to get + # information about a newly created instance + instances = list_instances(credentials, opts[:id]) end end + else + instances = list_instances(credentials, nil) end instances = filter_on( instances, :state, opts ) instances -- 1.6.6.1 _______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
