sunzi 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -25,7 +25,7 @@ Install:
25
25
  $ gem install sunzi
26
26
  ```
27
27
 
28
- Go to your project directory, then:
28
+ Go into your project directory (if it's a Rails project, `config` would be a good place to start with), then:
29
29
 
30
30
  ```bash
31
31
  $ sunzi create
@@ -56,6 +56,7 @@ Commands
56
56
 
57
57
  ```bash
58
58
  $ sunzi # Show command help
59
+ $ sunzi compile # Compile Sunzi project
59
60
  $ sunzi create # Create a new Sunzi project
60
61
  $ sunzi deploy [user@host:port] # Deploy Sunzi project
61
62
  $ sunzi setup [linode|ec2] # Setup a new VM on the Cloud services
@@ -129,6 +130,8 @@ recipes:
129
130
 
130
131
  `rvm.sh` will be available and you can refer to that recipe by `source recipes/rvm.sh`.
131
132
 
133
+ You may find sample recipes in this repository useful: https://github.com/kenn/sunzi-recipes
134
+
132
135
  Cloud Support
133
136
  -------------
134
137
 
data/Rakefile CHANGED
@@ -7,3 +7,5 @@ Rake::TestTask.new do |t|
7
7
  t.test_files = FileList['test/test*.rb']
8
8
  t.verbose = true
9
9
  end
10
+
11
+ task :default => :test
@@ -24,8 +24,6 @@ module Sunzi
24
24
  # When route53 is specified for DNS, check if it's properly configured and if not, fail earlier.
25
25
  setup_route53 if @config['dns'] == 'route53'
26
26
 
27
- @ui = HighLine.new
28
-
29
27
  @sshkey = File.read(File.expand_path(@config['root_sshkey_path'])).chomp
30
28
  if @sshkey.match(/\n/)
31
29
  abort_with "RootSSHKey #{@sshkey.inspect} must not be multi-line! Check inside \"#{@config['root_sshkey_path']}\""
@@ -74,7 +72,7 @@ module Sunzi
74
72
  @swap_size = ask('swap size in MB? (default: 256MB): ', Integer) { |q| q.default = 256 }
75
73
 
76
74
  # Go ahead?
77
- moveon = ask("Are you sure to go ahead and create #{@fqdn}? (y/n) ", String) {|q| q.in = ['y','n']}
75
+ moveon = ask("Are you ready to go ahead and create #{@fqdn}? (y/n) ", String) {|q| q.in = ['y','n']}
78
76
  exit unless moveon == 'y'
79
77
 
80
78
  # Create
@@ -88,16 +86,9 @@ module Sunzi
88
86
 
89
87
  # Update settings
90
88
  say "Updating settings..."
91
- result = @api.linode.update(
92
- :LinodeID => @linodeid,
93
- :Label => @label,
94
- :lpm_displayGroup => @group,
95
- # :Alert_cpu_threshold => 90,
96
- # :Alert_diskio_threshold => 1000,
97
- # :Alert_bwin_threshold => 5,
98
- # :Alert_bwout_threshold => 5,
99
- # :Alert_bwquota_threshold => 80,
100
- )
89
+ settings = { :LinodeID => @linodeid, :Label => @label, :lpm_displayGroup => @group }
90
+ settings.update(@config['settings']) if @config['settings']
91
+ result = @api.linode.update(settings)
101
92
 
102
93
  # Create a root disk
103
94
  say "Creating a root disk..."
@@ -192,23 +183,30 @@ module Sunzi
192
183
  setup_route53 if @config['dns'] == 'route53'
193
184
 
194
185
  @instance = YAML.load(File.read("linode/instances/#{name}.yml"))
186
+ @linode_id_hash = { :LinodeID => @instance[:linode_id] }
195
187
  @api = ::Linode.new(:api_key => @config['api_key'])
196
188
 
189
+ # Are you sure?
190
+ moveon = ask("Are you sure about deleting #{@instance[:fqdn]} permanently? (y/n) ", String) {|q| q.in = ['y','n']}
191
+ exit unless moveon == 'y'
192
+
197
193
  # Shutdown first or disk deletion will fail
198
194
  say 'shutting down...'
199
- @api.linode.shutdown(:LinodeID => @instance[:linode_id])
200
- sleep 10
195
+ @api.linode.shutdown(@linode_id_hash)
196
+ # Wait until linode.shutdown has completed
197
+ wait_for('linode.shutdown')
201
198
 
202
199
  # Delete the disks. It is required - http://www.linode.com/api/linode/linode%2Edelete
203
200
  say 'deleting root disk...'
204
- @api.linode.disk.delete(:LinodeID => @instance[:linode_id], :DiskID => @instance[:root_diskid]) rescue nil
201
+ @api.linode.disk.delete(@linode_id_hash.merge(:DiskID => @instance[:root_diskid]))
205
202
  say 'deleting swap disk...'
206
- @api.linode.disk.delete(:LinodeID => @instance[:linode_id], :DiskID => @instance[:swap_diskid]) rescue nil
207
- sleep 5
203
+ @api.linode.disk.delete(@linode_id_hash.merge(:DiskID => @instance[:swap_diskid]))
204
+ # Wait until linode.disk.delete has completed
205
+ wait_for('fs.delete')
208
206
 
209
207
  # Delete the instance
210
208
  say 'deleting linode...'
211
- @api.linode.delete(:LinodeID => @instance[:linode_id])
209
+ @api.linode.delete(@linode_id_hash)
212
210
 
213
211
  # Delete DNS record
214
212
  case @config['dns']
@@ -236,6 +234,12 @@ module Sunzi
236
234
  route53 = Route53::Connection.new(@config['route53']['key'], @config['route53']['secret'])
237
235
  @route53_zone = route53.get_zones.find{|i| i.name.sub(/\.$/,'') == @config['fqdn']['zone'] }
238
236
  end
237
+
238
+ def wait_for(action)
239
+ begin
240
+ sleep 3
241
+ end until @api.linode.job.list(@linode_id_hash).find{|i| i.action == action }.host_success == 1
242
+ end
239
243
  end
240
244
  end
241
245
  end
data/lib/sunzi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sunzi
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -6,7 +6,7 @@ root_sshkey_path: ~/.ssh/id_rsa.pub
6
6
  # payment_term must be 1, 12 or 24
7
7
  payment_term: 1
8
8
 
9
- # Add / remove environments
9
+ # add / remove environments
10
10
  environments:
11
11
  - production
12
12
  - staging
@@ -21,7 +21,7 @@ group:
21
21
  production: example
22
22
  staging: example-staging
23
23
 
24
- # Filter out large lists by keyword
24
+ # filter out large lists by keyword
25
25
  distributions_filter: debian
26
26
  kernels_filter: latest
27
27
 
@@ -31,4 +31,12 @@ dns: linode
31
31
  # only used when route53 is chosen for DNS
32
32
  route53:
33
33
  key: your_aws_key
34
- secret: your_aws_secret
34
+ secret: your_aws_secret
35
+
36
+ # other parameters for settings.
37
+ # settings:
38
+ # alert_cpu_threshold: 90
39
+ # alert_diskio_threshold: 1000
40
+ # alert_bwin_threshold: 5
41
+ # alert_bwout_threshold: 5
42
+ # alert_bwquota_threshold: 80
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunzi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-01 00:00:00.000000000 Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &2152827160 !ruby/object:Gem::Requirement
16
+ requirement: &2160582840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152827160
24
+ version_requirements: *2160582840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rainbow
27
- requirement: &2152825860 !ruby/object:Gem::Requirement
27
+ requirement: &2160582300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152825860
35
+ version_requirements: *2160582300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2152824980 !ruby/object:Gem::Requirement
38
+ requirement: &2160581480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152824980
46
+ version_requirements: *2160581480
47
47
  description: Server provisioning utility for minimalists
48
48
  email:
49
49
  - kenn.ejima@gmail.com