From: David Lutterkort <[email protected]> --- server/lib/cimi/collections/credentials.rb | 74 ++++++++++++++++++++ server/lib/cimi/collections/machine_admins.rb | 74 -------------------- server/lib/cimi/models.rb | 2 +- server/lib/cimi/models/credential.rb | 62 ++++++++++++++++ server/lib/cimi/models/machine.rb | 6 +- server/lib/cimi/models/machine_admin.rb | 62 ---------------- server/lib/cimi/models/machine_template.rb | 2 +- server/tests/cimi/spec/cimi/data/credential.json | 14 ++++ server/tests/cimi/spec/cimi/data/credential.xml | 10 +++ .../tests/cimi/spec/cimi/data/machine_admin.json | 14 ---- server/tests/cimi/spec/cimi/data/machine_admin.xml | 10 --- .../tests/cimi/spec/cimi/model/credential_spec.rb | 35 +++++++++ .../cimi/spec/cimi/model/machine_admin_spec.rb | 35 --------- 13 files changed, 200 insertions(+), 200 deletions(-) create mode 100644 server/lib/cimi/collections/credentials.rb delete mode 100644 server/lib/cimi/collections/machine_admins.rb create mode 100644 server/lib/cimi/models/credential.rb delete mode 100644 server/lib/cimi/models/machine_admin.rb create mode 100644 server/tests/cimi/spec/cimi/data/credential.json create mode 100644 server/tests/cimi/spec/cimi/data/credential.xml delete mode 100644 server/tests/cimi/spec/cimi/data/machine_admin.json delete mode 100644 server/tests/cimi/spec/cimi/data/machine_admin.xml create mode 100644 server/tests/cimi/spec/cimi/model/credential_spec.rb delete mode 100644 server/tests/cimi/spec/cimi/model/machine_admin_spec.rb
diff --git a/server/lib/cimi/collections/credentials.rb b/server/lib/cimi/collections/credentials.rb new file mode 100644 index 0000000..2fc5c58 --- /dev/null +++ b/server/lib/cimi/collections/credentials.rb @@ -0,0 +1,74 @@ +# 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::Collections + class Credentials < Base + + set :capability, lambda { |m| driver.respond_to? m } + + collection :credentials do + description 'Machine Admin entity' + + operation :index, :with_capability => :keys do + description "List all machine admins" + param :CIMISelect, :string, :optional + control do + credentials = Credential.list(self).filter_by(params[:CIMISelect]) + respond_to do |format| + format.xml { credentials.to_xml } + format.json { credentials.to_json } + end + end + end + + operation :show, :with_capability => :key do + description "Show specific machine admin" + control do + credential = Credential.find(params[:id], self) + respond_to do |format| + format.xml { credential.to_xml } + format.json { credential.to_json } + end + end + end + + operation :create, :with_capability => :create_key do + description "Show specific machine admin" + control do + if request.content_type.end_with?("+json") + new_admin = Credential.create_from_json(request.body.read, self) + else + new_admin = Credential.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 + + operation :delete, :with_capability => :destroy_key do + description "Delete specified Credential entity" + control do + Credential.delete!(params[:id], self) + no_content_with_status(200) + end + end + + end + + end +end diff --git a/server/lib/cimi/collections/machine_admins.rb b/server/lib/cimi/collections/machine_admins.rb deleted file mode 100644 index e6bac61..0000000 --- a/server/lib/cimi/collections/machine_admins.rb +++ /dev/null @@ -1,74 +0,0 @@ -# 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::Collections - class MachineAdmins < Base - - set :capability, lambda { |m| driver.respond_to? m } - - collection :machine_admins do - description 'Machine Admin entity' - - operation :index, :with_capability => :keys do - description "List all machine admins" - param :CIMISelect, :string, :optional - control do - machine_admins = MachineAdmin.list(self).filter_by(params[:CIMISelect]) - respond_to do |format| - format.xml { machine_admins.to_xml } - format.json { machine_admins.to_json } - end - end - end - - operation :show, :with_capability => :key do - description "Show specific machine admin" - 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, :with_capability => :create_key do - description "Show specific machine admin" - 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 - - operation :delete, :with_capability => :destroy_key do - description "Delete specified MachineAdmin entity" - control do - MachineAdmin.delete!(params[:id], self) - no_content_with_status(200) - end - end - - end - - end -end diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb index f7e2d93..722bbad 100644 --- a/server/lib/cimi/models.rb +++ b/server/lib/cimi/models.rb @@ -32,7 +32,7 @@ require_relative './models/machine_configuration' require_relative './models/action' require_relative './models/machine' require_relative './models/volume' -require_relative './models/machine_admin' +require_relative './models/credential' require_relative './models/volume_configuration' require_relative './models/volume_image' require_relative './models/volume_template' diff --git a/server/lib/cimi/models/credential.rb b/server/lib/cimi/models/credential.rb new file mode 100644 index 0000000..cf19f82 --- /dev/null +++ b/server/lib/cimi/models/credential.rb @@ -0,0 +1,62 @@ +# 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. + +class CIMI::Model::Credential < CIMI::Model::Base + + acts_as_root_entity + + text :username + text :password + text :key + + array :operations do + scalar :rel, :href + end + + def self.find(id, context) + if id == :all + return [] unless context.driver.respond_to?(:keys) + 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) + credential = Credential.from_xml(body) + key = context.driver.create_key(context.credentials, :key_name => credential.name) + from_key(key, context) + end + + def self.delete!(id, context) + context.driver.destroy_key(context.credentials, :id => id) + 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, + :id => context.credential_url(key.id), + :created => Time.now + ) + end + +end diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb index a5d3302..41b6b6b 100644 --- a/server/lib/cimi/models/machine.rb +++ b/server/lib/cimi/models/machine.rb @@ -65,8 +65,8 @@ class CIMI::Model::Machine < CIMI::Model::Base image_id = machine_template['machineImage'][0]["href"].split('/').last additional_params = {} additional_params[:name] =xml['name'][0] if xml['name'] - if machine_template.has_key? 'machineAdmin' - additional_params[:keyname] = machine_template['machineAdmin'][0]["href"].split('/').last + if machine_template.has_key? 'credential' + additional_params[:keyname] = machine_template['credential'][0]["href"].split('/').last end instance = context.driver.create_instance(context.credentials, image_id, { :hwp_id => hardware_profile_id @@ -145,7 +145,7 @@ class CIMI::Model::Machine < CIMI::Model::Base properties = {} properties["machine_image"] = context.machine_image_url(instance.image_id) if instance.respond_to? :keyname - properties["machine_admin"] = context.machine_admin_url(instance.keyname) + properties["credential"] = context.credential_url(instance.keyname) end properties end diff --git a/server/lib/cimi/models/machine_admin.rb b/server/lib/cimi/models/machine_admin.rb deleted file mode 100644 index fd435a1..0000000 --- a/server/lib/cimi/models/machine_admin.rb +++ /dev/null @@ -1,62 +0,0 @@ -# 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. - -class CIMI::Model::MachineAdmin < CIMI::Model::Base - - acts_as_root_entity - - text :username - text :password - text :key - - array :operations do - scalar :rel, :href - end - - def self.find(id, context) - if id == :all - return [] unless context.driver.respond_to?(:keys) - 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 - - def self.delete!(id, context) - context.driver.destroy_key(context.credentials, :id => id) - 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, - :id => context.machine_admin_url(key.id), - :created => Time.now - ) - end - -end diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb index b09cc40..7b64b98 100644 --- a/server/lib/cimi/models/machine_template.rb +++ b/server/lib/cimi/models/machine_template.rb @@ -19,7 +19,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base href :machine_config href :machine_image - href :machine_admin + href :credential array :volumes do scalar :href diff --git a/server/tests/cimi/spec/cimi/data/credential.json b/server/tests/cimi/spec/cimi/data/credential.json new file mode 100644 index 0000000..35ab04b --- /dev/null +++ b/server/tests/cimi/spec/cimi/data/credential.json @@ -0,0 +1,14 @@ +{ + "id": "http://cimi.example.org/machine_admins/1", + "name": "credentials1", + "description": "Machine Admin One", + "created": "2011-11-16", + "username": "mockuser", + "password": "mockpassword", + "operations": [ + { "rel": "edit", + "href": "http://cimi.example.org/machine_admins/1/edit" }, + { "rel": "delete", + "href": "http://cimi.example.org/machine_admins/1/delete" } + ] +} diff --git a/server/tests/cimi/spec/cimi/data/credential.xml b/server/tests/cimi/spec/cimi/data/credential.xml new file mode 100644 index 0000000..fb813db --- /dev/null +++ b/server/tests/cimi/spec/cimi/data/credential.xml @@ -0,0 +1,10 @@ +<Credential xmlns="http://www.dmtf.org/cimi"> + <id>http://cimi.example.org/machine_admins/1</id> + <name>credentials1</name> + <description>Machine Admin One</description> + <created>2011-11-16</created> + <username>mockuser</username> + <password>mockpassword</password> + <operation rel="edit" href="http://cimi.example.org/machine_admins/1/edit"/> + <operation rel="delete" href="http://cimi.example.org/machine_admins/1/delete"/> +</Credential> diff --git a/server/tests/cimi/spec/cimi/data/machine_admin.json b/server/tests/cimi/spec/cimi/data/machine_admin.json deleted file mode 100644 index 35ab04b..0000000 --- a/server/tests/cimi/spec/cimi/data/machine_admin.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "id": "http://cimi.example.org/machine_admins/1", - "name": "credentials1", - "description": "Machine Admin One", - "created": "2011-11-16", - "username": "mockuser", - "password": "mockpassword", - "operations": [ - { "rel": "edit", - "href": "http://cimi.example.org/machine_admins/1/edit" }, - { "rel": "delete", - "href": "http://cimi.example.org/machine_admins/1/delete" } - ] -} diff --git a/server/tests/cimi/spec/cimi/data/machine_admin.xml b/server/tests/cimi/spec/cimi/data/machine_admin.xml deleted file mode 100644 index 1f395c3..0000000 --- a/server/tests/cimi/spec/cimi/data/machine_admin.xml +++ /dev/null @@ -1,10 +0,0 @@ -<MachineAdmin xmlns="http://www.dmtf.org/cimi"> - <id>http://cimi.example.org/machine_admins/1</id> - <name>credentials1</name> - <description>Machine Admin One</description> - <created>2011-11-16</created> - <username>mockuser</username> - <password>mockpassword</password> - <operation rel="edit" href="http://cimi.example.org/machine_admins/1/edit"/> - <operation rel="delete" href="http://cimi.example.org/machine_admins/1/delete"/> -</MachineAdmin> diff --git a/server/tests/cimi/spec/cimi/model/credential_spec.rb b/server/tests/cimi/spec/cimi/model/credential_spec.rb new file mode 100644 index 0000000..8c8cafc --- /dev/null +++ b/server/tests/cimi/spec/cimi/model/credential_spec.rb @@ -0,0 +1,35 @@ +# 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. +# + +require 'rubygems' +require 'require_relative' if RUBY_VERSION < '1.9' + +if require 'minitest/autorun' + require_relative '../../spec_helper.rb' +end + +describe "Credential model" do + + before do + @xml = IO::read(File::join(DATA_DIR, "credential.xml")) + @json = IO::read(File::join(DATA_DIR, "credential.json")) + end + + it "can be constructed from XML and JSON" do + should_properly_serialize_model CIMI::Model::Credential, @xml, @json + end + +end diff --git a/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb b/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb deleted file mode 100644 index e2a5d5c..0000000 --- a/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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. -# - -require 'rubygems' -require 'require_relative' if RUBY_VERSION < '1.9' - -if require 'minitest/autorun' - require_relative '../../spec_helper.rb' -end - -describe "MachineAdmin model" do - - before do - @xml = IO::read(File::join(DATA_DIR, "machine_admin.xml")) - @json = IO::read(File::join(DATA_DIR, "machine_admin.json")) - end - - it "can be constructed from XML and JSON" do - should_properly_serialize_model CIMI::Model::MachineAdmin, @xml, @json - end - -end -- 1.7.7.6
