Return-Path: X-Original-To: apmail-deltacloud-dev-archive@www.apache.org Delivered-To: apmail-deltacloud-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 928B57A57 for ; Wed, 7 Dec 2011 10:07:51 +0000 (UTC) Received: (qmail 32286 invoked by uid 500); 7 Dec 2011 10:07:51 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 32262 invoked by uid 500); 7 Dec 2011 10:07:51 -0000 Mailing-List: contact dev-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list dev@deltacloud.apache.org Received: (qmail 32254 invoked by uid 99); 7 Dec 2011 10:07:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Dec 2011 10:07:51 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mfojtik@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Dec 2011 10:07:43 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB7A7Lgj014792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Dec 2011 05:07:21 -0500 Received: from dhcp-29-121.brq.redhat.com (dhcp-29-121.brq.redhat.com [10.34.29.121]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB7A7Kqf032435 for ; Wed, 7 Dec 2011 05:07:20 -0500 From: mfojtik@redhat.com To: dev@deltacloud.apache.org Subject: [PATCH core] CIMI: Added MachineAdmin model operations (rev 2) Date: Wed, 7 Dec 2011 11:08:16 +0100 Message-Id: <1323252496-11086-1-git-send-email-mfojtik@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Virus-Checked: Checked by ClamAV on apache.org From: Michal Fojtik Signed-off-by: Michal fojtik --- server/lib/cimi/model.rb | 1 + server/lib/cimi/model/base.rb | 8 ----- server/lib/cimi/model/errors.rb | 40 ++++++++++++++++++++++++++ server/lib/cimi/model/machine_admin.rb | 27 +++++++++++++++++- server/lib/cimi/server.rb | 49 ++++++++++++++++++++++++++++++- 5 files changed, 114 insertions(+), 11 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 d11d77b..79645b2 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 fe12628..cd49518 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 + + diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb index dff5065..b3f2f86 100644 --- a/server/lib/cimi/model/machine_admin.rb +++ b/server/lib/cimi/model/machine_admin.rb @@ -24,7 +24,32 @@ class CIMI::Model::MachineAdmin < CIMI::Model::Base 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 diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb index ac7d51f..757ceb5 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