vagrant-arubacloud 0.0.2dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +95 -0
  6. data/Rakefile +22 -0
  7. data/Vagrantfile +41 -0
  8. data/dummy.box +0 -0
  9. data/example_box/metadata.json +3 -0
  10. data/gemfiles/vagrant-arubacloud-0.0.1dev.gem +0 -0
  11. data/gemfiles/vagrant-arubacloud-0.0.2dev.gem +0 -0
  12. data/lib/vagrant-arubacloud/action/aruba_provision.rb +37 -0
  13. data/lib/vagrant-arubacloud/action/connect_arubacloud.rb +38 -0
  14. data/lib/vagrant-arubacloud/action/create_server.rb +105 -0
  15. data/lib/vagrant-arubacloud/action/delete_server.rb +33 -0
  16. data/lib/vagrant-arubacloud/action/disable_requiretty.rb +24 -0
  17. data/lib/vagrant-arubacloud/action/halt_server.rb +55 -0
  18. data/lib/vagrant-arubacloud/action/is_created.rb +19 -0
  19. data/lib/vagrant-arubacloud/action/list_servers.rb +23 -0
  20. data/lib/vagrant-arubacloud/action/list_templates.rb +34 -0
  21. data/lib/vagrant-arubacloud/action/message_already_created.rb +16 -0
  22. data/lib/vagrant-arubacloud/action/message_not_created.rb +16 -0
  23. data/lib/vagrant-arubacloud/action/read_ssh_info.rb +43 -0
  24. data/lib/vagrant-arubacloud/action/read_state.rb +46 -0
  25. data/lib/vagrant-arubacloud/action.rb +163 -0
  26. data/lib/vagrant-arubacloud/cap/disable_requiretty.rb +13 -0
  27. data/lib/vagrant-arubacloud/command/root.rb +67 -0
  28. data/lib/vagrant-arubacloud/command/servers.rb +21 -0
  29. data/lib/vagrant-arubacloud/command/templates.rb +21 -0
  30. data/lib/vagrant-arubacloud/config.rb +124 -0
  31. data/lib/vagrant-arubacloud/errors.rb +19 -0
  32. data/lib/vagrant-arubacloud/plugin.rb +48 -0
  33. data/lib/vagrant-arubacloud/provider.rb +51 -0
  34. data/lib/vagrant-arubacloud/version.rb +5 -0
  35. data/lib/vagrant-arubacloud.rb +53 -0
  36. data/locales/en.yml +64 -0
  37. data/spec/spec_helper.rb +2 -0
  38. data/spec/vagrant-arubacloud/action/connect_arubacloud_spec.rb +36 -0
  39. data/spec/vagrant-arubacloud/action_spec.rb +25 -0
  40. data/spec/vagrant-arubacloud/config_spec.rb +192 -0
  41. data/vagrant-arubacloud.gemspec +28 -0
  42. metadata +158 -0
