deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <di...@fast.au.fujitsu.com>
Subject [PATCH] CIMI: fix system operations (start, stop) and use rabbit helpers for system subcollection urls
Date Fri, 05 Apr 2013 13:39:03 GMT
From: Dies Koper <diesk@fast.au.fujitsu.com>

---
 server/lib/cimi/collections/systems.rb             | 24 ++++------------------
 server/lib/cimi/service/system.rb                  |  7 ++++---
 server/lib/cimi/service/system_address.rb          |  5 +++--
 server/lib/cimi/service/system_credential.rb       |  5 +++--
 server/lib/cimi/service/system_forwarding_group.rb |  5 +++--
 server/lib/cimi/service/system_machine.rb          |  5 +++--
 server/lib/cimi/service/system_network.rb          |  5 +++--
 server/lib/cimi/service/system_network_port.rb     |  5 +++--
 server/lib/cimi/service/system_system.rb           |  5 +++--
 server/lib/cimi/service/system_template.rb         |  5 +++--
 server/lib/cimi/service/system_volume.rb           |  5 +++--
 .../drivers/fgcp/fgcp_driver_cimi_methods.rb       |  2 --
 12 files changed, 35 insertions(+), 43 deletions(-)

diff --git a/server/lib/cimi/collections/systems.rb b/server/lib/cimi/collections/systems.rb
index 179daea..4f0457c 100644
--- a/server/lib/cimi/collections/systems.rb
+++ b/server/lib/cimi/collections/systems.rb
@@ -44,11 +44,7 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read.gsub("restart", "reboot"))
-          else
-            action = Action.from_xml(request.body.read.gsub("restart", "reboot"))
-          end
+          action = Action.parse(self)
           system.perform(action, self) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
@@ -61,11 +57,7 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
+          action = Action.parse(self)
           system.perform(action, self) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
@@ -78,11 +70,7 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
+          action = Action.parse(self)
           system.perform(action, self) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
@@ -95,11 +83,7 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
+          action = Action.parse(self)
           system.perform(action, self) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
diff --git a/server/lib/cimi/service/system.rb b/server/lib/cimi/service/system.rb
index bb28e82..9324783 100644
--- a/server/lib/cimi/service/system.rb
+++ b/server/lib/cimi/service/system.rb
@@ -18,16 +18,17 @@ class CIMI::Service::System < CIMI::Service::Base
   def self.find(id, context)
     if id == :all
       systems = context.driver.systems(context.credentials, {:env=>context})
+      systems.collect {|e| CIMI::Service::System.new(context, :model => e)}
     else
       systems = context.driver.systems(context.credentials, {:env=>context, :id=>id})
-      raise CIMI::Model::NotFound unless systems.first
-      systems.first
+      raise CIMI::Model::NotFound if systems.empty?
+      CIMI::Service::System.new(context, :model => systems.first)
     end
   end
 
   def perform(action, context, &block)
     begin
-      if context.driver.send(:"#{action.name}_system", context.credentials, self.id.split("/").last)
+      if context.driver.send(:"#{action.operation}_system", context.credentials, :id =>
self.id.split("/").last)
         block.callback :success
       else
         raise "Operation failed to execute on given System"
diff --git a/server/lib/cimi/service/system_address.rb b/server/lib/cimi/service/system_address.rb
index 2afaf4f..83ac075 100644
--- a/server/lib/cimi/service/system_address.rb
+++ b/server/lib/cimi/service/system_address.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemAddress < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       addresses = context.driver.system_addresses(context.credentials, {:env=>context,
:system_id=>system_id})
+      addresses.collect {|e| CIMI::Service::SystemAddress.new(context, :model => e)}
     else
       addresses = context.driver.system_addresses(context.credentials, {:env=>context,
:system_id=>system_id, :id=>id})
       raise CIMI::Model::NotFound if addresses.empty?
