CIMI: made id optional in client UI helper method
so it can be used for collection operations such as import
diff --git a/clients/cimi/lib/client.rb b/clients/cimi/lib/client.rb
index e0ba51b..7a9ba60 100644
--- a/clients/cimi/lib/client.rb
+++ b/clients/cimi/lib/client.rb
@@ -57,8 +57,11 @@
client["%s/%s" % [entity_type, id]].delete(auth_header(credentials))
end
- def entity_action(entity_type, action, id, body, credentials)
- client["%s/%s/%s" % [entity_type, id, action.to_s]].post(body, auth_header(credentials).merge(:content_type => 'application/xml'))
+ def entity_action(entity_type, action, body, credentials, id=nil)
+ entity_href = get_entity_collection_href(entity_type, credentials)
+ raise RestClient::ResourceNotFound if not entity_href
+ url = id ? '%s/%s/%s' % [entity_href, id, action.to_s] : '%s/%s' % [entity_href, action.to_s]
+ RestClient::Resource.new(url).post(body, auth_header(credentials).merge(:content_type => 'application/xml'))
end
def provider_header(credentials)
diff --git a/clients/cimi/lib/entities/machine.rb b/clients/cimi/lib/entities/machine.rb
index f193ebd..d124f5f 100644
--- a/clients/cimi/lib/entities/machine.rb
+++ b/clients/cimi/lib/entities/machine.rb
@@ -69,7 +69,7 @@
xml.action "http://schemas.dmtf.org/cimi/1/action/stop"
}
end.to_xml
- entity_action 'machines', 'stop', params[:id], action_xml, credentials
+ entity_action 'machines', 'stop', action_xml, credentials, params[:id]
flash[:success] = "Machine successfully stopped."
redirect '/cimi/machines/%s' % params[:id]
end
@@ -80,7 +80,7 @@
xml.action "http://schemas.dmtf.org/cimi/1/action/start"
}
end.to_xml
- entity_action 'machines', 'start', params[:id], action_xml, credentials
+ entity_action 'machines', 'start', action_xml, credentials, params[:id]
flash[:success] = "Machine successfully started."
redirect '/cimi/machines/%s' % params[:id]
end
@@ -91,7 +91,7 @@
xml.action "http://schemas.dmtf.org/cimi/1/action/restart"
}
end.to_xml
- entity_action 'machines', 'restart', params[:id], action_xml, credentials
+ entity_action 'machines', 'restart', action_xml, credentials, action_xml
flash[:success] = "Machine successfully restarted."
redirect '/cimi/machines/%s' % params[:id]
end