From: marios <[email protected]>
Signed-off-by: marios <[email protected]> --- .../lib/cimi/collections/network_port_templates.rb | 51 ++++++++++++++++++++++ server/lib/cimi/models/network_port_template.rb | 34 +++++++++++++++ .../models/network_port_template_collection.rb | 37 ++++++++++++++++ .../data/cimi/network_port_template/template1.json | 10 +++++ .../data/cimi/network_port_template/template2.json | 10 +++++ 5 files changed, 142 insertions(+) create mode 100644 server/lib/cimi/collections/network_port_templates.rb create mode 100644 server/lib/cimi/models/network_port_template.rb create mode 100644 server/lib/cimi/models/network_port_template_collection.rb create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template1.json create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template2.json diff --git a/server/lib/cimi/collections/network_port_templates.rb b/server/lib/cimi/collections/network_port_templates.rb new file mode 100644 index 0000000..1995e56 --- /dev/null +++ b/server/lib/cimi/collections/network_port_templates.rb @@ -0,0 +1,51 @@ +# 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 NetworkPortTemplates < Base + + set :capability, lambda { |m| driver.respond_to? m } + + collection :network_port_templates do + + description 'The NetworkPort Template is a set of Configuration values for realizing a NetworkPort. A NetworkPort Template may be used to create multiple NetworkPorts' + + operation :index, :with_capability => :network_port_templates do + description 'List all NetworkPortTemplates in the NetworkPortTemplateCollection' + param :CIMISelect, :string, :optional + control do + network_port_templates = NetworkPortTemplateCollection.default(self).filter_by(params[:CIMISelect]) + respond_to do |format| + format.xml {network_port_templates.to_xml} + format.json {network_port_templates.to_json} + end + end + end + + operation :show, :with_capability => :network_port_templates do + description 'Show a specific NetworkPortTemplate' + control do + network_port_template = NetworkPortTemplate.find(params[:id], self) + respond_to do |format| + format.xml {network_port_template.to_xml} + format.json {network_port_template.to_json} + end + end + end + + end + + end +end diff --git a/server/lib/cimi/models/network_port_template.rb b/server/lib/cimi/models/network_port_template.rb new file mode 100644 index 0000000..8fb7ef1 --- /dev/null +++ b/server/lib/cimi/models/network_port_template.rb @@ -0,0 +1,34 @@ +# 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::NetworkPortTemplate < CIMI::Model::Base + + href :network + + href :network_port_config + + array :operations do + scalar :rel, :href + end + + def self.find(id, context) + if id==:all + context.driver.network_port_templates(context.credentials, {:env=>context}) + else + context.driver.network_port_templates(context.credentials, {:env=>context, :id=>id}) + end + end + +end diff --git a/server/lib/cimi/models/network_port_template_collection.rb b/server/lib/cimi/models/network_port_template_collection.rb new file mode 100644 index 0000000..782af0d --- /dev/null +++ b/server/lib/cimi/models/network_port_template_collection.rb @@ -0,0 +1,37 @@ +# 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::NetworkPortTemplateCollection < CIMI::Model::Base + + CIMI::Model.register_as_root_entity! "NetworkPortTemplates" + + text :count + + #add array of network_port_templates: + self << CIMI::Model::NetworkPortTemplate + + def self.default(context) + network_port_templates = CIMI::Model::NetworkPortTemplate.all(context) + self.new( + :id => context.network_port_templates_url, + :name => 'default', + :created => Time.now, + :description => "#{context.driver.name.capitalize} NetworkPortTemplateCollection", + :count => network_port_templates.size, + :network_port_templates => network_port_templates + ) + end + +end diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template1.json b/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template1.json new file mode 100644 index 0000000..3c81787 --- /dev/null +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template1.json @@ -0,0 +1,10 @@ +{ "id": "http://cimi.example.org/network_port_templates/template1", + "name": "template1", + "description": "A mock NetworkPortTemplate", + "created": "Fri Mar 16 19:26:41 EET 2012", + "network": { "href": "http://cimi.example.org/networks/network1"}, + "networkPortConfig": { "href": "http://cimi.example.org/network_port_configurations/portconfig1"}, + "operations": [ + { "rel": "edit", "href": "http://cimi.example.org/network_port_templates/template1" }, + { "rel": "delete", "href": "http://cimi.example.org/network_port_templates/template1" }] +} diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template2.json b/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template2.json new file mode 100644 index 0000000..99386a7 --- /dev/null +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_port_template/template2.json @@ -0,0 +1,10 @@ +{ "id": "http://cimi.example.org/network_port_templates/template2", + "name": "template2", + "description": "A mock NetworkPortTemplate", + "created": "Fri Mar 16 19:26:41 EET 2012", + "network": { "href": "http://cimi.example.org/networks/network2"}, + "networkPortConfig": { "href": "http://cimi.example.org/network_port_configurations/portconfig2"}, + "operations": [ + { "rel": "edit", "href": "http://cimi.example.org/network_port_templates/template2" }, + { "rel": "delete", "href": "http://cimi.example.org/network_port_templates/template2" }] +} -- 1.7.11.4
