You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2013/04/03 16:20:00 UTC
[PATCH core 1/5] Client: Added base64#encode for user_data (DTACLOUD-522)
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/lib/deltacloud/client.rb | 1 +
client/lib/deltacloud/client/methods/instance.rb | 1 +
2 files changed, 2 insertions(+)
diff --git a/client/lib/deltacloud/client.rb b/client/lib/deltacloud/client.rb
index c7048dd..7304146 100644
--- a/client/lib/deltacloud/client.rb
+++ b/client/lib/deltacloud/client.rb
@@ -19,6 +19,7 @@ module Deltacloud
require 'ostruct'
require 'nokogiri'
require 'faraday'
+ require 'base64'
# Core extensions
require_relative './core_ext'
diff --git a/client/lib/deltacloud/client/methods/instance.rb b/client/lib/deltacloud/client/methods/instance.rb
index 506c338..3ed6a31 100644
--- a/client/lib/deltacloud/client/methods/instance.rb
+++ b/client/lib/deltacloud/client/methods/instance.rb
@@ -52,6 +52,7 @@ module Deltacloud::Client
# Returns created instance, or list of created instances or all instances.
#
def create_instance(image_id, create_opts={})
+ create_opts[:user_data] = Base64::encode64(create_opts[:user_data]) if create_opts[:user_data]
r = create_resource :instance, create_opts.merge(
:image_id => image_id,
:no_convert_model => true
--
1.8.1.4
[PATCH core 2/5] Client: Make possible to retrieve attrs from InstanceAddress (DTACLOUD-522)
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
.../lib/deltacloud/client/models/instance_address.rb | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/client/lib/deltacloud/client/models/instance_address.rb b/client/lib/deltacloud/client/models/instance_address.rb
index f40c264..1099c8b 100644
--- a/client/lib/deltacloud/client/models/instance_address.rb
+++ b/client/lib/deltacloud/client/models/instance_address.rb
@@ -14,10 +14,18 @@
# under the License.
module Deltacloud::Client
- class InstanceAddress < OpenStruct
+ class InstanceAddress
- attr_reader :type
- attr_reader :value
+ attr_reader :type, :value
+
+ def initialize(type, value)
+ @type = type
+ @value = value
+ end
+
+ def [](attr)
+ instance_variable_get("@#{attr}")
+ end
def to_s
@value
@@ -25,10 +33,7 @@ module Deltacloud::Client
def self.convert(address_xml_block)
address_xml_block.map do |addr|
- new(
- :type => addr['type'],
- :value => addr.text
- )
+ new(addr['type'].to_sym, addr.text)
end
end
end
--
1.8.1.4
[PATCH core 4/5] Client: Updated tests for #url and InstanceAddress (DTACLOUD-523)
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/tests/methods/instance_test.rb | 6 ++++++
client/tests/models/image_test.rb | 2 ++
2 files changed, 8 insertions(+)
diff --git a/client/tests/methods/instance_test.rb b/client/tests/methods/instance_test.rb
index 47b3934..4abe1b2 100644
--- a/client/tests/methods/instance_test.rb
+++ b/client/tests/methods/instance_test.rb
@@ -50,6 +50,12 @@ describe Deltacloud::Client::Methods::Instance do
@client.must_respond_to :instance
result = @client.instance('inst1')
result.must_be_instance_of Deltacloud::Client::Instance
+ result.public_addresses.wont_be_empty
+ result.public_addresses.first[:type].must_equal :hostname
+ result.public_addresses.first.type.must_equal :hostname
+ result.public_addresses.first[:value].must_equal 'img1.inst1.public.com'
+ result.public_addresses.first.value.must_equal 'img1.inst1.public.com'
+ result.public_addresses.first.to_s.must_equal 'img1.inst1.public.com'
lambda { @client.instance(nil) }.must_raise Deltacloud::Client::NotFound
lambda { @client.instance('foo') }.must_raise Deltacloud::Client::NotFound
end
diff --git a/client/tests/models/image_test.rb b/client/tests/models/image_test.rb
index 6c32d06..a9305ed 100644
--- a/client/tests/models/image_test.rb
+++ b/client/tests/models/image_test.rb
@@ -58,6 +58,8 @@ describe Deltacloud::Client::Image do
it 'supports #id' do
img = @client.image('img1')
lambda { img.id.must_equal 'img1' }.must_output nil, "[DEPRECATION] `id` is deprecated because of a possible conflict with Object#id. Use `_id` instead.\n"
+ img.must_respond_to :url
+ img.url.must_equal 'http://localhost:3001/api/images/img1'
end
end
--
1.8.1.4
[PATCH core 3/5] Client: Added #url method to all client objects
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/lib/deltacloud/client/models/base.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/client/lib/deltacloud/client/models/base.rb b/client/lib/deltacloud/client/models/base.rb
index dbf34f7..cfdab5d 100644
--- a/client/lib/deltacloud/client/models/base.rb
+++ b/client/lib/deltacloud/client/models/base.rb
@@ -27,6 +27,7 @@ module Deltacloud::Client
# - obj_id -> The :id of Deltacloud API model (eg. instance ID)
#
attr_reader :obj_id
+ attr_reader :url
attr_reader :name
attr_reader :description
@@ -122,6 +123,7 @@ module Deltacloud::Client
attrs = parse(body)
attrs.merge!({
:_id => body['id'],
+ :url => body['href'],
:_client => client_ref,
:name => body.text_at(:name),
:description => body.text_at(:description)
--
1.8.1.4
[PATCH core 5/5] Client: Added #actions and #create_image for Instance
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/lib/deltacloud/client/models/instance.rb | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/client/lib/deltacloud/client/models/instance.rb b/client/lib/deltacloud/client/models/instance.rb
index 01e1882..77d3498 100644
--- a/client/lib/deltacloud/client/models/instance.rb
+++ b/client/lib/deltacloud/client/models/instance.rb
@@ -26,6 +26,7 @@ module Deltacloud::Client
attr_reader :owner_id
attr_reader :image_id
attr_reader :hardware_profile_id
+ attr_reader :actions
attr_accessor :state
attr_accessor :public_addresses
@@ -74,6 +75,15 @@ module Deltacloud::Client
super
end
+ def can_create_image?
+ actions.include? :create_image
+ end
+
+ def create_image(create_opts={})
+ return false unless can_create_image?
+ super(_id, create_opts)
+ end
+
# Helper for is_STATE?
#
# is_running?
@@ -100,7 +110,8 @@ module Deltacloud::Client
),
:private_addresses => InstanceAddress.convert(
xml_body.xpath('private_addresses/address')
- )
+ ),
+ :actions => xml_body.xpath('actions/link').map { |a| a['rel'].to_sym }
}
end
--
1.8.1.4
Re: [PATCH core 1/5] Client: Added base64#encode for user_data
(DTACLOUD-522)
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2013-04-04 at 16:06 -0700, David Lutterkort wrote:
> On Wed, 2013-04-03 at 16:20 +0200, mfojtik@redhat.com wrote:
> > From: Michal Fojtik <mf...@redhat.com>
> >
>
> ACK
nm .. just saw that they were ack'd already in tracker.
David
Re: [PATCH core 1/5] Client: Added base64#encode for user_data
(DTACLOUD-522)
Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2013-04-03 at 16:20 +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
ACK