vagrant-arubacloud 0.0.7 → 0.0.9
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 +4 -4
- data/CHANGELOG.md +36 -36
- data/Gemfile +12 -12
- data/LICENSE.txt +22 -22
- data/README.md +954 -954
- data/Vagrantfile_base +23 -23
- data/Vagrantfile_multi_machine +108 -108
- data/Vagrantfile_only_arubacloud_tmpl_srv +22 -22
- data/Vagrantfile_pro +32 -32
- data/Vagrantfile_syncing_and_sample_provision +27 -27
- data/lib/vagrant-arubacloud/action.rb +204 -204
- data/lib/vagrant-arubacloud/action/connect_arubacloud.rb +39 -39
- data/lib/vagrant-arubacloud/action/create_server.rb +116 -116
- data/lib/vagrant-arubacloud/action/delete_server.rb +35 -35
- data/lib/vagrant-arubacloud/action/halt_server.rb +61 -61
- data/lib/vagrant-arubacloud/action/list_servers.rb +61 -61
- data/lib/vagrant-arubacloud/action/list_templates.rb +36 -36
- data/lib/vagrant-arubacloud/action/read_ssh_info.rb +43 -43
- data/lib/vagrant-arubacloud/action/read_state.rb +43 -43
- data/lib/vagrant-arubacloud/action/start_server.rb +59 -59
- data/lib/vagrant-arubacloud/command/root.rb +66 -66
- data/lib/vagrant-arubacloud/command/servers.rb +49 -49
- data/lib/vagrant-arubacloud/command/snapshot.rb +175 -175
- data/lib/vagrant-arubacloud/config.rb +166 -167
- data/lib/vagrant-arubacloud/plugin.rb +56 -56
- data/lib/vagrant-arubacloud/provider.rb +51 -51
- data/lib/vagrant-arubacloud/version.rb +5 -5
- data/locales/en.yml +105 -105
- data/spec/vagrant-arubacloud/action_spec.rb +166 -166
- data/spec/vagrant-arubacloud/config_spec.rb +185 -185
- data/vagrant-arubacloud.gemspec +26 -27
- metadata +2 -16
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'vagrant-arubacloud/action'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module ArubaCloud
|
5
|
-
module Command
|
6
|
-
class Root < Vagrant.plugin('2', :command)
|
7
|
-
def self.synopsis
|
8
|
-
'query ArubaCloud for servers and templates'
|
9
|
-
end
|
10
|
-
def initialize(argv, env)
|
11
|
-
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
12
|
-
@env = env
|
13
|
-
|
14
|
-
@subcommands = Vagrant::Registry.new
|
15
|
-
@subcommands.register(:templates) do
|
16
|
-
require File.expand_path('../templates', __FILE__)
|
17
|
-
Templates
|
18
|
-
end
|
19
|
-
@subcommands.register(:servers) do
|
20
|
-
require File.expand_path('../servers', __FILE__)
|
21
|
-
Servers
|
22
|
-
end
|
23
|
-
|
24
|
-
super(argv, env)
|
25
|
-
end
|
26
|
-
|
27
|
-
def execute
|
28
|
-
if @main_args.include?('-h') || @main_args.include?('--help')
|
29
|
-
return help
|
30
|
-
end
|
31
|
-
|
32
|
-
# Set command_class to default nil
|
33
|
-
command_class = nil
|
34
|
-
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
35
|
-
return help if command_class.nil? || !@sub_command
|
36
|
-
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
37
|
-
|
38
|
-
# Initialize and execute the command class
|
39
|
-
command_class.new(@sub_args, @env).execute
|
40
|
-
end
|
41
|
-
|
42
|
-
def help
|
43
|
-
opts = OptionParser.new do |opts|
|
44
|
-
opts.banner = 'Usage: vagrant arubacloud <subcommand> [<args>]'
|
45
|
-
opts.separator ''
|
46
|
-
opts.separator 'Available subcommands:'
|
47
|
-
|
48
|
-
# Add the available subcommands as separators in order to print them
|
49
|
-
# out as well.
|
50
|
-
keys = []
|
51
|
-
@subcommands.each { |key, value| keys << key.to_s }
|
52
|
-
|
53
|
-
keys.sort.each do |key|
|
54
|
-
opts.separator " #{key}"
|
55
|
-
end
|
56
|
-
|
57
|
-
opts.separator ''
|
58
|
-
opts.separator 'For help on any individual subcommand run `vagrant arubacloud <subcommand> -h`'
|
59
|
-
end
|
60
|
-
|
61
|
-
@env.ui.info(opts.help, :prefix => false)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
require 'vagrant-arubacloud/action'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ArubaCloud
|
5
|
+
module Command
|
6
|
+
class Root < Vagrant.plugin('2', :command)
|
7
|
+
def self.synopsis
|
8
|
+
'query ArubaCloud for servers and templates'
|
9
|
+
end
|
10
|
+
def initialize(argv, env)
|
11
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
12
|
+
@env = env
|
13
|
+
|
14
|
+
@subcommands = Vagrant::Registry.new
|
15
|
+
@subcommands.register(:templates) do
|
16
|
+
require File.expand_path('../templates', __FILE__)
|
17
|
+
Templates
|
18
|
+
end
|
19
|
+
@subcommands.register(:servers) do
|
20
|
+
require File.expand_path('../servers', __FILE__)
|
21
|
+
Servers
|
22
|
+
end
|
23
|
+
|
24
|
+
super(argv, env)
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
if @main_args.include?('-h') || @main_args.include?('--help')
|
29
|
+
return help
|
30
|
+
end
|
31
|
+
|
32
|
+
# Set command_class to default nil
|
33
|
+
command_class = nil
|
34
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
35
|
+
return help if command_class.nil? || !@sub_command
|
36
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
37
|
+
|
38
|
+
# Initialize and execute the command class
|
39
|
+
command_class.new(@sub_args, @env).execute
|
40
|
+
end
|
41
|
+
|
42
|
+
def help
|
43
|
+
opts = OptionParser.new do |opts|
|
44
|
+
opts.banner = 'Usage: vagrant arubacloud <subcommand> [<args>]'
|
45
|
+
opts.separator ''
|
46
|
+
opts.separator 'Available subcommands:'
|
47
|
+
|
48
|
+
# Add the available subcommands as separators in order to print them
|
49
|
+
# out as well.
|
50
|
+
keys = []
|
51
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
52
|
+
|
53
|
+
keys.sort.each do |key|
|
54
|
+
opts.separator " #{key}"
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.separator ''
|
58
|
+
opts.separator 'For help on any individual subcommand run `vagrant arubacloud <subcommand> -h`'
|
59
|
+
end
|
60
|
+
|
61
|
+
@env.ui.info(opts.help, :prefix => false)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module ArubaCloud
|
5
|
-
module Command
|
6
|
-
class Servers < Vagrant.plugin('2', :command)
|
7
|
-
def execute
|
8
|
-
options = {}
|
9
|
-
opts = OptionParser.new do |o|
|
10
|
-
o.banner = 'Usage: vagrant arubacloud servers [options]'
|
11
|
-
end
|
12
|
-
argv = parse_options(opts)
|
13
|
-
return unless argv
|
14
|
-
|
15
|
-
vm_count = 1
|
16
|
-
vm_list = Array.new
|
17
|
-
vm_size = 0
|
18
|
-
|
19
|
-
with_target_vms(argv, :provider => :arubacloud , :plist => '1' ) do |machine|
|
20
|
-
if vm_count == 1
|
21
|
-
ll = machine.name.length
|
22
|
-
ui_ext = Vagrant::UI::Prefixed.new( Vagrant::UI::Colored.new, " "*ll )
|
23
|
-
ui_ext.opts = { :color => :white, :bold => true }
|
24
|
-
ui_ext.detail ('%-6s %-20s %-8s %-12s %-14s %s' % ['DC', 'Server Name', ' Id ', 'State Code', 'State meaning', 'IPv4 address'])
|
25
|
-
ui_ext.detail ("-" * 80)
|
26
|
-
# vm_size : how many vm are in .vagrant directory (is default)
|
27
|
-
# status : 'owned' all VM defined in my '.vagrant' directory
|
28
|
-
machine.provider_config.reserved_status = "owned"
|
29
|
-
vm_size = machine.config.vm.defined_vm_keys.length
|
30
|
-
end
|
31
|
-
if (vm_count == vm_size)
|
32
|
-
# if last element change 'status' to 'other' to output list of all external VM in current DC
|
33
|
-
# and send list all VM's ( server.name) founds in '.vagrant' directory
|
34
|
-
machine.provider_config.reserved_status = "other"
|
35
|
-
machine.provider_config.reserved_list_owned = vm_list
|
36
|
-
end
|
37
|
-
|
38
|
-
machine.action('list_servers')
|
39
|
-
vm_count += 1
|
40
|
-
# accum in append current server-name returned by list_server only if exist
|
41
|
-
if machine.provider_config.reserved_list_owned
|
42
|
-
vm_list << machine.provider_config.reserved_list_owned
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ArubaCloud
|
5
|
+
module Command
|
6
|
+
class Servers < Vagrant.plugin('2', :command)
|
7
|
+
def execute
|
8
|
+
options = {}
|
9
|
+
opts = OptionParser.new do |o|
|
10
|
+
o.banner = 'Usage: vagrant arubacloud servers [options]'
|
11
|
+
end
|
12
|
+
argv = parse_options(opts)
|
13
|
+
return unless argv
|
14
|
+
|
15
|
+
vm_count = 1
|
16
|
+
vm_list = Array.new
|
17
|
+
vm_size = 0
|
18
|
+
|
19
|
+
with_target_vms(argv, :provider => :arubacloud , :plist => '1' ) do |machine|
|
20
|
+
if vm_count == 1
|
21
|
+
ll = machine.name.length
|
22
|
+
ui_ext = Vagrant::UI::Prefixed.new( Vagrant::UI::Colored.new, " "*ll )
|
23
|
+
ui_ext.opts = { :color => :white, :bold => true }
|
24
|
+
ui_ext.detail ('%-6s %-20s %-8s %-12s %-14s %s' % ['DC', 'Server Name', ' Id ', 'State Code', 'State meaning', 'IPv4 address'])
|
25
|
+
ui_ext.detail ("-" * 80)
|
26
|
+
# vm_size : how many vm are in .vagrant directory (is default)
|
27
|
+
# status : 'owned' all VM defined in my '.vagrant' directory
|
28
|
+
machine.provider_config.reserved_status = "owned"
|
29
|
+
vm_size = machine.config.vm.defined_vm_keys.length
|
30
|
+
end
|
31
|
+
if (vm_count == vm_size)
|
32
|
+
# if last element change 'status' to 'other' to output list of all external VM in current DC
|
33
|
+
# and send list all VM's ( server.name) founds in '.vagrant' directory
|
34
|
+
machine.provider_config.reserved_status = "other"
|
35
|
+
machine.provider_config.reserved_list_owned = vm_list
|
36
|
+
end
|
37
|
+
|
38
|
+
machine.action('list_servers')
|
39
|
+
vm_count += 1
|
40
|
+
# accum in append current server-name returned by list_server only if exist
|
41
|
+
if machine.provider_config.reserved_list_owned
|
42
|
+
vm_list << machine.provider_config.reserved_list_owned
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,175 +1,175 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'vagrant-arubacloud/action'
|
3
|
-
require 'fog/arubacloud'
|
4
|
-
|
5
|
-
module VagrantPlugins
|
6
|
-
module Command
|
7
|
-
class Snapshot < Vagrant.plugin('2', :command)
|
8
|
-
def self.synopsis
|
9
|
-
'implement snapshot for vagrant-arubacloud '
|
10
|
-
end
|
11
|
-
def execute
|
12
|
-
options = {:snapop => nil, :namevm => nil}
|
13
|
-
myparser = OptionParser.new do |opts|
|
14
|
-
opts.banner = "Usage: vagrant snapshot -t [create|delete|restore|list] -n name_server"
|
15
|
-
opts.on('-n', '--name name', 'Name server of virtual machine') do |name|
|
16
|
-
options[:namevm] = name;
|
17
|
-
end
|
18
|
-
opts.on('-t', '--type type', 'Type of snapshot : create|delete|restore|list') do |type|
|
19
|
-
options[:snapop] = type;
|
20
|
-
end
|
21
|
-
opts.on('-h', '--help', 'Displays Help') do
|
22
|
-
puts opts
|
23
|
-
return
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
myparser.parse!
|
28
|
-
|
29
|
-
if options[:namevm] == nil
|
30
|
-
puts 'Name of VM is missing'
|
31
|
-
return
|
32
|
-
end
|
33
|
-
if options[:snapop] == nil
|
34
|
-
puts "Type of action: 'create,delete,restore,list' is missing"
|
35
|
-
return
|
36
|
-
end
|
37
|
-
ck1 = ["create", "delete", "restore", "list"].include? options[:snapop]
|
38
|
-
if !ck1
|
39
|
-
puts 'Valid option type are: create,delete,restore,list '
|
40
|
-
return
|
41
|
-
end
|
42
|
-
|
43
|
-
not_found = true
|
44
|
-
with_target_vms( nil, :provider => :arubacloud) do |machine|
|
45
|
-
# if not machine.id....
|
46
|
-
if machine.id == nil
|
47
|
-
next
|
48
|
-
end
|
49
|
-
config1 = machine.provider_config
|
50
|
-
#if no url in config....
|
51
|
-
unless config1.url
|
52
|
-
machine.ui.info(" [dc?] " + I18n.t('vagrant_arubacloud.wrong_dc'))
|
53
|
-
return
|
54
|
-
end
|
55
|
-
|
56
|
-
arubacloud_dc = config1.endpoint
|
57
|
-
myprefix = "[#{arubacloud_dc}] "
|
58
|
-
params = {
|
59
|
-
:provider => :arubacloud,
|
60
|
-
:arubacloud_username => config1.arubacloud_username,
|
61
|
-
:arubacloud_password => config1.arubacloud_password,
|
62
|
-
:url => config1.url
|
63
|
-
}
|
64
|
-
|
65
|
-
envx = Fog::Compute.new params
|
66
|
-
server = envx.servers.get(machine.id)
|
67
|
-
if server.name == options[:namevm]
|
68
|
-
|
69
|
-
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.connect_to_dc'))
|
70
|
-
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_req_type') + " '#{options[:snapop]}'" + " target id:#{machine.id}" )
|
71
|
-
not_found = false
|
72
|
-
case options[:snapop]
|
73
|
-
# output if exist date creation and date expire for snapshot
|
74
|
-
when "list"
|
75
|
-
begin
|
76
|
-
myreq = server.list_snapshot
|
77
|
-
if myreq["Success"]
|
78
|
-
machine.ui.info(myprefix + 'snapshot ' + I18n.t('vagrant_arubacloud.snapshot_info_create') + " #{myreq['credate']} " + I18n.t('vagrant_arubacloud.snapshot_info_expired') + " #{myreq['expdate']} " )
|
79
|
-
else
|
80
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_info_not_found'))
|
81
|
-
end
|
82
|
-
rescue Fog::ArubaCloud::Errors::RequestError => e
|
83
|
-
message = ''
|
84
|
-
error = nil
|
85
|
-
@logger.debug(e.inspect.to_yaml)
|
86
|
-
machine.ui.warn(myprefix + " *ERR* list response message: #{e.response.to_yaml}")
|
87
|
-
end
|
88
|
-
# creation of snapshot ....
|
89
|
-
when "create"
|
90
|
-
if server.state == Fog::ArubaCloud::Compute::Server::RUNNING
|
91
|
-
#
|
92
|
-
# if state active and request snapshot create ...
|
93
|
-
#
|
94
|
-
begin
|
95
|
-
myreq = server.create_snapshot
|
96
|
-
if myreq
|
97
|
-
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_created'))
|
98
|
-
else
|
99
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_create_err_fog'))
|
100
|
-
end
|
101
|
-
rescue Fog::ArubaCloud::Errors::RequestError => e
|
102
|
-
message = ''
|
103
|
-
error = nil
|
104
|
-
@logger.debug(e.inspect.to_yaml)
|
105
|
-
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
106
|
-
#raise error
|
107
|
-
end
|
108
|
-
#
|
109
|
-
else
|
110
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_create_err_not_on'))
|
111
|
-
end
|
112
|
-
# delete of snapshot...
|
113
|
-
when "delete"
|
114
|
-
#
|
115
|
-
# if snapshot delete ...
|
116
|
-
#
|
117
|
-
begin
|
118
|
-
myreq = server.delete_snapshot
|
119
|
-
if myreq
|
120
|
-
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_deleted'))
|
121
|
-
else
|
122
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_delete_err_fog'))
|
123
|
-
end
|
124
|
-
rescue Fog::ArubaCloud::Errors::RequestError => e
|
125
|
-
message = ''
|
126
|
-
error = nil
|
127
|
-
@logger.debug(e.inspect.to_yaml)
|
128
|
-
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
129
|
-
#raise error
|
130
|
-
end
|
131
|
-
# if vm is power off and esiste a snapshot resorre vm from snapshot
|
132
|
-
# (waring : the machine is not power on after restart and snapshot image is removed)
|
133
|
-
when "restore"
|
134
|
-
if server.state == Fog::ArubaCloud::Compute::Server::STOPPED
|
135
|
-
#
|
136
|
-
# if state stopped (power off) and requets restore
|
137
|
-
# WARNING : the snapshot file is removed after restore
|
138
|
-
#
|
139
|
-
begin
|
140
|
-
myreq = server.apply_snapshot
|
141
|
-
if myreq
|
142
|
-
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_restored'))
|
143
|
-
else
|
144
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_restore_err_fog'))
|
145
|
-
end
|
146
|
-
rescue Fog::ArubaCloud::Errors::RequestError => e
|
147
|
-
message = ''
|
148
|
-
error = nil
|
149
|
-
@logger.debug(e.inspect.to_yaml)
|
150
|
-
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
151
|
-
#raise error
|
152
|
-
end
|
153
|
-
else
|
154
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_restore_err_not_off'))
|
155
|
-
end
|
156
|
-
|
157
|
-
else
|
158
|
-
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_type_unknow') + " :#{options[:snapop]}" )
|
159
|
-
end
|
160
|
-
|
161
|
-
end # test if found machine.id
|
162
|
-
|
163
|
-
end #
|
164
|
-
|
165
|
-
if not_found
|
166
|
-
puts "==> ??? [dc?] " + I18n.t("vagrant_arubacloud.snapshot_server_unknow") + " :#{options[:namevm]}"
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-arubacloud/action'
|
3
|
+
require 'fog/arubacloud'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Command
|
7
|
+
class Snapshot < Vagrant.plugin('2', :command)
|
8
|
+
def self.synopsis
|
9
|
+
'implement snapshot for vagrant-arubacloud '
|
10
|
+
end
|
11
|
+
def execute
|
12
|
+
options = {:snapop => nil, :namevm => nil}
|
13
|
+
myparser = OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: vagrant snapshot -t [create|delete|restore|list] -n name_server"
|
15
|
+
opts.on('-n', '--name name', 'Name server of virtual machine') do |name|
|
16
|
+
options[:namevm] = name;
|
17
|
+
end
|
18
|
+
opts.on('-t', '--type type', 'Type of snapshot : create|delete|restore|list') do |type|
|
19
|
+
options[:snapop] = type;
|
20
|
+
end
|
21
|
+
opts.on('-h', '--help', 'Displays Help') do
|
22
|
+
puts opts
|
23
|
+
return
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
myparser.parse!
|
28
|
+
|
29
|
+
if options[:namevm] == nil
|
30
|
+
puts 'Name of VM is missing'
|
31
|
+
return
|
32
|
+
end
|
33
|
+
if options[:snapop] == nil
|
34
|
+
puts "Type of action: 'create,delete,restore,list' is missing"
|
35
|
+
return
|
36
|
+
end
|
37
|
+
ck1 = ["create", "delete", "restore", "list"].include? options[:snapop]
|
38
|
+
if !ck1
|
39
|
+
puts 'Valid option type are: create,delete,restore,list '
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
not_found = true
|
44
|
+
with_target_vms( nil, :provider => :arubacloud) do |machine|
|
45
|
+
# if not machine.id....
|
46
|
+
if machine.id == nil
|
47
|
+
next
|
48
|
+
end
|
49
|
+
config1 = machine.provider_config
|
50
|
+
#if no url in config....
|
51
|
+
unless config1.url
|
52
|
+
machine.ui.info(" [dc?] " + I18n.t('vagrant_arubacloud.wrong_dc'))
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
arubacloud_dc = config1.endpoint
|
57
|
+
myprefix = "[#{arubacloud_dc}] "
|
58
|
+
params = {
|
59
|
+
:provider => :arubacloud,
|
60
|
+
:arubacloud_username => config1.arubacloud_username,
|
61
|
+
:arubacloud_password => config1.arubacloud_password,
|
62
|
+
:url => config1.url
|
63
|
+
}
|
64
|
+
|
65
|
+
envx = Fog::Compute.new params
|
66
|
+
server = envx.servers.get(machine.id)
|
67
|
+
if server.name == options[:namevm]
|
68
|
+
|
69
|
+
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.connect_to_dc'))
|
70
|
+
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_req_type') + " '#{options[:snapop]}'" + " target id:#{machine.id}" )
|
71
|
+
not_found = false
|
72
|
+
case options[:snapop]
|
73
|
+
# output if exist date creation and date expire for snapshot
|
74
|
+
when "list"
|
75
|
+
begin
|
76
|
+
myreq = server.list_snapshot
|
77
|
+
if myreq["Success"]
|
78
|
+
machine.ui.info(myprefix + 'snapshot ' + I18n.t('vagrant_arubacloud.snapshot_info_create') + " #{myreq['credate']} " + I18n.t('vagrant_arubacloud.snapshot_info_expired') + " #{myreq['expdate']} " )
|
79
|
+
else
|
80
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_info_not_found'))
|
81
|
+
end
|
82
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
83
|
+
message = ''
|
84
|
+
error = nil
|
85
|
+
@logger.debug(e.inspect.to_yaml)
|
86
|
+
machine.ui.warn(myprefix + " *ERR* list response message: #{e.response.to_yaml}")
|
87
|
+
end
|
88
|
+
# creation of snapshot ....
|
89
|
+
when "create"
|
90
|
+
if server.state == Fog::ArubaCloud::Compute::Server::RUNNING
|
91
|
+
#
|
92
|
+
# if state active and request snapshot create ...
|
93
|
+
#
|
94
|
+
begin
|
95
|
+
myreq = server.create_snapshot
|
96
|
+
if myreq
|
97
|
+
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_created'))
|
98
|
+
else
|
99
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_create_err_fog'))
|
100
|
+
end
|
101
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
102
|
+
message = ''
|
103
|
+
error = nil
|
104
|
+
@logger.debug(e.inspect.to_yaml)
|
105
|
+
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
106
|
+
#raise error
|
107
|
+
end
|
108
|
+
#
|
109
|
+
else
|
110
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_create_err_not_on'))
|
111
|
+
end
|
112
|
+
# delete of snapshot...
|
113
|
+
when "delete"
|
114
|
+
#
|
115
|
+
# if snapshot delete ...
|
116
|
+
#
|
117
|
+
begin
|
118
|
+
myreq = server.delete_snapshot
|
119
|
+
if myreq
|
120
|
+
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_deleted'))
|
121
|
+
else
|
122
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_delete_err_fog'))
|
123
|
+
end
|
124
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
125
|
+
message = ''
|
126
|
+
error = nil
|
127
|
+
@logger.debug(e.inspect.to_yaml)
|
128
|
+
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
129
|
+
#raise error
|
130
|
+
end
|
131
|
+
# if vm is power off and esiste a snapshot resorre vm from snapshot
|
132
|
+
# (waring : the machine is not power on after restart and snapshot image is removed)
|
133
|
+
when "restore"
|
134
|
+
if server.state == Fog::ArubaCloud::Compute::Server::STOPPED
|
135
|
+
#
|
136
|
+
# if state stopped (power off) and requets restore
|
137
|
+
# WARNING : the snapshot file is removed after restore
|
138
|
+
#
|
139
|
+
begin
|
140
|
+
myreq = server.apply_snapshot
|
141
|
+
if myreq
|
142
|
+
machine.ui.info(myprefix + I18n.t('vagrant_arubacloud.snapshot_restored'))
|
143
|
+
else
|
144
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_restore_err_fog'))
|
145
|
+
end
|
146
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
147
|
+
message = ''
|
148
|
+
error = nil
|
149
|
+
@logger.debug(e.inspect.to_yaml)
|
150
|
+
machine.ui.warn(myprefix + " *ERROR* response message: #{e.response.to_yaml}")
|
151
|
+
#raise error
|
152
|
+
end
|
153
|
+
else
|
154
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_restore_err_not_off'))
|
155
|
+
end
|
156
|
+
|
157
|
+
else
|
158
|
+
machine.ui.warn(myprefix + I18n.t('vagrant_arubacloud.snapshot_type_unknow') + " :#{options[:snapop]}" )
|
159
|
+
end
|
160
|
+
|
161
|
+
end # test if found machine.id
|
162
|
+
|
163
|
+
end #
|
164
|
+
|
165
|
+
if not_found
|
166
|
+
puts "==> ??? [dc?] " + I18n.t("vagrant_arubacloud.snapshot_server_unknow") + " :#{options[:namevm]}"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
|