You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2011/06/17 17:06:35 UTC
[PATCH] Implements firewall support for ec2 instances
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/deltacloud/base_driver/features.rb | 2 +-
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 6 ++++--
server/lib/deltacloud/models/instance.rb | 1 +
server/server.rb | 1 +
server/views/instances/new.html.haml | 14 ++++++++++++++
server/views/instances/show.html.haml | 5 +++++
server/views/instances/show.xml.haml | 4 ++++
7 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index 4a2f1f8..c3e296f 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -187,7 +187,7 @@ module Deltacloud
end
end
- declare_feature :instances, :firewall do
+ declare_feature :instances, :firewalls do
description "Put instance in one or more firewalls (security groups) on launch"
operation :create do
param :firewalls, :array, :optional, nil, "Array of firewall ID strings"
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index b0b9712..2b9b0b1 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -39,7 +39,7 @@ module Deltacloud
feature :instances, :user_data
feature :instances, :authentication_key
- feature :instances, :firewall
+ feature :instances, :firewalls
feature :instances, :instance_count
feature :images, :owner_id
feature :buckets, :bucket_location
@@ -188,7 +188,8 @@ module Deltacloud
instance_options.merge!(:key_name => opts[:keyname]) if opts[:keyname]
instance_options.merge!(:availability_zone => opts[:realm_id]) if opts[:realm_id]
instance_options.merge!(:instance_type => opts[:hwp_id]) if opts[:hwp_id] && opts[:hwp_id].length > 0
- instance_options.merge!(:group_ids => opts[:firewalls]) if opts[:firewalls]
+ firewalls = opts.inject([]){|res, (k,v)| res << v if k =~ /firewalls\d+$/; res}
+ instance_options.merge!(:group_ids => firewalls ) unless firewalls.empty?
instance_options.merge!(
:min_count => opts[:instance_count],
:max_count => opts[:instance_count]
@@ -743,6 +744,7 @@ module Deltacloud
:realm_id => instance[:aws_availability_zone],
:private_addresses => instance[:private_dns_name],
:public_addresses => instance[:dns_name],
+ :firewalls => instance[:aws_groups],
:create_image => can_create_image
)
end
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index c7547e3..83e7e5f 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -31,6 +31,7 @@ class Instance < BaseModel
attr_accessor :username
attr_accessor :password
attr_accessor :create_image
+ attr_accessor :firewalls
def can_create_image?
self.create_image
diff --git a/server/server.rb b/server/server.rb
index 67d2b3d..4593637 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -261,6 +261,7 @@ get "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/instances/new" do
@hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture )
@realms = driver.realms(credentials)
@keys = driver.keys(credentials) if driver_has_feature?(:authentication_key)
+ @firewalls = driver.firewalls(credentials) if driver_has_feature?(:firewalls)
if driver_has_feature?(:register_to_load_balancer)
@load_balancers = driver.load_balancers(credentials)
end
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index 647bf63..70bd9d2 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -35,6 +35,20 @@
%option
- @keys.each do |key|
%option{ :value => key.id } #{key.id}
+ -if driver_has_feature?(:firewalls)
+ %p
+ %label
+ Firewalls:
+ %br
+ %br
+ - @firewalls.each_index do |i|
+ - if @firewalls[i].name == 'default'
+ %input{:type => :checkbox, :value => @firewalls[i].name, :name => "firewalls#{i}", :checked => :true}/
+ - else
+ %input{:type => :checkbox, :value => @firewalls[i].name, :name => "firewalls#{i}"}/
+ = @firewalls[i].name
+ %br
+ %br
- if !@hardware_profiles.empty?
%h3 What size machine?
- for hwp in @hardware_profiles
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 6c53bde..5fae5fe 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -50,6 +50,11 @@
%dt Key
%dd
= @instance.keyname
+ - if @instance.firewalls
+ %di
+ %dt Firewalls
+ %dd
+ = @instance.firewalls.join(", ")
%di
%dt
%dd
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index efbdac1..5fd85fc 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -43,6 +43,10 @@
- @instance.private_addresses.each do |address|
%address<
=address
+ - if @instance.firewalls
+ %firewalls<
+ - @instance.firewalls.each do |firewall|
+ %firewall{:href => firewall_url(firewall), :id => firewall }
- if driver_has_auth_features?
%authentication{ :type => driver_auth_feature_name }
- if @instance.authn_feature_failed?
--
1.7.3.4
Re: [PATCH] Implements firewall support for ec2 instances
Posted by Michal Fojtik <mf...@redhat.com>.
On Jun 17, 2011, at 5:06 PM, marios@redhat.com wrote:
ACK.
-- Michal
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/deltacloud/base_driver/features.rb | 2 +-
> server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 6 ++++--
> server/lib/deltacloud/models/instance.rb | 1 +
> server/server.rb | 1 +
> server/views/instances/new.html.haml | 14 ++++++++++++++
> server/views/instances/show.html.haml | 5 +++++
> server/views/instances/show.xml.haml | 4 ++++
> 7 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
> index 4a2f1f8..c3e296f 100644
> --- a/server/lib/deltacloud/base_driver/features.rb
> +++ b/server/lib/deltacloud/base_driver/features.rb
> @@ -187,7 +187,7 @@ module Deltacloud
> end
> end
>
> - declare_feature :instances, :firewall do
> + declare_feature :instances, :firewalls do
> description "Put instance in one or more firewalls (security groups) on launch"
> operation :create do
> param :firewalls, :array, :optional, nil, "Array of firewall ID strings"
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index b0b9712..2b9b0b1 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -39,7 +39,7 @@ module Deltacloud
>
> feature :instances, :user_data
> feature :instances, :authentication_key
> - feature :instances, :firewall
> + feature :instances, :firewalls
> feature :instances, :instance_count
> feature :images, :owner_id
> feature :buckets, :bucket_location
> @@ -188,7 +188,8 @@ module Deltacloud
> instance_options.merge!(:key_name => opts[:keyname]) if opts[:keyname]
> instance_options.merge!(:availability_zone => opts[:realm_id]) if opts[:realm_id]
> instance_options.merge!(:instance_type => opts[:hwp_id]) if opts[:hwp_id] && opts[:hwp_id].length > 0
> - instance_options.merge!(:group_ids => opts[:firewalls]) if opts[:firewalls]
> + firewalls = opts.inject([]){|res, (k,v)| res << v if k =~ /firewalls\d+$/; res}
> + instance_options.merge!(:group_ids => firewalls ) unless firewalls.empty?
> instance_options.merge!(
> :min_count => opts[:instance_count],
> :max_count => opts[:instance_count]
> @@ -743,6 +744,7 @@ module Deltacloud
> :realm_id => instance[:aws_availability_zone],
> :private_addresses => instance[:private_dns_name],
> :public_addresses => instance[:dns_name],
> + :firewalls => instance[:aws_groups],
> :create_image => can_create_image
> )
> end
> diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
> index c7547e3..83e7e5f 100644
> --- a/server/lib/deltacloud/models/instance.rb
> +++ b/server/lib/deltacloud/models/instance.rb
> @@ -31,6 +31,7 @@ class Instance < BaseModel
> attr_accessor :username
> attr_accessor :password
> attr_accessor :create_image
> + attr_accessor :firewalls
>
> def can_create_image?
> self.create_image
> diff --git a/server/server.rb b/server/server.rb
> index 67d2b3d..4593637 100644
> --- a/server/server.rb
> +++ b/server/server.rb
> @@ -261,6 +261,7 @@ get "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/instances/new" do
> @hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture )
> @realms = driver.realms(credentials)
> @keys = driver.keys(credentials) if driver_has_feature?(:authentication_key)
> + @firewalls = driver.firewalls(credentials) if driver_has_feature?(:firewalls)
> if driver_has_feature?(:register_to_load_balancer)
> @load_balancers = driver.load_balancers(credentials)
> end
> diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
> index 647bf63..70bd9d2 100644
> --- a/server/views/instances/new.html.haml
> +++ b/server/views/instances/new.html.haml
> @@ -35,6 +35,20 @@
> %option
> - @keys.each do |key|
> %option{ :value => key.id } #{key.id}
> + -if driver_has_feature?(:firewalls)
> + %p
> + %label
> + Firewalls:
> + %br
> + %br
> + - @firewalls.each_index do |i|
> + - if @firewalls[i].name == 'default'
> + %input{:type => :checkbox, :value => @firewalls[i].name, :name => "firewalls#{i}", :checked => :true}/
> + - else
> + %input{:type => :checkbox, :value => @firewalls[i].name, :name => "firewalls#{i}"}/
> + = @firewalls[i].name
> + %br
> + %br
> - if !@hardware_profiles.empty?
> %h3 What size machine?
> - for hwp in @hardware_profiles
> diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
> index 6c53bde..5fae5fe 100644
> --- a/server/views/instances/show.html.haml
> +++ b/server/views/instances/show.html.haml
> @@ -50,6 +50,11 @@
> %dt Key
> %dd
> = @instance.keyname
> + - if @instance.firewalls
> + %di
> + %dt Firewalls
> + %dd
> + = @instance.firewalls.join(", ")
> %di
> %dt
> %dd
> diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
> index efbdac1..5fd85fc 100644
> --- a/server/views/instances/show.xml.haml
> +++ b/server/views/instances/show.xml.haml
> @@ -43,6 +43,10 @@
> - @instance.private_addresses.each do |address|
> %address<
> =address
> + - if @instance.firewalls
> + %firewalls<
> + - @instance.firewalls.each do |firewall|
> + %firewall{:href => firewall_url(firewall), :id => firewall }
> - if driver_has_auth_features?
> %authentication{ :type => driver_auth_feature_name }
> - if @instance.authn_feature_failed?
> --
> 1.7.3.4
>
------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org