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 2010/12/07 13:42:24 UTC
[PATCH core] Added 'assign_address' for instance (EC2 Elastic IP)
From: Michal Fojtik <mf...@redhat.com>
---
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 13 +++++++++++++
server/server.rb | 13 +++++++++++++
server/views/instances/show.html.haml | 6 ++++++
3 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index a7a9dbb..d705131 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -199,6 +199,19 @@ class EC2Driver < Deltacloud::BaseDriver
end
end
+ def assign_address(credentials, opts={})
+ client = new_client(credentials, :ec2)
+ puts opts.inspect
+ safely do
+ unless client.associate_address(:instance_id => opts[:id], :public_ip => opts[:address])
+ raise Deltacloud::BackendError.new(500, "AssignAddress",
+ "This address cannot be associated to given instance")
+ else
+ return true
+ end
+ end
+ end
+
def generate_instance(ec2, id, backup)
begin
this_instance = ec2.describe_instances( :instance_id => id ).reservationSet.item.first.instancesSet.item.first
diff --git a/server/server.rb b/server/server.rb
index 076859d..0184311 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -339,6 +339,19 @@ END
param :id, :string, :required
control { instance_action(:destroy) }
end
+
+ operation :assign_address, :method => :post, :member => true do
+ description "Assign as Elastic IP address to instance"
+ with_capability :assign_address
+ param :id, :string, :required
+ param :address, :string, :required
+ control do
+ if driver.assign_address(credentials, params)
+ redirect instance_url(params[:id])
+ end
+ end
+ end
+
end
collection :hardware_profiles do
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 0a6e115..21069ca 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -32,6 +32,12 @@
%dt Public Addresses
%dd
= @instance.public_addresses.collect { |address| "<div>#{address}</div>" }.join
+ %dd
+ %form{ :action => assign_address_instance_url(@instance.id), :method => :post}
+ %label{ :for => :address}
+ Associate IP:
+ %input{ :type => :text, :value => "", :name => :address }
+ %input{ :type => :submit, :value => "Assign" }
%di
%dt Private Addresses
%dd
--
1.7.3.2
Re: [PATCH core] Added 'assign_address' for instance (EC2 Elastic
IP)
Posted by Michal Fojtik <mf...@redhat.com>.
On 07/12/10 16:49 +0200, marios@redhat.com wrote:
>Ack, applied fine, runs fine. I fired up an instance and associated
>an address which all worked ok.
>
>comments: i thought it would be nicer if we had some kind of 'list'
>of available addresses rather than a text field. I quickly realised
>this is dependent on 'ip address management' functions which we've
>talked about but not done yet. Having a quick look at the ec2 api, it
>seems really doable - i mean they have the lot:
>
>=AllocateAddress - request a new address for your account
POST /api/addresses
>=AssociateAddress - this is what you do in this patch
PUT /api/instances/address
>=DescribeAddresses - show current list of addresses, and you can work
>out which are available and which are assigned to instances
GET /api/addresses
>=DisassociateAddress - disassociate from an instance (release back
>into available pool)
DELETE /api/instances/address
>=ReleaseAddress - release from your account altogether.
DELETE /api/addresses/:address
>It makes sense for the 'associate address' part to happen in the
>'show instance' haml, but I think we probably need a new
>'ip_addresses' collection for the rest. I suspect that is not going
>to be as simple as it sounds - we will need some kind of 'list of
>instances' and 'list of ips' to be served together which might make
>for a long server response.
+1
Agree, I can make it as a collection and include it in API as well.
Also this will work for GoGrid, since they already have some 'IP'
managment and calls to get list of IP (you just can't create a new IP).
We can also 'link' from Instance to Address (or IpAddress) collection
as we do with Images or Hardware Profiles.
-- Michal
>marios
>
>
>
>On 07/12/10 14:42, mfojtik@redhat.com wrote:
>>From: Michal Fojtik<mf...@redhat.com>
>>
>>---
>> server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 13 +++++++++++++
>> server/server.rb | 13 +++++++++++++
>> server/views/instances/show.html.haml | 6 ++++++
>> 3 files changed, 32 insertions(+), 0 deletions(-)
>>
>>diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>index a7a9dbb..d705131 100644
>>--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>@@ -199,6 +199,19 @@ class EC2Driver< Deltacloud::BaseDriver
>> end
>> end
>>
>>+ def assign_address(credentials, opts={})
>>+ client = new_client(credentials, :ec2)
>>+ puts opts.inspect
>>+ safely do
>>+ unless client.associate_address(:instance_id => opts[:id], :public_ip => opts[:address])
>>+ raise Deltacloud::BackendError.new(500, "AssignAddress",
>>+ "This address cannot be associated to given instance")
>>+ else
>>+ return true
>>+ end
>>+ end
>>+ end
>>+
>> def generate_instance(ec2, id, backup)
>> begin
>> this_instance = ec2.describe_instances( :instance_id => id ).reservationSet.item.first.instancesSet.item.first
>>diff --git a/server/server.rb b/server/server.rb
>>index 076859d..0184311 100644
>>--- a/server/server.rb
>>+++ b/server/server.rb
>>@@ -339,6 +339,19 @@ END
>> param :id, :string, :required
>> control { instance_action(:destroy) }
>> end
>>+
>>+ operation :assign_address, :method => :post, :member => true do
>>+ description "Assign as Elastic IP address to instance"
>>+ with_capability :assign_address
>>+ param :id, :string, :required
>>+ param :address, :string, :required
>>+ control do
>>+ if driver.assign_address(credentials, params)
>>+ redirect instance_url(params[:id])
>>+ end
>>+ end
>>+ end
>>+
>> end
>>
>> collection :hardware_profiles do
>>diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
>>index 0a6e115..21069ca 100644
>>--- a/server/views/instances/show.html.haml
>>+++ b/server/views/instances/show.html.haml
>>@@ -32,6 +32,12 @@
>> %dt Public Addresses
>> %dd
>> = @instance.public_addresses.collect { |address| "<div>#{address}</div>" }.join
>>+ %dd
>>+ %form{ :action => assign_address_instance_url(@instance.id), :method => :post}
>>+ %label{ :for => :address}
>>+ Associate IP:
>>+ %input{ :type => :text, :value => "", :name => :address }
>>+ %input{ :type => :submit, :value => "Assign" }
>> %di
>> %dt Private Addresses
>> %dd
>
--
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------
Re: [PATCH core] Added 'assign_address' for instance (EC2 Elastic
IP)
Posted by "marios@redhat.com" <ma...@redhat.com>.
Ack, applied fine, runs fine. I fired up an instance and associated an
address which all worked ok.
comments: i thought it would be nicer if we had some kind of 'list' of
available addresses rather than a text field. I quickly realised this is
dependent on 'ip address management' functions which we've talked about
but not done yet. Having a quick look at the ec2 api, it seems really
doable - i mean they have the lot:
=AllocateAddress - request a new address for your account
=AssociateAddress - this is what you do in this patch
=DescribeAddresses - show current list of addresses, and you can work
out which are available and which are assigned to instances
=DisassociateAddress - disassociate from an instance (release back into
available pool)
=ReleaseAddress - release from your account altogether.
It makes sense for the 'associate address' part to happen in the 'show
instance' haml, but I think we probably need a new 'ip_addresses'
collection for the rest. I suspect that is not going to be as simple as
it sounds - we will need some kind of 'list of instances' and 'list of
ips' to be served together which might make for a long server response.
marios
On 07/12/10 14:42, mfojtik@redhat.com wrote:
> From: Michal Fojtik<mf...@redhat.com>
>
> ---
> server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 13 +++++++++++++
> server/server.rb | 13 +++++++++++++
> server/views/instances/show.html.haml | 6 ++++++
> 3 files changed, 32 insertions(+), 0 deletions(-)
>
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index a7a9dbb..d705131 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -199,6 +199,19 @@ class EC2Driver< Deltacloud::BaseDriver
> end
> end
>
> + def assign_address(credentials, opts={})
> + client = new_client(credentials, :ec2)
> + puts opts.inspect
> + safely do
> + unless client.associate_address(:instance_id => opts[:id], :public_ip => opts[:address])
> + raise Deltacloud::BackendError.new(500, "AssignAddress",
> + "This address cannot be associated to given instance")
> + else
> + return true
> + end
> + end
> + end
> +
> def generate_instance(ec2, id, backup)
> begin
> this_instance = ec2.describe_instances( :instance_id => id ).reservationSet.item.first.instancesSet.item.first
> diff --git a/server/server.rb b/server/server.rb
> index 076859d..0184311 100644
> --- a/server/server.rb
> +++ b/server/server.rb
> @@ -339,6 +339,19 @@ END
> param :id, :string, :required
> control { instance_action(:destroy) }
> end
> +
> + operation :assign_address, :method => :post, :member => true do
> + description "Assign as Elastic IP address to instance"
> + with_capability :assign_address
> + param :id, :string, :required
> + param :address, :string, :required
> + control do
> + if driver.assign_address(credentials, params)
> + redirect instance_url(params[:id])
> + end
> + end
> + end
> +
> end
>
> collection :hardware_profiles do
> diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
> index 0a6e115..21069ca 100644
> --- a/server/views/instances/show.html.haml
> +++ b/server/views/instances/show.html.haml
> @@ -32,6 +32,12 @@
> %dt Public Addresses
> %dd
> = @instance.public_addresses.collect { |address| "<div>#{address}</div>" }.join
> + %dd
> + %form{ :action => assign_address_instance_url(@instance.id), :method => :post}
> + %label{ :for => :address}
> + Associate IP:
> + %input{ :type => :text, :value => "", :name => :address }
> + %input{ :type => :submit, :value => "Assign" }
> %di
> %dt Private Addresses
> %dd