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 2012/04/17 15:40:05 UTC
[PATCH core 26/32] CIMI: Splitted CIMI server to separate collections like in Deltacloud
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/collections.rb | 58 ++
server/lib/cimi/collections/address_templates.rb | 49 +
server/lib/cimi/collections/addresses.rb | 74 ++
server/lib/cimi/collections/cloud_entry_point.rb | 32 +
server/lib/cimi/collections/entity_metadata.rb | 48 +
server/lib/cimi/collections/machine_admins.rb | 74 ++
.../lib/cimi/collections/machine_configurations.rb | 49 +
server/lib/cimi/collections/machine_images.rb | 50 +
server/lib/cimi/collections/machines.rb | 157 ++++
.../lib/cimi/collections/network_configurations.rb | 47 +
server/lib/cimi/collections/network_templates.rb | 48 +
server/lib/cimi/collections/networks.rb | 125 +++
.../cimi/collections/routing_group_templates.rb | 47 +
server/lib/cimi/collections/routing_groups.rb | 48 +
.../lib/cimi/collections/volume_configurations.rb | 48 +
server/lib/cimi/collections/volume_images.rb | 50 +
server/lib/cimi/collections/volumes.rb | 80 ++
server/lib/cimi/collections/vsp_configurations.rb | 48 +
server/lib/cimi/collections/vsp_templates.rb | 50 +
server/lib/cimi/collections/vsps.rb | 108 +++
server/lib/cimi/helpers.rb | 104 +++
server/lib/cimi/model.rb | 67 --
server/lib/cimi/models.rb | 75 ++
server/lib/cimi/server.rb | 959 +-------------------
24 files changed, 1499 insertions(+), 996 deletions(-)
create mode 100644 server/lib/cimi/collections.rb
create mode 100644 server/lib/cimi/collections/address_templates.rb
create mode 100644 server/lib/cimi/collections/addresses.rb
create mode 100644 server/lib/cimi/collections/cloud_entry_point.rb
create mode 100644 server/lib/cimi/collections/entity_metadata.rb
create mode 100644 server/lib/cimi/collections/machine_admins.rb
create mode 100644 server/lib/cimi/collections/machine_configurations.rb
create mode 100644 server/lib/cimi/collections/machine_images.rb
create mode 100644 server/lib/cimi/collections/machines.rb
create mode 100644 server/lib/cimi/collections/network_configurations.rb
create mode 100644 server/lib/cimi/collections/network_templates.rb
create mode 100644 server/lib/cimi/collections/networks.rb
create mode 100644 server/lib/cimi/collections/routing_group_templates.rb
create mode 100644 server/lib/cimi/collections/routing_groups.rb
create mode 100644 server/lib/cimi/collections/volume_configurations.rb
create mode 100644 server/lib/cimi/collections/volume_images.rb
create mode 100644 server/lib/cimi/collections/volumes.rb
create mode 100644 server/lib/cimi/collections/vsp_configurations.rb
create mode 100644 server/lib/cimi/collections/vsp_templates.rb
create mode 100644 server/lib/cimi/collections/vsps.rb
create mode 100644 server/lib/cimi/helpers.rb
delete mode 100644 server/lib/cimi/model.rb
create mode 100644 server/lib/cimi/models.rb
diff --git a/server/lib/cimi/collections.rb b/server/lib/cimi/collections.rb
new file mode 100644
index 0000000..b675fc4
--- /dev/null
+++ b/server/lib/cimi/collections.rb
@@ -0,0 +1,58 @@
+#
+# 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
+
+ def self.collection_names
+ @collections.map { |c| c.collection_name }
+ end
+
+ def self.collections
+ @collections ||= []
+ end
+
+ module Collections
+
+ def self.collection(name)
+ CIMI.collections.find { |c| c.collection_name == name }
+ end
+
+ def self.cimi_modules
+ @cimi_modules ||= []
+ end
+
+ Dir[File.join(File::dirname(__FILE__), "collections", "*.rb")].each do |collection|
+ require collection
+ base_collection_name = File.basename(collection).gsub('.rb', '')
+ cimi_module_class = CIMI::Collections.const_get(base_collection_name.camelize)
+ cimi_modules << cimi_module_class
+ unless cimi_module_class.collections.nil?
+ cimi_module_class.collections.each do |c|
+ CIMI.collections << c
+ end
+ else
+ warn "WARNING: File %s placed in collections directory but does not have any collections defined" % base_collection_name
+ end
+ end
+
+ def self.included(klass)
+ klass.class_eval do
+ CIMI::Collections.cimi_modules.each { |c| use c }
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/address_templates.rb b/server/lib/cimi/collections/address_templates.rb
new file mode 100644
index 0000000..db59507
--- /dev/null
+++ b/server/lib/cimi/collections/address_templates.rb
@@ -0,0 +1,49 @@
+# 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 AddressTemplates < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :address_templates do
+
+ operation :index do
+ description 'List all AddressTemplates in the AddressTemplateCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ address_templates = AddressTemplateCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {address_templates.to_xml}
+ format.json {address_templates.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific AddressTemplate'
+ control do
+ address_template = CIMI::Model::AddressTemplate.find(params[:id], self)
+ respond_to do |format|
+ format.xml {address_template.to_xml}
+ format.json {address_template.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/addresses.rb b/server/lib/cimi/collections/addresses.rb
new file mode 100644
index 0000000..96871c1
--- /dev/null
+++ b/server/lib/cimi/collections/addresses.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 Addresses < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :addresses do
+
+ description 'An Address represents an IP address, and its associated metdata, for a particular Network.'
+
+ operation :index do
+ description 'List all Addresses in the AddressCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ addresses = AddressCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {addresses.to_xml}
+ format.json {addresses.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific Address'
+ control do
+ address = CIMI::Model::Address.find(params[:id], self)
+ respond_to do |format|
+ format.xml {address.to_xml}
+ format.json {address.to_json}
+ end
+ end
+ end
+
+ operation :create do
+ description "Create a new Address"
+ control do
+ if request.content_type.end_with?("json")
+ address = CIMI::Model::Address.create(request.body.read, self, :json)
+ else
+ address = CIMI::Model::Address.create(request.body.read, self, :xml)
+ end
+ respond_to do |format|
+ format.xml { address.to_xml }
+ format.json { address.to_json }
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a specified Address"
+ param :id, :string, :required
+ control do
+ CIMI::Model::Address.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/cloud_entry_point.rb b/server/lib/cimi/collections/cloud_entry_point.rb
new file mode 100644
index 0000000..79454f3
--- /dev/null
+++ b/server/lib/cimi/collections/cloud_entry_point.rb
@@ -0,0 +1,32 @@
+# 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 CloudEntryPoint < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :cloudEntryPoint do
+ description 'Cloud entry point'
+ operation :index do
+ description "list all resources of the cloud"
+ control do
+ redirect API_ROOT_URL
+ end
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/entity_metadata.rb b/server/lib/cimi/collections/entity_metadata.rb
new file mode 100644
index 0000000..84e1fec
--- /dev/null
+++ b/server/lib/cimi/collections/entity_metadata.rb
@@ -0,0 +1,48 @@
+# 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 EntityMetadata < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :entity_metadata do
+
+ operation :index do
+ description "List all entity metadata defined for this provider"
+ control do
+ entity_metadata = CIMI::Model::EntityMetadataCollection.default(self)
+ respond_to do |format|
+ format.xml{entity_metadata.to_xml}
+ format.json{entity_metadata.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description "Get the entity metadata for a specific collection"
+ control do
+ entity_metadata = EntityMetadata.find(params[:id], self)
+ respond_to do |format|
+ format.xml{entity_metadata.to_xml}
+ format.json{entity_metadata.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/machine_admins.rb b/server/lib/cimi/collections/machine_admins.rb
new file mode 100644
index 0000000..c413cc9
--- /dev/null
+++ b/server/lib/cimi/collections/machine_admins.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 MachineAdmins < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :machine_admins do
+ description 'Machine Admin entity'
+
+ operation :index do
+ description "List all machine admins"
+ param :CIMISelect, :string, :optional
+ control do
+ machine_admins = MachineAdminCollection.default(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 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 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 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/collections/machine_configurations.rb b/server/lib/cimi/collections/machine_configurations.rb
new file mode 100644
index 0000000..5b09e6a
--- /dev/null
+++ b/server/lib/cimi/collections/machine_configurations.rb
@@ -0,0 +1,49 @@
+# 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 MachineConfigurations < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :machine_configurations do
+ description 'List all machine configurations'
+
+ operation :index do
+ param :CIMISelect, :string, :optional
+ description "List all machine configurations"
+ control do
+ machine_configs = MachineConfigurationCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { machine_configs.to_xml }
+ format.json { machine_configs.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ control do
+ machine_conf = MachineConfiguration.find(params[:id], self)
+ respond_to do |format|
+ format.xml { machine_conf.to_xml }
+ format.json { machine_conf.to_json }
+ end
+ end
+
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb
new file mode 100644
index 0000000..1296279
--- /dev/null
+++ b/server/lib/cimi/collections/machine_images.rb
@@ -0,0 +1,50 @@
+# 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 MachineImages < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :machine_images do
+ description 'List all machine images'
+
+ operation :index do
+ description "List all machine configurations"
+ param :CIMISelect, :string, :optional
+ control do
+ machine_images = MachineImageCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { machine_images.to_xml }
+ format.json { machine_images.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Show specific machine image."
+ control do
+ machine_image = MachineImage.find(params[:id], self)
+ respond_to do |format|
+ format.xml { machine_image.to_xml }
+ format.json { machine_image.to_json }
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
new file mode 100644
index 0000000..0abf63a
--- /dev/null
+++ b/server/lib/cimi/collections/machines.rb
@@ -0,0 +1,157 @@
+# 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 Machines < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :machines do
+ description 'List all machine'
+
+ operation :index do
+ param :CIMISelect, :string, :optional
+ description "List all machines"
+ control do
+ machines = MachineCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { machines.to_xml }
+ format.json { machines.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Show specific machine."
+ control do
+ machine = Machine.find(params[:id], self)
+ respond_to do |format|
+ format.xml { machine.to_xml }
+ format.json { machine.to_json }
+ end
+ end
+ end
+
+ operation :create do
+ description "Create a new Machine entity."
+ control do
+ if request.content_type.end_with?("+json")
+ new_machine = Machine.create_from_json(request.body.read, self)
+ else
+ new_machine = Machine.create_from_xml(request.body.read, self)
+ end
+ status 201 # Created
+ respond_to do |format|
+ format.json { new_machine.to_json }
+ format.xml { new_machine.to_xml }
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a specified machine."
+ param :id, :string, :required
+ control do
+ Machine.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
+ action :stop do
+ description "Stop specific machine."
+ control do
+ machine = Machine.find(params[:id], self)
+ if request.content_type.end_with?("+json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ machine.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ operation :restart do
+ description "Start specific machine."
+ control do
+ machine = Machine.find(params[:id], self)
+ if request.content_type.end_with?("+json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ machine.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ operation :start do
+ description "Start specific machine."
+ control do
+ machine = Machine.find(params[:id], self)
+ if request.content_type.end_with?("+json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ machine.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ #NOTE: The routes for attach/detach used here are NOT as specified by CIMI
+ #will likely move later. CIMI specifies PUT of the whole Machine description
+ #with inclusion/ommission of the volumes you want [att|det]ached
+ action :attach_volume, :http_method => :put do
+ description "Attach CIMI Volume(s) to a machine."
+ control do
+ if request.content_type.end_with?("+json")
+ volumes_to_attach = Volume.find_to_attach_from_json(request.body.read, self)
+ else
+ volumes_to_attach = Volume.find_to_attach_from_xml(request.body.read, self)
+ end
+ machine = Machine.attach_volumes(volumes_to_attach, self)
+ respond_to do |format|
+ format.json{ machine.to_json}
+ format.xml{machine.to_xml}
+ end
+ end
+ end
+
+ action :detach_volume, :http_method => :put do
+ description "Detach CIMI Volume(s) from a machine."
+ control do
+ if request.content_type.end_with?("+json")
+ volumes_to_detach = Volume.find_to_attach_from_json(request.body.read, self)
+ else
+ volumes_to_detach = Volume.find_to_attach_from_xml(request.body.read, self)
+ end
+ machine = Machine.detach_volumes(volumes_to_detach, self)
+ respond_to do |format|
+ format.json{ machine.to_json}
+ format.xml{machine.to_xml}
+ end
+ end
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/network_configurations.rb b/server/lib/cimi/collections/network_configurations.rb
new file mode 100644
index 0000000..02452a8
--- /dev/null
+++ b/server/lib/cimi/collections/network_configurations.rb
@@ -0,0 +1,47 @@
+# 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 NetworkConfigurations < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :network_configurations do
+
+ operation :index do
+ description 'List all NetworkConfigurations'
+ param :CIMISelect, :string, :optional
+ control do
+ network_configurations = NetworkConfigurationCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { network_configurations.to_xml }
+ format.json { network_configurations.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific NetworkConfiguration'
+ control do
+ network_config = NetworkConfiguration.find(params[:id], self)
+ respond_to do |format|
+ format.xml { network_config.to_xml }
+ format.json { network_config.to_json }
+ end
+ end
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/network_templates.rb b/server/lib/cimi/collections/network_templates.rb
new file mode 100644
index 0000000..0ff82b2
--- /dev/null
+++ b/server/lib/cimi/collections/network_templates.rb
@@ -0,0 +1,48 @@
+# 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 NetworkTemplates < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :network_templates do
+
+ operation :index do
+ description 'List all Network Templates in the NetworkTemplateCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ network_templates = NetworkTemplateCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {network_templates.to_xml}
+ format.json {network_templates.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific Network Template'
+ control do
+ network_template = NetworkTemplate.find(params[:id], self)
+ respond_to do |format|
+ format.xml {network_template.to_xml}
+ format.json {network_template.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
new file mode 100644
index 0000000..0aa21e8
--- /dev/null
+++ b/server/lib/cimi/collections/networks.rb
@@ -0,0 +1,125 @@
+# 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 Networks < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :networks do
+ description 'A Network represents an abstraction of a layer 2 broadcast domain'
+
+ operation :index do
+ description "List all Networks"
+ param :CIMISelect, :string, :optional
+ control do
+ networks = NetworkCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { networks.to_xml }
+ format.json { networks.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Show a specific Network"
+ control do
+ network = Network.find(params[:id], self)
+ respond_to do |format|
+ format.xml { network.to_xml }
+ format.json { network.to_json }
+ end
+ end
+ end
+
+ operation :create do
+ description "Create a new Network"
+ control do
+ if request.content_type.end_with?("json")
+ network = Network.create(request.body.read, self, :json)
+ else
+ network = Network.create(request.body.read, self, :xml)
+ end
+ respond_to do |format|
+ format.xml { network.to_xml}
+ format.json { network.to_json }
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a specified Network"
+ param :id, :string, :required
+ control do
+ Network.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
+ action :start do
+ description "Start specific network."
+ control do
+ network = Network.find(params[:id], self)
+ report_error(404) unless network
+ if request.content_type.end_with?("json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ network.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ action :stop do
+ description "Stop specific network."
+ control do
+ network = Network.find(params[:id], self)
+ report_error(404) unless network
+ if request.content_type.end_with?("json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ network.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ action :suspend do
+ description "Suspend specific network."
+ control do
+ network = Network.find(params[:id], self)
+ report_error(404) unless network
+ if request.content_type.end_with?("json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ network.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/routing_group_templates.rb b/server/lib/cimi/collections/routing_group_templates.rb
new file mode 100644
index 0000000..995b1f8
--- /dev/null
+++ b/server/lib/cimi/collections/routing_group_templates.rb
@@ -0,0 +1,47 @@
+# 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 RoutingGroupTemplates < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :routing_group_templates do
+
+ operation :index do
+ description 'List all RoutingGroupTemplates in the RoutingGroupTemplateCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ routing_group_templates = RoutingGroupTemplateCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {routing_group_templates.to_xml}
+ format.json {routing_group_templates.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific RoutingGroupTemplate'
+ control do
+ routing_group_template = RoutingGroupTemplate.find(params[:id], self)
+ respond_to do |format|
+ format.xml {routing_group_template.to_xml}
+ format.json {routing_group_template.to_json}
+ end
+ end
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/routing_groups.rb b/server/lib/cimi/collections/routing_groups.rb
new file mode 100644
index 0000000..5e7ccc5
--- /dev/null
+++ b/server/lib/cimi/collections/routing_groups.rb
@@ -0,0 +1,48 @@
+# 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 RoutingGroups < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :routing_groups do
+
+ operation :index do
+ description 'List all RoutingGroups in the RoutingGroupsCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ routing_groups = RoutingGroupCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {routing_groups.to_xml}
+ format.json {routing_groups.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific RoutingGroup'
+ control do
+ routing_group = RoutingGroup.find(params[:id], self)
+ respond_to do |format|
+ format.xml {routing_group.to_xml}
+ format.json {routing_group.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/volume_configurations.rb b/server/lib/cimi/collections/volume_configurations.rb
new file mode 100644
index 0000000..055e28c
--- /dev/null
+++ b/server/lib/cimi/collections/volume_configurations.rb
@@ -0,0 +1,48 @@
+# 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 VolumeConfigurations < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :volume_configurations do
+
+ operation :index do
+ description "Get list all VolumeConfigurations"
+ param :CIMISelect, :string, :optional
+ control do
+ volume_configuration = VolumeConfigurationCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { volume_configuration.to_xml }
+ format.json { volume_configuration.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Get a specific VolumeConfiguration"
+ control do
+ volume_config = VolumeConfiguration.find(params[:id], self)
+ respond_to do |format|
+ format.xml { volume_config.to_xml }
+ format.json { volume_config.json }
+ end
+ end
+ end
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/volume_images.rb b/server/lib/cimi/collections/volume_images.rb
new file mode 100644
index 0000000..78432b1
--- /dev/null
+++ b/server/lib/cimi/collections/volume_images.rb
@@ -0,0 +1,50 @@
+# 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 VolumeImages < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+
+ collection :volume_images do
+ description 'This entity represents an image that could be place on a pre-loaded volume.'
+
+ operation :index do
+ description "List all volumes images"
+ param :CIMISelect, :string, :optional
+ control do
+ volume_images = VolumeImageCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { volume_images.to_xml }
+ format.json { volume_images.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Show a specific volume image"
+ control do
+ volume_image = VolumeImage.find(params[:id], self)
+ respond_to do |format|
+ format.xml { volume_image.to_xml }
+ format.json { volume_image.to_json }
+ end
+ end
+ end
+ end
+
+
+ end
+end
diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb
new file mode 100644
index 0000000..1c45c9e
--- /dev/null
+++ b/server/lib/cimi/collections/volumes.rb
@@ -0,0 +1,80 @@
+# 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 Volumes < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :volumes do
+
+ operation :index do
+ description "List all volumes"
+ param :CIMISelect, :string, :optional
+ control do
+ volumes = VolumeCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml { volumes.to_xml }
+ format.json { volumes.to_json }
+ end
+ end
+ end
+
+ operation :show do
+ description "Show specific Volume."
+ control do
+ volume = Volume.find(params[:id], self)
+ if volume
+ respond_to do |format|
+ format.xml { volume.to_xml }
+ format.json { volume.to_json }
+ end
+ else
+ report_error(404)
+ end
+ end
+ end
+
+ operation :create do
+ description "Create a new Volume."
+ control do
+ content_type = (request.content_type.end_with?("+json") ? :json : :xml)
+ #((request.content_type.end_with?("+xml")) ? :xml : report_error(415) ) FIXME
+ case content_type
+ when :json
+ new_volume = Volume.create_from_json(request.body.read, self)
+ when :xml
+ new_volume = Volume.create_from_xml(request.body.read, self)
+ end
+ respond_to do |format|
+ format.json { new_volume.to_json }
+ format.xml { new_volume.to_xml }
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a specified Volume"
+ param :id, :string, :required
+ control do
+ Volume.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
+ end
+
+
+ end
+end
diff --git a/server/lib/cimi/collections/vsp_configurations.rb b/server/lib/cimi/collections/vsp_configurations.rb
new file mode 100644
index 0000000..31acceb
--- /dev/null
+++ b/server/lib/cimi/collections/vsp_configurations.rb
@@ -0,0 +1,48 @@
+# 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 VspConfigurations < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :vsp_configurations do
+
+ operation :index do
+ description 'List all VSPConfigurations in the VSPConfigurationCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ vsp_configs = VSPConfigurationCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {vsp_configs.to_xml}
+ format.json {vsp_configs.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific VSPConfiguration'
+ control do
+ vsp_config = VSPConfiguration.find(params[:id], self)
+ respond_to do |format|
+ format.xml {vsp_config.to_xml}
+ format.json {vsp_config.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/vsp_templates.rb b/server/lib/cimi/collections/vsp_templates.rb
new file mode 100644
index 0000000..503de50
--- /dev/null
+++ b/server/lib/cimi/collections/vsp_templates.rb
@@ -0,0 +1,50 @@
+# 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 VspTemplates < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :vsp_templates do
+
+ description 'The VSP Template is a set of Configuration values for realizing a VSP. A VSP Template may be used to create multiple VSPs'
+
+ operation :index do
+ description 'List all VSPTemplates in the VSPTemplateCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ vsp_templates = VSPTemplateCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {vsp_templates.to_xml}
+ format.json {vsp_templates.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific VSPTemplate'
+ control do
+ vsp_template = VSPTemplate.find(params[:id], self)
+ respond_to do |format|
+ format.xml {vsp_template.to_xml}
+ format.json {vsp_template.to_json}
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/collections/vsps.rb b/server/lib/cimi/collections/vsps.rb
new file mode 100644
index 0000000..52b1a5a
--- /dev/null
+++ b/server/lib/cimi/collections/vsps.rb
@@ -0,0 +1,108 @@
+# 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 Vsps < Base
+
+ check_capability :for => lambda { |m| driver.respond_to? m }
+ collection :vsps do
+
+ description 'A VSP represents the connection parameters of a network port'
+
+ operation :index do
+ description 'List all VSPs in the VSPCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ vsps = VSPCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {vsps.to_xml}
+ format.json {vsps.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific VSP'
+ control do
+ vsp = VSP.find(params[:id], self)
+ respond_to do |format|
+ format.xml {vsp.to_xml}
+ format.json {vsp.to_json}
+ end
+ end
+ end
+
+ operation :create do
+ description "Create a new VSP"
+ control do
+ if request.content_type.end_with?("json")
+ vsp = CIMI::Model::VSP.create(request.body.read, self, :json)
+ else
+ vsp = CIMI::Model::VSP.create(request.body.read, self, :xml)
+ end
+ respond_to do |format|
+ format.xml { vsp.to_xml }
+ format.json { vsp.to_json }
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a specified VSP"
+ control do
+ CIMI::Model::VSP.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
+ action :start do
+ description "Start specific VSP."
+ param :id, :string, :required
+ control do
+ vsp = VSP.find(params[:id], self)
+ report_error(404) unless vsp
+ if request.content_type.end_with?("json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ vsp.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ action :stop do
+ description "Stop specific VSP."
+ control do
+ vsp = VSP.find(params[:id], self)
+ report_error(404) unless vsp
+ if request.content_type.end_with?("json")
+ action = Action.from_json(request.body.read)
+ else
+ action = Action.from_xml(request.body.read)
+ end
+ vsp.perform(action, self) do |operation|
+ no_content_with_status(202) if operation.success?
+ # Handle errors using operation.failure?
+ end
+ end
+ end
+
+ end
+
+ end
+end
diff --git a/server/lib/cimi/helpers.rb b/server/lib/cimi/helpers.rb
new file mode 100644
index 0000000..4535c39
--- /dev/null
+++ b/server/lib/cimi/helpers.rb
@@ -0,0 +1,104 @@
+# 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 Deltacloud; end
+module CIMI; end
+
+require_relative '../deltacloud/drivers'
+require_relative '../deltacloud/models'
+require_relative '../deltacloud/helpers/driver_helper'
+require_relative '../deltacloud/helpers/auth_helper'
+require_relative '../deltacloud/helpers/url_helper'
+require_relative '../deltacloud/helpers/assets_helper'
+require_relative '../deltacloud/helpers/deltacloud_helper'
+require_relative '../deltacloud/helpers/rabbit_helper'
+require_relative '../deltacloud/helpers/rabbit_helper'
+require_relative '../deltacloud/core_ext/string'
+require_relative '../deltacloud/core_ext/array'
+require_relative '../deltacloud/core_ext/hash'
+require_relative '../deltacloud/core_ext/integer'
+require_relative '../deltacloud/core_ext/proc'
+require_relative './helpers/cimi_helper'
+require_relative './models'
+
+module CIMI::Collections
+ class Base < Sinatra::Base
+
+ extend Deltacloud::Helpers::Drivers
+ include Sinatra::Rabbit::Features
+ include CIMI::Model
+
+ helpers Deltacloud::Helpers::Drivers
+ helpers Sinatra::AuthHelper
+ helpers Sinatra::UrlForHelper
+ helpers Sinatra::StaticAssets::Helpers
+ helpers Rack::RespondTo::Helpers
+ helpers Deltacloud::Helpers::Application
+
+ register Rack::RespondTo
+
+ enable :xhtml
+ enable :dump_errors
+ enable :show_errors
+ disable :show_exceptions
+
+ set :root_url, API_ROOT_URL
+ set :version, API_VERSION
+ set :root, File.join(File.dirname(__FILE__), '..', '..')
+ set :views, root + '/views/cimi'
+ set :public_folder, root + '/public'
+
+ error do
+ report_error
+ end
+
+ error Deltacloud::ExceptionHandler::ValidationFailure do
+ report_error
+ end
+
+ before do
+ # Respond with 400, If we don't get a http Host header,
+ halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
+ end
+
+ after do
+ headers 'X-CIMI-Specification-Version' => API_VERSION
+ end
+
+ def self.new_route_for(route, &block)
+ get route_for('/' + route.to_s + '/new') do
+ instance_eval(&block) if block_given?
+ respond_to do |format|
+ format.html do
+ haml :"#{route}/new"
+ end
+ end
+ end
+ end
+
+ def self.check_capability(opts={})
+ Sinatra::Rabbit.set :check_capability, opts[:for]
+ end
+
+ def self.check_features(opts={})
+ Sinatra::Rabbit.set :check_features, opts[:for]
+ end
+
+ def self.route_for(url)
+ "#{settings.root_url}#{url}"
+ end
+
+ end
+end
diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
deleted file mode 100644
index fa3c771..0000000
--- a/server/lib/cimi/model.rb
+++ /dev/null
@@ -1,67 +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.
-#
-
-# Declare namespace for CIMI model
-#
-module CIMI
- module Model; end
-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'
-require 'cimi/model/machine_configuration'
-require 'cimi/model/action'
-require 'cimi/model/machine'
-require 'cimi/model/volume'
-require 'cimi/model/machine_admin'
-require 'cimi/model/volume_configuration'
-require 'cimi/model/volume_image'
-require 'cimi/model/volume_template'
-require 'cimi/model/machine_template_collection'
-require 'cimi/model/machine_image_collection'
-require 'cimi/model/machine_configuration_collection'
-require 'cimi/model/machine_collection'
-require 'cimi/model/volume_collection'
-require 'cimi/model/machine_admin_collection'
-require 'cimi/model/volume_configuration_collection'
-require 'cimi/model/volume_image_collection'
-require 'cimi/model/volume_template_collection'
-require 'cimi/model/entity_metadata'
-require 'cimi/model/entity_metadata_collection'
-require 'cimi/model/network'
-require 'cimi/model/network_collection'
-require 'cimi/model/network_configuration'
-require 'cimi/model/network_configuration_collection'
-require 'cimi/model/network_template'
-require 'cimi/model/network_template_collection'
-require 'cimi/model/routing_group'
-require 'cimi/model/routing_group_collection'
-require 'cimi/model/routing_group_template'
-require 'cimi/model/routing_group_template_collection'
-require 'cimi/model/vsp'
-require 'cimi/model/vsp_collection'
-require 'cimi/model/vsp_configuration'
-require 'cimi/model/vsp_configuration_collection'
-require 'cimi/model/vsp_template'
-require 'cimi/model/vsp_template_collection'
-require 'cimi/model/address'
-require 'cimi/model/address_collection'
-require 'cimi/model/address_template'
-require 'cimi/model/address_template_collection'
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
new file mode 100644
index 0000000..b0793ee
--- /dev/null
+++ b/server/lib/cimi/models.rb
@@ -0,0 +1,75 @@
+# 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 require_relatived 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_relative '../deltacloud/drivers/features'
+
+# Declare namespace for CIMI models
+#
+
+module CIMI
+ module Model; end
+
+ class FakeCollection
+ extend Sinatra::Rabbit::Features
+ include Deltacloud::InstanceFeatures
+ end
+end
+
+require_relative './models/schema'
+require_relative './models/base'
+require_relative './models/errors'
+require_relative './models/entity_metadata'
+require_relative './models/entity_metadata_collection'
+require_relative './models/cloud_entry_point'
+require_relative './models/machine_template'
+require_relative './models/machine_image'
+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/volume_configuration'
+require_relative './models/volume_image'
+require_relative './models/volume_template'
+require_relative './models/machine_template_collection'
+require_relative './models/machine_image_collection'
+require_relative './models/machine_configuration_collection'
+require_relative './models/machine_collection'
+require_relative './models/volume_collection'
+require_relative './models/machine_admin_collection'
+require_relative './models/volume_configuration_collection'
+require_relative './models/volume_image_collection'
+require_relative './models/volume_template_collection'
+require_relative './models/network'
+require_relative './models/network_collection'
+require_relative './models/network_configuration'
+require_relative './models/network_configuration_collection'
+require_relative './models/network_template'
+require_relative './models/network_template_collection'
+require_relative './models/routing_group'
+require_relative './models/routing_group_collection'
+require_relative './models/routing_group_template'
+require_relative './models/routing_group_template_collection'
+require_relative './models/vsp'
+require_relative './models/vsp_collection'
+require_relative './models/vsp_configuration'
+require_relative './models/vsp_configuration_collection'
+require_relative './models/vsp_template'
+require_relative './models/vsp_template_collection'
+require_relative './models/address'
+require_relative './models/address_collection'
+require_relative './models/address_template'
+require_relative './models/address_template_collection'
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 60f9a3b..a1c7ef9 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -13,947 +13,48 @@
# License for the specific language governing permissions and limitations
# under the License.
-require 'cimi/dependencies'
-require 'cimi/helpers/cimi_helper'
-require 'cimi/model'
+require 'rubygems'
+require 'crack'
+require 'json'
+require 'yaml'
+require 'haml'
+require 'sinatra/base'
+require 'sinatra/rabbit'
+require_relative '../sinatra'
-set :version, '0.1.0'
+require_relative './helpers'
+require_relative './collections'
-include Deltacloud::Drivers
-include CIMI::Model
+CMWG_NAMESPACE = "http://www.dmtf.org/cimi"
-set :drivers, Proc.new { driver_config }
+module CIMI
+ class API < Collections::Base
-Sinatra::Application.register Rack::RespondTo
+ # Enable logging
+ use Rack::CommonLogger
+ use Rack::Date
+ use Rack::ETag
+ use Rack::MatrixParams
+ use Rack::DriverSelect
+ use Rack::Accept
+ use Rack::MediaType
-use Rack::ETag
-use Rack::Runtime
-use Rack::MatrixParams
-use Rack::DriverSelect
-use Rack::MediaType
-use Rack::Date
-use Rack::CIMI
+ helpers CIMIHelper
-configure do
- set :root_url, "/cimi"
- set :views, File::join($top_srcdir, 'views', 'cimi')
- set :public_folder, File::join($top_srcdir, 'public')
- driver
-end
-
-configure :production do
- use Rack::SyslogLogger
- disable :logging
- enable :show_errors
- set :dump_errors, false
- $stdout = SyslogFile.new
- $stderr = $stdout
-end
-
-configure :development do
- set :raise_errors => false
- set :show_exceptions, false
- $stdout.sync = true
- $stderr.sync = true
-end
-
-# You could use $API_HOST environment variable to change your hostname to
-# whatever you want (eg. if you running API behind NAT)
-HOSTNAME=ENV['API_HOST'] ? ENV['API_HOST'] : nil
-
-error do
- report_error
-end
-
-get "/" do
- redirect settings.root_url
-end
-
-get "#{settings.root_url}\/?" do
- halt 401 if params[:force_auth] and not driver.valid_credentials?(credentials)
- redirect cloudEntryPoint_url, 301
-end
+ include Deltacloud::Helpers
+ include CIMI::Collections
+ include CIMI::Model
-global_collection :cloudEntryPoint do
- description 'Cloud entry point'
- operation :index do
- description "list all resources of the cloud"
- control do
- entry_point = CloudEntryPoint.create(self)
+ get API_ROOT_URL do
+ if params[:force_auth]
+ return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
+ end
+ entry_point = CIMI::Model::CloudEntryPoint.create(self)
respond_to do |format|
format.xml { entry_point.to_xml }
format.json { entry_point.to_json }
end
end
- end
-end
-
-global_collection :machine_configurations do
- description 'List all machine configurations'
-
- operation :index do
- param :CIMISelect, :string, :optional
- description "List all machine configurations"
- control do
- machine_configs = MachineConfigurationCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { machine_configs.to_xml }
- format.json { machine_configs.to_json }
- end
- end
- end
-
- operation :show do
-
- description "The Machine Configuration entity represents the set of configuration values "+
- "that define the (virtual) hardware resources of a to-be-realized Machine Instance.."
-
- param :id, :string, :required
-
- control do
- machine_conf = MachineConfiguration.find(params[:id], self)
- respond_to do |format|
- format.xml { machine_conf.to_xml }
- format.json { machine_conf.to_json }
- end
- end
-
- end
-end
-
-global_collection :machine_images do
- description 'List all machine images'
-
- operation :index do
- description "List all machine configurations"
- param :CIMISelect, :string, :optional
- control do
- machine_images = MachineImageCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { machine_images.to_xml }
- format.json { machine_images.to_json }
- end
- end
- end
-
- operation :show do
- description "Show specific machine image."
- param :id, :string, :required
- control do
- machine_image = MachineImage.find(params[:id], self)
- respond_to do |format|
- format.xml { machine_image.to_xml }
- format.json { machine_image.to_json }
- end
- end
- end
-
-end
-
-global_collection :machine_admins do
- description 'Machine Admin entity'
-
- operation :index do
- description "List all machine admins"
- param :CIMISelect, :string, :optional
- with_capability :keys
- control do
- machine_admins = MachineAdminCollection.default(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 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
-
- operation :delete, :method => :delete, :member => true do
- description "Delete specified MachineAdmin entity"
- param :id, :string, :required
- control do
- MachineAdmin.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
-end
-
-global_collection :machines do
- description 'List all machine'
-
- operation :index do
- param :CIMISelect, :string, :optional
- description "List all machines"
- control do
- machines = MachineCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { machines.to_xml }
- format.json { machines.to_json }
- end
- end
- end
-
- operation :show do
- description "Show specific machine."
- param :id, :string, :required
- control do
- machine = Machine.find(params[:id], self)
- respond_to do |format|
- format.xml { machine.to_xml }
- format.json { machine.to_json }
- end
- end
- end
- operation :create do
- description "Create a new Machine entity."
- control do
- if request.content_type.end_with?("+json")
- new_machine = Machine.create_from_json(request.body.read, self)
- else
- new_machine = Machine.create_from_xml(request.body.read, self)
- end
- status 201 # Created
- respond_to do |format|
- format.json { new_machine.to_json }
- format.xml { new_machine.to_xml }
- end
- end
end
-
- operation :destroy do
- description "Delete a specified machine."
- param :id, :string, :required
- control do
- Machine.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
- operation :stop, :method => :post, :member => true do
- description "Stop specific machine."
- param :id, :string, :required
- control do
- machine = Machine.find(params[:id], self)
- if request.content_type.end_with?("+json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- machine.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
- operation :restart, :method => :post, :member => true do
- description "Start specific machine."
- param :id, :string, :required
- control do
- machine = Machine.find(params[:id], self)
- if request.content_type.end_with?("+json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- machine.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
- operation :start, :method => :post, :member => true do
- description "Start specific machine."
- param :id, :string, :required
- control do
- machine = Machine.find(params[:id], self)
- if request.content_type.end_with?("+json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- machine.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
-#NOTE: The routes for attach/detach used here are NOT as specified by CIMI
-#will likely move later. CIMI specifies PUT of the whole Machine description
-#with inclusion/ommission of the volumes you want [att|det]ached
- operation :attach_volume, :method => :put, :member => true do
- description "Attach CIMI Volume(s) to a machine."
- param :id, :string, :required
- control do
- if request.content_type.end_with?("+json")
- volumes_to_attach = Volume.find_to_attach_from_json(request.body.read, self)
- else
- volumes_to_attach = Volume.find_to_attach_from_xml(request.body.read, self)
- end
- machine = Machine.attach_volumes(volumes_to_attach, self)
- respond_to do |format|
- format.json{ machine.to_json}
- format.xml{machine.to_xml}
- end
- end
- end
-
- operation :detach_volume, :method => :put, :member => true do
- description "Detach CIMI Volume(s) from a machine."
- param :id, :string, :required
- control do
- if request.content_type.end_with?("+json")
- volumes_to_detach = Volume.find_to_attach_from_json(request.body.read, self)
- else
- volumes_to_detach = Volume.find_to_attach_from_xml(request.body.read, self)
- end
- machine = Machine.detach_volumes(volumes_to_detach, self)
- respond_to do |format|
- format.json{ machine.to_json}
- format.xml{machine.to_xml}
- end
- end
- end
-end
-
-global_collection :volumes do
- description "Volume represents storage at either the block or file-system level. Volumes can be attached to Machines. Once attached, Volumes can be accessed by processes on that Machine"
-
- operation :index do
- description "List all volumes"
- param :CIMISelect, :string, :optional
- control do
- volumes = VolumeCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { volumes.to_xml }
- format.json { volumes.to_json }
- end
- end
- end
-
- operation :show do
- description "Show specific Volume."
- param :id, :string, :required
- control do
- volume = Volume.find(params[:id], self)
- if volume
- respond_to do |format|
- format.xml { volume.to_xml }
- format.json { volume.to_json }
- end
- else
- report_error(404)
- end
- end
- end
-
- operation :create do
- description "Create a new Volume."
- control do
- content_type = (request.content_type.end_with?("+json") ? :json : :xml)
- #((request.content_type.end_with?("+xml")) ? :xml : report_error(415) ) FIXME
- case content_type
- when :json
- new_volume = Volume.create_from_json(request.body.read, self)
- when :xml
- new_volume = Volume.create_from_xml(request.body.read, self)
- end
- respond_to do |format|
- format.json { new_volume.to_json }
- format.xml { new_volume.to_xml }
- end
- end
- end
-
- operation :destroy do
- description "Delete a specified Volume"
- param :id, :string, :required
- control do
- Volume.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
-end
-
-global_collection :volume_configurations do
- description "The Volume Configuration entity represents the set of configuration values needed to create a Volume with certain characteristics. Volume Configurations are created by Providers and MAY, at the Providers discretion, be created by Consumers"
-
- operation :index do
- description "Get list all VolumeConfigurations"
- param :CIMISelect, :string, :optional
- control do
- volume_configuration = VolumeConfigurationCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { volume_configuration.to_xml }
- format.json { volume_configuration.to_json }
- end
- end
- end
-
- operation :show do
- description "Get a specific VolumeConfiguration"
- param :id, :required, :string
- control do
- volume_config = VolumeConfiguration.find(params[:id], self)
- respond_to do |format|
- format.xml { volume_config.to_xml }
- format.json { volume_config.json }
- end
- end
- end
-
-global_collection :volume_images do
- description 'This entity represents an image that could be place on a pre-loaded volume.'
-
- operation :index do
- description "List all volumes images"
- param :CIMISelect, :string, :optional
- control do
- volume_images = VolumeImageCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { volume_images.to_xml }
- format.json { volume_images.to_json }
- end
- end
- end
-
- operation :show do
- description "Show a specific volume image"
- param :id, :string, :required
- control do
- volume_image = VolumeImage.find(params[:id], self)
- respond_to do |format|
- format.xml { volume_image.to_xml }
- format.json { volume_image.to_json }
- end
- end
- end
-
-end
-
-
-global_collection :entity_metadata do
- description 'This allows for the discovery of Provider defined constraints on the CIMI defined attributes as well as discovery of any new extension attributes that the Provider may have defined.'
-
- operation :index do
- description "List all entity metadata defined for this provider"
- control do
- entity_metadata = EntityMetadataCollection.default(self)
- respond_to do |format|
- format.xml{entity_metadata.to_xml}
- format.json{entity_metadata.to_json}
- end
- end
- end
-
- operation :show do
- description "Get the entity metadata for a specific collection"
- param :id, :required, :string
- control do
- entity_metadata = EntityMetadata.find(params[:id], self)
- respond_to do |format|
- format.xml{entity_metadata.to_xml}
- format.json{entity_metadata.to_json}
- end
- end
- end
-
-end
-
-global_collection :networks do
- description 'A Network represents an abstraction of a layer 2 broadcast domain'
-
- operation :index do
- description "List all Networks"
- param :CIMISelect, :string, :optional
- control do
- networks = NetworkCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { networks.to_xml }
- format.json { networks.to_json }
- end
- end
- end
-
- operation :show do
- description "Show a specific Network"
- param :id, :string, :required
- control do
- network = Network.find(params[:id], self)
- respond_to do |format|
- format.xml { network.to_xml }
- format.json { network.to_json }
- end
- end
- end
-
- operation :create do
- description "Create a new Network"
- control do
- if request.content_type.end_with?("json")
- network = Network.create(request.body.read, self, :json)
- else
- network = Network.create(request.body.read, self, :xml)
- end
- respond_to do |format|
- format.xml { network.to_xml}
- format.json { network.to_json }
- end
- end
- end
-
- operation :destroy do
- description "Delete a specified Network"
- param :id, :string, :required
- control do
- Network.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
- operation :start, :method => :post, :member => true do
- description "Start specific network."
- param :id, :string, :required
- control do
- network = Network.find(params[:id], self)
- report_error(404) unless network
- if request.content_type.end_with?("json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- network.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
- operation :stop, :method => :post, :member => true do
- description "Stop specific network."
- param :id, :string, :required
- control do
- network = Network.find(params[:id], self)
- report_error(404) unless network
- if request.content_type.end_with?("json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- network.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
- operation :suspend, :method => :post, :member => true do
- description "Suspend specific network."
- param :id, :string, :required
- control do
- network = Network.find(params[:id], self)
- report_error(404) unless network
- if request.content_type.end_with?("json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- network.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
-end
-
-global_collection :network_configurations do
- description 'Network Configurations contain the set of configuration values representing the information needed to create a Network with certain characteristics'
-
- operation :index do
- description 'List all NetworkConfigurations'
- param :CIMISelect, :string, :optional
- control do
- network_configurations = NetworkConfigurationCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml { network_configurations.to_xml }
- format.json { network_configurations.to_json }
- end
- end
- end
-
- operation :show do
- description 'Show a specific NetworkConfiguration'
- param :id, :string, :required
- control do
- network_config = NetworkConfiguration.find(params[:id], self)
- respond_to do |format|
- format.xml { network_config.to_xml }
- format.json { network_config.to_json }
- end
- end
- end
-end
-end
-
-global_collection :network_templates do
-
- description 'Network Template is a set of configuration values for realizing a Network. An instance of Network Template may be used to create multiple Networks'
-
- operation :index do
- description 'List all Network Templates in the NetworkTemplateCollection'
- param :CIMISelect, :string, :optional
- control do
- network_templates = NetworkTemplateCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {network_templates.to_xml}
- format.json {network_templates.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific Network Template'
- param :id, :string, :required
- control do
- network_template = NetworkTemplate.find(params[:id], self)
- respond_to do |format|
- format.xml {network_template.to_xml}
- format.json {network_template.to_json}
- end
- end
- end
-
-end
-
-
-global_collection :routing_groups do
-
- description 'Routing Groups represent a collection of Networks that route to each other. Providers shall not allow two Networks to be routable to each other unless they are explicitly connected by being part of a common RoutingGroup.'
-
- operation :index do
- description 'List all RoutingGroups in the RoutingGroupsCollection'
- param :CIMISelect, :string, :optional
- control do
- routing_groups = RoutingGroupCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {routing_groups.to_xml}
- format.json {routing_groups.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific RoutingGroup'
- param :id, :string, :required
- control do
- routing_group = RoutingGroup.find(params[:id], self)
- respond_to do |format|
- format.xml {routing_group.to_xml}
- format.json {routing_group.to_json}
- end
- end
- end
-
-end
-
-
-global_collection :routing_group_templates do
-
- description 'Routing Groups Templates capture the configuration values for realizing a RoutingGroup. A Routing Group Template may be used to create multiple RoutingGroups'
-
- operation :index do
- description 'List all RoutingGroupTemplates in the RoutingGroupTemplateCollection'
- param :CIMISelect, :string, :optional
- control do
- routing_group_templates = RoutingGroupTemplateCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {routing_group_templates.to_xml}
- format.json {routing_group_templates.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific RoutingGroupTemplate'
- param :id, :string, :required
- control do
- routing_group_template = RoutingGroupTemplate.find(params[:id], self)
- respond_to do |format|
- format.xml {routing_group_template.to_xml}
- format.json {routing_group_template.to_json}
- end
- end
- end
-
-end
-
-
-global_collection :vsps do
-
- description 'A VSP represents the connection parameters of a network port'
-
- operation :index do
- description 'List all VSPs in the VSPCollection'
- param :CIMISelect, :string, :optional
- control do
- vsps = VSPCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {vsps.to_xml}
- format.json {vsps.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific VSP'
- param :id, :string, :required
- control do
- vsp = VSP.find(params[:id], self)
- respond_to do |format|
- format.xml {vsp.to_xml}
- format.json {vsp.to_json}
- end
- end
- end
-
- operation :create do
- description "Create a new VSP"
- control do
- if request.content_type.end_with?("json")
- vsp = CIMI::Model::VSP.create(request.body.read, self, :json)
- else
- vsp = CIMI::Model::VSP.create(request.body.read, self, :xml)
- end
- respond_to do |format|
- format.xml { vsp.to_xml }
- format.json { vsp.to_json }
- end
- end
- end
-
- operation :destroy do
- description "Delete a specified VSP"
- param :id, :string, :required
- control do
- CIMI::Model::VSP.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
- operation :start, :method => :post, :member => true do
- description "Start specific VSP."
- param :id, :string, :required
- control do
- vsp = VSP.find(params[:id], self)
- report_error(404) unless vsp
- if request.content_type.end_with?("json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- vsp.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
- operation :stop, :method => :post, :member => true do
- description "Stop specific VSP."
- param :id, :string, :required
- control do
- vsp = VSP.find(params[:id], self)
- report_error(404) unless vsp
- if request.content_type.end_with?("json")
- action = Action.from_json(request.body.read)
- else
- action = Action.from_xml(request.body.read)
- end
- vsp.perform(action, self) do |operation|
- no_content_with_status(202) if operation.success?
- # Handle errors using operation.failure?
- end
- end
- end
-
-end
-
-global_collection :vsp_configurations do
-
- description 'A VSP Configuration is the set of configuration values representing the information needed to create a VSP with certain characteristics'
-
- operation :index do
- description 'List all VSPConfigurations in the VSPConfigurationCollection'
- param :CIMISelect, :string, :optional
- control do
- vsp_configs = VSPConfigurationCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {vsp_configs.to_xml}
- format.json {vsp_configs.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific VSPConfiguration'
- param :id, :string, :required
- control do
- vsp_config = VSPConfiguration.find(params[:id], self)
- respond_to do |format|
- format.xml {vsp_config.to_xml}
- format.json {vsp_config.to_json}
- end
- end
- end
-
-end
-
-
-global_collection :vsp_templates do
-
- description 'The VSP Template is a set of Configuration values for realizing a VSP. A VSP Template may be used to create multiple VSPs'
-
- operation :index do
- description 'List all VSPTemplates in the VSPTemplateCollection'
- param :CIMISelect, :string, :optional
- control do
- vsp_templates = VSPTemplateCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {vsp_templates.to_xml}
- format.json {vsp_templates.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific VSPTemplate'
- param :id, :string, :required
- control do
- vsp_template = VSPTemplate.find(params[:id], self)
- respond_to do |format|
- format.xml {vsp_template.to_xml}
- format.json {vsp_template.to_json}
- end
- end
- end
-
-end
-
-global_collection :addresses do
-
- description 'An Address represents an IP address, and its associated metdata, for a particular Network.'
-
- operation :index do
- description 'List all Addresses in the AddressCollection'
- param :CIMISelect, :string, :optional
- control do
- addresses = AddressCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {addresses.to_xml}
- format.json {addresses.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific Address'
- param :id, :string, :required
- control do
- address = CIMI::Model::Address.find(params[:id], self)
- respond_to do |format|
- format.xml {address.to_xml}
- format.json {address.to_json}
- end
- end
- end
-
- operation :create do
- description "Create a new Address"
- control do
- if request.content_type.end_with?("json")
- address = CIMI::Model::Address.create(request.body.read, self, :json)
- else
- address = CIMI::Model::Address.create(request.body.read, self, :xml)
- end
- respond_to do |format|
- format.xml { address.to_xml }
- format.json { address.to_json }
- end
- end
- end
-
- operation :destroy do
- description "Delete a specified Address"
- param :id, :string, :required
- control do
- CIMI::Model::Address.delete!(params[:id], self)
- no_content_with_status(200)
- end
- end
-
-end
-
-
-global_collection :address_templates do
-
- description 'An AddressTemplate captures the configuration values for realizing an Address. An Address Template may be used to create multiple Addresses.'
-
- operation :index do
- description 'List all AddressTemplates in the AddressTemplateCollection'
- param :CIMISelect, :string, :optional
- control do
- address_templates = AddressTemplateCollection.default(self).filter_by(params[:CIMISelect])
- respond_to do |format|
- format.xml {address_templates.to_xml}
- format.json {address_templates.to_json}
- end
- end
- end
-
- operation :show do
- description 'Show a specific AddressTemplate'
- param :id, :string, :required
- control do
- address_template = CIMI::Model::AddressTemplate.find(params[:id], self)
- respond_to do |format|
- format.xml {address_template.to_xml}
- format.json {address_template.to_json}
- end
- end
- end
-
end
--
1.7.10