-      addresses.first
+      CIMI::Service::SystemAddress.new(context, :model => addresses.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_addresses = self.find(system_id, context)
-    addresses_url = context.url("/system/#{system_id}/addresses") if context.driver.has_capability?
:add_addresses_to_system
+    addresses_url = context.system_addresses_url(system_id) if context.driver.has_capability?
:add_addresses_to_system
     CIMI::Model::SystemAddress.list(addresses_url, system_addresses, :add_url => addresses_url)
   end
 
diff --git a/server/lib/cimi/service/system_credential.rb b/server/lib/cimi/service/system_credential.rb
index 3ff256b..d3de64b 100644
--- a/server/lib/cimi/service/system_credential.rb
+++ b/server/lib/cimi/service/system_credential.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemCredential < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       credentials = context.driver.system_credentials(context.credentials, {:env=>context,
:system_id=>system_id})
+      credentials.collect {|e| CIMI::Service::SystemCredential.new(context, :model =>
e)}
     else
       credentials = context.driver.system_credentials(context.credentials, {:env=>context,
:system_id=>system_id, :id=>id})
       raise CIMI::Model::NotFound if credentials.empty?
-      credentials.first
+      CIMI::Service::SystemCredential.new(context, :model => credentials.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_credentials = self.find(system_id, context)
-    credentials_url = context.url("/system/#{system_id}/credentials") if context.driver.has_capability?
:add_credentials_to_system
+    credentials_url = context.system_credentials_url(system_id) if context.driver.has_capability?
:add_credentials_to_system
     CIMI::Model::SystemCredential.list(credentials_url, system_credentials, :add_url =>
credentials_url)
   end
 
diff --git a/server/lib/cimi/service/system_forwarding_group.rb b/server/lib/cimi/service/system_forwarding_group.rb
index e7c269c..69012d8 100644
--- a/server/lib/cimi/service/system_forwarding_group.rb
+++ b/server/lib/cimi/service/system_forwarding_group.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemForwardingGroup < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       groups = context.driver.system_forwarding_groups(context.credentials, {:env=>context,
:system_id=>system_id})
+      groups.collect {|e| CIMI::Service::SystemForwardingGroup.new(context, :model =>
e)}
     else
       groups = context.driver.system_forwarding_groups(context.credentials, {:env=>context,
:system_id=>system_id, :id=>id})
       raise CIMI::Model::NotFound if groups.empty?
-      groups.first
+      CIMI::Service::SystemForwardingGroup.new(context, :model => groups.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_forwarding_groups = self.find(system_id, context)
-    forwarding_groups_url = context.url("/system/#{system_id}/forwarding_groups") if context.driver.has_capability?
:add_forwarding_groups_to_system
+    forwarding_groups_url = context.system_forwarding_groups_url(system_id) if context.driver.has_capability?
:add_forwarding_groups_to_system
     CIMI::Model::SystemForwardingGroup.list(forwarding_groups_url, system_forwarding_groups,
:add_url => forwarding_groups_url)
   end
 
diff --git a/server/lib/cimi/service/system_machine.rb b/server/lib/cimi/service/system_machine.rb
index d19026a..cdf515e 100644
--- a/server/lib/cimi/service/system_machine.rb
+++ b/server/lib/cimi/service/system_machine.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemMachine < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       machines = context.driver.system_machines(context.credentials, {:env=>context, :system_id=>system_id})
+      machines.collect {|e| CIMI::Service::SystemMachine.new(context, :model => e)}
     else
       machines = context.driver.system_machines(context.credentials, {:env=>context, :system_id=>system_id,
:id=>id})
       raise CIMI::Model::NotFound if machines.empty?
-      machines.first
+      CIMI::Service::SystemMachine.new(context, :model => machines.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_machines = self.find(system_id, context)
-    machines_url = context.url("/system/#{system_id}/machines") if context.driver.has_capability?
:add_machines_to_system
+    machines_url = context.system_machines_url(system_id) if context.driver.has_capability?
:add_machines_to_system
     CIMI::Model::SystemMachine.list(machines_url, system_machines, :add_url => machines_url)
   end
 
diff --git a/server/lib/cimi/service/system_network.rb b/server/lib/cimi/service/system_network.rb
index 5ff9323..a921910 100644
--- a/server/lib/cimi/service/system_network.rb
+++ b/server/lib/cimi/service/system_network.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemNetwork < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       networks = context.driver.system_networks(context.credentials, {:env=>context, :system_id=>system_id})
+      networks.collect {|e| CIMI::Service::SystemNetwork.new(context, :model => e)}
     else
       networks = context.driver.system_networks(context.credentials, {:env=>context, :system_id=>system_id,
:id=>id})
       raise CIMI::Model::NotFound if networks.empty?
-      networks.first
+      CIMI::Service::SystemNetwork.new(context, :model => networks.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_networks = self.find(system_id, context)
-    networks_url = context.url("/system/#{system_id}/networks") if context.driver.has_capability?
:add_networks_to_system
+    networks_url = context.system_networks_url(system_id) if context.driver.has_capability?
:add_networks_to_system
     CIMI::Model::SystemNetwork.list(networks_url, system_networks, :add_url => networks_url)
   end
 
diff --git a/server/lib/cimi/service/system_network_port.rb b/server/lib/cimi/service/system_network_port.rb
index f7b3e69..3811e67 100644
--- a/server/lib/cimi/service/system_network_port.rb
+++ b/server/lib/cimi/service/system_network_port.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemNetworkPort < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       ports = context.driver.system_network_ports(context.credentials, {:env=>context,
:system_id=>system_id})
+      ports.collect {|e| CIMI::Service::SystemNetworkPort.new(context, :model => e)}
     else
       ports = context.driver.system_network_ports(context.credentials, {:env=>context,
:system_id=>system_id, :id=>id})
       raise CIMI::Model::NotFound if ports.empty?
-      ports.first
+      CIMI::Service::SystemNetworkPort.new(context, :model => ports.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_network_ports = self.find(system_id, context)
-    network_ports_url = context.url("/system/#{system_id}/network_ports") if context.driver.has_capability?
:add_network_ports_to_system
+    network_ports_url = context.system_network_ports_url(system_id) if context.driver.has_capability?
:add_network_ports_to_system
     CIMI::Model::SystemNetworkPort.list(network_ports_url, system_network_ports, :add_url
=> network_ports_url)
   end
 
diff --git a/server/lib/cimi/service/system_system.rb b/server/lib/cimi/service/system_system.rb
index 233825c..0787f26 100644
--- a/server/lib/cimi/service/system_system.rb
+++ b/server/lib/cimi/service/system_system.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemSystem < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       systems = context.driver.system_systems(context.systems, {:env=>context, :system_id=>system_id})
+      systems.collect {|e| CIMI::Service::SystemSystem.new(context, :model => e)}
     else
       systems = context.driver.system_systems(context.systems, {:env=>context, :system_id=>system_id,
:id=>id})
       raise CIMI::Model::NotFound if systems.empty?
-      systems.first
+      CIMI::Service::SystemSystem.new(context, :model => systems.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_systems = self.find(system_id, context)
-    systems_url = context.url("/system/#{system_id}/systems") if context.driver.has_capability?
:add_systems_to_system
+    systems_url = context.system_systems_url(system_id) if context.driver.has_capability?
:add_systems_to_system
     CIMI::Model::SystemSystem.list(systems_url, system_systems, :add_url => systems_url)
   end
 
diff --git a/server/lib/cimi/service/system_template.rb b/server/lib/cimi/service/system_template.rb
index 785f79d..90a55b8 100644
--- a/server/lib/cimi/service/system_template.rb
+++ b/server/lib/cimi/service/system_template.rb
@@ -18,10 +18,11 @@ class CIMI::Service::SystemTemplate < CIMI::Service::Base
   def self.find(id, context)
     if id == :all
       templates = context.driver.system_templates(context.credentials, {:env=>context})
+      templates.collect {|e| CIMI::Service::SystemTemplate.new(context, :model => e)}
     else
       templates = context.driver.system_templates(context.credentials, {:env=>context,
:id=>id})
-      raise CIMI::Model::NotFound unless templates.first
-      templates.first
+      raise CIMI::Model::NotFound if templates.empty?
+      CIMI::Service::SystemTemplate.new(context, :model => templates.first)
     end
   end
 
diff --git a/server/lib/cimi/service/system_volume.rb b/server/lib/cimi/service/system_volume.rb
index 7f4306b..431c7a0 100644
--- a/server/lib/cimi/service/system_volume.rb
+++ b/server/lib/cimi/service/system_volume.rb
@@ -18,16 +18,17 @@ class CIMI::Service::SystemVolume < CIMI::Service::Base
   def self.find(system_id, context, id=:all)
     if id == :all
       vols = context.driver.system_volumes(context.credentials, {:env=>context, :system_id=>system_id})
+      vols.collect {|e| CIMI::Service::SystemVolume.new(context, :model => e)}
     else
       vols = context.driver.system_volumes(context.credentials, {:env=>context, :system_id=>system_id,
:id=>id})
       raise CIMI::Model::NotFound if vols.empty?
-      vols.first
+      CIMI::Service::SystemVolume.new(context, :model => vols.first)
     end
   end
 
   def self.collection_for_system(system_id, context)
     system_volumes = self.find(system_id, context)
-    volumes_url = context.url("/system/#{system_id}/volumes") if context.driver.has_capability?
:add_volumes_to_system
+    volumes_url = context.system_volumes_url(system_id) if context.driver.has_capability?
:add_volumes_to_system
     CIMI::Model::SystemVolume.list(volumes_url, system_volumes, :add_url => volumes_url)
   end
 
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
index d0ae1ea..0380fb1 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
@@ -94,7 +94,6 @@ module Deltacloud::Drivers::Fgcp
     def start_system(credentials, opts={})
       safely do
         client = new_client(credentials)
-        context = opts[:env]
         vsys_id = opts[:id]
         xml = client.list_vservers(vsys_id)['vservers']
         return unless xml and xml[0]['vserver']
@@ -114,7 +113,6 @@ module Deltacloud::Drivers::Fgcp
     def stop_system(credentials, opts={})
       safely do
         client = new_client(credentials)
-        context = opts[:env]
         vsys_id = opts[:id]
         xml = client.list_vservers(vsys_id)['vservers']
         return unless xml and xml[0]['vserver']
-- 
1.8.0.msysgit.0



Mime
View raw message