vagrant-hp 0.1.0 → 0.1.1

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.
@@ -1,121 +1,124 @@
1
- #
2
- # Author:: Mohit Sethi (<mohit@sethis.in>)
3
- # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
- #
5
-
6
- require 'vagrant/util/retryable'
7
- require "fog"
8
- require "log4r"
9
-
10
-
11
- module VagrantPlugins
12
- module HP
13
- module Action
14
- # This creates server on HP Cloud.
15
- class CreateServer
16
- include Vagrant::Util::Retryable
17
-
18
- def initialize(app, env)
19
- @app = app
20
- @logger = Log4r::Logger.new("vagrant_hp::action::create_server")
21
- end
22
-
23
- def call(env)
24
- # Get the configs
25
- config = env[:machine].provider_config
26
-
27
- # Find the flavor
28
- env[:ui].info(I18n.t("vagrant_hp.finding_flavor"))
29
- flavor = find_match(env[:hp_compute].flavors.all, config.flavor)
30
- raise Errors::NoMatchingFlavor if !flavor
31
-
32
- # Find the image
33
- env[:ui].info(I18n.t("vagrant_hp.finding_image"))
34
- image = find_match(env[:hp_compute].images, config.image)
35
- raise Errors::NoMatchingImage if !image
36
-
37
- # Figure out the name for the server
38
- server_name = config.server_name || env[:machine].name if env[:machine].name != "default" || get_server_name()
39
-
40
- # Output the settings we're going to use to the user
41
- env[:ui].info(I18n.t("vagrant_hp.launching_server"))
42
- env[:ui].info(" -- Flavor: #{flavor.name}")
43
- env[:ui].info(" -- Image: #{image.name}")
44
- env[:ui].info(" -- Name: #{server_name}")
45
-
46
- # Build the options for launching...
47
- options = {
48
- :flavor_id => flavor.id,
49
- :image_id => image.id,
50
- :name => server_name,
51
- :key_name => config.keypair_name
52
- }
53
-
54
- # Create the server
55
- server = env[:hp_compute].servers.create(options)
56
-
57
- # Store the ID right away so we can track it
58
- env[:machine].id = server.id
59
-
60
- # Wait for the server to finish building
61
- env[:ui].info(I18n.t("vagrant_hp.waiting_for_build"))
62
- retryable(:on => Timeout::Error, :tries => 200) do
63
- # If we're interrupted don't worry about waiting
64
- next if env[:interrupted]
65
-
66
- # Set the progress
67
- env[:ui].clear_line
68
- env[:ui].report_progress(server.progress, 100, false)
69
-
70
- # Wait for the server to be ready
71
- begin
72
- server.wait_for(15) { ready? }
73
- rescue RuntimeError, Fog::Errors::TimeoutError => e
74
- # If we don't have an error about a state transition, then
75
- # we just move on.
76
- #raise if e.message !~ /should have transitioned/
77
- env[:ui].info("Error: #{e.message}")
78
- end
79
- end
80
-
81
- if !env[:interrupted]
82
- # Clear the line one more time so the progress is removed
83
- env[:ui].clear_line
84
-
85
- # Wait for SSH to become available
86
- env[:ui].info(I18n.t("vagrant_hp.waiting_for_ssh"))
87
- while true
88
- begin
89
- # If we're interrupted then just back out
90
- break if env[:interrupted]
91
- break if env[:machine].communicate.ready?
92
- rescue Errno::ENETUNREACH
93
- end
94
- sleep 2
95
- end
96
-
97
- env[:ui].info(I18n.t("vagrant_hp.ready"))
98
- end
99
-
100
- @app.call(env)
101
- end
102
-
103
- protected
104
-
105
- # generate a random name if server_name is empty
106
- def get_server_name()
107
- server_name = "vagrant_hp-#{rand.to_s.split('.')[1]}"
108
- server_name.to_s
109
- end
110
-
111
- def find_match(collection, name)
112
- collection.each do |single|
113
- return single if single.id == name
114
- return single if single.name == name
115
- end
116
- nil
117
- end
118
- end
119
- end
120
- end
121
- end
1
+ #
2
+ # Author:: Mohit Sethi (<mohit@sethis.in>)
3
+ # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
+ #
5
+
6
+ require 'vagrant/util/retryable'
7
+ require "log4r"
8
+
9
+
10
+ module VagrantPlugins
11
+ module HP
12
+ module Action
13
+ # This creates server on HP Cloud.
14
+ class CreateServer
15
+ include Vagrant::Util::Retryable
16
+
17
+ def initialize(app, env)
18
+ @app = app
19
+ @logger = Log4r::Logger.new("vagrant_hp::action::create_server")
20
+ end
21
+
22
+ def call(env)
23
+ # Get the configs
24
+ config = env[:machine].provider_config
25
+
26
+ # Find the flavor
27
+ env[:ui].info(I18n.t("vagrant_hp.finding_flavor"))
28
+ flavor = find_match(env[:hp_compute].flavors.all, config.flavor)
29
+ raise Errors::NoMatchingFlavor if !flavor
30
+
31
+ # Find the image
32
+ env[:ui].info(I18n.t("vagrant_hp.finding_image"))
33
+ image = find_match(env[:hp_compute].images, config.image)
34
+ raise Errors::NoMatchingImage if !image
35
+
36
+ # Figure out the name for the server
37
+ server_name = config.server_name || env[:machine].name if env[:machine].name != "default" || get_server_name()
38
+
39
+ # Output the settings we're going to use to the user
40
+ env[:ui].info(I18n.t("vagrant_hp.launching_server"))
41
+ env[:ui].info(" -- Flavor: #{flavor.name}")
42
+ env[:ui].info(" -- Image: #{image.name}")
43
+ env[:ui].info(" -- Name: #{server_name}")
44
+ if config.security_groups
45
+ env[:ui].info(" -- Security Groups: #{config.security_groups}")
46
+ end
47
+
48
+ # Build the options for launching...
49
+ options = {
50
+ :flavor_id => flavor.id,
51
+ :image_id => image.id,
52
+ :name => server_name,
53
+ :key_name => config.keypair_name,
54
+ :security_groups => config.security_groups
55
+ }
56
+
57
+ # Create the server
58
+ server = env[:hp_compute].servers.create(options)
59
+
60
+ # Store the ID right away so we can track it
61
+ env[:machine].id = server.id
62
+
63
+ # Wait for the server to finish building
64
+ env[:ui].info(I18n.t("vagrant_hp.waiting_for_build"))
65
+ retryable(:on => Timeout::Error, :tries => 200) do
66
+ # If we're interrupted don't worry about waiting
67
+ next if env[:interrupted]
68
+
69
+ # Set the progress
70
+ env[:ui].clear_line
71
+ env[:ui].report_progress(server.progress, 100, false)
72
+
73
+ # Wait for the server to be ready
74
+ begin
75
+ server.wait_for(15) { ready? }
76
+ rescue RuntimeError, Fog::Errors::TimeoutError => e
77
+ # If we don't have an error about a state transition, then
78
+ # we just move on.
79
+ #raise if e.message !~ /should have transitioned/
80
+ env[:ui].info("Error: #{e.message}")
81
+ end
82
+ end
83
+
84
+ if !env[:interrupted]
85
+ # Clear the line one more time so the progress is removed
86
+ env[:ui].clear_line
87
+
88
+ # Wait for SSH to become available
89
+ env[:ui].info(I18n.t("vagrant_hp.waiting_for_ssh"))
90
+ while true
91
+ begin
92
+ # If we're interrupted then just back out
93
+ break if env[:interrupted]
94
+ break if env[:machine].communicate.ready?
95
+ rescue Errno::ENETUNREACH
96
+ end
97
+ sleep 2
98
+ end
99
+
100
+ env[:ui].info(I18n.t("vagrant_hp.ready"))
101
+ end
102
+
103
+ @app.call(env)
104
+ end
105
+
106
+ protected
107
+
108
+ # generate a random name if server_name is empty
109
+ def get_server_name()
110
+ server_name = "vagrant_hp-#{rand.to_s.split('.')[1]}"
111
+ server_name.to_s
112
+ end
113
+
114
+ def find_match(collection, name)
115
+ collection.each do |single|
116
+ return single if single.id == name
117
+ return single if single.name == name
118
+ end
119
+ nil
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -1,30 +1,30 @@
1
- #
2
- # Author:: Mohit Sethi (<mohit@sethis.in>)
3
- # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
- #
5
-
6
- require "log4r"
7
-
8
- module VagrantPlugins
9
- module HP
10
- module Action
11
- # This deletes the running server, if there is one.
12
- class DeleteServer
13
- def initialize(app, env)
14
- @app = app
15
- @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
16
- end
17
-
18
- def call(env)
19
- if env[:machine].id
20
- @logger.info(I18n.t("vagrant_hp.deleting_server"))
21
- server = env[:hp_compute].servers.get(env[:machine].id)
22
- server.destroy
23
- env[:machine].id = nil
24
- end
25
- @app.call(env)
26
- end
27
- end
28
- end
29
- end
30
- end
1
+ #
2
+ # Author:: Mohit Sethi (<mohit@sethis.in>)
3
+ # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
+ #
5
+
6
+ require "log4r"
7
+
8
+ module VagrantPlugins
9
+ module HP
10
+ module Action
11
+ # This deletes the running server, if there is one.
12
+ class DeleteServer
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
16
+ end
17
+
18
+ def call(env)
19
+ if env[:machine].id
20
+ @logger.info(I18n.t("vagrant_hp.deleting_server"))
21
+ server = env[:hp_compute].servers.get(env[:machine].id)
22
+ server.destroy
23
+ env[:machine].id = nil
24
+ end
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,30 +1,30 @@
1
- #
2
- # Author:: Mohit Sethi (<mohit@sethis.in>)
3
- # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
- #
5
-
6
- require "log4r"
7
-
8
- module VagrantPlugins
9
- module HP
10
- module Action
11
- # This deletes the running server, if there is one.
12
- class HaltServer
13
- def initialize(app, env)
14
- @app = app
15
- @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
16
- end
17
-
18
- def call(env)
19
- if env[:machine].id
20
- @logger.info(I18n.t("vagrant_hp.deleting_server"))
21
- server = env[:hp_compute].servers.get(env[:machine].id)
22
- server.stop # verify this
23
- env[:machine].id = nil
24
- end
25
- @app.call(env)
26
- end
27
- end
28
- end
29
- end
30
- end
1
+ #
2
+ # Author:: Mohit Sethi (<mohit@sethis.in>)
3
+ # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
+ #
5
+
6
+ require "log4r"
7
+
8
+ module VagrantPlugins
9
+ module HP
10
+ module Action
11
+ # This deletes the running server, if there is one.
12
+ class HaltServer
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
16
+ end
17
+
18
+ def call(env)
19
+ if env[:machine].id
20
+ @logger.info(I18n.t("vagrant_hp.deleting_server"))
21
+ server = env[:hp_compute].servers.get(env[:machine].id)
22
+ server.stop # verify this
23
+ env[:machine].id = nil
24
+ end
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,23 +1,23 @@
1
- #
2
- # Author:: Mohit Sethi (<mohit@sethis.in>)
3
- # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
- #
5
-
6
- module VagrantPlugins
7
- module HP
8
- module Action
9
- # This can be used with "Call" built-in to check if the machine
10
- # is created and branch in the middleware.
11
- class IsCreated
12
- def initialize(app, env)
13
- @app = app
14
- end
15
-
16
- def call(env)
17
- env[:result] = env[:machine].state.id != :not_created
18
- @app.call(env)
19
- end
20
- end
21
- end
22
- end
23
- end
1
+ #
2
+ # Author:: Mohit Sethi (<mohit@sethis.in>)
3
+ # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
+ #
5
+
6
+ module VagrantPlugins
7
+ module HP
8
+ module Action
9
+ # This can be used with "Call" built-in to check if the machine
10
+ # is created and branch in the middleware.
11
+ class IsCreated
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ env[:result] = env[:machine].state.id != :not_created
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,23 +1,23 @@
1
- #
2
- # Author:: Mohit Sethi (<mohit@sethis.in>)
3
- # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
- #
5
-
6
- module VagrantPlugins
7
- module HP
8
- module Action
9
- # This can be used with "Call" built-in to check if the machine
10
- # is created and branch in the middleware.
11
- class IsRunning
12
- def initialize(app, env)
13
- @app = app
14
- end
15
-
16
- def call(env)
17
- env[:result] = env[:machine].state.id != :running
18
- @app.call(env)
19
- end
20
- end
21
- end
22
- end
23
- end
1
+ #
2
+ # Author:: Mohit Sethi (<mohit@sethis.in>)
3
+ # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
+ #
5
+
6
+ module VagrantPlugins
7
+ module HP
8
+ module Action
9
+ # This can be used with "Call" built-in to check if the machine
10
+ # is created and branch in the middleware.
11
+ class IsRunning
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ env[:result] = env[:machine].state.id != :running
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end