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,61 +1,61 @@
1
- module VagrantPlugins
2
- module ArubaCloud
3
- module Action
4
- class ListServers
5
-
6
- def initialize(app, env)
7
- @app = app
8
- end
9
-
10
- def call(env )
11
- config = env[:machine].provider_config
12
- arubacloud_dc = config.endpoint
13
- compute_service = env[:arubacloud_compute]
14
-
15
- vm_in_dc = compute_service.servers
16
- server_fnd = vm_in_dc.select{ |s| (s.id).to_i == (env[:machine].id).to_i }
17
-
18
- if server_fnd && server_fnd.length == 1
19
- server = server_fnd[0]
20
- server.get_public_ip
21
- ip_found = server.ipv4_addr
22
- if server.hypervisor == 4
23
- ip_found = server.smart_ipv4
24
- end
25
-
26
- env[:machine].ui.info('%-6s %-20s %-8s %-12s %-14s %s' % [arubacloud_dc, server.name, server.id, server.state, Fog::ArubaCloud::Compute::Server::STATE_DES[server.state], ip_found] )
27
- end
28
-
29
- if config.reserved_status == "other"
30
- #
31
- # output all info relate VM found in current DC , but not found in '.vagrant' directory
32
- #
33
- ll = env[:machine].name.length
34
- ui_ext = Vagrant::UI::Prefixed.new( Vagrant::UI::Colored.new, "-".center(ll) )
35
- if server && server.name
36
- config.reserved_list_owned << server.name
37
- end
38
- server_xs = vm_in_dc.select{ |s| not (config.reserved_list_owned.include? s.name)}
39
- server_xs.sort_by(&:name).each do |server|
40
- server.get_public_ip
41
- ip_found = server.ipv4_addr
42
- if server.hypervisor == 4
43
- ip_found = server.smart_ipv4
44
- end
45
- ui_ext.detail('%-6s %-20s %-8s %-12s %-14s %s' % [arubacloud_dc, server.name, server.id, server.state, Fog::ArubaCloud::Compute::Server::STATE_DES[server.state], ip_found] )
46
- end
47
- config.reserved_list_owned = []
48
- else
49
- if server && server.name
50
- config.reserved_list_owned = server.name
51
- else
52
- config.reserver_list_owned = ""
53
- end
54
- end
55
-
56
- @app.call(env)
57
- end
58
- end
59
- end
60
- end
61
- end
1
+ module VagrantPlugins
2
+ module ArubaCloud
3
+ module Action
4
+ class ListServers
5
+
6
+ def initialize(app, env)
7
+ @app = app
8
+ end
9
+
10
+ def call(env )
11
+ config = env[:machine].provider_config
12
+ arubacloud_dc = config.endpoint
13
+ compute_service = env[:arubacloud_compute]
14
+
15
+ vm_in_dc = compute_service.servers
16
+ server_fnd = vm_in_dc.select{ |s| (s.id).to_i == (env[:machine].id).to_i }
17
+
18
+ if server_fnd && server_fnd.length == 1
19
+ server = server_fnd[0]
20
+ server.get_public_ip
21
+ ip_found = server.ipv4_addr
22
+ if server.hypervisor == 4
23
+ ip_found = server.smart_ipv4
24
+ end
25
+
26
+ env[:machine].ui.info('%-6s %-20s %-8s %-12s %-14s %s' % [arubacloud_dc, server.name, server.id, server.state, Fog::ArubaCloud::Compute::Server::STATE_DES[server.state], ip_found] )
27
+ end
28
+
29
+ if config.reserved_status == "other"
30
+ #
31
+ # output all info relate VM found in current DC , but not found in '.vagrant' directory
32
+ #
33
+ ll = env[:machine].name.length
34
+ ui_ext = Vagrant::UI::Prefixed.new( Vagrant::UI::Colored.new, "-".center(ll) )
35
+ if server && server.name
36
+ config.reserved_list_owned << server.name
37
+ end
38
+ server_xs = vm_in_dc.select{ |s| not (config.reserved_list_owned.include? s.name)}
39
+ server_xs.sort_by(&:name).each do |server|
40
+ server.get_public_ip
41
+ ip_found = server.ipv4_addr
42
+ if server.hypervisor == 4
43
+ ip_found = server.smart_ipv4
44
+ end
45
+ ui_ext.detail('%-6s %-20s %-8s %-12s %-14s %s' % [arubacloud_dc, server.name, server.id, server.state, Fog::ArubaCloud::Compute::Server::STATE_DES[server.state], ip_found] )
46
+ end
47
+ config.reserved_list_owned = []
48
+ else
49
+ if server && server.name
50
+ config.reserved_list_owned = server.name
51
+ else
52
+ config.reserver_list_owned = ""
53
+ end
54
+ end
55
+
56
+ @app.call(env)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,36 +1,36 @@
1
- module VagrantPlugins
2
- module ArubaCloud
3
- module Action
4
- class ListTemplates
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- config = env[:machine].provider_config
11
- arubacloud_dc = config.endpoint
12
- compute_service = env[:arubacloud_compute]
13
- env[:ui].info ('%-5s %-40s %-60s %-20s %s' % ['DC', 'Template Name', 'Description', 'ID', 'Hypervisor ID'])
14
- compute_service.templates.sort_by(&:hypervisor).each do |template|
15
- env[:ui].info ('%-5s %-40s %-60s %-20s %s' % [arubacloud_dc, template.name,
16
- template.description,
17
- template.id,
18
- enum_hypervisor_id(template.hypervisor)])
19
- end
20
- @app.call(env)
21
- end
22
-
23
- def enum_hypervisor_id(id)
24
- case id
25
- when 1 then return 'Pro Hyper-V'
26
- when 2 then return 'Pro VmWare'
27
- when 3 then return 'Pro Hyper-V LowCost'
28
- when 4 then return 'Pro Smart'
29
- else
30
- return 'Not Found'
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
1
+ module VagrantPlugins
2
+ module ArubaCloud
3
+ module Action
4
+ class ListTemplates
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ config = env[:machine].provider_config
11
+ arubacloud_dc = config.endpoint
12
+ compute_service = env[:arubacloud_compute]
13
+ env[:ui].info ('%-5s %-40s %-60s %-20s %s' % ['DC', 'Template Name', 'Description', 'ID', 'Hypervisor ID'])
14
+ compute_service.templates.sort_by(&:hypervisor).each do |template|
15
+ env[:ui].info ('%-5s %-40s %-60s %-20s %s' % [arubacloud_dc, template.name,
16
+ template.description,
17
+ template.id,
18
+ enum_hypervisor_id(template.hypervisor)])
19
+ end
20
+ @app.call(env)
21
+ end
22
+
23
+ def enum_hypervisor_id(id)
24
+ case id
25
+ when 1 then return 'Pro Hyper-V'
26
+ when 2 then return 'Pro VmWare'
27
+ when 3 then return 'Pro Hyper-V LowCost'
28
+ when 4 then return 'Pro Smart'
29
+ else
30
+ return 'Not Found'
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,43 +1,43 @@
1
- require 'log4r'
2
-
3
- module VagrantPlugins
4
- module ArubaCloud
5
- module Action
6
-
7
- # This action reads the SSH info for the machine and puts it into
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_arubacloud::action::read_ssh_info')
13
- end
14
-
15
- def call(env)
16
- env[:machine_ssh_info] = read_ssh_info(env[:arubacloud_compute], env[:machine])
17
- @app.call(env)
18
- end
19
-
20
- def read_ssh_info(arubacloud, machine)
21
- return nil if machine.id.nil?
22
-
23
- # Find the machine
24
- server = arubacloud.servers.get(machine.id)
25
- if server.nil?
26
- # The machine can't be found
27
- @logger.info("Machine couldn't be found, assuming it got destroyed.")
28
- machine.id = nil
29
- nil
30
- else
31
- @logger.info("read_ssh_info: server.smart_ipv4: #{server.smart_ipv4}")
32
- # Return the server object
33
- {
34
- :host => server.get_public_ip,
35
- :port => 22,
36
- :username => 'root'
37
- }
38
- end
39
- end # read_ssh_info
40
- end # ReadSSHInfo
41
- end # Action
42
- end # ArubaCloud
43
- end # VagrantPlugins
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module ArubaCloud
5
+ module Action
6
+
7
+ # This action reads the SSH info for the machine and puts it into
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_arubacloud::action::read_ssh_info')
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_ssh_info] = read_ssh_info(env[:arubacloud_compute], env[:machine])
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_ssh_info(arubacloud, machine)
21
+ return nil if machine.id.nil?
22
+
23
+ # Find the machine
24
+ server = arubacloud.servers.get(machine.id)
25
+ if server.nil?
26
+ # The machine can't be found
27
+ @logger.info("Machine couldn't be found, assuming it got destroyed.")
28
+ machine.id = nil
29
+ nil
30
+ else
31
+ @logger.info("read_ssh_info: server.smart_ipv4: #{server.smart_ipv4}")
32
+ # Return the server object
33
+ {
34
+ :host => server.get_public_ip,
35
+ :port => 22,
36
+ :username => 'root'
37
+ }
38
+ end
39
+ end # read_ssh_info
40
+ end # ReadSSHInfo
41
+ end # Action
42
+ end # ArubaCloud
43
+ end # VagrantPlugins
@@ -1,43 +1,43 @@
1
- require 'log4r'
2
-
3
- module VagrantPlugins
4
- module ArubaCloud
5
- module Action
6
- # This action reads the state of the machine and puts it in the
7
- # `:machine_state_id` key in the environment.
8
- class ReadState
9
- def initialize(app, env)
10
- @app = app
11
- @env = env
12
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::read_state')
13
- end
14
-
15
- def call(env)
16
- env[:machine_state_id] = read_state(env[:arubacloud_compute], env[:machine])
17
- @app.call(env)
18
- end
19
-
20
- def read_state(arubacloud, machine)
21
- return :not_created if machine.id.nil?
22
-
23
- # Find the machine
24
- server = arubacloud.servers.get(machine.id)
25
- unless server.instance_of? Fog::ArubaCloud::Compute::Server
26
- msg = "VagrantPlugins::ArubaCloud::Action::ReadState.read_state, 'server' must be Fog::ArubaCloud::Compute::Server, got: #{server.class}"
27
- @logger.critical("#{msg}")
28
- end
29
- if server.nil? || server.state == Fog::ArubaCloud::Compute::Server::DELETED
30
- # The machine can't be found
31
- @logger.info('Machine not found or deleted, assuming it got destroyed.')
32
- machine.id = nil
33
- return :not_created
34
- end
35
-
36
- @logger.debug("VagrantPlugins::ArubaCloud::Action::ReadState.read_state, server state : #{server.state}")
37
- # Return the state
38
- server.state
39
- end
40
- end
41
- end
42
- end
43
- end
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module ArubaCloud
5
+ module Action
6
+ # This action reads the state of the machine and puts it in the
7
+ # `:machine_state_id` key in the environment.
8
+ class ReadState
9
+ def initialize(app, env)
10
+ @app = app
11
+ @env = env
12
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::read_state')
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_state_id] = read_state(env[:arubacloud_compute], env[:machine])
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_state(arubacloud, machine)
21
+ return :not_created if machine.id.nil?
22
+
23
+ # Find the machine
24
+ server = arubacloud.servers.get(machine.id)
25
+ unless server.instance_of? Fog::ArubaCloud::Compute::Server
26
+ msg = "VagrantPlugins::ArubaCloud::Action::ReadState.read_state, 'server' must be Fog::ArubaCloud::Compute::Server, got: #{server.class}"
27
+ @logger.critical("#{msg}")
28
+ end
29
+ if server.nil? || server.state == Fog::ArubaCloud::Compute::Server::DELETED
30
+ # The machine can't be found
31
+ @logger.info('Machine not found or deleted, assuming it got destroyed.')
32
+ machine.id = nil
33
+ return :not_created
34
+ end
35
+
36
+ @logger.debug("VagrantPlugins::ArubaCloud::Action::ReadState.read_state, server state : #{server.state}")
37
+ # Return the state
38
+ server.state
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,59 +1,59 @@
1
- require 'log4r'
2
- require 'vagrant/util/retryable'
3
- require 'fog/arubacloud/error'
4
- require 'optparse'
5
-
6
- module VagrantPlugins
7
- module ArubaCloud
8
- module Action
9
- # This stop a server, if it exists
10
- class StartServer
11
- include Vagrant::Util::Retryable
12
-
13
- def initialize(app, env)
14
- @app = app
15
- @env = env
16
- @logger = Log4r::Logger.new('vagrant_arubacloud::action::start_server')
17
- end
18
-
19
- def call(env)
20
- if env[:machine].id
21
- config = env[:machine].provider_config
22
- arubacloud_dc = config.endpoint
23
-
24
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.starting_server'))
25
- server = env[:arubacloud_compute].servers.get(env[:machine].id)
26
- # Check if the vm is already powered on
27
- @logger.debug("VM ready?: #{server.ready?}")
28
- if server.ready?
29
- # continue the middleware
30
- @app.call(env)
31
- else
32
- # Try to power-on the VM.
33
- begin
34
- server.power_on
35
- rescue Fog::ArubaCloud::Errors::VmStatus
36
- env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
37
- return
38
- rescue Fog::ArubaCloud::Errors::RequestError => e
39
- if e.response['ResultCode'].eql? 17
40
- env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue'))
41
- return
42
- end
43
- end
44
-
45
- # Wait for the server to be proper started and up
46
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.waiting_server_powered_on'))
47
- retryable(:tries => 40, :sleep => 2) do
48
- server.wait_for(1) { ready? }
49
- end
50
- env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.server_powered_on'))
51
- end
52
- end
53
-
54
- @app.call(env)
55
- end
56
- end
57
- end
58
- end
59
- end
1
+ require 'log4r'
2
+ require 'vagrant/util/retryable'
3
+ require 'fog/arubacloud/error'
4
+ require 'optparse'
5
+
6
+ module VagrantPlugins
7
+ module ArubaCloud
8
+ module Action
9
+ # This stop a server, if it exists
10
+ class StartServer
11
+ include Vagrant::Util::Retryable
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @env = env
16
+ @logger = Log4r::Logger.new('vagrant_arubacloud::action::start_server')
17
+ end
18
+
19
+ def call(env)
20
+ if env[:machine].id
21
+ config = env[:machine].provider_config
22
+ arubacloud_dc = config.endpoint
23
+
24
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.starting_server'))
25
+ server = env[:arubacloud_compute].servers.get(env[:machine].id)
26
+ # Check if the vm is already powered on
27
+ @logger.debug("VM ready?: #{server.ready?}")
28
+ if server.ready?
29
+ # continue the middleware
30
+ @app.call(env)
31
+ else
32
+ # Try to power-on the VM.
33
+ begin
34
+ server.power_on
35
+ rescue Fog::ArubaCloud::Errors::VmStatus
36
+ env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
37
+ return
38
+ rescue Fog::ArubaCloud::Errors::RequestError => e
39
+ if e.response['ResultCode'].eql? 17
40
+ env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue'))
41
+ return
42
+ end
43
+ end
44
+
45
+ # Wait for the server to be proper started and up
46
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.waiting_server_powered_on'))
47
+ retryable(:tries => 40, :sleep => 2) do
48
+ server.wait_for(1) { ready? }
49
+ end
50
+ env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.server_powered_on'))
51
+ end
52
+ end
53
+
54
+ @app.call(env)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end