befog 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
data/lib/befog/commands/add.rb
CHANGED
@@ -30,6 +30,10 @@ module Befog
|
|
30
30
|
option :type,
|
31
31
|
:short => :t,
|
32
32
|
:description => "The type of machines to provision"
|
33
|
+
|
34
|
+
option :spot,
|
35
|
+
:short => :s,
|
36
|
+
:description => "Provision a spot instance"
|
33
37
|
|
34
38
|
def run
|
35
39
|
provision_servers(options[:count].to_i)
|
@@ -71,10 +75,21 @@ module Befog
|
|
71
75
|
end
|
72
76
|
|
73
77
|
def provision_server
|
74
|
-
|
78
|
+
if options[:spot]
|
79
|
+
request = compute.spot_requests.create(
|
80
|
+
:price => price.to_f, :instance_count => 1,
|
75
81
|
:tags => {"Name" => generate_server_name},
|
76
82
|
:region => region, :flavor_id => flavor, :image_id => image,
|
77
|
-
:
|
83
|
+
:groups => [ security_group ], :key_name => keypair)
|
84
|
+
server = nil
|
85
|
+
Fog.wait_for {(server = compute.servers.get(request.reload.instance_id)) rescue nil}
|
86
|
+
server
|
87
|
+
else
|
88
|
+
compute.servers.create(
|
89
|
+
:tags => {"Name" => generate_server_name},
|
90
|
+
:region => region, :flavor_id => flavor, :image_id => image,
|
91
|
+
:security_group_ids => security_group, :key_name => keypair)
|
92
|
+
end
|
78
93
|
end
|
79
94
|
|
80
95
|
def generate_server_name
|
@@ -51,6 +51,10 @@ module Befog
|
|
51
51
|
option :type,
|
52
52
|
:short => :t,
|
53
53
|
:description => "The number of machines to provision"
|
54
|
+
|
55
|
+
option :price,
|
56
|
+
:short => :z,
|
57
|
+
:description => "The spot instance price"
|
54
58
|
|
55
59
|
def run
|
56
60
|
safely do
|
@@ -58,7 +62,7 @@ module Befog
|
|
58
62
|
_key = key.to_sym
|
59
63
|
provider[key] = options[_key] if options[_key]
|
60
64
|
end
|
61
|
-
%w( region image keypair group type ).each do |key|
|
65
|
+
%w( region image keypair group type price ).each do |key|
|
62
66
|
_key = key.to_sym
|
63
67
|
bank[key] = options[_key] if options[_key]
|
64
68
|
end
|
@@ -89,6 +89,11 @@ module Befog
|
|
89
89
|
error("Specify a keypair with --keypair or by adding one to the '#{bank_name}' bank.")
|
90
90
|
end
|
91
91
|
|
92
|
+
def price
|
93
|
+
options[:price] or bank["price"] or
|
94
|
+
error("Specify a spot instance price with --price or by adding one to the '#{bank_name}' bank.")
|
95
|
+
end
|
96
|
+
|
92
97
|
def keypair?
|
93
98
|
!!options[:keypair] or bank["keypair"]
|
94
99
|
end
|
data/lib/befog/commands/run.rb
CHANGED
@@ -25,8 +25,11 @@ module Befog
|
|
25
25
|
|
26
26
|
option :command,
|
27
27
|
:short => :c,
|
28
|
-
:
|
29
|
-
|
28
|
+
:description => "Command to run"
|
29
|
+
|
30
|
+
option :shell,
|
31
|
+
:short => :y,
|
32
|
+
:description => "Shell script to run remotely"
|
30
33
|
|
31
34
|
option :all,
|
32
35
|
:short => :a,
|
@@ -34,14 +37,25 @@ module Befog
|
|
34
37
|
|
35
38
|
|
36
39
|
def run
|
40
|
+
script = if options[:command] and not options[:shell]
|
41
|
+
$stdout.puts "Running command '#{options[:command]}' ..."
|
42
|
+
options[:command]
|
43
|
+
elsif options[:shell] and not options[:command]
|
44
|
+
$stdout.puts "Running script '#{options[:shell]}' ..."
|
45
|
+
# We add the sleep in case the last command is run in the bg
|
46
|
+
File.open options[:shell] { |file| file.read + "\nsleep 1"}
|
47
|
+
else
|
48
|
+
raise "Must specify one of --shell or --command"
|
49
|
+
end
|
37
50
|
run_for_selected do |id|
|
38
51
|
threads = []; threads << Thread.new do
|
39
52
|
safely do
|
53
|
+
# TODO: Add check to see if we have a bad ID in the config
|
40
54
|
server = get_server(id)
|
41
55
|
if server.state == "running"
|
42
56
|
address = server.public_ip_address
|
43
|
-
$stdout.puts "
|
44
|
-
result = Fog::SSH.new(address, "root").run(
|
57
|
+
$stdout.puts "... for '#{address}'"
|
58
|
+
result = Fog::SSH.new(address, "root").run(script).first
|
45
59
|
$stdout.puts "#{address} STDOUT: #{result.stdout}"
|
46
60
|
$stderr.puts "#{address} STDERR: #{result.stderr}" unless result.stderr.empty?
|
47
61
|
else
|
metadata
CHANGED
@@ -1,63 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: befog
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
9
|
-
-
|
7
|
+
authors:
|
8
|
+
- Lance Lakey lancelakey@gmail.com
|
9
|
+
- Carlo Flores lo@js.la
|
10
|
+
- Dan Yoder danielyoder@gmail.com
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
20
19
|
none: false
|
21
|
-
requirements:
|
20
|
+
requirements:
|
22
21
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.3'
|
25
24
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
25
|
prerelease: false
|
30
|
-
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
27
|
none: false
|
32
|
-
requirements:
|
28
|
+
requirements:
|
33
29
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '1.3'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rspec
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.7'
|
36
40
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: yard
|
40
41
|
prerelease: false
|
41
|
-
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
43
|
none: false
|
43
|
-
requirements:
|
44
|
+
requirements:
|
44
45
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.7'
|
47
56
|
type: :development
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.7'
|
64
|
+
description: ! "\t\tThe befog gem allows you to manage your cloud servers\n\t\tdirectly
|
65
|
+
from the command-line. \n"
|
66
|
+
email:
|
67
|
+
-
|
52
68
|
-
|
53
69
|
-
|
54
|
-
executables:
|
70
|
+
executables:
|
55
71
|
- befog
|
56
72
|
extensions: []
|
57
|
-
|
58
73
|
extra_rdoc_files: []
|
59
|
-
|
60
|
-
files:
|
74
|
+
files:
|
61
75
|
- lib/befog/cli.rb
|
62
76
|
- lib/befog/commands/add.rb
|
63
77
|
- lib/befog/commands/configure.rb
|
@@ -76,33 +90,29 @@ files:
|
|
76
90
|
- lib/befog/commands.rb
|
77
91
|
- lib/befog.rb
|
78
92
|
- bin/befog
|
79
|
-
homepage: https://github.com/
|
93
|
+
homepage: https://github.com/dyoder/befog
|
80
94
|
licenses: []
|
81
|
-
|
82
95
|
post_install_message:
|
83
96
|
rdoc_options: []
|
84
|
-
|
85
|
-
require_paths:
|
97
|
+
require_paths:
|
86
98
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
100
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
106
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version:
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
99
111
|
requirements: []
|
100
|
-
|
101
112
|
rubyforge_project:
|
102
113
|
rubygems_version: 1.8.23
|
103
114
|
signing_key:
|
104
115
|
specification_version: 3
|
105
116
|
summary: Cloud provisioning CLI
|
106
117
|
test_files: []
|
107
|
-
|
108
118
|
has_rdoc:
|