deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core] Added 'assign_address' for instance (EC2 Elastic IP)
Date Tue, 07 Dec 2010 14:49:47 GMT
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<mfojtik@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


Mime
View raw message