Skip to content
This repository
Browse code

Add ftl terminate and fix bug with pricing on spot requests

  • Loading branch information...
commit 375814de1a83641ad883f0e450ba1223682ab60d 1 parent 574bae1
Matt Petty authored

Showing 2 changed files with 32 additions and 14 deletions. Show diff stats Hide diff stats

  1. +8 4 Changelog
  2. +24 10 lib/ftl/client.rb
12 Changelog
... ... @@ -1,11 +1,15 @@
1 1 # Release Version 0.3.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 2
3   -* Add ftl <script> to execute arbitrary ruby locally within ftl environment
4   -* Add ftl ips to show Elastic IP addresses
5   -* Add ftl stop to stop running instances
6   -* Add ftl start to start running instances
  3 +* Feature: Add ftl <script> to execute arbitrary ruby locally within ftl environment
  4 +* Feature: Add ftl ips to show Elastic IP addresses
  5 +* Feature: Add ftl stop to stop running instances
  6 +* Feature: Add ftl start to start running instances
  7 +* Feature: Add option to pass in spot request instance count
  8 +* Feature: Add ftl terminate to specifically terminate any instance vs only running ones
  9 +* Bug fix: Spot requests were launching as regular instances
7 10 * Bug fixes
8 11
  12 +
9 13 # Release Version 0.2.4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 14
11 15 * Add ftl <action> <server> to execute arbitrary commands on running instances
34 lib/ftl/client.rb
@@ -57,12 +57,14 @@ def initialize(args=nil, opts={})
57 57 def launch_instance(args)
58 58 display "Spinning up FTL..."
59 59 opts = options
60   - opts = options[:templates][args.first.to_sym] if !options[:templates][args.first.to_sym].nil?
  60 + opts = options.merge(options[:templates][args.first.to_sym]) if !options[:templates][args.first.to_sym].nil?
61 61
62 62 opts[:group_ids] = (opts[:group_ids] || []) + opts[:groups].select { | group | group.to_s =~ /^sg-[0-9a-f]{8}$/ }
63 63 opts[:groups] = opts[:groups].reject { | group | group.to_s =~ /^sg-[0-9a-f]{8}$/ }
64 64
65   - server = con.servers.create(:user_data => opts[:user_data],
  65 + launcher = options.delete(:launcher) || :servers
  66 + server = con.send(launcher).create(
  67 + :user_data => opts[:user_data],
66 68 :key_name => opts[:keypair],
67 69 :groups => opts[:groups],
68 70 :security_group_ids => opts[:group_ids],
@@ -73,7 +75,8 @@ def launch_instance(args)
73 75 :tags => opts[:tags].merge(:Name => args.first),
74 76 :subnet_id => opts[:subnet_id],
75 77 :private_ip_address => opts[:ip_private],
76   - :ip_address => opts[:ip_address]
  78 + :ip_address => opts[:ip_address],
  79 + :price => opts[:price]
77 80 )
78 81
79 82 display server
@@ -96,9 +99,11 @@ def spot(args={})
96 99 guard(args[1], "Please provide a price for spot request\n\t[bold]ftl[/] spot <name> <price>")
97 100 display "Spinning up FTL..."
98 101 options.merge(options[:templates][args.first.to_sym]) if !options[:templates][args.first.to_sym].nil?
99   - options[:price] = args[1]
  102 + options[:price] = args[1] || options[:templates][args.first.to_sym][:price] || options[:price]
  103 + options.merge!(:launcher => :spot_requests)
100 104 server = launch_instance(args)
101 105 end
  106 + alias :request :spot
102 107
103 108 def spots(args={})
104 109 con.spot_requests.table(_headers_for(:spot_requests))
@@ -164,15 +169,12 @@ def stop(args={})
164 169 alias :pause :stop
165 170
166 171 def destroy(args={})
167   - if on_what.nil?
168   - display "Please provide the name (or partial name for the instance(s) you want to delete. For instance, like: ftl destroy ninja"
169   - return
170   - end
  172 + guard(on_what, "Please provide the name (or partial name for the instance(s) you want to delete. For instance, like: ftl destroy ninja")
171 173 display "Spinning down FTL..."
172 174 instances = find_instances(on_what).select{|i| i.state == 'running' }
173 175 if !instances.empty?
174 176 instances.map(&:destroy)
175   - display "Terminated [bold]\[#{instances.map(&:id).join(', ')}\][/]"
  177 + display "Destroyed [bold]\[#{instances.map(&:id).join(', ')}\][/]"
176 178 else
177 179 display "No instances found"
178 180 end
@@ -182,7 +184,19 @@ def destroy(args={})
182 184 alias :kill :destroy
183 185 alias :down :destroy
184 186 alias :shutdown :destroy
185   - alias :terminate :destroy
  187 +
  188 + def terminate(args={})
  189 + guard(on_what, "Please provide the name (or partial name for the instance(s) you want to terminate. For instance, like: ftl destroy ninja")
  190 + display "Spinning down FTL..."
  191 + instances = find_instances(on_what)
  192 + if !instances.empty?
  193 + instances.map(&:destroy)
  194 + display "Destroyed [bold]\[#{instances.map(&:id).join(', ')}\][/]"
  195 + else
  196 + display "No instances found"
  197 + end
  198 + end
  199 + alias :t :terminate
186 200
187 201 def info(args={})
188 202 display find_instance(args.first)

0 comments on commit 375814d

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