vagrant-aliyun 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: acda4fa7b423ee238e2d3355cc3923d2c08e025d
4
+ data.tar.gz: 6489423b6e46b1fc426e4c67db4a62d09398a32f
5
+ SHA512:
6
+ metadata.gz: 766db2437fee642134f264e41cab63557ba9c12ebc4176686847e56215e3a8df89c25f3d81842a6dbc51d546149ab2cf18240b02d6886ce1b34988ae73d5b0a4
7
+ data.tar.gz: ae887abc558246a61af48961ae3dd6f459296a9ee581a230f5b36a0b2666bb0881b3d595de1ab58c651bf0f5c434a70b855682b223fdffe76eab9cd9b6897228
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-aliyun.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
8
+ end
9
+
10
+ group :plugins do
11
+ gem "vagrant-aliyun", path: "."
12
+ gem "aliyun-api", "0.0.7"
13
+ gem "ruby-hmac", "0.4.0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ GIT
2
+ remote: https://github.com/mitchellh/vagrant.git
3
+ revision: 3fed57043d23eebf17cf7daf97481d656916eb01
4
+ specs:
5
+ vagrant (1.7.4)
6
+ bundler (>= 1.5.2, <= 1.10.5)
7
+ childprocess (~> 0.5.0)
8
+ erubis (~> 2.7.0)
9
+ hashicorp-checkpoint (~> 0.1.1)
10
+ i18n (>= 0.6.0, <= 0.8.0)
11
+ listen (~> 3.0.2)
12
+ log4r (~> 1.1.9, < 1.1.11)
13
+ net-scp (~> 1.1.0)
14
+ net-sftp (~> 2.1)
15
+ net-ssh (>= 2.6.6, < 2.10.0)
16
+ nokogiri (= 1.6.3.1)
17
+ rb-kqueue (~> 0.2.0)
18
+ rest-client (>= 1.6.0, < 2.0)
19
+ wdm (~> 0.1.0)
20
+ winrm (~> 1.3)
21
+ winrm-fs (~> 0.2.2)
22
+
23
+ PATH
24
+ remote: .
25
+ specs:
26
+ vagrant-aliyun (0.0.2)
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ aliyun-api (0.0.7)
32
+ rest-client
33
+ builder (3.2.2)
34
+ childprocess (0.5.6)
35
+ ffi (~> 1.0, >= 1.0.11)
36
+ domain_name (0.5.24)
37
+ unf (>= 0.0.5, < 1.0.0)
38
+ erubis (2.7.0)
39
+ ffi (1.9.10)
40
+ gssapi (1.2.0)
41
+ ffi (>= 1.0.1)
42
+ gyoku (1.3.1)
43
+ builder (>= 2.1.2)
44
+ hashicorp-checkpoint (0.1.4)
45
+ http-cookie (1.0.2)
46
+ domain_name (~> 0.5)
47
+ httpclient (2.6.0.1)
48
+ i18n (0.7.0)
49
+ listen (3.0.3)
50
+ rb-fsevent (>= 0.9.3)
51
+ rb-inotify (>= 0.9)
52
+ little-plugger (1.1.3)
53
+ log4r (1.1.10)
54
+ logging (1.8.2)
55
+ little-plugger (>= 1.1.3)
56
+ multi_json (>= 1.8.4)
57
+ mime-types (2.6.1)
58
+ mini_portile (0.6.0)
59
+ multi_json (1.11.2)
60
+ net-scp (1.1.2)
61
+ net-ssh (>= 2.6.5)
62
+ net-sftp (2.1.2)
63
+ net-ssh (>= 2.6.5)
64
+ net-ssh (2.9.2)
65
+ netrc (0.10.3)
66
+ nokogiri (1.6.3.1)
67
+ mini_portile (= 0.6.0)
68
+ nori (2.6.0)
69
+ rb-fsevent (0.9.5)
70
+ rb-inotify (0.9.5)
71
+ ffi (>= 0.5.0)
72
+ rb-kqueue (0.2.4)
73
+ ffi (>= 0.5.0)
74
+ rest-client (1.8.0)
75
+ http-cookie (>= 1.0.2, < 2.0)
76
+ mime-types (>= 1.16, < 3.0)
77
+ netrc (~> 0.7)
78
+ ruby-hmac (0.4.0)
79
+ rubyntlm (0.4.0)
80
+ rubyzip (1.1.7)
81
+ unf (0.1.4)
82
+ unf_ext
83
+ unf_ext (0.0.7.1)
84
+ uuidtools (2.1.5)
85
+ wdm (0.1.1)
86
+ winrm (1.3.4)
87
+ builder (>= 2.1.2)
88
+ gssapi (~> 1.2)
89
+ gyoku (~> 1.0)
90
+ httpclient (~> 2.2, >= 2.2.0.2)
91
+ logging (~> 1.6, >= 1.6.1)
92
+ nori (~> 2.0)
93
+ rubyntlm (~> 0.4.0)
94
+ uuidtools (~> 2.1.2)
95
+ winrm-fs (0.2.2)
96
+ erubis (~> 2.7)
97
+ logging (~> 1.6, >= 1.6.1)
98
+ rubyzip (~> 1.1)
99
+ winrm (~> 1.3.0)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ aliyun-api (= 0.0.7)
106
+ ruby-hmac (= 0.4.0)
107
+ vagrant!
108
+ vagrant-aliyun!
109
+
110
+ BUNDLED WITH
111
+ 1.10.5
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Vagrant::Aliyun
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vagrant/aliyun`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vagrant-aliyun'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vagrant-aliyun
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-aliyun.
36
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
1
+ # Vagrant Aliyun Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `aliyun` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf dummy.box ./metadata.json
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "aliyun"
3
+ }
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AliyunECS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AliyunECS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is stopped and branch in the middleware.
6
+ class IsStopped
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :stopped
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AliyunECS
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aliyun.already_status", :status => "created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AliyunECS
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aliyun.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AliyunECS
3
+ module Action
4
+ class MessageWillNotDestroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aliyun.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ require "log4r"
2
+ require "aliyun"
3
+
4
+ module VagrantPlugins
5
+ module AliyunECS
6
+ module Action
7
+ # This action reads the SSH info for the machine and puts it into the
8
+ # `:machine_ssh_info` key in the environment.
9
+ class ReadSSHInfo
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aliyun::action::read_ssh_info")
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_ssh_info] = read_ssh_info(env[:machine], env)
17
+
18
+ @app.call(env)
19
+ end
20
+
21
+ def read_ssh_info(machine, env)
22
+ return nil if machine.id.nil?
23
+
24
+ config = env[:machine].provider_config
25
+ options = {
26
+ :access_key_id => config.access_key_id,
27
+ :access_key_secret => config.access_key_secret
28
+ }
29
+ Aliyun.config options
30
+ ecs = Aliyun::ECS.new
31
+ instance = ecs.describe_instance_attribute :instance_id=>machine.id
32
+
33
+ return { :host => instance["PublicIpAddress"]["IpAddress"][0], :port => 22 }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require "log4r"
2
+ require "aliyun"
3
+
4
+ module VagrantPlugins
5
+ module AliyunECS
6
+ module Action
7
+ # This action reads the state of the machine and puts it in the
8
+ # `:machine_state_id` key in the environment.
9
+ class ReadState
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aliyun::action::read_state")
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_state_id] = read_state(env[:machine], env)
17
+
18
+ @app.call(env)
19
+ end
20
+
21
+ def read_state(machine, env)
22
+ return :not_created if machine.id.nil?
23
+
24
+ config = env[:machine].provider_config
25
+ options = {
26
+ :access_key_id => config.access_key_id,
27
+ :access_key_secret => config.access_key_secret
28
+ }
29
+ Aliyun.config options
30
+ ecs = Aliyun::ECS.new
31
+ instance = ecs.describe_instance_attribute :instance_id=>machine.id
32
+
33
+ # Return the state
34
+ if instance["Status"] == "Stopped"
35
+ return :stopped
36
+ elsif instance["Status"] == "Running"
37
+ return :running
38
+ elsif instance["Status"] == "Starting"
39
+ return :starting
40
+ else
41
+ return :not_created
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,100 @@
1
+ require "log4r"
2
+ require 'json'
3
+ require "aliyun"
4
+ require "timeout"
5
+ require 'vagrant-aliyun/util/timer'
6
+
7
+ module VagrantPlugins
8
+ module AliyunECS
9
+ module Action
10
+ # This runs the configured instance.
11
+ class RunInstance
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant_aliyun::action::run_instance")
16
+ end
17
+
18
+ def call(env)
19
+ run_instance(env[:machine], env)
20
+
21
+ @app.call(env)
22
+ end
23
+
24
+ def run_instance(machine, env)
25
+ config = machine.provider_config
26
+ options = {
27
+ :access_key_id => config.access_key_id,
28
+ :access_key_secret => config.access_key_secret
29
+ }
30
+ Aliyun.config options
31
+ ecs = Aliyun::ECS.new
32
+
33
+ env[:ui].info(I18n.t("vagrant_aliyun.launching_instance"))
34
+ env[:ui].info(" -- Region ID: #{config.region_id}")
35
+ env[:ui].info(" -- Image ID: #{config.image_id}")
36
+ env[:ui].info(" -- Instance Type: #{config.instance_type}")
37
+ env[:ui].info(" -- Internet Max Bandwidth Out: #{config.internet_max_bandwidth_out}")
38
+ env[:ui].info(" -- Security Group ID: #{config.security_group_id}")
39
+ instance = ecs.create_instance :region_id=>config.region_id,:image_id=>config.image_id,:instance_type=>config.instance_type,:internet_max_bandwidth_out=>config.internet_max_bandwidth_out,:security_group_id=>config.security_group_id,:password=>config.password
40
+ ecs.allocate_public_ip_address :instance_id=>instance["InstanceId"]
41
+ env[:ui].info(I18n.t("vagrant_aliyun.starting"))
42
+ ecs.start_instance :instance_id=>instance["InstanceId"]
43
+
44
+ machine.id = instance["InstanceId"]
45
+
46
+ # Wait for the instance to be ready first
47
+ env[:ui].info(I18n.t("vagrant_aliyun.waiting_for_ready"))
48
+ begin
49
+ instance = ecs.describe_instance_attribute :instance_id=>machine.id
50
+ Timeout.timeout(config.instance_ready_timeout) do
51
+ until instance["Status"] == "Running"
52
+ sleep 2
53
+ instance = ecs.describe_instance_attribute :instance_id=>machine.id
54
+ end
55
+ end
56
+ rescue Timeout::Error
57
+ env[:result] = false # couldn't reach state in time
58
+ # Delete the instance
59
+ terminate(env)
60
+
61
+ # Notify the user
62
+ raise Errors::InstanceReadyTimeout,
63
+ timeout: config.instance_ready_timeout
64
+ end
65
+
66
+ if !env[:interrupted]
67
+ # Wait for SSH to be ready.
68
+ env[:ui].info(I18n.t("vagrant_aliyun.waiting_for_ssh"))
69
+ network_ready_retries = 0
70
+ network_ready_retries_max = 10
71
+ while true
72
+ # If we're interrupted then just back out
73
+ break if env[:interrupted]
74
+ # When an ECS instance comes up, it's networking may not be ready
75
+ # by the time we connect.
76
+ begin
77
+ break if env[:machine].communicate.ready?
78
+ rescue Exception => e
79
+ if network_ready_retries < network_ready_retries_max then
80
+ network_ready_retries += 1
81
+ @logger.warn(I18n.t("vagrant_aliyun.waiting_for_ssh, retrying"))
82
+ else
83
+ raise e
84
+ end
85
+ end
86
+ sleep 2
87
+ end
88
+
89
+ # Ready and booted!
90
+ env[:ui].info(I18n.t("vagrant_aliyun.ready"))
91
+ end
92
+
93
+ # Terminate the instance if we were interrupted
94
+ terminate(env) if env[:interrupted]
95
+ end
96
+
97
+ end
98
+ end
99
+ end
100
+ end