engineyard 0.2.13 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/engineyard.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module EY
2
2
  require 'engineyard/ruby_ext'
3
3
 
4
- VERSION = "0.2.13"
4
+ VERSION = "0.3.0"
5
5
 
6
6
  autoload :Account, 'engineyard/account'
7
7
  autoload :API, 'engineyard/api'
@@ -5,7 +5,7 @@ module EY
5
5
  class Deploy
6
6
  extend Util
7
7
 
8
- EYSD_VERSION = "~>0.2.7"
8
+ EYSD_VERSION = "~>0.3.0"
9
9
 
10
10
  def self.call(env_name, branch, options)
11
11
  env_name ||= EY.config.default_environment
@@ -14,34 +14,6 @@ module EY
14
14
  @repo ||= EY::Repo.new
15
15
  end
16
16
 
17
- def app_and_envs(all_envs = false)
18
- app = account.app_for_repo(repo)
19
-
20
- if all_envs || !app
21
- envs = account.environments
22
- EY.ui.warn(NoAppError.new(repo).message) unless app || all_envs
23
- [nil, envs]
24
- else
25
- envs = app.environments
26
- if envs.empty?
27
- EY.ui.warn %|You have no environments set up for the application "#{app.name}"|
28
- EY.ui.warn %|You can make one at #{EY.config.endpoint}|
29
- end
30
- envs.empty? ? [app, nil] : [app, envs]
31
- end
32
- end
33
-
34
- def env_named(name)
35
- env = account.environment_named(name)
36
-
37
- if env.nil?
38
- raise EnvironmentError, "Environment '#{env_name}' can't be found\n" +
39
- "You can create it at #{EY.config.endpoint}"
40
- else
41
- env
42
- end
43
- end
44
-
45
17
  end
46
18
  end
47
19
  end
@@ -32,8 +32,16 @@ module EY
32
32
  desc "environments [--all]", "List cloud environments for this app, or all environments"
33
33
  method_option :all, :type => :boolean, :aliases => %(-a)
34
34
  def environments
35
- require 'engineyard/action/list_environments'
36
- EY::Action::ListEnvironments.call(options[:all])
35
+ app, envs = app_and_envs(options[:all])
36
+ if app
37
+ EY.ui.say %|Cloud environments for #{app.name}:|
38
+ EY.ui.print_envs(envs, EY.config.default_environment)
39
+ elsif envs
40
+ EY.ui.say %|Cloud environments:|
41
+ EY.ui.print_envs(envs, EY.config.default_environment)
42
+ else
43
+ EY.ui.say %|You do not have any cloud environments.|
44
+ end
37
45
  end
38
46
  map "envs" => :environments
39
47
 
@@ -45,20 +53,38 @@ module EY
45
53
 
46
54
  desc "ssh ENV", "Open an ssh session to the environment's application server"
47
55
  def ssh(name)
48
- require 'engineyard/action/ssh'
49
- EY::Action::SSH.call(name)
56
+ env = account.environment_named(name)
57
+ if env
58
+ Kernel.exec "ssh", "#{env.username}@#{env.app_master.public_hostname}", *ARGV[2..-1]
59
+ else
60
+ EY.ui.warn %|Could not find an environment named "#{name}"|
61
+ end
50
62
  end
51
63
 
52
64
  desc "logs ENV", "Retrieve the latest logs for an enviornment"
53
65
  def logs(name)
54
- require 'engineyard/action/show_logs'
55
- EY::Action::ShowLogs.call(name)
66
+ env_named(name).logs.each do |log|
67
+ EY.ui.info log.instance_name
68
+
69
+ if log.main
70
+ EY.ui.info "Main logs:"
71
+ EY.ui.say log.main
72
+ end
73
+
74
+ if log.custom
75
+ EY.ui.info "Custom logs:"
76
+ EY.ui.say log.custom
77
+ end
78
+ end
56
79
  end
57
80
 
58
81
  desc "upload_recipes ENV", "Upload custom chef recipes from the current directory to ENV"
59
82
  def upload_recipes(name)
60
- require 'engineyard/action/upload_recipes'
61
- EY::Action::UploadRecipes.call(name)
83
+ if account.upload_recipes_for(env_named(name))
84
+ EY.ui.say "Recipes uploaded successfully"
85
+ else
86
+ EY.ui.error "Recipes upload failed"
87
+ end
62
88
  end
63
89
 
64
90
  desc "version", "Print the version of the engineyard gem"
@@ -67,5 +93,42 @@ module EY
67
93
  end
68
94
  map "-v" => :version
69
95
 
