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 2013/01/24 18:44:35 UTC
git commit: Digital Ocean driver - adds retrieval of
hardware_profiles from provider - image filter
Updated Branches:
refs/heads/master 3cb1e9600 -> fae504fa3
Digital Ocean driver - adds retrieval of hardware_profiles from provider - image filter
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/fae504fa
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/fae504fa
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/fae504fa
Branch: refs/heads/master
Commit: fae504fa30c5ed197a23ee8d698cebfc4f11a81a
Parents: 3cb1e96
Author: marios <ma...@redhat.com>
Authored: Mon Jan 21 13:23:42 2013 +0200
Committer: marios <ma...@redhat.com>
Committed: Thu Jan 24 19:44:08 2013 +0200
----------------------------------------------------------------------
.../drivers/digitalocean/digitalocean_driver.rb | 123 ++++++---------
1 files changed, 48 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fae504fa/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb b/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
index 00a9496..2868e93 100644
--- a/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
+++ b/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
@@ -23,76 +23,6 @@ module Deltacloud
feature :instances, :user_name
feature :images, :owner_id
- define_hardware_profile '66' do
- cpu 1
- memory 512
- storage 20 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '63' do
- cpu 1
- memory 1024
- storage 30 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '62' do
- cpu 2
- memory 2 * 1024
- storage 40 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '64' do
- cpu 2
- memory 4 * 1024
- storage 60 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '65' do
- cpu 4
- memory 8 * 1024
- storage 80 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '61' do
- cpu 8
- memory 16 * 1024
- storage 160 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '60' do
- cpu 12
- memory 32 * 1024
- storage 320 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '70' do
- cpu 16
- memory 48 * 1024
- storage 480 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '69' do
- cpu 16
- memory 64 * 1024
- storage 640 * 1024
- architecture ['i386', 'x86_64']
- end
-
- define_hardware_profile '68' do
- cpu 24
- memory 96 * 1024
- storage 960 * 1024
- architecture ['i386', 'x86_64']
- end
-
define_instance_states do
start.to( :pending ) .on( :create )
pending.to( :running ) .automatically
@@ -105,6 +35,36 @@ module Deltacloud
error.from(:running, :pending, :stopping)
end
+ define_hardware_profile('default')
+
+ def hardware_profiles(credentials, opts={})
+ do_client = new_client(credentials)
+ results = []
+ safely do
+ if opts[:id]
+ size = do_client.get("sizes/#{opts[:id]}")["size"]
+ results << hardware_profile_from(size)
+ else
+ sizes = do_client.get("sizes")["sizes"].each do |s|
+ size = do_client.get("sizes/#{s['id']}")["size"]
+ results << hardware_profile_from(size)
+ end
+ end
+ filter_hardware_profiles(results, opts)
+ end
+ end
+
+ def hardware_profile_ids(credentials)
+ do_client = new_client(credentials)
+ hwps = []
+ safely do
+ do_client.get("sizes")["sizes"].each do |s|
+ hwps << HardwareProfile.new(s["id"].to_s)
+ end
+ end
+ hwps
+ end
+
def realms(credentials, opts={})
safely do
new_client(credentials).get('regions')['regions'].map do |r|
@@ -124,18 +84,19 @@ module Deltacloud
# values to get less images.
#
def images(credentials, opts={})
+ hwps = hardware_profile_ids(credentials)
unless opts[:id]
- filter = opts[:owner_id] ? { :filter => opts[:owner_id] } : {}
+ filter = opts[:owner_id] ? { :filter => "my_images" } : {}
img_arr = safely do
new_client(credentials).get('images', filter)['images'].map do |i|
- convert_image(credentials, i)
+ convert_image(hwps, i)
end
end
filter_on( img_arr, :architecture, opts )
else
safely do
[convert_image(
- credentials,
+ hwps,
new_client(credentials).get('images/%s' % opts[:id])['image']
)]
end
@@ -289,7 +250,7 @@ module Deltacloud
)
end
- def convert_image(credentials, i)
+ def convert_image(hwps, i)
Image.new(
:id => i['id'].to_s,
:name => i['name'],
@@ -297,10 +258,22 @@ module Deltacloud
:owner_id => 'global',
:state => 'AVAILABLE',
:architecture => extract_arch_from_name(i['name']),
- :hardware_profiles => hardware_profiles(credentials)
+ :hardware_profiles => hwps
)
end
+ #{"cost_per_hour"=>0.00744, "cpu"=>1, "disk"=>20, "id"=>66, "memory"=>512, "name"=>"512MB"}
+ def hardware_profile_from(size)
+ hwp = HardwareProfile.new(size["id"].to_s) do
+ architecture 'x86_64'
+ memory size["memory"]
+ storage size["disk"]
+ cpu size["cpu"]
+ end
+ hwp.name=size["name"]
+ return hwp
+ end
+
end
end
end