deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 10/10] CIMI: make the network ports on a network a proper subcollection
Date Thu, 08 Nov 2012 04:05:36 GMT
From: David Lutterkort <lutter@redhat.com>

---
 server/lib/cimi/collections/networks.rb |    2 +-
 server/lib/cimi/models/network.rb       |    7 ++++++-
 server/lib/cimi/models/network_port.rb  |   13 +++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
index 20b0b1b..002b828 100644
--- a/server/lib/cimi/collections/networks.rb
+++ b/server/lib/cimi/collections/networks.rb
@@ -124,7 +124,7 @@ module CIMI::Collections
         description "Retrieve the Network's NetworkPortCollection"
         param :id, :string, :required
         control do
-          network_ports = NetworkPortCollection.for_network(params[:id], self)
+          network_ports = NetworkPort.collection_for_network(params[:id], self)
           respond_to do |format|
             format.json {network_ports.to_json}
             format.xml  {network_ports.to_xml}
diff --git a/server/lib/cimi/models/network.rb b/server/lib/cimi/models/network.rb
index b08984a..f415664 100644
--- a/server/lib/cimi/models/network.rb
+++ b/server/lib/cimi/models/network.rb
@@ -25,7 +25,7 @@ class CIMI::Model::Network < CIMI::Model::Base
 
   text :class_of_service
 
-  href :network_ports
+  collection :network_ports, :class => CIMI::Model::NetworkPort
 
   href :forwarding_group
 
@@ -44,6 +44,11 @@ class CIMI::Model::Network < CIMI::Model::Base
     else
       networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
     end
+    if context.expand? :networkPorts
+      networks.each do |network|
+        network.network_ports = CIMI::Model::NetworkPort.collection_for_network(network.id,
context)
+      end
+    end
     networks
   end
 
diff --git a/server/lib/cimi/models/network_port.rb b/server/lib/cimi/models/network_port.rb
index 2951ffd..d69dc3f 100644
--- a/server/lib/cimi/models/network_port.rb
+++ b/server/lib/cimi/models/network_port.rb
@@ -74,6 +74,19 @@ class CIMI::Model::NetworkPort < CIMI::Model::Base
     end
   end
 
+  def self.collection_for_network(network_id, context)
+    net_url = context.network_url(network_id)
+    network_ports = CIMI::Model::NetworkPort.all(context)
+    ports_collection = network_ports.inject([]){|res, current| res << current if current.network.href
== net_url ; res}
+    CIMI::Model::NetworkPortCollection.new(
+      :id => net_url+"/network_ports",
+      :name => 'default',
+      :created => Time.now,
+      :description => "#{context.driver.name.capitalize} NetworkPortCollection",
+      :count => ports_collection.size,
+      :network_ports => ports_collection
+    )
+  end
 
   private
 
-- 
1.7.7.6


Mime
View raw message