@@ -0,0 +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
@@ -0,0 +1,46 @@
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[:ui].output(":machine_state_id: #{env[:machine_state_id]}")
17
+ # env[:ui].output(":arubacloud_compute: #{env[:arubacloud_compute]}")
18
+ # env[:ui].output(":machine: #{env[:machine]}")
19
+ env[:machine_state_id] = read_state(env[:arubacloud_compute], env[:machine])
20
+ @app.call(env)
21
+ end
22
+
23
+ def read_state(arubacloud, machine)
24
+ return :not_created if machine.id.nil?
25
+
26
+ # Find the machine
27
+ server = arubacloud.servers.get(machine.id)
28
+ unless server.instance_of? Fog::Compute::ArubaCloud::Server
29
+ msg = "VagrantPlugins::ArubaCloud::Action::ReadState.read_state, 'server' must be Fog::Compute::ArubaCloud::Server, got: #{server.class}"
30
+ @logger.critical("#{msg}")
31
+ end
32
+ if server.nil? || server.state == Fog::Compute::ArubaCloud::Server::DELETED
33
+ # The machine can't be found
34
+ @logger.info('Machine not found or deleted, assuming it got destroyed.')
35
+ machine.id = nil
36
+ return :not_created
37
+ end
38
+
39
+ @logger.debug("VagrantPlugins::ArubaCloud::Action::ReadState.read_state, server state : #{server.state}")
40
+ # Return the state
41
+ server.state
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,163 @@
1
+ require 'vagrant/action/builder'
2
+ require 'vagrant/action'
3
+
4
+ module VagrantPlugins
5
+ module ArubaCloud
6
+ module Action
7
+
8
+ # Access top level stuff
9
+ include Vagrant::Action::Builtin
10
+
11
+ def self.action_destroy
12
+ Vagrant::Action::Builder.new.tap do |b|
13
+ b.use ConfigValidate
14
+ b.use Call, IsCreated do |env, b1|
15
+ unless env[:result]
16
+ b1.use MessageNotCreated
17
+ next
18
+ end
19
+
20
+ b1.use Call, DestroyConfirm do |env1, b2|
21
+ if env1[:result]
22
+ b2.use ConnectArubaCloud
23
+ b2.use HaltServer
24
+ b2.use DeleteServer
25
+ else
26
+ b2.use Message, ' The server will not be deleted.'
27
+ next
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.action_halt
35
+ Vagrant::Action::Builder.new.tap do |b|
36
+ b.use ConfigValidate #shame on you
37
+ b.use Call, IsCreated do |env, b1|
38
+ unless env[:result]
39
+ b1.use MessageNotCreated
40
+ next
41
+ end
42
+ b1.use ConnectArubaCloud
43
+ b1.use HaltServer
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.action_provision
49
+ Vagrant::Action::Builder.new.tap do |b|
50
+ b.use ConfigValidate
51
+ b.use Call, IsCreated do |env, b2|
52
+ unless env[:result]
53
+ b2.use MessageNotCreated
54
+ next
55
+ end
56
+ # Use our custom provisioning class
57
+ b2.use ArubaProvision
58
+ b2.use SyncedFolders
59
+ end
60
+ end
61
+ end
62
+
63
+ #def self.action_reload
64
+ #Vagrant::Action::Builder.new.tap do |b|
65
+
66
+ #end
67
+ #end
68
+
69
+ def self.action_read_ssh_info
70
+ Vagrant::Action::Builder.new.tap do |b|
71
+ b.use ConfigValidate
72
+ b.use ConnectArubaCloud
73
+ b.use ReadSSHInfo
74
+ end
75
+ end
76
+
77
+ # This action is called to read the state of the machine. The
78
+ # resulting state is expected to be put into the `:machine_state_id`
79
+ # key.
80
+ def self.action_read_state
81
+ Vagrant::Action::Builder.new.tap do |b|
82
+ b.use ConfigValidate
83
+ b.use ConnectArubaCloud
84
+ b.use ReadState
85
+ end
86
+ end
87
+
88
+ def self.action_ssh
89
+ Vagrant::Action::Builder.new.tap do |b|
90
+ b.use ConfigValidate
91
+ b.use Call, IsCreated do |env, b2|
92
+ unless env[:result]
93
+ b2.use MessageNotCreated
94
+ next
95
+ end
96
+ b2.use SSHExec
97
+ end
98
+ end
99
+ end
100
+
101
+ def self.action_ssh_run
102
+ Vagrant::Action::Builder.new.tap do |b|
103
+ b.use ConfigValidate
104
+ b.use Call, IsCreated do |env, b2|
105
+ unless env[:result]
106
+ b2.use MessageNotCreated
107
+ next
108
+ end
109
+
110
+ b2.use SSHRun
111
+ end
112
+ end
113
+ end
114
+
115
+ def self.action_up
116
+ Vagrant::Action::Builder.new.tap do |b|
117
+ b.use ConfigValidate
118
+ b.use Call, IsCreated do |env, b2|
119
+ if env[:result]
120
+ b2.use MessageAlreadyCreated
121
+ next
122
+ end
123
+
124
+ b2.use ConnectArubaCloud
125
+ # b2.use RunInitScript # temporarily removed
126
+ b2.use CreateServer
127
+ b2.use WaitForCommunicator
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.action_list_servers
133
+ Vagrant::Action::Builder.new.tap do |b|
134
+ b.use ConnectArubaCloud
135
+ b.use ListServers
136
+ end
137
+ end
138
+
139
+ def self.action_list_templates
140
+ Vagrant::Action::Builder.new.tap do |b|
141
+ b.use ConnectArubaCloud
142
+ b.use ListTemplates
143
+ end
144
+ end
145
+
146
+ # The autoload farm
147
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
148
+ autoload :ConnectArubaCloud, action_root.join('connect_arubacloud')
149
+ autoload :CreateServer, action_root.join('create_server')
150
+ autoload :HaltServer, action_root.join('halt_server')
151
+ autoload :DeleteServer, action_root.join('delete_server')
152
+ autoload :IsCreated, action_root.join('is_created')
153
+ autoload :MessageNotCreated, action_root.join('message_not_created')
154
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
155
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
156
+ autoload :ReadState, action_root.join('read_state')
157
+ # autoload :RunInitScript, action_root.join("run_init_script")
158
+ autoload :ListServers, action_root.join('list_servers')
159
+ autoload :ListTemplates, action_root.join('list_templates')
160
+ autoload :ArubaProvision, action_root.join('aruba_provision')
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,13 @@
1
+ module Cap
2
+ class DisableRequireTty
3
+ def self.disable_requiretty(machine)
4
+ output = ''
5
+ command = 'sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers'
6
+
7
+ machine.communicate.execute(command) do |type, data|
8
+ output += data if type == :stdout
9
+ end
10
+ output.chomp!
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,67 @@
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
+
11
+ def initialize(argv, env)
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
+ @env = env
14
+
15
+ @subcommands = Vagrant::Registry.new
16
+ @subcommands.register(:templates) do
17
+ require File.expand_path('../templates', __FILE__)
18
+ Templates
19
+ end
20
+ @subcommands.register(:servers) do
21
+ require File.expand_path('../servers', __FILE__)
22
+ Servers
23
+ end
24
+
25
+ super(argv, env)
26
+ end
27
+
28
+ def execute
29
+ if @main_args.include?('-h') || @main_args.include?('--help')
30
+ return help
31
+ end
32
+
33
+ # Set command_class to default nil
34
+ command_class = nil
35
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
36
+ return help if command_class.nil? || !@sub_command
37
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
38
+
39
+ # Initialize and execute the command class
40
+ command_class.new(@sub_args, @env).execute
41
+ end
42
+
43
+ def help
44
+ opts = OptionParser.new do |opts|
45
+ opts.banner = 'Usage: vagrant arubacloud <subcommand> [<args>]'
46
+ opts.separator ''
47
+ opts.separator 'Available subcommands:'
48
+
49
+ # Add the available subcommands as separators in order to print them
50
+ # out as well.
51
+ keys = []
52
+ @subcommands.each { |key, value| keys << key.to_s }
53
+
54
+ keys.sort.each do |key|
55
+ opts.separator " #{key}"
56
+ end
57
+
58
+ opts.separator ''
59
+ opts.separator 'For help on any individual subcommand run `vagrant arubacloud <subcommand> -h`'
60
+ end
61
+
62
+ @env.ui.info(opts.help, :prefix => false)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module ArubaCloud
3
+ module Command
4
+ class Servers < Vagrant.plugin('2', :command)
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |o|
8
+ o.banner = 'Usage: vagrant arubacloud templates [options]'
9
+ end
10
+
11
+ argv = parse_options(opts)
12
+ return unless argv
13
+
14
+ with_target_vms(argv, :provider => :arubacloud) do |machine|
15
+ machine.action('list_servers')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module ArubaCloud
3
+ module Command
4
+ class Templates < Vagrant.plugin('2', :command)
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |o|
8
+ o.banner = 'Usage: vagrant arubacloud templates [options]'
9
+ end
10
+
11
+ argv = parse_options(opts)
12
+ return unless argv
13
+
14
+ with_target_vms(argv, :provider => :arubacloud) do |machine|
15
+ machine.action('list_templates')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,124 @@
1
+ require 'vagrant'
2
+ require 'fog'
3
+
4
+ module VagrantPlugins
5
+ module ArubaCloud
6
+
7
+ class Config < Vagrant.plugin('2', :config)
8
+ # ArubaCloud Username
9
+ # @return [String]
10
+ attr_accessor :arubacloud_username
11
+
12
+ # ArubaCloud Password
13
+ # @return [String]
14
+ attr_accessor :arubacloud_password
15
+
16
+ # Ws EndPoint Url
17
+ # Expected to be the url of the web service to use
18
+ # @return [String]
19
+ attr_accessor :url
20
+
21
+ # The name of the server. This defaults to the name of the machine
22
+ # defined by Vagrant (via 'config.vm.define'), but can be override here.
23
+ # @return [String]
24
+ attr_accessor :server_name
25
+
26
+ # The ID of the template to use, use vagrant arubacloud templates to obtain
27
+ # the complete list.
28
+ # @return [Integer]
29
+ attr_accessor :template_id
30
+
31
+ # The smart vm type expressed in ID:
32
+ # 1 = small
33
+ # 2 = medium
34
+ # 3 = large
35
+ # 4 = extra-large
36
+ # @return [Integer]
37
+ attr_accessor :package_id
38
+
39
+ # The admin password of the vm (root user) .
40
+ # @return [String]
41
+ attr_accessor :admin_password
42
+
43
+ # Service Type expressed in ID [Integer]:
44
+ # 1 = Pro Hyper-V
45
+ # 2 = Pro VMWare
46
+ # 3 = Pro Hyper-V Low Cost
47
+ # 4 = Smart
48
+ # @return [Integer]
49
+ attr_accessor :service_type
50
+
51
+ # Number of Virtual CPU to be assigned to the VM
52
+ # Pro VMWare: 1 < n < 8
53
+ # Pro Hyper-V: 1 < n < 4
54
+ # @return [Integer]
55
+ attr_accessor :cpu_number
56
+
57
+ # Amount of GB of RAM to be assigned to the VM
58
+ # n <= 16
59
+ # @return [Integer]
60
+ attr_accessor :ram_qty
61
+
62
+ # Array containing hard disk Configuration
63
+ # Example configuration (size is expressed in GB):
64
+ # Hds = [{:type => 0, :size => 100}, {:type => 1, :size => 200}]
65
+ # Hd type 0 is required because specify the first hard disk, max size per hd: 500 GB
66
+ # Hd type > 0 < 4 are 3 additional hard disks (optional)
67
+ # @return [Array]
68
+ attr_accessor :hds
69
+
70
+ def initialize
71
+ @arubacloud_username = UNSET_VALUE
72
+ @arubacloud_password = UNSET_VALUE
73
+ @admin_password = UNSET_VALUE
74
+ @url = UNSET_VALUE
75
+ @server_name = UNSET_VALUE
76
+ @template_id = UNSET_VALUE
77
+ @package_id = UNSET_VALUE
78
+ @service_type = UNSET_VALUE
79
+ @cpu_number = UNSET_VALUE
80
+ @ram_qty = UNSET_VALUE
81
+ @hds = UNSET_VALUE
82
+ end
83
+
84
+ def finalize!
85
+ @arubacloud_username = nil if @arubacloud_username == UNSET_VALUE
86
+ @arubacloud_password = nil if @arubacloud_password == UNSET_VALUE
87
+ @admin_password = nil if @admin_password == UNSET_VALUE
88
+ @url = nil if @url == UNSET_VALUE
89
+ @server_name = nil if @server_name == UNSET_VALUE
90
+ @template_id = nil if @template_id == UNSET_VALUE
91
+ @package_id = nil if @package_id == UNSET_VALUE
92
+ @service_type = nil if @service_type == UNSET_VALUE
93
+ @cpu_number = nil if @cpu_number == UNSET_VALUE
94
+ @ram_qty = nil if @ram_qty == UNSET_VALUE
95
+ @hds = nil if @hds == UNSET_VALUE
96
+ end
97
+
98
+ def validate(machine)
99
+ errors = _detected_errors
100
+
101
+ # Global configurations needed by all service types
102
+ errors << I18n.t('vagrant_arubacloud.config.arubacloud_username_required') unless @arubacloud_username
103
+ errors << I18n.t('vagrant_arubacloud.config.arubacloud_password_required') unless @arubacloud_password
104
+ errors << I18n.t('vagrant_arubacloud.config.admin_password_required') unless @admin_password
105
+ errors << I18n.t('vagrant_arubacloud.config.template_id_required') unless @template_id
106
+ errors << I18n.t('vagrant_arubacloud.config.service_type_required') unless @service_type
107
+
108
+ if @service_type.eql? 4
109
+ errors << I18n.t('vagrant_arubacloud.config.package_id_required') unless @package_id
110
+ else
111
+ errors << I18n.t('vagrant_arubacloud.config.cpu_number_required') unless @cpu_number
112
+ errors << I18n.t('vagrant_arubacloud.config.ram_qty_required') unless @ram_qty
113
+ if @hds
114
+ errors << I18n.t('vagrant_arubacloud.config.hds_conf_must_be_array') unless @hds.kind_of?(Array)
115
+ elsif
116
+ errors << I18n.t('vagrant_arubacloud.config.hds_conf_required')
117
+ end
118
+ end
119
+ {'ArubaCloud Provider' => errors}
120
+ end
121
+
122
+ end # Config
123
+ end # ArubaCloud
124
+ end # VagrantPlugins
@@ -0,0 +1,19 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module ArubaCloud
5
+ module Errors
6
+
7
+ class ArubaCloudError < Vagrant::Errors::VagrantError
8
+ error_namespace('vagrant_aruba_cloud.errors')
9
+ end
10
+
11
+ class MachineAlreadyPresent < ArubaCloudError
12
+ end
13
+
14
+ class BadServerResponse < ArubaCloudError
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The ArubaCloud IaaS provider must be run within Vagrant.'
5
+ end
6
+
7
+ if Vagrant::VERSION < '1.2.0'
8
+ raise 'ArubaCloud IaaS provider is only compatible with Vagrant 1.2+'
9
+ end
10
+
11
+ module VagrantPlugins
12
+ module ArubaCloud
13
+ class Plugin < Vagrant.plugin('2')
14
+ # noinspection RubyArgCount
15
+ name 'ArubaCloud'
16
+ description <<-DESC
17
+ This plugin enable Vagrant to manage machines in ArubaCloud IaaS service.
18
+ DESC
19
+
20
+ config(:arubacloud, :provider) do
21
+ require_relative 'config'
22
+ Config
23
+ end
24
+
25
+ provider(:arubacloud, { :box_optional => true, :parallel => true }) do
26
+ ArubaCloud.init_i18n
27
+ ArubaCloud.init_logging
28
+
29
+ require_relative 'provider'
30
+ Provider
31
+ end
32
+
33
+ command('arubacloud') do
34
+ ArubaCloud.init_i18n
35
+ ArubaCloud.init_logging
36
+
37
+ require_relative 'command/root'
38
+ Command::Root
39
+ end
40
+
41
+ # Disable require tty for centOS
42
+ guest_capability 'redhat', 'disable_requiretty' do
43
+ require_relative 'cap/disable_requiretty'
44
+ Cap::DisableRequireTty
45
+ end
46
+ end # Plugin
47
+ end # ArubaCloud
48
+ end # VagrantPlugins
@@ -0,0 +1,51 @@
1
+ require 'vagrant'
2
+
3
+ require 'vagrant-arubacloud/action'
4
+
5
+
6
+ module VagrantPlugins
7
+ module ArubaCloud
8
+ class Provider < Vagrant.plugin('2', :provider)
9
+ def initialize(machine)
10
+ @machine = machine
11
+ end
12
+
13
+ def action(name)
14
+ # Attempt to get the action method from the Action class if it
15
+ # exists, otherwise return nil to show that we don't support the
16
+ # given action.
17
+ action_method = "action_#{name}"
18
+ return Action.send(action_method) if Action.respond_to?(action_method)
19
+ nil
20
+ end
21
+
22
+ def ssh_info
23
+ # Run a custom action called "read_ssh_info" which does what it
24
+ # says and puts the resulting SSH info into the `:machine_ssh_info`
25
+ # key in the environment.
26
+ env = @machine.action("read_ssh_info")
27
+ env[:machine_ssh_info]
28
+ end
29
+
30
+ def state
31
+ # Run a custom action we define called "read_state" which does
32
+ # what it says. It puts the state in the `:machine_state_id`
33
+ # key in the environment.
34
+ env = @machine.action('read_state')
35
+
36
+ state_id = env[:machine_state_id]
37
+
38
+ # Get the short and long description
39
+ short = I18n.t("vagrant_arubacloud.states.short_#{state_id}")
40
+ long = I18n.t("vagrant_arubacloud.states.long_#{state_id}")
41
+
42
+ # Return the MachineState object
43
+ Vagrant::MachineState.new(state_id, short, long)
44
+ end
45
+
46
+ def to_s
47
+ 'ArubaCloud IaaS'
48
+ end
49
+ end # Provider
50
+ end # ArubaCloud
51
+ end # VagrantPlugins
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module ArubaCloud
3
+ VERSION = '0.0.2dev'
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'vagrant-arubacloud/version'
2
+ require 'vagrant-arubacloud/plugin'
3
+
4
+ require 'pathname'
5
+
6
+ module VagrantPlugins
7
+ module ArubaCloud
8
+
9
+ lib_path = Pathname.new(File.expand_path('../vagrant-arubacloud', __FILE__))
10
+ autoload :Errors, lib_path.join('errors')
11
+
12
+ def self.init_i18n
13
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
14
+ I18n.reload!
15
+ end
16
+
17
+ # This initializes the logging so that our logs are outputted at
18
+ # the same level as Vagrant core logs.
19
+ def self.init_logging
20
+ # Initialize logging
21
+ level = nil
22
+ begin
23
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
24
+ rescue NameError
25
+ # This means that the logging constant wasn't found,
26
+ # which is fine. We just keep `level` as `nil`. But
27
+ # we tell the user.
28
+ level = nil
29
+ end
30
+
31
+ # Some constants, such as "true" resolve to booleans, so the
32
+ # above error checking doesn't catch it. This will check to make
33
+ # sure that the log level is an integer, as Log4r requires.
34
+ level = nil unless level.is_a?(Integer)
35
+
36
+ # Set the logging level on all "vagrant" namespaced
37
+ # logs as long as we have a valid level.
38
+ if level
39
+ logger = Log4r::Logger.new('vagrant_arubacloud')
40
+ logger.outputters = Log4r::Outputter.stderr
41
+ logger.level = level
42
+ logger = nil
43
+ end
44
+ end
45
+
46
+ # This returns the path to the source of this plugin.
47
+ #
48
+ # @return [Pathname]
49
+ def self.source_root
50
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
51
+ end
52
+ end
53
+ end