deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 4/4] CIMI: Added support for $expand in Network model
Date Wed, 03 Oct 2012 16:10:32 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/collections/networks.rb           |    2 +-
 server/lib/cimi/models.rb                         |    2 +-
 server/lib/cimi/models/network.rb                 |    7 ++++++-
 server/lib/cimi/models/network_port.rb            |   13 +++++++++++++
 server/lib/cimi/models/network_port_collection.rb |   14 --------------
 5 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
index e006503..3b8b864 100644
--- a/server/lib/cimi/collections/networks.rb
+++ b/server/lib/cimi/collections/networks.rb
@@ -125,7 +125,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.rb b/server/lib/cimi/models.rb
index f5ae48b..d726bd3 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -42,10 +42,10 @@ require_relative './models/machine_template'
 require_relative './models/machine_configuration'
 require_relative './models/machine_image'
 require_relative './models/credential'
+require_relative './models/network_port'
 require_relative './models/network'
 require_relative './models/network_template'
 require_relative './models/network_configuration'
-require_relative './models/network_port'
 require_relative './models/network_port_template'
 require_relative './models/network_port_configuration'
 require_relative './models/address'
diff --git a/server/lib/cimi/models/network.rb b/server/lib/cimi/models/network.rb
index b08984a..aa9c6ca 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
+  subcollection :network_ports
 
   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.cimi_expand.include? '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
 
diff --git a/server/lib/cimi/models/network_port_collection.rb b/server/lib/cimi/models/network_port_collection.rb
index 32642cf..8b4f62e 100644
--- a/server/lib/cimi/models/network_port_collection.rb
+++ b/server/lib/cimi/models/network_port_collection.rb
@@ -34,18 +34,4 @@ class CIMI::Model::NetworkPortCollection < CIMI::Model::Base
     )
   end
 
-  def self.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}
-    self.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
-
 end
-- 
1.7.10.2


Mime
View raw message