deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 7/7] CIMI: use embedded collection for Machine.disks and Machine.volumes
Date Sat, 06 Oct 2012 00:52:11 GMT
From: David Lutterkort <lutter@redhat.com>

---
 server/lib/cimi/models.rb                          |    2 -
 server/lib/cimi/models/disk_collection.rb          |   37 --------------------
 server/lib/cimi/models/machine.rb                  |   13 +++----
 .../lib/cimi/models/machine_volume_collection.rb   |   34 ------------------
 4 files changed, 5 insertions(+), 81 deletions(-)
 delete mode 100644 server/lib/cimi/models/disk_collection.rb
 delete mode 100644 server/lib/cimi/models/machine_volume_collection.rb

diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index df328f5..1eae2c9 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -25,9 +25,7 @@ require_relative './models/collection'
 require_relative './models/errors'
 require_relative './models/action'
 require_relative './models/disk'
-require_relative './models/disk_collection'
 require_relative './models/machine_volume'
-require_relative './models/machine_volume_collection'
 
 # Toplevel entities; order matters as it determines the order
 # in which the entities appear in the CEP
diff --git a/server/lib/cimi/models/disk_collection.rb b/server/lib/cimi/models/disk_collection.rb
deleted file mode 100644
index 7dbff39..0000000
--- a/server/lib/cimi/models/disk_collection.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-class CIMI::Model::DiskCollection < CIMI::Model::Base
-  text :count
-
-  #add disks array:
-  self << CIMI::Model::Disk
-
-  array :operations do
-    scalar :rel, :href
-  end
-
-  def self.default(instance_id, context)
-    instance = context.driver.instance(context.credentials, :id=>instance_id)
-    machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name,
context)
-    disks = CIMI::Model::Disk.find(instance, machine_conf, context, :all)
-    self.new(
-      :id => context.machine_url(instance_id)+"/disks",
-      :description => "DiskCollection for Machine #{instance_id}",
-      :created => instance.launch_time,
-      :count => disks.size,
-      :disks => disks
-    )
-  end
-end
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index c605d2a..a15fa81 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -24,11 +24,8 @@ class CIMI::Model::Machine < CIMI::Model::Base
 
   href :event_log
 
-  href :disks
-
-  href :volumes
-
-  href :network_interfaces
+  collection :disks, :class => CIMI::Model::Disk
+  collection :volumes, :class => CIMI::Model::MachineVolume
 
   array :meters do
     scalar :href
@@ -118,6 +115,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
   private
   def self.from_instance(instance, context)
     cpu =  memory = (instance.instance_profile.id == "opaque")? "n/a" : nil
+    machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name,
context)
     self.new(
       :name => instance.id,
       :description => instance.name,
@@ -126,10 +124,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
       :state => convert_instance_state(instance.state),
       :cpu => cpu || convert_instance_cpu(instance.instance_profile, context),
       :memory => memory || convert_instance_memory(instance.instance_profile, context),
-      :disks => {:href => context.machine_url(instance.id)+"/disks"},
-      :network_interfaces => {:href => context.machine_url(instance.id+"/network_interfaces")},
+      :disks => CIMI::Model::Disk.find(instance, machine_conf, context, :all),
       :operations => convert_instance_actions(instance, context),
-      :volumes=>{:href=>context.machine_url(instance.id)+"/volumes"},
+      :volumes => CIMI::Model::MachineVolume.find(instance.id, context, :all),
       :property => convert_instance_properties(instance, context)
     )
   end
diff --git a/server/lib/cimi/models/machine_volume_collection.rb b/server/lib/cimi/models/machine_volume_collection.rb
deleted file mode 100644
index b9dfcad..0000000
--- a/server/lib/cimi/models/machine_volume_collection.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-class CIMI::Model::MachineVolumeCollection < CIMI::Model::Base
-
-  text :count
-
-  self << CIMI::Model::MachineVolume
-
-  array :operations do
-    scalar :rel, :href
-  end
-
-  def self.default(instance_id, context)
-    volumes = CIMI::Model::MachineVolume.find(instance_id, context)
-    self.new(
-      :id => context.machine_url(instance_id)+"/volumes",
-      :description => "MachineVolumeCollection for Machine #{instance_id}",
-      :count => volumes.size,
-      :machine_volumes => volumes
-    )
-  end
-end
-- 
1.7.7.6


Mime
View raw message