From 414e149debf8fd1a954d4b7d3e4ac65edfbf6e96 Mon Sep 17 00:00:00 2001 From: Jerry Jackson Date: Thu, 15 Nov 2012 10:53:16 -0600 Subject: [PATCH 1/4] added some more bits to recognize elastic ips; Ironfan still ignoring my pleas to asscoiate at this point in time. --- lib/chef/knife/ironfan_knife_common.rb | 3 ++- lib/ironfan/dsl/ec2.rb | 6 +++--- lib/ironfan/provider/ec2/elastic_ip.rb | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/chef/knife/ironfan_knife_common.rb b/lib/chef/knife/ironfan_knife_common.rb index 5bc6a946..dbb2f022 100644 --- a/lib/chef/knife/ironfan_knife_common.rb +++ b/lib/chef/knife/ironfan_knife_common.rb @@ -1,4 +1,4 @@ -require 'chef/knife' + require 'chef/knife' module Ironfan module KnifeCommon @@ -140,6 +140,7 @@ def bootstrapper(computer) bootstrap.name_args = [ hostname ] bootstrap.config[:computer] = computer bootstrap.config[:server] = server + bootstrap.config[:elastic_ip] = connection.server.associate_address bootstrap.config[:run_list] = server.run_list bootstrap.config[:ssh_user] = config[:ssh_user] || computer.ssh_user bootstrap.config[:attribute] = config[:attribute] diff --git a/lib/ironfan/dsl/ec2.rb b/lib/ironfan/dsl/ec2.rb index 2943edc3..0b20944a 100644 --- a/lib/ironfan/dsl/ec2.rb +++ b/lib/ironfan/dsl/ec2.rb @@ -14,7 +14,7 @@ class Ec2 < Cloud magic :bootstrap_distro, String, :default => ->{ image_info[:bootstrap_distro] } magic :chef_client_script, String magic :default_availability_zone, String, :default => ->{ availability_zones.first } - magic :elastic_ip String + magic :elastic_ip, String collection :elastic_load_balancers, Ironfan::Dsl::Ec2::ElasticLoadBalancer, :key_method => :name magic :flavor, String, :default => 't1.micro' collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name @@ -51,6 +51,7 @@ def elastic_ip(address) Ironfan.safely do Ironfan.fog_connection.associate_address(self.fog_server.id, address) end + end def ssh_key_name(computer) keypair ? keypair.to_s : computer.server.cluster_name @@ -67,8 +68,7 @@ def to_display(style,values={}) values["AZ"] = default_availability_zone return values if style == :default - # values["Elastic IP"] = public_ip if public_ip - values["Elastic IP"] = elastic_ip if elastic_ip + values["Elastic IP"] = public_ip if public_ip values end diff --git a/lib/ironfan/provider/ec2/elastic_ip.rb b/lib/ironfan/provider/ec2/elastic_ip.rb index 012e5a30..ca550833 100644 --- a/lib/ironfan/provider/ec2/elastic_ip.rb +++ b/lib/ironfan/provider/ec2/elastic_ip.rb @@ -3,7 +3,13 @@ class Provider class Ec2 class ElasticIp < Ironfan::Provider::Resource + delegate :allocate_address, :associate_address, :describe_addresses + field :domain, Ironfan::DSL::Compute end end end end + +# 'publicIp', 'domain' +# vpc use only = 'allocationId', 'associationId', 'instanceId', 'requestId' + From 714f53cff7ec4fc8fea59dfaaab30c069c6756d0 Mon Sep 17 00:00:00 2001 From: Jerry Jackson Date: Thu, 15 Nov 2012 15:05:41 -0600 Subject: [PATCH 2/4] pushed still non-working state to repo for coop testing --- lib/chef/knife/ironfan_knife_common.rb | 2 +- lib/ironfan/dsl/compute.rb | 6 ++++++ lib/ironfan/dsl/ec2.rb | 9 ++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/chef/knife/ironfan_knife_common.rb b/lib/chef/knife/ironfan_knife_common.rb index dbb2f022..0b987841 100644 --- a/lib/chef/knife/ironfan_knife_common.rb +++ b/lib/chef/knife/ironfan_knife_common.rb @@ -140,7 +140,7 @@ def bootstrapper(computer) bootstrap.name_args = [ hostname ] bootstrap.config[:computer] = computer bootstrap.config[:server] = server - bootstrap.config[:elastic_ip] = connection.server.associate_address + bootstrap.config[:elastic_ip] = server.associate_address(elastic_ip) bootstrap.config[:run_list] = server.run_list bootstrap.config[:ssh_user] = config[:ssh_user] || computer.ssh_user bootstrap.config[:attribute] = config[:attribute] diff --git a/lib/ironfan/dsl/compute.rb b/lib/ironfan/dsl/compute.rb index 3adf8af5..17aafad3 100644 --- a/lib/ironfan/dsl/compute.rb +++ b/lib/ironfan/dsl/compute.rb @@ -32,6 +32,12 @@ def initialize(attrs={},&block) super end + def elastic_ip(address) + Ironfan.safely do + Ironfan.fog_connection.associate_address(self.fog_server.id, address) + end + end + def full_name() name; end # Add the given role/recipe to the run list. You can specify placement of diff --git a/lib/ironfan/dsl/ec2.rb b/lib/ironfan/dsl/ec2.rb index 0b20944a..3c4b0a69 100644 --- a/lib/ironfan/dsl/ec2.rb +++ b/lib/ironfan/dsl/ec2.rb @@ -47,12 +47,6 @@ def image_id result = read_attribute(:image_id) || image_info[:image_id] end - def elastic_ip(address) - Ironfan.safely do - Ironfan.fog_connection.associate_address(self.fog_server.id, address) - end - end - def ssh_key_name(computer) keypair ? keypair.to_s : computer.server.cluster_name end @@ -68,7 +62,8 @@ def to_display(style,values={}) values["AZ"] = default_availability_zone return values if style == :default - values["Elastic IP"] = public_ip if public_ip + # values["Elastic IP"] = public_ip if public_ip + values["Elastic IP"] = elastic_ip if elastic_ip values end From 951b9dc14ac09add135253b945c07fa5a77dc410 Mon Sep 17 00:00:00 2001 From: Jerry Jackson Date: Mon, 19 Nov 2012 14:23:57 -0600 Subject: [PATCH 3/4] recent changes added to the mix; todo: fix missing method --- lib/ironfan/dsl/compute.rb | 6 ------ lib/ironfan/dsl/ec2.rb | 8 ++++++++ lib/ironfan/provider/ec2/elastic_ip.rb | 3 ++- lib/ironfan/provider/ec2/machine.rb | 1 + lib/ironfan/requirements.rb | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/ironfan/dsl/compute.rb b/lib/ironfan/dsl/compute.rb index 17aafad3..3adf8af5 100644 --- a/lib/ironfan/dsl/compute.rb +++ b/lib/ironfan/dsl/compute.rb @@ -32,12 +32,6 @@ def initialize(attrs={},&block) super end - def elastic_ip(address) - Ironfan.safely do - Ironfan.fog_connection.associate_address(self.fog_server.id, address) - end - end - def full_name() name; end # Add the given role/recipe to the run list. You can specify placement of diff --git a/lib/ironfan/dsl/ec2.rb b/lib/ironfan/dsl/ec2.rb index 3c4b0a69..df8c81a0 100644 --- a/lib/ironfan/dsl/ec2.rb +++ b/lib/ironfan/dsl/ec2.rb @@ -5,6 +5,14 @@ class Dsl class Compute < Ironfan::Dsl def ec2(*attrs,&block) cloud(:ec2,*attrs,&block); end + + def elastic_ip(address) + pp(self.fog_connection) + pp(self.fog_server) + Ironfan.safely do + Ironfan.fog_connection.associate_address(self.fog_server.id, address) + end + end end class Ec2 < Cloud diff --git a/lib/ironfan/provider/ec2/elastic_ip.rb b/lib/ironfan/provider/ec2/elastic_ip.rb index ca550833..cf8222c8 100644 --- a/lib/ironfan/provider/ec2/elastic_ip.rb +++ b/lib/ironfan/provider/ec2/elastic_ip.rb @@ -4,7 +4,8 @@ class Ec2 class ElasticIp < Ironfan::Provider::Resource delegate :allocate_address, :associate_address, :describe_addresses - field :domain, Ironfan::DSL::Compute + :to => :adaptee + field :domain, String, :default => 'standard' end end end diff --git a/lib/ironfan/provider/ec2/machine.rb b/lib/ironfan/provider/ec2/machine.rb index 8557d0cd..4105641a 100644 --- a/lib/ironfan/provider/ec2/machine.rb +++ b/lib/ironfan/provider/ec2/machine.rb @@ -87,6 +87,7 @@ def to_display(style,values={}) values["Volumes"] = volumes.map(&:id).join(', ') values["SSH Key"] = key_name values + pp(public_ip_address) end def ssh_key diff --git a/lib/ironfan/requirements.rb b/lib/ironfan/requirements.rb index 77fa9ca4..8bb7a04f 100644 --- a/lib/ironfan/requirements.rb +++ b/lib/ironfan/requirements.rb @@ -35,6 +35,7 @@ require 'ironfan/provider/ec2/keypair' require 'ironfan/provider/ec2/placement_group' require 'ironfan/provider/ec2/security_group' +require 'ironfan/provider/ec2/elastic_ip' require 'ironfan/provider/ec2/elastic_load_balancer' require 'ironfan/provider/ec2/iam_server_certificate' From e6418e6c0337782f4764f621b8496bb2a065e93f Mon Sep 17 00:00:00 2001 From: Jerry Jackson Date: Tue, 20 Nov 2012 13:39:18 -0600 Subject: [PATCH 4/4] Elastic IP now attaches at launch time; still working on knife cluster ssh functionality. --- lib/ironfan/dsl/ec2.rb | 8 -------- lib/ironfan/provider/ec2.rb | 7 +++++++ lib/ironfan/provider/ec2/elastic_ip.rb | 18 +++++++++++++++--- lib/ironfan/provider/ec2/machine.rb | 4 +++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/ironfan/dsl/ec2.rb b/lib/ironfan/dsl/ec2.rb index df8c81a0..3c4b0a69 100644 --- a/lib/ironfan/dsl/ec2.rb +++ b/lib/ironfan/dsl/ec2.rb @@ -5,14 +5,6 @@ class Dsl class Compute < Ironfan::Dsl def ec2(*attrs,&block) cloud(:ec2,*attrs,&block); end - - def elastic_ip(address) - pp(self.fog_connection) - pp(self.fog_server) - Ironfan.safely do - Ironfan.fog_connection.associate_address(self.fog_server.id, address) - end - end end class Ec2 < Cloud diff --git a/lib/ironfan/provider/ec2.rb b/lib/ironfan/provider/ec2.rb index dc133873..370ef678 100644 --- a/lib/ironfan/provider/ec2.rb +++ b/lib/ironfan/provider/ec2.rb @@ -15,6 +15,13 @@ def self.connection @@connection ||= Fog::Compute.new(self.aws_credentials.merge({ :provider => 'AWS' })) end + def self.eip + c ||= Fog::Compute.new(self.aws_credentials.merge({ :provider => 'AWS' })) + address = c.addresses.create + address.server = server + server.reload + end + def self.elb @@elb ||= Fog::AWS::ELB.new(self.aws_credentials) end diff --git a/lib/ironfan/provider/ec2/elastic_ip.rb b/lib/ironfan/provider/ec2/elastic_ip.rb index cf8222c8..6132395d 100644 --- a/lib/ironfan/provider/ec2/elastic_ip.rb +++ b/lib/ironfan/provider/ec2/elastic_ip.rb @@ -3,9 +3,22 @@ class Provider class Ec2 class ElasticIp < Ironfan::Provider::Resource - delegate :allocate_address, :associate_address, :describe_addresses - :to => :adaptee + delegate :allocate, :associate, :describe, :to => :adaptee field :domain, String, :default => 'standard' + + :associate + + def address(ip) + + end + + def attach(ip, timeout) + + end + + def detach(ip, timeout) + + end end end end @@ -13,4 +26,3 @@ class ElasticIp < Ironfan::Provider::Resource # 'publicIp', 'domain' # vpc use only = 'allocationId', 'associationId', 'instanceId', 'requestId' - diff --git a/lib/ironfan/provider/ec2/machine.rb b/lib/ironfan/provider/ec2/machine.rb index 4105641a..988551c5 100644 --- a/lib/ironfan/provider/ec2/machine.rb +++ b/lib/ironfan/provider/ec2/machine.rb @@ -160,6 +160,8 @@ def self.create!(computer) fog_server = Ec2.connection.servers.create(launch_desc) machine = Machine.new(:adaptee => fog_server) computer.machine = machine + # set elastic_ip here? + # machine.ip = elastic_ip if elastic_ip remember machine, :id => computer.name fog_server.wait_for { ready? } @@ -237,7 +239,7 @@ def self.launch_description(computer) :user_data => JSON.pretty_generate(user_data_hsh), :block_device_mapping => block_device_mapping(computer), :availability_zone => cloud.default_availability_zone, - :monitoring => cloud.monitoring, + :monitoring => cloud.monitoring } # VPC security_groups can only be addressed by id (not name)