Skip to content
This repository
Browse code

Merge pull request #219 from schade/develop

196_elastic_ips
  • Loading branch information...
commit 21dd0d506d26932789205f1ea3dd68def4449368 2 parents b4efd4e + 468b81f
Nathaniel Eliot authored December 10, 2012
5  config/knife.bash
@@ -129,6 +129,11 @@ _knife() {
129 129
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
130 130
         return 0
131 131
         ;;
  132
+    *knife_cluster_launch|*knife_cluster_show|*knife_cluster_edit)
  133
+        _chef_completion_cache -c ${words[0]}_cluster "${words[0]} cluster list|awk '{ print $1 }'"
  134
+        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  135
+        return 0
  136
+        ;;
132 137
     *knife_environment_show|*knife_environment_edit|*knife_environment_delete)
133 138
         _chef_completion_cache -c ${words[0]}_environments "${words[0]} environment list|${SED} -r -e 's/[\"\ ,]//g' -e '/[^0-9A-Za-z._-]+/d'"
134 139
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
5  lib/chef/knife/cluster_launch.rb
@@ -87,7 +87,6 @@ def run
87 87
         section("Launching computers", :green)
88 88
         display(target)
89 89
         launched = target.launch
90  
-
91 90
         # As each server finishes, configure it
92 91
         Ironfan.parallel(launched) do |computer|
93 92
           if (computer.is_a?(Exception)) then ui.warn "Error launching #{computer.inspect}; skipping after-launch tasks."; next; end
@@ -107,7 +106,7 @@ def perform_after_launch_tasks(computer)
107 106
         Ironfan.step(computer.name, 'waiting for ready', :white)
108 107
         # Wait for machine creation on amazon side
109 108
         computer.machine.wait_for{ ready? }
110  
-
  109
+        
111 110
         # Try SSH
112 111
         unless config[:dry_run]
113 112
           Ironfan.step(computer.name, 'trying ssh', :white)
@@ -116,7 +115,7 @@ def perform_after_launch_tasks(computer)
116 115
 
117 116
         Ironfan.step(computer.name, 'final provisioning', :white)
118 117
         computer.save
119  
-
  118
+        
120 119
         # Run Bootstrap
121 120
         if config[:bootstrap]
122 121
           Chef::Log.warn "UNTESTED --bootstrap"
2  lib/chef/knife/ironfan_knife_common.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'chef/knife'
  1
+ require 'chef/knife'
2 2
 
3 3
 module Ironfan
4 4
   module KnifeCommon
5  lib/ironfan/dsl/ec2.rb
@@ -14,6 +14,7 @@ class Ec2 < Cloud
14 14
       magic :bootstrap_distro,          String,         :default => ->{ image_info[:bootstrap_distro] }
15 15
       magic :chef_client_script,        String
16 16
       magic :default_availability_zone, String,         :default => ->{ availability_zones.first }
  17
+      magic :domain,                    String,         :default => 'standard'
17 18
       collection :elastic_load_balancers,  Ironfan::Dsl::Ec2::ElasticLoadBalancer, :key_method => :name
18 19
       magic :flavor,                    String,         :default => 't1.micro'
19 20
       collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name
@@ -25,7 +26,7 @@ class Ec2 < Cloud
25 26
       magic :permanent,                 :boolean,       :default => false
26 27
       magic :placement_group,           String
27 28
       magic :provider,                  Whatever,       :default => Ironfan::Provider::Ec2
28  
-      magic :public_ip,                 String
  29
+      magic :elastic_ip,                String
29 30
       magic :region,                    String,         :default => ->{ default_region }
30 31
       collection :security_groups,      Ironfan::Dsl::Ec2::SecurityGroup, :key_method => :name
31 32
       magic :ssh_user,                  String,         :default => ->{ image_info[:ssh_user] }
@@ -61,7 +62,7 @@ def to_display(style,values={})
61 62
         values["AZ"] =                default_availability_zone
62 63
         return values if style == :default
63 64
 
64  
-        values["Elastic IP"] =        public_ip if public_ip
  65
+        values["Public IP"] =        elastic_ip if elastic_ip
65 66
         values
66 67
       end
67 68
 
2  lib/ironfan/provider/ec2.rb
@@ -5,7 +5,7 @@ class Ec2 < Ironfan::IaasProvider
5 5
       self.handle = :ec2
6 6
 
7 7
       def self.resources
8  
-        [ Machine, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ]
  8
+        [ Machine, ElasticIp, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ]
9 9
       end
10 10
 
11 11
       #
73  lib/ironfan/provider/ec2/elastic_ip.rb
@@ -3,6 +3,79 @@ class Provider
3 3
     class Ec2
4 4
 
5 5
       class ElasticIp < Ironfan::Provider::Resource
  6
+      	delegate :addresses, :associate_address, :allocation_id, 
  7
+            :allocation_id=, :destroy, :domain, :domain=, 
  8
+            :describe_addresses, :disassociate_address, :domain, :id,
  9
+            :network_interface_id, :network_interface_id=, :public_ip, 
  10
+            :public_ip=, :public_ip_address, :save, :server=, :server, :server_id, 
  11
