You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/30 16:20:39 UTC
[PATCH core 1/2] CIMI: Moved exceptions to a separate file
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model.rb | 1 +
server/lib/cimi/model/base.rb | 8 -------
server/lib/cimi/model/errors.rb | 40 +++++++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 8 deletions(-)
create mode 100644 server/lib/cimi/model/errors.rb
diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index 243f693..d98c2af 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -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'
diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index ddc1b8a..53ed3c1 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -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)
diff --git a/server/lib/cimi/model/errors.rb b/server/lib/cimi/model/errors.rb
new file mode 100644
index 0000000..9fb82f1
--- /dev/null
+++ b/server/lib/cimi/model/errors.rb
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+module CIMI::Model
+
+ class NotFound < StandardError
+ attr_accessor :code
+
+ def initialize
+ super("Requested Entity Not Found")
+ self.code = 404
+ end
+
+ end
+
+ class NotImplemented < StandardError
+ attr_accessor :code
+
+ def initialize
+ super("Requested operation is not implemented by backend provider")
+ self.code = 501
+ end
+
+ end
+
+end
+
+
--
1.7.4.4
Re: [PATCH core 2/2] CIMI: Added MachineAdmin model operations
Posted by Michal Fojtik <mf...@redhat.com>.
On Dec 1, 2011, at 10:51 AM, marios@redhat.com wrote:
> nack - couple minor issues below to fix before push please:
>
> On 30/11/11 17:20, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>>
>>
>> Signed-off-by: Michal fojtik <mf...@redhat.com>
>> ---
>> server/lib/cimi/model/machine_admin.rb | 27 +++++++++++++++++
>> server/lib/cimi/server.rb | 49 ++++++++++++++++++++++++++++++-
>> 2 files changed, 74 insertions(+), 2 deletions(-)
>>
>> diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb
>> index 4f73223..fa27ca4 100644
>> --- a/server/lib/cimi/model/machine_admin.rb
>> +++ b/server/lib/cimi/model/machine_admin.rb
>> @@ -25,4 +25,31 @@ class CIMI::Model::MachineAdmin < CIMI::Model::Base
>> scalar :rel, :href
>> end
>>
>> + def self.find(id, context)
>> + 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.fingerprint,
>> + :key => key.pem_rsa_key
>> + )
>> + end
>
> you need to add :uri to the new MachineAdmin, otherwise the
> to_xxx_collection method will explode
>
> I tested create and it works fine for ec2, since they use
> Deltacloud::Key of type :key - but what if its type :password... need to
> extend the self.from_key with some logic using the is_password (so
> :password => key.password) or is_key methods (as you have above)
Agree completely. I forgot to handle this. Plus I'm missing the ':created'
value. Will add those and resent this patch. Thanks!
>> +
>> end
>> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
>> index 1e85d0f..a7fd778 100644
>> --- a/server/lib/cimi/server.rb
>> +++ b/server/lib/cimi/server.rb
>> @@ -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)
>
------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
Re: [PATCH core 2/2] CIMI: Added MachineAdmin model operations
Posted by "marios@redhat.com" <ma...@redhat.com>.
nack - couple minor issues below to fix before push please:
On 30/11/11 17:20, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/lib/cimi/model/machine_admin.rb | 27 +++++++++++++++++
> server/lib/cimi/server.rb | 49 ++++++++++++++++++++++++++++++-
> 2 files changed, 74 insertions(+), 2 deletions(-)
>
> diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb
> index 4f73223..fa27ca4 100644
> --- a/server/lib/cimi/model/machine_admin.rb
> +++ b/server/lib/cimi/model/machine_admin.rb
> @@ -25,4 +25,31 @@ class CIMI::Model::MachineAdmin < CIMI::Model::Base
> scalar :rel, :href
> end
>
> + def self.find(id, context)
> + 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.fingerprint,
> + :key => key.pem_rsa_key
> + )
> + end
you need to add :uri to the new MachineAdmin, otherwise the
to_xxx_collection method will explode
I tested create and it works fine for ec2, since they use
Deltacloud::Key of type :key - but what if its type :password... need to
extend the self.from_key with some logic using the is_password (so
:password => key.password) or is_key methods (as you have above)
> +
> end
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index 1e85d0f..a7fd778 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -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)
[PATCH core 2/2] CIMI: Added MachineAdmin model operations
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model/machine_admin.rb | 27 +++++++++++++++++
server/lib/cimi/server.rb | 49 ++++++++++++++++++++++++++++++-
2 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb
index 4f73223..fa27ca4 100644
--- a/server/lib/cimi/model/machine_admin.rb
+++ b/server/lib/cimi/model/machine_admin.rb
@@ -25,4 +25,31 @@ class CIMI::Model::MachineAdmin < CIMI::Model::Base
scalar :rel, :href
end
+ def self.find(id, context)
+ 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.fingerprint,
+ :key => key.pem_rsa_key
+ )
+ end
+
end
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 1e85d0f..a7fd778 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -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)
--
1.7.4.4