deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1207921 - in /deltacloud/trunk/server/lib/cimi: model/machine.rb server.rb
Date Tue, 29 Nov 2011 15:32:55 GMT
Author: mfojtik
Date: Tue Nov 29 15:32:54 2011
New Revision: 1207921

URL: http://svn.apache.org/viewvc?rev=1207921&view=rev
Log:
CIMI: Added create and destroy operations for Machine entity

Modified:
    deltacloud/trunk/server/lib/cimi/model/machine.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model/machine.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine.rb?rev=1207921&r1=1207920&r2=1207921&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine.rb Tue Nov 29 15:32:54 2011
@@ -63,10 +63,27 @@ class CIMI::Model::Machine < CIMI::Model
       instances.map { |instance| from_instance(instance, _self) }.compact
     else
       instance = _self.driver.instance(_self.credentials, :id => id)
+      raise CIMI::Model::NotFound unless instance
       from_instance(instance, _self)
     end
   end
 
+  def self.create_from_json(body, _self)
+    json = JSON.parse(body)
+    hardware_profile_id = xml['MachineTemplate']['MachineConfig']["href"].split('/').last
+    image_id = xml['MachineTemplate']['MachineImage']["href"].split('/').last
+    instance = _self.create_instance(_self.credentials, image_id, { :hwp_id => hardware_profile_id
})
+    from_instance(instance, _self)
+  end
+
+  def self.create_from_xml(body, _self)
+    xml = XmlSimple.xml_in(body)
+    hardware_profile_id = xml['MachineTemplate'][0]['MachineConfig'][0]["href"].split('/').last
+    image_id = xml['MachineTemplate'][0]['MachineImage'][0]["href"].split('/').last
+    instance = _self.driver.create_instance(_self.credentials, image_id, { :hwp_id =>
hardware_profile_id })
+    from_instance(instance, _self)
+  end
+
   def perform(action, _self, &block)
     begin
       if _self.driver.send(:"#{action.name}_instance", _self.credentials, self.name)
@@ -79,6 +96,10 @@ class CIMI::Model::Machine < CIMI::Model
     end
   end
 
+  def self.delete!(id, _self)
+    _self.driver.destroy_instance(_self.credentials, id)
+  end
+
   private
 
   def self.from_instance(instance, _self)

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1207921&r1=1207920&r2=1207921&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Tue Nov 29 15:32:54 2011
@@ -180,23 +180,28 @@ global_collection :machines do
     end
   end
 
-  operation :delete, :method => :post, :member => true do
+  operation :create do
+    description "Create a new Machine entity."
+    control do
+      if request.content_type.end_with?("+json")
+        new_machine = Machine.create_from_json(request.body.read, self)
+      else
+        new_machine = Machine.create_from_xml(request.body.read, self)
+      end
+      status 201 # Created
+      respond_to do |format|
+        format.json { new_machine.to_json }
+        format.xml { new_machine.to_xml }
+      end
+    end
+  end
+
+  operation :delete, :method => :delete, :member => true do
     description "Reboot specific machine."
     param :id,          :string,    :required
     control do
-      machine = Machine.find(params[:id], self)
-      machine.perform :destroy do |operation|
-        operation.body = request.body.read
-        operation.content_type = params[:content_type]
-        operation.on :success do
-          # We *should* return 202 - Accepted because the 'reboot' operation will not be
processed
-          # immediately
-          no_content_with_status 202
-        end
-        operation.on :failure do
-          # error...
-        end
-      end
+      Machine.delete!(params[:id], self)
+      no_content_with_status(200)
     end
   end
 



Mime
View raw message