+            :server_id=,
  12
+        :to => :adaptee
  13
+ 
  14
+        def self.shared?()              true;                               end
  15
+        def self.multiple?()            false;                              end
  16
+        def self.resource_type()        :elastic_ip;                        end
  17
+
  18
+        def self.expected_ids(computer)
  19
+          [ computer.server.ec2.elastic_ip ]
  20
+        end
  21
+
  22
+        def name()                      adaptee.public_ip ;                 end
  23
+
  24
+        # FIXME: This is very broken, but somehow works around the breakage
  25
+        def self.new(*args)
  26
+          x = super
  27
+          x.adaptee = args[0][:adaptee]
  28
+          x
  29
+        end
  30
+
  31
+        #
  32
+        # Discovery
  33
+        #
  34
+
  35
+        def self.load!(cluster=nil, machine)
  36
+          Ec2.connection.addresses.each do |eip|
  37
+            register eip
  38
+            Chef::Log.debug("Loaded #{eip}")
  39
+          # The rest of this definition shows relevant information when -VV is passed to knife and aids in troubleshooting any refusal to attach Elastic IPs
  40
+            machine.facets.each do |f| 
  41
+              unless f.servers[0].clouds[:ec2].elastic_ip.nil? or eip.domain == "vpc"
  42
+                if eip.domain == "standard" and eip.public_ip == f.servers[0].clouds[:ec2].elastic_ip
  43
+                  Chef::Log.debug( "AWS domain: #{eip.domain}" )
  44
+                  Chef::Log.debug( "available ip match: #{eip.public_ip}" )
  45
+                  Chef::Log.debug( "----------------------" )
  46
+                end
  47
+              end
  48
+              unless eip.public_ip.nil? 
  49
+                if eip.domain == "standard"
  50
+                  if eip.public_ip == f.servers[0].clouds[:ec2].elastic_ip
  51
+                    unless f.servers[0].clouds[:ec2].elastic_ip.nil?
  52
+                      Chef::Log.debug( "ip given by cluster definition: #{f.servers[0].clouds[:ec2].elastic_ip}" )
  53
+                    else
  54
+                      Chef::Log.debug( "No matching Elastic IP available to your account." )
  55
+                    end
  56
+                  end
  57
+                end
  58
+              end
  59
+            end
  60
+          end
  61
+        end
  62
+
  63
+        #
  64
+        # Manipulation
  65
+        #
  66
+
  67
+        def self.save!(computer)
  68
+          return unless computer.machine?
  69
+          elastic_ip = computer.server.cloud(:ec2).elastic_ip
  70
+          return unless computer.created?
  71
+          Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
  72
+          Ironfan.unless_dry_run do
  73
+            Ironfan.safely do
  74
+              Ec2.connection.associate_address( computer.machine.id, elastic_ip )
  75
+            end
  76
+          end
  77
+        end
  78
+
6 79
       end
7 80
     end
8 81
   end
9  lib/ironfan/provider/ec2/machine.rb
@@ -71,8 +71,8 @@ def stop
71 71
         def to_display(style,values={})
72 72
           # style == :minimal
73 73
           values["State"] =             state.to_sym
74  
-          values["MachineID"] =        id
75  
-          values["Public IP"] =         public_ip_address
  74
+          values["MachineID"] =         id
  75
+          values["Public IP"] =         public_ip_address 
76 76
           values["Private IP"] =        private_ip_address
77 77
           values["Created On"] =        created_at.to_date
78 78
           return values if style == :minimal
@@ -163,7 +163,7 @@ def self.create!(computer)
163 163
 
164 164
             fog_server.wait_for { ready? }
165 165
           end
166  
-
  166
+          
167 167
           # tag the computer correctly
168 168
           tags = {
169 169
             'cluster' =>      computer.server.cluster_name,
@@ -224,7 +224,6 @@ def self.launch_description(computer)
224 224
             :client_key =>              computer.private_key
225 225
           }
226 226
 
227  
-
228 227
           # Fog does not actually create tags when it creates a server;
229 228
           #  they and permanence are applied during sync
230 229
           description = {
@@ -236,7 +235,7 @@ def self.launch_description(computer)
236 235
             :user_data            => JSON.pretty_generate(user_data_hsh),
237 236
             :block_device_mapping => block_device_mapping(computer),
238 237
             :availability_zone    => cloud.default_availability_zone,
239  
-            :monitoring           => cloud.monitoring,
  238
+            :monitoring           => cloud.monitoring
240 239
           }
241 240
 
242 241
           # VPC security_groups can only be addressed by id (not name)
1  lib/ironfan/requirements.rb
@@ -35,6 +35,7 @@
35 35
 require 'ironfan/provider/ec2/keypair'
36 36
 require 'ironfan/provider/ec2/placement_group'
37 37
 require 'ironfan/provider/ec2/security_group'
  38
+require 'ironfan/provider/ec2/elastic_ip'
38 39
 require 'ironfan/provider/ec2/elastic_load_balancer'
39 40
 require 'ironfan/provider/ec2/iam_server_certificate'
40 41
 

0 notes on commit 21dd0d5

Please sign in to comment.
Something went wrong with that request. Please try again.