96
+ private
97
+ def account
98
+ @account ||= EY::Account.new(EY::CLI::API.new)
99
+ end
100
+
101
+ def repo
102
+ @repo ||= EY::Repo.new
103
+ end
104
+
105
+ def env_named(env_name)
106
+ env = account.environment_named(env_name)
107
+
108
+ if env.nil?
109
+ raise EnvironmentError, "Environment '#{env_name}' can't be found\n" +
110
+ "You can create it at #{EY.config.endpoint}"
111
+ end
112
+
113
+ env
114
+ end
115
+
116
+ def app_and_envs(all_envs = false)
117
+ app = account.app_for_repo(repo)
118
+
119
+ if all_envs || !app
120
+ envs = account.environments
121
+ EY.ui.warn(NoAppError.new(repo).message) unless app || all_envs
122
+ [nil, envs]
123
+ else
124
+ envs = app.environments
125
+ if envs.empty?
126
+ EY.ui.warn %|You have no environments set up for the application "#{app.name}"|
127
+ EY.ui.warn %|You can make one at #{EY.config.endpoint}|
128
+ end
129
+ envs.empty? ? [app, nil] : [app, envs]
130
+ end
131
+ end
132
+
70
133
  end # CLI
71
134
  end # EY
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 13
9
- version: 0.2.13
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - EY Cloud Team
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-07 00:00:00 -07:00
17
+ date: 2010-05-12 00:00:00 -07:00
18
18
  default_executable: ey
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -94,7 +94,6 @@ extra_rdoc_files: []
94
94
 
95
95
  files:
96
96
  - bin/ey
97
- - lib/engineyard/#repo.rb#
98
97
  - lib/engineyard/account/api_struct.rb
99
98
  - lib/engineyard/account/app.rb
100
99
  - lib/engineyard/account/app_master.rb
@@ -103,11 +102,7 @@ files:
103
102
  - lib/engineyard/account/log.rb
104
103
  - lib/engineyard/account.rb
105
104
  - lib/engineyard/action/deploy.rb
106
- - lib/engineyard/action/list_environments.rb
107
105
  - lib/engineyard/action/rebuild.rb
108
- - lib/engineyard/action/show_logs.rb
109
- - lib/engineyard/action/ssh.rb
110
- - lib/engineyard/action/upload_recipes.rb
111
106
  - lib/engineyard/action/util.rb
112
107
  - lib/engineyard/api.rb
113
108
  - lib/engineyard/cli/api.rb
@@ -1,24 +0,0 @@
1
- module EY
2
- class Repo
3
-
4
- def initialize(path=File.expand_path('.'))
5
- @path = path
6
- end
7
-
8
- def current_branch
9
- head = File.read(File.join(@path, ".git/HEAD")).chomp
10
- if head.gsub!("ref: refs/heads/", "")
11
- head
12
- else
13
- nil
14
- end
15
- end
16
-
17
- def urls
18
- `git config -f #{@path}/.git/config --get-regexp 'remote.*.url'`.split(/\n/).map do |c|
19
- c.split.last
20
- end
21
- end
22
-
23
- end # Repo
24
- end # EY
@@ -1,22 +0,0 @@
1
- require 'engineyard/action/util'
2
-
3
- module EY
4
- module Action
5
- class ListEnvironments
6
- extend Util
7
-
8
- def self.call(all)
9
- app, envs = app_and_envs(all)
10
- if app
11
- EY.ui.say %|Cloud environments for #{app.name}:|
12
- EY.ui.print_envs(envs, EY.config.default_environment)
13
- elsif envs
14
- EY.ui.say %|Cloud environments:|
15
- EY.ui.print_envs(envs, EY.config.default_environment)
16
- else
17
- EY.ui.say %|You do not have any cloud environments.|
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- require 'engineyard/action/util'
2
-
3
- module EY
4
- module Action
5
- class ShowLogs
6
- extend Util
7
-
8
- def self.call(name)
9
- env_named(name).logs.each do |log|
10
- EY.ui.info log.instance_name
11
-
12
- if log.main
13
- EY.ui.info "Main logs:"
14
- EY.ui.say log.main
15
- end
16
-
17
- if log.custom
18
- EY.ui.info "Custom logs:"
19
- EY.ui.say log.custom
20
- end
21
- end
22
-
23
- end
24
- end
25
- end
26
- end
@@ -1,19 +0,0 @@
1
- require 'engineyard/action/util'
2
-
3
- module EY
4
- module Action
5
- class SSH
6
- extend Util
7
-
8
- def self.call(name)
9
-
10
- env = account.environment_named(name)
11
- if env
12
- Kernel.exec "ssh", "#{env.username}@#{env.app_master.public_hostname}", *ARGV[2..-1]
13
- else
14
- EY.ui.warn %|Could not find an environment named "#{name}"|
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- require 'engineyard/action/util'
2
-
3
- module EY
4
- module Action
5
- class UploadRecipes
6
- extend Util
7
-
8
- def self.call(name)
9
- if account.upload_recipes_for(env_named(name))
10
- EY.ui.say "Recipes uploaded successfully"
11
- else
12
- EY.ui.error "Recipes upload failed"
13
- end
14
- end
15
- end
16
- end
17
- end