deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1211424 - in /deltacloud/trunk/server/lib/cimi: model.rb model/base.rb model/errors.rb model/machine_admin.rb server.rb
Date Wed, 07 Dec 2011 13:11:21 GMT
Author: mfojtik
Date: Wed Dec  7 13:11:21 2011
New Revision: 1211424

URL: http://svn.apache.org/viewvc?rev=1211424&view=rev
Log:
CIMI: Added MachineAdmin model operations (rev 2)

Added:
    deltacloud/trunk/server/lib/cimi/model/errors.rb
      - copied, changed from r1211360, deltacloud/trunk/server/lib/cimi/model/machine_admin.rb
Modified:
    deltacloud/trunk/server/lib/cimi/model.rb
    deltacloud/trunk/server/lib/cimi/model/base.rb
    deltacloud/trunk/server/lib/cimi/model/machine_admin.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model.rb?rev=1211424&r1=1211423&r2=1211424&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model.rb Wed Dec  7 13:11:21 2011
@@ -22,6 +22,7 @@ end
 
 require 'cimi/model/schema'
 require 'cimi/model/base'
+require 'cimi/model/errors'
 require 'cimi/model/cloud_entry_point'
 require 'cimi/model/machine_template'
 require 'cimi/model/machine_image'

Modified: deltacloud/trunk/server/lib/cimi/model/base.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/base.rb?rev=1211424&r1=1211423&r2=1211424&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/base.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/base.rb Wed Dec  7 13:11:21 2011
@@ -67,14 +67,6 @@ require 'json'
 #     An array of structured subobjects; the block defines the schema of
 #     the subobjects.
 
-class CIMI::Model::NotFound < StandardError
-  attr_accessor :code
-  def initialize
-    super("Requested Entity Not Found")
-    self.code = 404
-  end
-end
-
 module CIMI::Model
 
   def self.register_as_root_entity!(name)

Copied: deltacloud/trunk/server/lib/cimi/model/errors.rb (from r1211360, deltacloud/trunk/server/lib/cimi/model/machine_admin.rb)
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/errors.rb?p2=deltacloud/trunk/server/lib/cimi/model/errors.rb&p1=deltacloud/trunk/server/lib/cimi/model/machine_admin.rb&r1=1211360&r2=1211424&rev=1211424&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_admin.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/errors.rb Wed Dec  7 13:11:21 2011
@@ -13,18 +13,28 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-class CIMI::Model::MachineAdmin < CIMI::Model::Base
+module CIMI::Model
 
-  text :username
-  text :password
-  text :key
+  class NotFound < StandardError
+    attr_accessor :code
+
+    def initialize
+      super("Requested Entity Not Found")
+      self.code = 404
+    end
 
-  array :operations do
-    scalar :rel, :href
   end
 
-  def self.find(id, context)
-    [] # TODO: Implement this
+  class NotImplemented < StandardError
+    attr_accessor :code
+
+    def initialize
+      super("Requested operation is not implemented by backend provider")
+      self.code = 501
+    end
+
   end
 
 end
+
+

Modified: deltacloud/trunk/server/lib/cimi/model/machine_admin.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_admin.rb?rev=1211424&r1=1211423&r2=1211424&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_admin.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_admin.rb Wed Dec  7 13:11:21 2011
@@ -24,7 +24,32 @@ class CIMI::Model::MachineAdmin < CIMI::
   end
 
   def self.find(id, context)
-    [] # TODO: Implement this
+    if id == :all
+      keys = context.driver.keys(context.credentials)
+      keys.map { |key| from_key(key, context) }
+    else
+      key = context.driver.key(context.credentials, :id => id)
+      from_key(key, context)
+    end
+  end
+
+  def self.create_from_xml(body, context)
+    machine_admin = MachineAdmin.from_xml(body)
+    key = context.driver.create_key(context.credentials, :key_name => machine_admin.name)
+    from_key(key, context)
+  end
+
+  private
+
+  def self.from_key(key, context)
+    self.new(
+      :name => key.id,
+      :username => key.username,
+      :password => key.is_password? ? key.password : key.fingerprint,
+      :key => key.is_key? ? key.pem_rsa_key : nil,
+      :uri => context.machine_admin_url(key.id),
+      :created => Time.now
+    )
   end
 
 end

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1211424&r1=1211423&r2=1211424&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Wed Dec  7 13:11:21 2011
@@ -136,7 +136,6 @@ global_collection :machine_images do
 
   operation :show do
     description "Show specific machine image."
-    with_capability :image
     param :id,          :string,    :required
     control do
       machine_image = MachineImage.find(params[:id], self)
@@ -149,6 +148,53 @@ global_collection :machine_images do
 
 end
 
+global_collection :machine_admins do
+  description 'Machine Admin entity'
+
+  operation :index do
+    description "List all machine admins"
+    with_capability :keys
+    control do
+      machine_admins = MachineAdmin.all(self)
+      respond_to do |format|
+        format.xml { machine_admins.to_xml_cimi_collection(self) }
+        format.json { machine_admins.to_json_cimi_collection(self) }
+      end
+    end
+  end
+
+  operation :show do
+    description "Show specific machine admin"
+    param :id,          :string,    :required
+    with_capability :key
+    control do
+      machine_admin = MachineAdmin.find(params[:id], self)
+      respond_to do |format|
+        format.xml { machine_admin.to_xml }
+        format.json { machine_admin.to_json }
+      end
+    end
+  end
+
+  operation :create do
+    description "Show specific machine admin"
+    with_capability :create_key
+    control do
+      if request.content_type.end_with?("+json")
+        new_admin = MachineAdmin.create_from_json(request.body.read, self)
+      else
+        new_admin = MachineAdmin.create_from_xml(request.body.read, self)
+      end
+      status 201 # Created
+      respond_to do |format|
+        format.json { new_admin.to_json }
+        format.xml { new_admin.to_xml }
+      end
+    end
+  end
+
+end
+
 global_collection :machines do
   description 'List all machine'
 
@@ -165,7 +211,6 @@ global_collection :machines do
 
   operation :show do
     description "Show specific machine."
-    with_capability :instance
     param :id,          :string,    :required
     control do
       machine = Machine.find(params[:id], self)



Mime
View raw message