From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/lib/cimi/collections/address_templates.rb | 46 ++----------------- server/lib/cimi/collections/addresses.rb | 48 +++----------------- server/lib/cimi/collections/base.rb | 6 ++- server/lib/cimi/collections/credentials.rb | 47 ++----------------- .../cimi/collections/forwarding_group_templates.rb | 22 +-------- server/lib/cimi/collections/forwarding_groups.rb | 23 +--------- .../lib/cimi/collections/machine_configurations.rb | 22 +-------- server/lib/cimi/collections/machine_images.rb | 46 ++----------------- server/lib/cimi/collections/machine_templates.rb | 46 ++----------------- server/lib/cimi/collections/machines.rb | 46 ++----------------- .../lib/cimi/collections/network_configurations.rb | 22 +-------- .../collections/network_port_configurations.rb | 23 +--------- .../lib/cimi/collections/network_port_templates.rb | 25 +---------- server/lib/cimi/collections/network_ports.rb | 52 +++------------------- server/lib/cimi/collections/network_templates.rb | 23 +--------- server/lib/cimi/collections/networks.rb | 44 ++---------------- server/lib/cimi/collections/resource_metadata.rb | 23 +--------- server/lib/cimi/collections/system_templates.rb | 49 ++------------------ server/lib/cimi/collections/systems.rb | 49 ++------------------ .../lib/cimi/collections/volume_configurations.rb | 49 ++------------------ server/lib/cimi/collections/volume_images.rb | 46 ++----------------- server/lib/cimi/collections/volume_templates.rb | 49 +++----------------- server/lib/cimi/collections/volumes.rb | 52 ++-------------------- server/lib/cimi/helpers.rb | 1 + server/lib/cimi/service/cloud_entry_point.rb | 4 ++ 25 files changed, 86 insertions(+), 777 deletions(-) diff --git a/server/lib/cimi/collections/address_templates.rb b/server/lib/cimi/collections/address_templates.rb index 99fe745..0754002 100644 --- a/server/lib/cimi/collections/address_templates.rb +++ b/server/lib/cimi/collections/address_templates.rb @@ -20,48 +20,10 @@ module CIMI::Collections collection :address_templates do - operation :index do - description 'List all AddressTemplates in the AddressTemplateCollection' - control do - address_templates = AddressTemplate.list(self).select_by(params['$select']) - 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 = AddressTemplate.find(params[:id], self) - respond_to do |format| - format.xml {address_template.to_xml} - format.json {address_template.to_json} - end - end - end - - operation :create do - description "Create new AddressTemplate" - control do - addr_templ = AddressTemplateCreate.parse(self) - new_address_template = addr_templ.create - headers_for_create new_address_template - respond_to do |format| - format.json { new_address_template.to_json } - format.xml { new_address_template.to_xml } - end - end - end - - operation :destroy do - description "Delete a specified AddressTemplate" - control do - AddressTemplate.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_index_operation + generate_show_operation + generate_create_operation + generate_delete_operation end diff --git a/server/lib/cimi/collections/addresses.rb b/server/lib/cimi/collections/addresses.rb index 682cce4..1877c67 100644 --- a/server/lib/cimi/collections/addresses.rb +++ b/server/lib/cimi/collections/addresses.rb @@ -19,53 +19,15 @@ module CIMI::Collections set :capability, lambda { |m| driver.respond_to? m } collection :addresses do - description 'An Address represents an IP address, and its associated metadata, for a particular Network.' - operation :index, :with_capability => :addresses do - description 'List all Addresses in the AddressCollection' - control do - addresses = Address.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {addresses.to_xml} - format.json {addresses.to_json} - end - end - end - - operation :show, :with_capability => :address do - description 'Show a specific Address' - control do - address = Address.find(params[:id], self) - respond_to do |format| - format.xml {address.to_xml} - format.json {address.to_json} - end - end - end - - operation :create, :with_capability => :create_address do - description "Create a new Address" - control do - addr = AddressCreate.parse(self) - address = addr.create - respond_to do |format| - format.xml { address.to_xml } - format.json { address.to_json } - end - end - end - - operation :destroy, :with_capability => :delete_address do - description "Delete a specified Address" - param :id, :string, :required - control do - Address.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_index_operation :with_capability => :addresses + generate_show_operation :with_capability => :address + generate_delete_operation :with_capability => :destroy_address + generate_create_operation :with_capability => :create_address end + end end diff --git a/server/lib/cimi/collections/base.rb b/server/lib/cimi/collections/base.rb index 29657ab..515a074 100644 --- a/server/lib/cimi/collections/base.rb +++ b/server/lib/cimi/collections/base.rb @@ -22,6 +22,10 @@ module CIMI::Collections enable :use_namespace end + helpers Sinatra::Rabbit::URLHelper + + Sinatra::Rabbit::Collection.extend(CIMI::RabbitHelper) + include Sinatra::Rabbit include Sinatra::Rabbit::Features include CIMI::Service @@ -29,7 +33,7 @@ module CIMI::Collections helpers Deltacloud::Helpers::Drivers helpers Deltacloud::Helpers::Database helpers Sinatra::AuthHelper - helpers Sinatra::Rabbit::URLHelper + helpers Deltacloud::Helpers::Application helpers CIMI::Helper diff --git a/server/lib/cimi/collections/credentials.rb b/server/lib/cimi/collections/credentials.rb index 0cd44b9..5abbd85 100644 --- a/server/lib/cimi/collections/credentials.rb +++ b/server/lib/cimi/collections/credentials.rb @@ -21,49 +21,10 @@ module CIMI::Collections collection :credentials do description 'Machine Admin entity' - operation :index, :with_capability => :keys do - description "List all machine admins" - control do - credentials = Credential.list(self).select_by(params['$select']) - 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 - c = CredentialCreate.parse(self) - new_admin = c.create - headers_for_create new_admin - 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 - + generate_show_operation :with_capability => :keys + generate_index_operation :with_capability => :keys + generate_create_operation :with_capability => :create_key + generate_delete_operation :with_capability => :delete_key end end diff --git a/server/lib/cimi/collections/forwarding_group_templates.rb b/server/lib/cimi/collections/forwarding_group_templates.rb index 98c19d5..072783a 100644 --- a/server/lib/cimi/collections/forwarding_group_templates.rb +++ b/server/lib/cimi/collections/forwarding_group_templates.rb @@ -19,27 +19,9 @@ module CIMI::Collections collection :forwarding_group_templates do - operation :index, :with_capability => :forwarding_groups do - description 'List all ForwardingGroupTemplates in the ForwardingGroupTemplateCollection' - control do - forwarding_group_templates = ForwardingGroupTemplate.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {forwarding_group_templates.to_xml} - format.json {forwarding_group_templates.to_json} - end - end - end + generate_index_operation :with_capability => :forwarding_groups + generate_show_operation :with_capability => :forwarding_groups - operation :show, :with_capability => :forwarding_groups do - description 'Show a specific ForwardingGroupTemplate' - control do - forwarding_group_template = ForwardingGroupTemplate.find(params[:id], self) - respond_to do |format| - format.xml {forwarding_group_template.to_xml} - format.json {forwarding_group_template.to_json} - end - end - end end end diff --git a/server/lib/cimi/collections/forwarding_groups.rb b/server/lib/cimi/collections/forwarding_groups.rb index 6422b50..fe2ec3d 100644 --- a/server/lib/cimi/collections/forwarding_groups.rb +++ b/server/lib/cimi/collections/forwarding_groups.rb @@ -19,27 +19,8 @@ module CIMI::Collections collection :forwarding_groups do - operation :index, :with_capability => :forwarding_groups do - description 'List all ForwardingGroups in the ForwardingGroupsCollection' - control do - forwarding_groups = ForwardingGroup.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {forwarding_groups.to_xml} - format.json {forwarding_groups.to_json} - end - end - end - - operation :show, :with_capability => :forwarding_groups do - description 'Show a specific ForwardingGroup' - control do - forwarding_group = ForwardingGroup.find(params[:id], self) - respond_to do |format| - format.xml {forwarding_group.to_xml} - format.json {forwarding_group.to_json} - end - end - end + generate_index_operation :with_capability => :forwarding_groups + generate_show_operation :with_capability => :forwarding_groups end diff --git a/server/lib/cimi/collections/machine_configurations.rb b/server/lib/cimi/collections/machine_configurations.rb index 2d75559..6a48183 100644 --- a/server/lib/cimi/collections/machine_configurations.rb +++ b/server/lib/cimi/collections/machine_configurations.rb @@ -21,27 +21,9 @@ module CIMI::Collections collection :machine_configurations do description 'List all machine configurations' - operation :index, :with_capability => :hardware_profiles do - description "List all machine configurations" - control do - machine_configs = MachineConfiguration.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { machine_configs.to_xml } - format.json { machine_configs.to_json } - end - end - end + generate_show_operation :with_capability => :hardware_profile + generate_index_operation :with_capability => :hardware_profiles - operation :show, :with_capability => :hardware_profile 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 diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb index 66c74c2..3c6e5f3 100644 --- a/server/lib/cimi/collections/machine_images.rb +++ b/server/lib/cimi/collections/machine_images.rb @@ -21,48 +21,10 @@ module CIMI::Collections collection :machine_images do description 'List all machine images' - operation :index, :with_capability => :images do - description "List all machine configurations" - control do - machine_images = MachineImage.list(self) - respond_to do |format| - format.xml { machine_images.to_xml } - format.json { machine_images.to_json } - end - end - end - - operation :show, :with_capability => :image 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 - - operation :create, :with_capability => :create_image do - description "Create a new machine image." - control do - mi = MachineImageCreate.parse(self) - machine_image = mi.create - headers_for_create machine_image - respond_to do |format| - format.xml { machine_image.to_xml } - format.json { machine_image.to_json } - end - end - end - - operation :destroy, :with_capability => :destroy_image do - description "Delete a specified MachineImage" - control do - MachineImage.delete!(params[:id], self) - no_content_with_status 200 - end - end + generate_show_operation :with_capability => :image + generate_index_operation :with_capability => :images + generate_delete_operation :with_capability => :destroy_image + generate_create_operation :with_capability => :create_image end diff --git a/server/lib/cimi/collections/machine_templates.rb b/server/lib/cimi/collections/machine_templates.rb index fcdafcc..04f9093 100644 --- a/server/lib/cimi/collections/machine_templates.rb +++ b/server/lib/cimi/collections/machine_templates.rb @@ -20,48 +20,10 @@ module CIMI::Collections collection :machine_templates do - operation :index do - description "List all machine templates" - control do - machine_templates = MachineTemplate.list(self) - respond_to do |format| - format.xml { machine_templates.to_xml } - format.json { machine_templates.to_json } - end - end - end - - operation :show do - description "Show specific machine template" - control do - machine_template = MachineTemplate.find(params[:id], self) - respond_to do |format| - format.xml { machine_template.to_xml } - format.json { machine_template.to_json } - end - end - end - - operation :create do - description "Create new machine template" - control do - mt = MachineTemplateCreate.parse(self) - new_machine_template = mt.create - headers_for_create new_machine_template - respond_to do |format| - format.json { new_machine_template.to_json } - format.xml { new_machine_template.to_xml } - end - end - end - - operation :destroy do - description "Delete a specified machine template" - control do - MachineTemplate.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_show_operation + generate_index_operation + generate_create_operation + generate_delete_operation end diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb index f74b02b..0892604 100644 --- a/server/lib/cimi/collections/machines.rb +++ b/server/lib/cimi/collections/machines.rb @@ -21,48 +21,10 @@ module CIMI::Collections collection :machines do description 'List all machine' - operation :index, :with_capability => :instances do - description "List all machines" - control do - machines = Machine.list(self) - respond_to do |format| - format.xml { machines.to_xml } - format.json { machines.to_json } - end - end - end - - operation :show, :with_capability => :instance 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, :with_capability => :create_instance do - description "Create a new Machine entity." - control do - mc = MachineCreate.parse(self) - new_machine = mc.create - headers_for_create new_machine - respond_to do |format| - format.json { new_machine.to_json } - format.xml { new_machine.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_instance do - description "Delete a specified machine." - control do - Machine.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_show_operation :with_capability => :instance + generate_index_operation :with_capability => :instances + generate_delete_operation :with_capability => :destroy_instance + generate_create_operation :with_capability => :create_instance action :stop, :with_capability => :stop_instance do description "Stop specific machine." diff --git a/server/lib/cimi/collections/network_configurations.rb b/server/lib/cimi/collections/network_configurations.rb index 5dcaa9b..007f844 100644 --- a/server/lib/cimi/collections/network_configurations.rb +++ b/server/lib/cimi/collections/network_configurations.rb @@ -20,27 +20,9 @@ module CIMI::Collections collection :network_configurations do - operation :index, :with_capability => :network_configurations do - description 'List all NetworkConfigurations' - control do - network_configurations = NetworkConfiguration.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { network_configurations.to_xml } - format.json { network_configurations.to_json } - end - end - end + generate_show_operation :with_capability => :network_configurations + generate_index_operation :with_capability => :network_configurations - operation :show, :with_capability => :network_configurations 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 diff --git a/server/lib/cimi/collections/network_port_configurations.rb b/server/lib/cimi/collections/network_port_configurations.rb index 52a8b86..ea1b49b 100644 --- a/server/lib/cimi/collections/network_port_configurations.rb +++ b/server/lib/cimi/collections/network_port_configurations.rb @@ -20,27 +20,8 @@ module CIMI::Collections collection :network_port_configurations do - operation :index, :with_capability => :network_port_configurations do - description 'List all NetworkPortConfigurations in the NetworkPortConfigurationCollection' - control do - net_port_configs = NetworkPortConfiguration.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {net_port_configs.to_xml} - format.json {net_port_configs.to_json} - end - end - end - - operation :show, :with_capability => :network_port_configurations do - description 'Show a specific NetworkPortConfiguration' - control do - net_port_config = NetworkPortConfiguration.find(params[:id], self) - respond_to do |format| - format.xml {net_port_config.to_xml} - format.json {net_port_config.to_json} - end - end - end + generate_index_operation :with_capability => :network_port_configurations + generate_show_operation :with_capability => :network_port_configurations end diff --git a/server/lib/cimi/collections/network_port_templates.rb b/server/lib/cimi/collections/network_port_templates.rb index 94c6744..38f6b4d 100644 --- a/server/lib/cimi/collections/network_port_templates.rb +++ b/server/lib/cimi/collections/network_port_templates.rb @@ -20,29 +20,8 @@ module CIMI::Collections 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' - control do - network_port_templates = NetworkPortTemplate.list(self).select_by(params['$select']) - 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 + generate_show_operation :with_capability => :network_port_templates + generate_index_operation :with_capability => :network_port_templates end diff --git a/server/lib/cimi/collections/network_ports.rb b/server/lib/cimi/collections/network_ports.rb index 021ae7b..878b532 100644 --- a/server/lib/cimi/collections/network_ports.rb +++ b/server/lib/cimi/collections/network_ports.rb @@ -19,53 +19,13 @@ module CIMI::Collections set :capability, lambda { |m| driver.respond_to? m } collection :network_ports do + description 'A NetworkPort is a realized connection point between a Network'+ + ' and a resource - such as a Machine.' - description 'A NetworkPort is a realized connection point between a Network and a resource - such as a Machine.' - - operation :index, :with_capability => :network_ports do - description 'List all NetworkPorts in the NetworkPortCollection' - control do - network_ports = NetworkPort.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {network_ports.to_xml} - format.json {network_ports.to_json} - end - end - end - - operation :show, :with_capability => :network_ports do - description 'Show a specific NetworkPort' - control do - network_port = NetworkPort.find(params[:id], self) - respond_to do |format| - format.xml {network_port.to_xml} - format.json {network_port.to_json} - end - end - end - - operation :create, :with_capability => :create_network_port do - description "Create a new NetworkPort" - control do - if current_content_type == :json - network_port = NetworkPort.create(request.body.read, self, :json) - else - network_port = NetworkPort.create(request.body.read, self, :xml) - end - respond_to do |format| - format.xml { network_port.to_xml } - format.json { network_port.to_json } - end - end - end - - operation :destroy, :with_capability => :delete_network_port do - description "Delete a specified NetworkPort" - control do - NetworkPort.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_show_operation :with_capability => :network_port + generate_index_operation :with_capability => :networks_ports + generate_create_operation :with_capability => :create_network_port + generate_delete_operation :with_capability => :destroy_network_port action :start, :with_capability => :start_network_port do description "Start specific NetworkPort." diff --git a/server/lib/cimi/collections/network_templates.rb b/server/lib/cimi/collections/network_templates.rb index 541d607..887f1db 100644 --- a/server/lib/cimi/collections/network_templates.rb +++ b/server/lib/cimi/collections/network_templates.rb @@ -20,27 +20,8 @@ module CIMI::Collections collection :network_templates do - operation :index, :with_capability => :network_templates do - description 'List all Network Templates in the NetworkTemplateCollection' - control do - network_templates = NetworkTemplate.list(self).select_by(params['$select']) - respond_to do |format| - format.xml {network_templates.to_xml} - format.json {network_templates.to_json} - end - end - end - - operation :show, :with_capability => :network_templates 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 + generate_index_operation :with_capability => :network_templates + generate_show_operation :with_capability => :network_templates end diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb index f3d6fc9..92f56ca 100644 --- a/server/lib/cimi/collections/networks.rb +++ b/server/lib/cimi/collections/networks.rb @@ -21,47 +21,11 @@ module CIMI::Collections collection :networks do description 'A Network represents an abstraction of a layer 2 broadcast domain' - operation :index, :with_capability => :networks do - description "List all Networks" - control do - networks = Network.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { networks.to_xml } - format.json { networks.to_json } - end - end - end + generate_show_operation :with_capability => :network + generate_index_operation :with_capability => :networks + generate_delete_operation :with_capability => :destroy_network + generate_create_operation :with_capability => :create_network - operation :show, :with_capability => :networks 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, :with_capability => :create_network do - description "Create a new Network" - control do - n = NetworkCreate.parse(self) - network = n.create - respond_to do |format| - format.xml { network.to_xml} - format.json { network.to_json } - end - end - end - - operation :destroy, :with_capability => :delete_network do - description "Delete a specified Network" - control do - Network.delete!(params[:id], self) - no_content_with_status(200) - end - end action :start, :with_capability => :start_network do description "Start specific network." diff --git a/server/lib/cimi/collections/resource_metadata.rb b/server/lib/cimi/collections/resource_metadata.rb index f27ee33..b453dc6 100644 --- a/server/lib/cimi/collections/resource_metadata.rb +++ b/server/lib/cimi/collections/resource_metadata.rb @@ -18,27 +18,8 @@ module CIMI::Collections collection :resource_metadata do - operation :index do - description "List all resource metadata defined for this provider" - control do - resource_metadata = CIMI::Service::ResourceMetadata.list(self) - respond_to do |format| - format.xml{resource_metadata.to_xml} - format.json{resource_metadata.to_json} - end - end - end - - operation :show do - description "Get the resource metadata for a specific collection" - control do - resource_metadata = CIMI::Service::ResourceMetadata.find(params[:id], self) - respond_to do |format| - format.xml{resource_metadata.to_xml} - format.json{resource_metadata.to_json} - end - end - end + generate_index_operation + generate_show_operation end diff --git a/server/lib/cimi/collections/system_templates.rb b/server/lib/cimi/collections/system_templates.rb index fe27cd3..d7e51f6 100644 --- a/server/lib/cimi/collections/system_templates.rb +++ b/server/lib/cimi/collections/system_templates.rb @@ -20,51 +20,10 @@ module CIMI::Collections collection :system_templates do - operation :index, :with_capability => :system_templates do - description "List all system templates" - control do - system_templates = SystemTemplate.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { system_templates.to_xml } - format.json { system_templates.to_json } - end - end - end - - operation :show, :with_capability => :system_templates do - description "Show specific system template" - control do - system_template = SystemTemplate.find(params[:id], self) - respond_to do |format| - format.xml { system_template.to_xml } - format.json { system_template.to_json } - end - end - end - - operation :create, :with_capability => :create_system_template do - description "Create new system template" - control do - if grab_content_type(request.content_type, request.body) == :json - new_system_template = SystemTemplate.create_from_json(request.body.read, self) - else - new_system_template = SystemTemplate.create_from_xml(request.body.read, self) - end - headers_for_create new_system_template - respond_to do |format| - format.json { new_system_template.to_json } - format.xml { new_system_template.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_system_template do - description "Delete a specified system template" - control do - SystemTemplate.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_index_operation :with_capability => :system_templates + generate_show_operation :with_capability => :system_templates + generate_create_operation :with_capability => :create_system_template + generate_delete_operation :with_capability => :destroy_system_template end diff --git a/server/lib/cimi/collections/systems.rb b/server/lib/cimi/collections/systems.rb index a6adb8d..5c3903e 100644 --- a/server/lib/cimi/collections/systems.rb +++ b/server/lib/cimi/collections/systems.rb @@ -21,51 +21,10 @@ module CIMI::Collections collection :systems do description 'List all systems' - operation :index, :with_capability => :systems do - description "List all systems" - control do - systems = System.list(self).select_by(params['$select']).filter_by(params['$filter']) - respond_to do |format| - format.xml { systems.to_xml } - format.json { systems.to_json } - end - end - end - - operation :show, :with_capability => :systems do - description "Show specific system." - control do - system = System.find(params[:id], self) - respond_to do |format| - format.xml { system.to_xml } - format.json { system.to_json } - end - end - end - - operation :create, :with_capability => :create_system do - description "Create a new System entity." - control do - if grab_content_type(request.content_type, request.body) == :json - new_system = System.create_from_json(request.body.read, self) - else - new_system = System.create_from_xml(request.body.read, self) - end - headers_for_create new_system - respond_to do |format| - format.json { new_system.to_json } - format.xml { new_system.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_system do - description "Delete a specified system." - control do - System.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_index_operation :with_capability => :systems + generate_show_operation :with_capability => :systems + generate_create_operation :with_capability => :create_system + generate_delete_operation :with_capability => :destroy_system action :stop, :with_capability => :stop_system do description "Stop specific system." diff --git a/server/lib/cimi/collections/volume_configurations.rb b/server/lib/cimi/collections/volume_configurations.rb index 45a9d47..405e194 100644 --- a/server/lib/cimi/collections/volume_configurations.rb +++ b/server/lib/cimi/collections/volume_configurations.rb @@ -20,51 +20,10 @@ module CIMI::Collections collection :volume_configurations do - operation :index, :with_capability => :storage_volumes do - description "Get list all VolumeConfigurations" - control do - volume_configuration = VolumeConfiguration.list(self) - respond_to do |format| - format.xml { volume_configuration.to_xml } - format.json { volume_configuration.to_json } - end - end - end - - operation :show, :with_capability => :storage_volume 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 - - operation :create, :with_capability => :create_storage_volume do - description "Create new VolumeConfiguration" - control do - if current_content_type == :json - new_config = VolumeConfiguration.create_from_json(request.body.read, self) - else - new_config = VolumeConfiguration.create_from_xml(request.body.read, self) - end - headers_for_create new_config - respond_to do |format| - format.json { new_config.to_json } - format.xml { new_config.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_storage_volume do - description "Delete a specified VolumeConfiguration" - control do - VolumeConfiguration.delete!(params[:id], self) - no_content_with_status(200) - end - end + generate_index_operation :with_capability => :storage_volumes + generate_show_operation :with_capability => :storage_volume + generate_create_operation :with_capability => :create_storage_volume + generate_delete_operation :with_capability => :storage_volume end diff --git a/server/lib/cimi/collections/volume_images.rb b/server/lib/cimi/collections/volume_images.rb index b9970b4..22ae879 100644 --- a/server/lib/cimi/collections/volume_images.rb +++ b/server/lib/cimi/collections/volume_images.rb @@ -21,48 +21,10 @@ module CIMI::Collections collection :volume_images do description 'This entity represents an image that could be place on a pre-loaded volume.' - operation :index, :with_capability => :storage_snapshots do - description "List all volumes images" - control do - volume_images = VolumeImage.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { volume_images.to_xml } - format.json { volume_images.to_json } - end - end - end - - operation :show, :with_capability => :storage_snapshot 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 - - operation :create, :with_capability => :create_storage_snapshot do - description "Create a new volume image." - control do - img = VolumeImageCreate.parse(self) - volume_image = img.create - headers_for_create volume_image - respond_to do |format| - format.xml { volume_image.to_xml } - format.json { volume_image.to_json } - end - end - end - - operation :destroy, :with_capability => :destroy_storage_snapshot do - description "Delete a specified VolumeImage" - control do - VolumeImage.delete!(params[:id], self) - no_content_with_status 200 - end - end + generate_index_operation :with_capability => :storage_snapshots + generate_show_operation :with_capability => :storage_snapshot + generate_create_operation :with_capability => :create_storage_snapshot + generate_delete_operation :with_capability => :destroy_storage_snapshot end diff --git a/server/lib/cimi/collections/volume_templates.rb b/server/lib/cimi/collections/volume_templates.rb index 556fe96..9e2a2b4 100644 --- a/server/lib/cimi/collections/volume_templates.rb +++ b/server/lib/cimi/collections/volume_templates.rb @@ -20,51 +20,12 @@ module CIMI::Collections collection :volume_templates do - operation :index, :with_capability => :storage_volumes do - description "Retrieve the Volume Template Collection" - control do - volume_template = VolumeTemplate.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { volume_template.to_xml } - format.json { volume_template.to_json } - end - end - end + generate_index_operation :with_capability => :storage_volumes + generate_show_operation :with_capability => :storage_volume + generate_create_operation :with_capability => :create_storage_volume + generate_delete_operation :with_capability => :destroy_storage_volume - operation :show, :with_capability => :storage_volume do - description "Get a specific VolumeTemplate" - control do - volume_template = VolumeTemplate.find(params[:id], self) - respond_to do |format| - format.xml { volume_template.to_xml } - format.json { volume_template.json } - end - end - end - - operation :create, :with_capability => :create_storage_volume do - description "Create new VolumeTemplate" - control do - puts request.body - vol = VolumeTemplateCreate.parse(self) - new_template = vol.create - headers_for_create new_template - respond_to do |format| - format.json { new_template.to_json } - format.xml { new_template.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_storage_volume do - description "Delete a specified VolumeTemplate" - control do - VolumeTemplate.delete!(params[:id], self) - no_content_with_status(200) - end - end - - end + end end end diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb index 49a58b3..c32cfa8 100644 --- a/server/lib/cimi/collections/volumes.rb +++ b/server/lib/cimi/collections/volumes.rb @@ -19,54 +19,10 @@ module CIMI::Collections set :capability, lambda { |m| driver.respond_to? m } collection :volumes do - - operation :index, :with_capability => :storage_volumes do - description "List all volumes" - control do - volumes = Volume.list(self).select_by(params['$select']) - respond_to do |format| - format.xml { volumes.to_xml } - format.json { volumes.to_json } - end - end - end - - operation :show, :with_capability => :storage_volume 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, :with_capability => :create_storage_volume do - description "Create a new Volume." - control do - vol = VolumeCreate.parse(self) - new_volume = vol.create - headers_for_create new_volume - respond_to do |format| - format.json { new_volume.to_json } - format.xml { new_volume.to_xml } - end - end - end - - operation :destroy, :with_capability => :destroy_storage_volume do - description "Delete a specified Volume" - control do - Volume.delete!(params[:id], self) - no_content_with_status(200) - end - end - + generate_index_operation :with_capability => :storage_volumes + generate_show_operation :with_capability => :storage_volume + generate_create_operation :with_capability => :create_storage_volume + generate_delete_operation :with_capability => :destroy_storage_volume end diff --git a/server/lib/cimi/helpers.rb b/server/lib/cimi/helpers.rb index 75f9770..43f61f3 100644 --- a/server/lib/cimi/helpers.rb +++ b/server/lib/cimi/helpers.rb @@ -35,4 +35,5 @@ require_relative '../deltacloud/helpers/deltacloud_helper' require_relative '../deltacloud/helpers/rabbit_helper' require_relative './helpers/cimi_helper' +require_relative './helpers/cimi_rabbit_helper' require_relative './helpers/database_helper' diff --git a/server/lib/cimi/service/cloud_entry_point.rb b/server/lib/cimi/service/cloud_entry_point.rb index 9491e3d..a61eec7 100644 --- a/server/lib/cimi/service/cloud_entry_point.rb +++ b/server/lib/cimi/service/cloud_entry_point.rb @@ -34,6 +34,10 @@ class CIMI::Service::CloudEntryPoint < CIMI::Service::Base def self.entities(context) CIMI::Collections.modules(:cimi).inject({}) do |supported_entities, m| m.collections.each do |c| + if c.operation(:index).nil? + warn "#{c} does not have :index operation." + next + end index_operation_capability = c.operation(:index).required_capability next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability) supported_entities[c.collection_name.to_s] = { :href => context.send(:"#{c.collection_name}_url") } -- 1.8.1.4
