You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2012/09/04 14:52:40 UTC
[2/3] git commit: CIMI: fixes Machine with subcollections for disk,
machine_volume
CIMI: fixes Machine with subcollections for disk, machine_volume
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/9b3ce420
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/9b3ce420
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/9b3ce420
Branch: refs/heads/master
Commit: 9b3ce4203653764726c9e9355930bdecc8eb2dcb
Parents: 30c895d
Author: marios <ma...@redhat.com>
Authored: Fri Aug 31 22:28:41 2012 +0300
Committer: marios <ma...@redhat.com>
Committed: Tue Sep 4 12:55:49 2012 +0300
----------------------------------------------------------------------
server/lib/cimi/collections/machines.rb | 22 ++++++
server/lib/cimi/helpers/cimi_helper.rb | 12 +++-
server/lib/cimi/models.rb | 4 +
server/lib/cimi/models/disk.rb | 40 +++++++++++
server/lib/cimi/models/disk_collection.rb | 38 +++++++++++
server/lib/cimi/models/machine.rb | 52 +++------------
server/lib/cimi/models/machine_configuration.rb | 23 ++----
server/lib/cimi/models/machine_volume.rb | 42 ++++++++++++
.../lib/cimi/models/machine_volume_collection.rb | 34 ++++++++++
9 files changed, 208 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index 6084506..74a31dc 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -117,6 +117,28 @@ module CIMI::Collections
end
end
+ operation :disks, :with_capability => :hardware_profiles do
+ description "Retrieve the Machine's DiskCollection"
+ control do
+ disks = DiskCollection.default(params[:id], self)
+ respond_to do |format|
+ format.json {disks.to_json}
+ format.xml {disks.to_xml}
+ end
+ end
+ end
+
+ operation :volumes, :with_capability => :storage_volumes do
+ description "Retrieve the Machine's MachineVolumeCollection"
+ control do
+ volumes = MachineVolumeCollection.default(params[:id], self)
+ respond_to do |format|
+ format.json {volumes.to_json}
+ format.xml {volumes.to_xml}
+ end
+ end
+ end
+
#NOTE: The routes for attach/detach used here are NOT as specified by CIMI
#will likely move later. CIMI specifies PUT of the whole Machine description
#with inclusion/ommission of the volumes you want [att|det]ached
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/helpers/cimi_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index e48fa8e..be64dbd 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -20,12 +20,22 @@ module CIMIHelper
status code
end
-
def href_id(href, entity)
split_on = self.send(:"#{entity.to_s}_url")
href.split("#{split_on}/").last
end
+ def to_kibibyte(value, unit)
+ case unit
+ when "GB"
+ value*1024*1024
+ when "MB"
+ value*1024
+ else
+ nil # should probably be exploding something here...
+ end
+ end
+
end
class Array
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 2eaf345..b447e50 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -64,3 +64,7 @@ require_relative './models/address'
require_relative './models/address_collection'
require_relative './models/address_template'
require_relative './models/address_template_collection'
+require_relative './models/disk'
+require_relative './models/disk_collection'
+require_relative './models/machine_volume'
+require_relative './models/machine_volume_collection'
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/disk.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk.rb b/server/lib/cimi/models/disk.rb
new file mode 100644
index 0000000..d74ec54
--- /dev/null
+++ b/server/lib/cimi/models/disk.rb
@@ -0,0 +1,40 @@
+# 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::Disk < CIMI::Model::Base
+
+ text :capacity
+ text :initial_location
+
+ array :operations do
+ scalar :rel, :href
+ end
+
+ def self.find(instance, machine_config, context, id=:all)
+ if id == :all
+ storage_override = instance.instance_profile.overrides.find { |p, v| p == :storage }
+ capacity = storage_override.nil? ? machine_config.disks[0][:capacity] : context.to_kibibyte(storage_override[1].to_i, "MB")
+ name = instance.id+"_disk_#{capacity}" #assuming one disk for now...
+ [ self.new(
+ :id => context.machine_url(instance.id)+"/disks/#{name}",
+ :name => name,
+ :description => "DiskCollection for Machine #{instance.id}",
+ :created => instance.launch_time,
+ :capacity => capacity
+ ) ]
+ else
+ end
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/disk_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk_collection.rb b/server/lib/cimi/models/disk_collection.rb
new file mode 100644
index 0000000..b86a3c9
--- /dev/null
+++ b/server/lib/cimi/models/disk_collection.rb
@@ -0,0 +1,38 @@
+# 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.schema.add_collection_member_array(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)
+ storage_override = instance.instance_profile.overrides.find { |p, v| p == :storage }
+ 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
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 415b0b5..7cc659a 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -18,33 +18,15 @@ class CIMI::Model::Machine < CIMI::Model::Base
text :state
text :cpu
- struct :memory do
- scalar :quantity
- scalar :units
- end
+ text :memory
href :event_log
- array :disks do
- struct :capacity do
- scalar :quantity
- scalar :units
- end
- scalar :format
- scalar :attachment_point
- end
+ href :disks
- array :volumes do
- scalar :href
- scalar :protocol
- scalar :attachment_point
- end
+ href :volumes
- array :network_interfaces do
- href :vsp
- text :hostname, :mac_address, :state, :protocol, :allocation
- text :address, :default_gateway, :dns, :max_transmission_unit
- end
+ href :network_interfaces
array :meters do
scalar :href
@@ -133,7 +115,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
private
def self.from_instance(instance, context)
- cpu = memory = disks = (instance.instance_profile.id == "opaque")? "n/a" : nil
+ cpu = memory = (instance.instance_profile.id == "opaque")? "n/a" : nil
self.new(
:name => instance.id,
:description => instance.name,
@@ -142,10 +124,10 @@ 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 => disks || convert_instance_storage(instance.instance_profile, context),
- :network_interfaces => convert_instance_addresses(instance),
+ :disks => {:href => context.machine_url(instance.id)+"/disks"},
+ :network_interfaces => {:href => context.machine_url(instance.id+"/network_interfaces")},
:operations => convert_instance_actions(instance, context),
- :volumes=>convert_storage_volumes(instance, context),
+ :volumes=>{:href=>context.machine_url(instance.id)+"/volumes"},
:property => convert_instance_properties(instance, context)
)
end
@@ -178,23 +160,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
def self.convert_instance_memory(profile, context)
machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
memory_override = profile.overrides.find { |p, v| p == :memory }
- {
- :quantity => memory_override.nil? ? machine_conf.memory[:quantity] : memory_override[1],
- :units => machine_conf.memory[:units]
- }
- end
-
- def self.convert_instance_storage(profile, context)
- machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
- return nil unless machine_conf.disks
- storage_override = profile.overrides.find { |p, v| p == :storage }
- [
- { :capacity => {
- :quantity => storage_override.nil? ? machine_conf.disks.first[:capacity][:quantity] : storage_override[1],
- :units => machine_conf.disks.first[:capacity][:units]
- }
- }
- ]
+ memory_override.nil? ? machine_conf.memory : context.to_kibibyte(memory_override[1].to_i,"MB")
end
def self.convert_instance_addresses(instance)
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/machine_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_configuration.rb b/server/lib/cimi/models/machine_configuration.rb
index 28bf3ab..6ea92dd 100644
--- a/server/lib/cimi/models/machine_configuration.rb
+++ b/server/lib/cimi/models/machine_configuration.rb
@@ -15,20 +15,13 @@
class CIMI::Model::MachineConfiguration < CIMI::Model::Base
- struct :memory do
- scalar :quantity
- scalar :units
- end
-
+ text :memory
text :cpu
array :disks do
- struct :capacity do
- scalar :quantity
- scalar :units
- end
- scalar :format
- scalar :attachment_point
+ text :capacity
+ text :format
+ text :attachment_point
end
array :operations do
@@ -51,17 +44,17 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
def self.from_hardware_profile(profile, context)
# We accept just profiles with all properties set
return unless profile.memory or profile.cpu or profile.storage
- memory = profile.memory.value || profile.memory.default
+ memory = profile.memory ? context.to_kibibyte((profile.memory.value || profile.memory.default), profile.memory.unit) : nil
cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
- storage = (profile.storage ? (profile.storage.value || profile.storage.default) : nil )
+ storage = profile.storage ? context.to_kibibyte((profile.storage.value || profile.storage.default), profile.storage.unit) : nil
machine_hash = {
:name => profile.name,
:description => "Machine Configuration with #{memory} #{profile.memory.unit} "+
"of memory and #{cpu} CPU",
:cpu => ( cpu if cpu ) ,
:created => Time.now.to_s, # FIXME: DC hardware_profile has no mention about created_at
- :memory => { :quantity => profile.memory.value || profile.memory.default, :units => profile.memory.unit },
- :disks => ( [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ] if storage ),
+ :memory => (memory if memory),
+ :disks => ( [ { :capacity => storage } ] if storage ),
:id => context.machine_configuration_url(profile.name)
}
self.new(machine_hash)
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/machine_volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_volume.rb b/server/lib/cimi/models/machine_volume.rb
new file mode 100644
index 0000000..2337bdf
--- /dev/null
+++ b/server/lib/cimi/models/machine_volume.rb
@@ -0,0 +1,42 @@
+# 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::MachineVolume < CIMI::Model::Base
+
+ text :initial_location
+ href :volume
+
+ array :operations do
+ scalar :rel, :href
+ end
+
+ def self.find(instance_id, context, id=:all)
+ if id == :all
+ volumes = context.driver.storage_volumes(context.credentials)
+ volumes.inject([]) do |attached, vol|
+ attached << self.new(
+ :id => context.machine_url(instance_id)+"/volumes/#{vol.id}",
+ :name => vol.id,
+ :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
+ :created => vol.created,
+ :initial_location => vol.device,
+ :volume => {:href=>context.volume_url(vol.id)}
+ ) if vol.instance_id == instance_id
+ attached
+ end
+ else
+ end
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9b3ce420/server/lib/cimi/models/machine_volume_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_volume_collection.rb b/server/lib/cimi/models/machine_volume_collection.rb
new file mode 100644
index 0000000..85483ff
--- /dev/null
+++ b/server/lib/cimi/models/machine_volume_collection.rb
@@ -0,0 +1,34 @@
+# 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.schema.add_collection_member_array(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