You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by di...@fast.au.fujitsu.com on 2013/04/05 06:24:52 UTC

[PATCH] mock: fix href urls in mock system and subcollections. Also include start action for newly created system

From: Dies Koper <di...@fast.au.fujitsu.com>

---
 .../drivers/mock/data/cimi/system/system1.json     |  2 --
 .../drivers/mock/data/cimi/system/system2.json     |  2 --
 .../drivers/mock/mock_driver_cimi_methods.rb       | 28 ++++++++++------------
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
index a73bb5f..f921632 100644
--- a/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
+++ b/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
@@ -3,8 +3,6 @@
   "description": "the first system",
   "created": "Fri Feb 08 15:25:41 EET 2013",
   "state": "STOPPED",
-  "machines": { "href": "http://cimi.example.org/systems/system1/machines"},
-  "networks": { "href": "http://cimi.example.org/systems/system1/networks"},
   "operations": [
     { "rel": "http://schemas.dmtf.org/cimi/1/action/start", "href": "http://cimi.example.org/systems/system1/start" },
     { "rel": "edit", "href": "http://cimi.example.org/systems/system1" },
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json b/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
index 5a62e73..208feca 100644
--- a/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
+++ b/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
@@ -3,8 +3,6 @@
   "description": "the second system",
   "created": "Fri Feb 08 15:25:41 EET 2013",
   "state": "STOPPED",
-  "machines": { "href": "http://cimi.example.org/systems/system2/machines"},
-  "networks": { "href": "http://cimi.example.org/systems/system2/networks"},
   "operations": [
     { "rel": "http://schemas.dmtf.org/cimi/1/action/start", "href": "http://cimi.example.org/systems/system1/start" },
     { "rel": "edit", "href": "http://cimi.example.org/systems/system2" },
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
index b0d4f9a..4ac01aa 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -44,7 +44,8 @@ module Deltacloud::Drivers::Mock
                   "created" => Time.now,
                   "state" => "STOPPED",
                   "systemTemplate"=> { "href" => opts[:system_template].id },
-                  "operations" => [{"rel"=>"edit", "href"=> id},
+                  "operations" => [{"rel"=>"http://schemas.dmtf.org/cimi/1/action/start", "href"=> "#{id}/start"},
+                                   {"rel"=>"edit", "href"=> id},
                                    {"rel"=>"delete", "href"=> id}]    }
       system = CIMI::Model::System.from_json(JSON.generate(sys_hsh))
 
@@ -78,9 +79,7 @@ module Deltacloud::Drivers::Mock
           return []
         end
       end
-      #FIXME: with ":machines", delete url becomes 'http://localhost:3001/cimi/machines?id=sysmach1'
-      #with ":system_machine"/":system_machines", undefined method `system_machine_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
-      machines.map{|mach|convert_cimi_mock_urls(:machines, mach, opts[:env])}.flatten
+      machines.map{|m|convert_urls(m, opts[:env])}.flatten
     end
 
     def system_volumes(credentials, opts={})
@@ -94,9 +93,7 @@ module Deltacloud::Drivers::Mock
           return []
         end
       end
-      #FIXME: with ":volumes", delete url becomes 'http://localhost:3001/cimi/volumes?id=sysvol1'
-      #with ":system_volume"/":system_volumes", undefined method `system_volume_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
-      volumes.map{|vol|convert_cimi_mock_urls(:volumes, vol, opts[:env])}.flatten
+      volumes.map{|vol|convert_urls(vol, opts[:env])}.flatten
     end
 
     def system_networks(credentials, opts={})
@@ -110,8 +107,7 @@ module Deltacloud::Drivers::Mock
           return []
         end
       end
-      #FIXME
-      networks.map{|vol|convert_cimi_mock_urls(:networks, vol, opts[:env])}.flatten
+      networks.map{|n|convert_urls(n, opts[:env])}.flatten
     end
 
     def system_addresses(credentials, opts={})
@@ -125,8 +121,7 @@ module Deltacloud::Drivers::Mock
           return []
         end
       end
-      #FIXME
-      addresses.map{|a|convert_cimi_mock_urls(:addresses, a, opts[:env])}.flatten
+      addresses.map{|a|convert_urls(a, opts[:env])}.flatten
     end
 
     def system_forwarding_groups(credentials, opts={})
@@ -140,8 +135,7 @@ module Deltacloud::Drivers::Mock
           return []
         end
       end
-      #FIXME
-      groups.map{|group|convert_cimi_mock_urls(:forwarding_groups, group, opts[:env])}.flatten
+      groups.map{|g|convert_urls(g, opts[:env])}.flatten
     end
 
     def system_templates(credentials, opts={})
@@ -337,10 +331,12 @@ module Deltacloud::Drivers::Mock
         return s
       end
       return s unless u.scheme == 'http' && u.host == 'cimi.example.org'
-      _, coll, id = u.path.split("/")
-      method = "#{coll.singularize}_url"
+      _, coll, id, sub_coll, sub_id = u.path.split("/")
+      method = sub_coll ? "#{coll.singularize}_#{sub_coll.singularize}_url"
+                        : "#{coll.singularize}_url"
       if context.respond_to?(method)
-        context.send(method, id)
+        sub_coll ? context.send(method, :id => id, :ent_id => sub_id)
+                 : context.send(method, id)
       else
         s
       end
-- 
1.8.0.msysgit.0



Re: [PATCH] mock: fix href urls in mock system and subcollections. Also include start action for newly created system

Posted by Michal Fojtik <mf...@redhat.com>.
On 04/05/2013 06:24 AM, diesk@fast.au.fujitsu.com wrote:

ACK.

> From: Dies Koper <di...@fast.au.fujitsu.com>
>
> ---
>   .../drivers/mock/data/cimi/system/system1.json     |  2 --
>   .../drivers/mock/data/cimi/system/system2.json     |  2 --
>   .../drivers/mock/mock_driver_cimi_methods.rb       | 28 ++++++++++------------
>   3 files changed, 12 insertions(+), 20 deletions(-)
>
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
> index a73bb5f..f921632 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/system/system1.json
> @@ -3,8 +3,6 @@
>     "description": "the first system",
>     "created": "Fri Feb 08 15:25:41 EET 2013",
>     "state": "STOPPED",
> -  "machines": { "href": "http://cimi.example.org/systems/system1/machines"},
> -  "networks": { "href": "http://cimi.example.org/systems/system1/networks"},
>     "operations": [
>       { "rel": "http://schemas.dmtf.org/cimi/1/action/start", "href": "http://cimi.example.org/systems/system1/start" },
>       { "rel": "edit", "href": "http://cimi.example.org/systems/system1" },
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json b/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
> index 5a62e73..208feca 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/system/system2.json
> @@ -3,8 +3,6 @@
>     "description": "the second system",
>     "created": "Fri Feb 08 15:25:41 EET 2013",
>     "state": "STOPPED",
> -  "machines": { "href": "http://cimi.example.org/systems/system2/machines"},
> -  "networks": { "href": "http://cimi.example.org/systems/system2/networks"},
>     "operations": [
>       { "rel": "http://schemas.dmtf.org/cimi/1/action/start", "href": "http://cimi.example.org/systems/system1/start" },
>       { "rel": "edit", "href": "http://cimi.example.org/systems/system2" },
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
> index b0d4f9a..4ac01aa 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
> @@ -44,7 +44,8 @@ module Deltacloud::Drivers::Mock
>                     "created" => Time.now,
>                     "state" => "STOPPED",
>                     "systemTemplate"=> { "href" => opts[:system_template].id },
> -                  "operations" => [{"rel"=>"edit", "href"=> id},
> +                  "operations" => [{"rel"=>"http://schemas.dmtf.org/cimi/1/action/start", "href"=> "#{id}/start"},
> +                                   {"rel"=>"edit", "href"=> id},
>                                      {"rel"=>"delete", "href"=> id}]    }
>         system = CIMI::Model::System.from_json(JSON.generate(sys_hsh))
>
> @@ -78,9 +79,7 @@ module Deltacloud::Drivers::Mock
>             return []
>           end
>         end
> -      #FIXME: with ":machines", delete url becomes 'http://localhost:3001/cimi/machines?id=sysmach1'
> -      #with ":system_machine"/":system_machines", undefined method `system_machine_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
> -      machines.map{|mach|convert_cimi_mock_urls(:machines, mach, opts[:env])}.flatten
> +      machines.map{|m|convert_urls(m, opts[:env])}.flatten
>       end
>
>       def system_volumes(credentials, opts={})
> @@ -94,9 +93,7 @@ module Deltacloud::Drivers::Mock
>             return []
>           end
>         end
> -      #FIXME: with ":volumes", delete url becomes 'http://localhost:3001/cimi/volumes?id=sysvol1'
> -      #with ":system_volume"/":system_volumes", undefined method `system_volume_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
> -      volumes.map{|vol|convert_cimi_mock_urls(:volumes, vol, opts[:env])}.flatten
> +      volumes.map{|vol|convert_urls(vol, opts[:env])}.flatten
>       end
>
>       def system_networks(credentials, opts={})
> @@ -110,8 +107,7 @@ module Deltacloud::Drivers::Mock
>             return []
>           end
>         end
> -      #FIXME
> -      networks.map{|vol|convert_cimi_mock_urls(:networks, vol, opts[:env])}.flatten
> +      networks.map{|n|convert_urls(n, opts[:env])}.flatten
>       end
>
>       def system_addresses(credentials, opts={})
> @@ -125,8 +121,7 @@ module Deltacloud::Drivers::Mock
>             return []
>           end
>         end
> -      #FIXME
> -      addresses.map{|a|convert_cimi_mock_urls(:addresses, a, opts[:env])}.flatten
> +      addresses.map{|a|convert_urls(a, opts[:env])}.flatten
>       end
>
>       def system_forwarding_groups(credentials, opts={})
> @@ -140,8 +135,7 @@ module Deltacloud::Drivers::Mock
>             return []
>           end
>         end
> -      #FIXME
> -      groups.map{|group|convert_cimi_mock_urls(:forwarding_groups, group, opts[:env])}.flatten
> +      groups.map{|g|convert_urls(g, opts[:env])}.flatten
>       end
>
>       def system_templates(credentials, opts={})
> @@ -337,10 +331,12 @@ module Deltacloud::Drivers::Mock
>           return s
>         end
>         return s unless u.scheme == 'http' && u.host == 'cimi.example.org'
> -      _, coll, id = u.path.split("/")
> -      method = "#{coll.singularize}_url"
> +      _, coll, id, sub_coll, sub_id = u.path.split("/")
> +      method = sub_coll ? "#{coll.singularize}_#{sub_coll.singularize}_url"
> +                        : "#{coll.singularize}_url"
>         if context.respond_to?(method)
> -        context.send(method, id)
> +        sub_coll ? context.send(method, :id => id, :ent_id => sub_id)

This introduces a rule when you create a sub-collections in Rabbit, 
where the URI need to follow this pattern:

/collection/:id/subcollection/:ent_id

If you give some other name to the parameters (:ent_id) this method will 
not work.

I'm fine with this as long as we document that somewhere or drop a 
comment in Rabbit code we have in collections.

   -- Michal

> +                 : context.send(method, id)
>         else
>           s
>         end
>


-- 

Michal Fojtik <mf...@redhat.com>
Deltacloud API, CloudForms