vagrant-arubacloud 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +1,39 @@
1
- require 'fog/arubacloud'
2
- require 'log4r'
3
-
4
- module VagrantPlugins
5
- module ArubaCloud
6
- module Action
7
-
8
- class ConnectArubaCloud
9
- def initialize(app, env)
10
- @app = app
11
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::connect_arubacloud')
12
- end
13
-
14
- def call(env)
15
- # Set the datacenter
16
- config = env[:machine].provider_config
17
- arubacloud_username = config.arubacloud_username
18
- arubacloud_password = config.arubacloud_password
19
- arubacloud_dc = config.endpoint
20
-
21
- params = {
22
- :provider => :arubacloud,
23
- :arubacloud_username => arubacloud_username,
24
- :arubacloud_password => arubacloud_password,
25
- }
26
-
27
- if config.url
28
- @logger.info("Connecting to Datacenter: #{arubacloud_dc} url: #{config.url} ")
29
- params[:url] = config.url
30
- end
31
-
32
- env[:arubacloud_compute] = Fog::Compute.new params
33
-
34
- @app.call(env)
35
- end
36
- end
37
- end
38
- end
39
- end
1
+ require 'fog/arubacloud'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module ArubaCloud
6
+ module Action
7
+
8
+ class ConnectArubaCloud
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::connect_arubacloud')
12
+ end
13
+
14
+ def call(env)
15
+ # Set the datacenter
16
+ config = env[:machine].provider_config
17
+ arubacloud_username = config.arubacloud_username
18
+ arubacloud_password = config.arubacloud_password
19
+ arubacloud_dc = config.endpoint
20
+
21
+ params = {
22
+ :provider => :arubacloud,
23
+ :arubacloud_username => arubacloud_username,
24
+ :arubacloud_password => arubacloud_password,
25
+ }
26
+
27
+ if config.url
28
+ @logger.info("Connecting to Datacenter: #{arubacloud_dc} url: #{config.url} ")
29
+ params[:url] = config.url
30
+ end
31
+
32
+ env[:arubacloud_compute] = Fog::Compute.new params
33
+
34
+ @app.call(env)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,116 +1,116 @@
1
- require 'fog/arubacloud'
2
- require 'log4r'
3
-
4
- require 'vagrant/util/retryable'
5
-
6
- module VagrantPlugins
7
- module ArubaCloud
8
- module Action
9
-
10
- # Create a new server
11
- class CreateServer
12
- include Vagrant::Util::Retryable
13
-
14
- def initialize(app, env)
15
- @app = app
16
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::create_server')
17
- end
18
-
19
- def call(env)
20
- config = env[:machine].provider_config
21
- arubacloud_dc = config.endpoint
22
- tb_package_id = {'small' => 'CPU: 1, Ram(GB): 1, DiskSize(GB): 20',
23
- 'medium' => 'CPU: 1, Ram(GB): 2, DiskSize(GB): 40',
24
- 'large' => 'CPU: 2, Ram(GB): 4, DiskSize(GB): 80',
25
- 'extra large' => 'CPU: 4, Ram(GB): 8, DiskSize(GB): 160'
26
- }
27
- tb_package_id.default = " *unknow package_id* "
28
-
29
- sshpwd = env[:machine].config.ssh.password
30
-
31
- # Set Server Name
32
- server_name = config.server_name || env[:machine].name
33
-
34
- # Output the settings we're going to use to the user
35
- env[:ui].info('Creating a server with the following settings...')
36
- env[:ui].info(" -- Datacenter: #{arubacloud_dc}")
37
- env[:ui].info(" -- Name: #{server_name}")
38
- env[:ui].info(" -- Root Password: #{sshpwd}")
39
- # Build the config hash according to the service type
40
- if config.service_type.eql? 4
41
- options = {
42
- :name => server_name,
43
- :vm_type => 'smart',
44
- :admin_passwd => sshpwd,
45
- :cpu => 1,
46
- :memory => 1,
47
- :template_id => config.template_id,
48
- :package_id => config.package_id
49
- }
50
- env[:ui].info(" -- Package: #{config.package_id} config as: #{tb_package_id[config.package_id]}")
51
-
52
- else
53
- # Processing hds
54
- disks = []
55
- accum = "["
56
- config.hds.each do |disk_spec|
57
- disks << env[:arubacloud_compute].disks.create({
58
- :size => disk_spec[:size],
59
- :virtual_disk_type => disk_spec[:type]}).get_hash
60
- accum += "(hd#{disk_spec[:type]}: #{disk_spec[:size]})"
61
- end
62
- accum += "]"
63
- options = {
64
- :name => server_name,
65
- :vm_type => 'pro',
66
- :admin_passwd => sshpwd,
67
- :cpu => config.cpu_number,
68
- :memory => config.ram_qty,
69
- :template_id => config.template_id,
70
- :disks => disks
71
- }
72
- env[:ui].info(" -- Config as: CPU: #{config.cpu_number}, Ram(GB): #{config.ram_qty}, Disk(GB): #{accum} ")
73
- end
74
-
75
- env[:ui].info(" -- OS Template: #{config.template_id}")
76
- env[:ui].info(" -- Service Type: #{config.service_type} (#{options[:vm_type]}) ")
77
-
78
- # Create the server
79
- begin
80
- server = env[:arubacloud_compute].servers.create(options)
81
- rescue Fog::ArubaCloud::Errors::RequestError => e
82
- message = ''
83
- error = nil
84
- @logger.debug(e.inspect.to_yaml)
85
- if e.response['ResultCode'].eql? 16
86
- message = "Virtual machine with name: #{options[:name]}, already present. Bailout!"
87
- error = Errors::MachineAlreadyPresent
88
- elsif e.response['ResultCode'].eql?(-500)
89
- message = 'Server returned an unexpected response. Bailout!'
90
- error = Errors::BadServerResponse
91
- end
92
- env[:ui].warn("Response message: #{e.response.to_yaml}")
93
- env[:ui].warn(message)
94
- raise error
95
- end
96
-
97
- # Store id of the machine
98
- env[:machine].id = server.id
99
-
100
- # Wait for ssh to be ready
101
- env[:ui].info(" [#{arubacloud_dc}] " + 'Waiting until server is ready...')
102
-
103
- retryable(:tries => 20, :sleep => 45) do
104
- next if env[:interrupted]
105
- server.wait_for(5) { ready? }
106
- end
107
-
108
- env[:ui].info(" [#{arubacloud_dc}] " + 'The server is ready!')
109
-
110
- @app.call(env)
111
- end
112
-
113
- end
114
- end
115
- end
116
- end
1
+ require 'fog/arubacloud'
2
+ require 'log4r'
3
+
4
+ require 'vagrant/util/retryable'
5
+
6
+ module VagrantPlugins
7
+ module ArubaCloud
8
+ module Action
9
+
10
+ # Create a new server
11
+ class CreateServer
12
+ include Vagrant::Util::Retryable
13
+
14
+ def initialize(app, env)
15
+ @app = app
16
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::create_server')
17
+ end
18
+
19
+ def call(env)
20
+ config = env[:machine].provider_config
21
+ arubacloud_dc = config.endpoint
22
+ tb_package_id = {'small' => 'CPU: 1, Ram(GB): 1, DiskSize(GB): 20',
23
+ 'medium' => 'CPU: 1, Ram(GB): 2, DiskSize(GB): 40',
24
+ 'large' => 'CPU: 2, Ram(GB): 4, DiskSize(GB): 80',
25
+ 'extra large' => 'CPU: 4, Ram(GB): 8, DiskSize(GB): 160'
26
+ }
27
+ tb_package_id.default = " *unknow package_id* "
28
+
29
+ sshpwd = env[:machine].config.ssh.password
30
+
31
+ # Set Server Name
32
+ server_name = config.server_name || env[:machine].name
33
+
34
+ # Output the settings we're going to use to the user
35
+ env[:ui].info('Creating a server with the following settings...')
36
+ env[:ui].info(" -- Datacenter: #{arubacloud_dc}")
37
+ env[:ui].info(" -- Name: #{server_name}")
38
+ env[:ui].info(" -- Root Password: #{sshpwd}")
39
+ # Build the config hash according to the service type
40
+ if config.service_type.eql? 4
41
+ options = {
42
+ :name => server_name,
43
+ :vm_type => 'smart',
44
+ :admin_passwd => sshpwd,
45
+ :cpu => 1,
46
+ :memory => 1,
47
+ :template_id => config.template_id,
48
+ :package_id => config.package_id
49
+ }
50
+ env[:ui].info(" -- Package: #{config.package_id} config as: #{tb_package_id[config.package_id]}")
51
+
52
+ else
53
+ # Processing hds
54
+ disks = []
55
+ accum = "["
56
+ config.hds.each do |disk_spec|
57
+ disks << env[:arubacloud_compute].disks.create({
58
+ :size => disk_spec[:size],
59
+ :virtual_disk_type => disk_spec[:type]}).get_hash
60
+ accum += "(hd#{disk_spec[:type]}: #{disk_spec[:size]})"
61
+ end
62
+ accum += "]"
63
+ options = {
64
+ :name => server_name,
65
+ :vm_type => 'pro',
66
+ :admin_passwd => sshpwd,
67
+ :cpu => config.cpu_number,
68
+ :memory => config.ram_qty,
69
+ :template_id => config.template_id,
70
+ :disks => disks
71
+ }
72
+ env[:ui].info(" -- Config as: CPU: #{config.cpu_number}, Ram(GB): #{config.ram_qty}, Disk(GB): #{accum} ")
73
+ end
74
+
75
+ env[:ui].info(" -- OS Template: #{config.template_id}")
76
+ env[:ui].info(" -- Service Type: #{config.service_type} (#{options[:vm_type]}) ")
77
+
78
+ # Create the server
79
+ begin
80
+ server = env[:arubacloud_compute].servers.create(options)
81
+ rescue Fog::ArubaCloud::Errors::RequestError => e
82
+ message = ''
83
+ error = nil
84
+ @logger.debug(e.inspect.to_yaml)
85
+ if e.response['ResultCode'].eql? 16
86
+ message = "Virtual machine with name: #{options[:name]}, already present. Bailout!"
87
+ error = Errors::MachineAlreadyPresent
88
+ elsif e.response['ResultCode'].eql?(-500)
89
+ message = 'Server returned an unexpected response. Bailout!'
90
+ error = Errors::BadServerResponse
91
+ end
92
+ env[:ui].warn("Response message: #{e.response.to_yaml}")
93
+ env[:ui].warn(message)
94
+ raise error
95
+ end
96
+
97
+ # Store id of the machine
98
+ env[:machine].id = server.id
99
+
100
+ # Wait for ssh to be ready
101
+ env[:ui].info(" [#{arubacloud_dc}] " + 'Waiting until server is ready...')
102
+
103
+ retryable(:tries => 20, :sleep => 45) do
104
+ next if env[:interrupted]
105
+ server.wait_for(5) { ready? }
106
+ end
107
+
108
+ env[:ui].info(" [#{arubacloud_dc}] " + 'The server is ready!')
109
+
110
+ @app.call(env)
111
+ end
112
+
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,35 +1,35 @@
1
- require 'log4r'
2
- require 'fog/arubacloud/error'
3
-
4
- module VagrantPlugins
5
- module ArubaCloud
6
- module Action
7
- # This deletes the running server, if there is one.
8
- class DeleteServer
9
- def initialize(app, env)
10
- @app = app
11
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::delete_server')
12
- end
13
-
14
- def call(env)
15
- if env[:machine].id
16
- config = env[:machine].provider_config
17
- arubacloud_dc = config.endpoint
18
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.deleting_server'))
19
- # On fog side, get will call get_service_details, I must be sure
20
- # that the returned object has the "id" parameters not nil
21
- server = env[:arubacloud_compute].servers.get(env[:machine].id)
22
- begin
23
- server.delete
24
- rescue Fog::ArubaCloud::Errors::VmStatus
25
- env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
26
- end
27
- env[:machine].id = nil
28
- end
29
-
30
- @app.call(env)
31
- end
32
- end
33
- end
34
- end
35
- end
1
+ require 'log4r'
2
+ require 'fog/arubacloud/error'
3
+
4
+ module VagrantPlugins
5
+ module ArubaCloud
6
+ module Action
7
+ # This deletes the running server, if there is one.
8
+ class DeleteServer
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::delete_server')
12
+ end
13
+
14
+ def call(env)
15
+ if env[:machine].id
16
+ config = env[:machine].provider_config
17
+ arubacloud_dc = config.endpoint
18
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.deleting_server'))
19
+ # On fog side, get will call get_service_details, I must be sure
20
+ # that the returned object has the "id" parameters not nil
21
+ server = env[:arubacloud_compute].servers.get(env[:machine].id)
22
+ begin
23
+ server.delete
24
+ rescue Fog::ArubaCloud::Errors::VmStatus
25
+ env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
26
+ end
27
+ env[:machine].id = nil
28
+ end
29
+
30
+ @app.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,61 +1,61 @@
1
- require 'log4r'
2
- require 'vagrant/util/retryable'
3
- require 'fog/arubacloud/error'
4
-
5
- module VagrantPlugins
6
- module ArubaCloud
7
- module Action
8
- # This stop a server, if it exists
9
- class HaltServer
10
- include Vagrant::Util::Retryable
11
-
12
- def initialize(app, env)
13
- @app = app
14
- @env = env
15
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::halt_server')
16
- end
17
-
18
- def call(env)
19
- if env[:machine].id
20
- config = env[:machine].provider_config
21
- arubacloud_dc = config.endpoint
22
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.halting_server'))
23
- server = env[:arubacloud_compute].servers.get(env[:machine].id)
24
-
25
- # Check if the vm is already powered off
26
- @logger.debug("VM stopped?: #{server.stopped?}")
27
- if server.stopped?
28
- # continue the middleware
29
- @logger.debug("VM is stopped ...")
30
- @app.call(env)
31
- else
32
- # Try to poweroff the VM.
33
- begin
34
- @logger.debug("before make do power_off ...")
35
- server.power_off
36
- rescue Fog::ArubaCloud::Errors::VmStatus
37
- env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
38
- return
39
- rescue Fog::ArubaCloud::Errors::RequestError => e
40
- if e.response['ResultCode'].eql? 17
41
- env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue'))
42
- return
43
- end
44
- end
45
-
46
- # Wait for the server to be proper shut down
47
- @logger.debug("after do power_off wait status stopped .......")
48
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.waiting_server_powered_off'))
49
- retryable(:tries => 30, :sleep => 2) do
50
- server.wait_for(2) { stopped? }
51
- end
52
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.server_powered_off'))
53
- end
54
- end
55
-
56
- @app.call(env)
57
- end
58
- end
59
- end
60
- end
61
- end
1
+ require 'log4r'
2
+ require 'vagrant/util/retryable'
3
+ require 'fog/arubacloud/error'
4
+
5
+ module VagrantPlugins
6
+ module ArubaCloud
7
+ module Action
8
+ # This stop a server, if it exists
9
+ class HaltServer
10
+ include Vagrant::Util::Retryable
11
+
12
+ def initialize(app, env)
13
+ @app = app
14
+ @env = env
15
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::halt_server')
16
+ end
17
+
18
+ def call(env)
19
+ if env[:machine].id
20
+ config = env[:machine].provider_config
21
+ arubacloud_dc = config.endpoint
22
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.halting_server'))
23
+ server = env[:arubacloud_compute].servers.get(env[:machine].id)
24
+
25
+ # Check if the vm is already powered off
26
+ @logger.debug("VM stopped?: #{server.stopped?}")
27
+ if server.stopped?
28
+ # continue the middleware
29
+ @logger.debug("VM is stopped ...")
30
+ @app.call(env)
31
+ else
32
+ # Try to poweroff the VM.
33
+ begin
34
+ @logger.debug("before make do power_off ...")
35
+ server.power_off
36
+ rescue Fog::ArubaCloud::Errors::VmStatus
37
+ env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
38
+ return
39
+ rescue Fog::ArubaCloud::Errors::RequestError => e
40
+ if e.response['ResultCode'].eql? 17
41
+ env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue'))
42
+ return
43
+ end
44
+ end
45
+
46
+ # Wait for the server to be proper shut down
47
+ @logger.debug("after do power_off wait status stopped .......")
48
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.waiting_server_powered_off'))
49
+ retryable(:tries => 30, :sleep => 2) do
50
+ server.wait_for(2) { stopped? }
51
+ end
52
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.server_powered_off'))
53
+ end
54
+ end
55
+
56
+ @app.call(env)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end