vagrant-cosmic 0.1.0

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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/CHANGELOG.md +8 -0
  4. data/Docker/.dockerignore +2 -0
  5. data/Docker/Dockerfile +48 -0
  6. data/Docker/Dockerfile.chefdk_0_17 +49 -0
  7. data/Docker/Dockerfile.latest_dependencies +49 -0
  8. data/Docker/README.md +95 -0
  9. data/Docker/vac.ps1 +29 -0
  10. data/Docker/vac.sh +30 -0
  11. data/Gemfile +21 -0
  12. data/Gemfile.lock +187 -0
  13. data/LICENSE +8 -0
  14. data/README.md +409 -0
  15. data/Rakefile +106 -0
  16. data/build_rpm.sh +7 -0
  17. data/functional-tests/basic/Vagrantfile.basic_networking +34 -0
  18. data/functional-tests/basic/basic_spec.rb +15 -0
  19. data/functional-tests/networking/Vagrantfile.advanced_networking +106 -0
  20. data/functional-tests/networking/networking_spec.rb +14 -0
  21. data/functional-tests/rsync/Vagrantfile.advanced_networking +40 -0
  22. data/functional-tests/rsync/rsync_spec.rb +9 -0
  23. data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +64 -0
  24. data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +25 -0
  25. data/lib/vagrant-cosmic/action/connect_cosmic.rb +47 -0
  26. data/lib/vagrant-cosmic/action/is_created.rb +18 -0
  27. data/lib/vagrant-cosmic/action/is_stopped.rb +18 -0
  28. data/lib/vagrant-cosmic/action/message_already_created.rb +16 -0
  29. data/lib/vagrant-cosmic/action/message_not_created.rb +16 -0
  30. data/lib/vagrant-cosmic/action/message_will_not_destroy.rb +16 -0
  31. data/lib/vagrant-cosmic/action/read_rdp_info.rb +42 -0
  32. data/lib/vagrant-cosmic/action/read_ssh_info.rb +70 -0
  33. data/lib/vagrant-cosmic/action/read_state.rb +38 -0
  34. data/lib/vagrant-cosmic/action/read_transport_info.rb +59 -0
  35. data/lib/vagrant-cosmic/action/read_winrm_info.rb +69 -0
  36. data/lib/vagrant-cosmic/action/run_instance.rb +819 -0
  37. data/lib/vagrant-cosmic/action/start_instance.rb +81 -0
  38. data/lib/vagrant-cosmic/action/stop_instance.rb +28 -0
  39. data/lib/vagrant-cosmic/action/terminate_instance.rb +208 -0
  40. data/lib/vagrant-cosmic/action/timed_provision.rb +21 -0
  41. data/lib/vagrant-cosmic/action/wait_for_state.rb +41 -0
  42. data/lib/vagrant-cosmic/action/warn_networks.rb +19 -0
  43. data/lib/vagrant-cosmic/action.rb +210 -0
  44. data/lib/vagrant-cosmic/capabilities/rdp.rb +12 -0
  45. data/lib/vagrant-cosmic/capabilities/winrm.rb +12 -0
  46. data/lib/vagrant-cosmic/config.rb +422 -0
  47. data/lib/vagrant-cosmic/errors.rb +27 -0
  48. data/lib/vagrant-cosmic/exceptions/exceptions.rb +15 -0
  49. data/lib/vagrant-cosmic/model/cosmic_resource.rb +51 -0
  50. data/lib/vagrant-cosmic/plugin.rb +82 -0
  51. data/lib/vagrant-cosmic/provider.rb +58 -0
  52. data/lib/vagrant-cosmic/service/cosmic_resource_service.rb +76 -0
  53. data/lib/vagrant-cosmic/util/timer.rb +17 -0
  54. data/lib/vagrant-cosmic/version.rb +5 -0
  55. data/lib/vagrant-cosmic.rb +17 -0
  56. data/locales/en.yml +131 -0
  57. data/spec/spec_helper.rb +53 -0
  58. data/spec/vagrant-cosmic/action/read_ssh_info_spec.rb +80 -0
  59. data/spec/vagrant-cosmic/action/retrieve_public_ip_port_spec.rb +94 -0
  60. data/spec/vagrant-cosmic/action/run_instance_spec.rb +573 -0
  61. data/spec/vagrant-cosmic/action/terminate_instance_spec.rb +207 -0
  62. data/spec/vagrant-cosmic/config_spec.rb +340 -0
  63. data/spec/vagrant-cosmic/model/cosmic_resource_spec.rb +95 -0
  64. data/spec/vagrant-cosmic/service/cosmic_resource_service_spec.rb +43 -0
  65. data/spec/vagrant-cosmic/support/be_a_resource.rb +6 -0
  66. data/vagrant-cosmic.gemspec +59 -0
  67. data/vagrant-cosmic.spec +42 -0
  68. metadata +218 -0
@@ -0,0 +1,422 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module Cosmic
5
+ class Config < Vagrant.plugin("2", :config)
6
+ INSTANCE_VAR_DEFAULT_NIL = %w(host name path port domain_id network_id network_name project_id service_offering_id service_offering_name
7
+ template_id template_name zone_id zone_name keypair pf_ip_address_id pf_ip_address pf_public_port
8
+ pf_public_rdp_port pf_private_port pf_trusted_networks display_name group user_data ssh_key ssh_user
9
+ ssh_network_id ssh_network_name vm_user vm_password private_ip_address).freeze
10
+ INSTANCE_VAR_DEFAULT_EMPTY_ARRAY = %w(static_nat port_forwarding_rules firewall_rules).freeze
11
+
12
+ # Cosmic API host.
13
+ #
14
+ # @return [String]
15
+ attr_accessor :host
16
+
17
+ # Hostname for the machine instance
18
+ # This will be passed through to the api.
19
+ #
20
+ # @return [String]
21
+ attr_accessor :name
22
+
23
+ # Cosmic API path.
24
+ #
25
+ # @return [String]
26
+ attr_accessor :path
27
+
28
+ # Cosmic API port.
29
+ #
30
+ # @return [String]
31
+ attr_accessor :port
32
+
33
+ # Cosmic API scheme
34
+ #
35
+ # @return [String]
36
+ attr_accessor :scheme
37
+
38
+ # The API key for accessing Cosmic.
39
+ #
40
+ # @return [String]
41
+ attr_accessor :api_key
42
+
43
+ # The secret key for accessing Cosmic.
44
+ #
45
+ # @return [String]
46
+ attr_accessor :secret_key
47
+
48
+ # The timeout to wait for an instance to become ready.
49
+ #
50
+ # @return [Fixnum]
51
+ attr_accessor :instance_ready_timeout
52
+
53
+ # Domain id to launch the instance into.
54
+ #
55
+ # @return [String]
56
+ attr_accessor :domain_id
57
+
58
+ # Network uuid(s) that the instance should use
59
+ #
60
+ # @return [String,Array]
61
+ attr_accessor :network_id
62
+
63
+ # Network name(s) that the instance should use
64
+ #
65
+ # @return [String,Array]
66
+ attr_accessor :network_name
67
+
68
+ # Network Type
69
+ #
70
+ # @return [String]
71
+ attr_accessor :network_type
72
+
73
+ # Project uuid that the instance should belong to
74
+ #
75
+ # @return [String]
76
+ attr_accessor :project_id
77
+
78
+ # Service offering uuid to use for the instance
79
+ #
80
+ # @return [String]
81
+ attr_accessor :service_offering_id
82
+
83
+ # Service offering name to use for the instance
84
+ #
85
+ # @return [String]
86
+ attr_accessor :service_offering_name
87
+
88
+ # Disk offering uuid to use for the instance
89
+ #
90
+ # @return [String]
91
+ attr_accessor :disk_offering_id
92
+
93
+ # Disk offering name to use for the instance
94
+ #
95
+ # @return [String]
96
+ attr_accessor :disk_offering_name
97
+
98
+ # Template uuid to use for the instance
99
+ #
100
+ # @return [String]
101
+ attr_accessor :template_id
102
+
103
+ # Template name to use for the instance
104
+ #
105
+ # @return [String]
106
+ attr_accessor :template_name
107
+
108
+ # Zone uuid to launch the instance into. If nil, it will
109
+ # launch in default project.
110
+ #
111
+ # @return [String]
112
+ attr_accessor :zone_id
113
+
114
+ # Zone name to launch the instance into. If nil, it will
115
+ # launch in default project.
116
+ #
117
+ # @return [String]
118
+ attr_accessor :zone_name
119
+
120
+ # The name of the keypair to use.
121
+ #
122
+ # @return [String]
123
+ attr_accessor :keypair
124
+
125
+ # Paramters for Static NAT
126
+ #
127
+ # @return [String]
128
+ attr_accessor :static_nat
129
+
130
+ # IP address id to use for port forwarding rule
131
+ #
132
+ # @return [String]
133
+ attr_accessor :pf_ip_address_id
134
+
135
+ # IP address to use for port forwarding rule
136
+ #
137
+ # @return [String]
138
+ attr_accessor :pf_ip_address
139
+
140
+ # public port to use for port forwarding rule
141
+ #
142
+ # @return [String]
143
+ attr_accessor :pf_public_port
144
+
145
+ # public port to use for port forwarding rule
146
+ #
147
+ # @return [String]
148
+ attr_accessor :pf_public_rdp_port
149
+
150
+ # private port to use for port forwarding rule
151
+ #
152
+ # @return [String]
153
+ attr_accessor :pf_private_rdp_port
154
+
155
+ # public port to use for port forwarding rule
156
+ #
157
+ # @return [Range]
158
+ attr_accessor :pf_public_port_randomrange
159
+
160
+ # private port to use for port forwarding rule
161
+ #
162
+ # @return [String]
163
+ attr_accessor :pf_private_port
164
+
165
+ # flag to enable/disable automatic open firewall rule
166
+ #
167
+ # @return [Boolean]
168
+ attr_accessor :pf_open_firewall
169
+
170
+ # CIDR List string of trusted networks
171
+ #
172
+ # @return [String]
173
+ attr_accessor :pf_trusted_networks
174
+
175
+ # comma separated list of port forwarding rules
176
+ # (hash with rule parameters)
177
+ #
178
+ # @return [Array]
179
+ attr_accessor :port_forwarding_rules
180
+
181
+ # comma separated list of firewall rules
182
+ # (hash with rule parameters)
183
+ #
184
+ # @return [Array]
185
+ attr_accessor :firewall_rules
186
+
187
+ # display name for the instance
188
+ #
189
+ # @return [String]
190
+ attr_accessor :display_name
191
+
192
+ # group for the instance
193
+ #
194
+ # @return [String]
195
+ attr_accessor :group
196
+
197
+ # The user data string
198
+ #
199
+ # @return [String]
200
+ attr_accessor :user_data
201
+
202
+ # The key to be used when loging in to the vm via ssh
203
+ #
204
+ # @return [String]
205
+ attr_accessor :ssh_key
206
+
207
+ # The username to be used when loging in to the vm via ssh
208
+ #
209
+ # @return [String]
210
+ attr_accessor :ssh_user
211
+
212
+ # The network_id to be used when loging in to the vm via ssh
213
+ #
214
+ # @return [String]
215
+ attr_accessor :ssh_network_id
216
+
217
+ # The network_name to be used when loging in to the vm via ssh
218
+ #
219
+ # @return [String]
220
+ attr_accessor :ssh_network_name
221
+
222
+ # The username to be used when loging in to the vm
223
+ #
224
+ # @return [String]
225
+ attr_accessor :vm_user
226
+
227
+ # The username to be used when loging in to the vm
228
+ #
229
+ # @return [String]
230
+ attr_accessor :vm_password
231
+
232
+ # Private ip for the instance
233
+ #
234
+ # @return [String]
235
+ attr_accessor :private_ip_address
236
+
237
+ # flag to enable/disable expunge vm on destroy
238
+ #
239
+ # @return [Boolean]
240
+ attr_accessor :expunge_on_destroy
241
+
242
+ def initialize(domain_specific = false)
243
+ # Initialize groups in bulk, re-use these groups to set defaults in bulk
244
+ INSTANCE_VAR_DEFAULT_NIL.each do |instance_variable|
245
+ instance_variable_set("@#{instance_variable}", UNSET_VALUE)
246
+ end
247
+ # Initialize groups in bulk, re-use these groups to set defaults in bulk
248
+ INSTANCE_VAR_DEFAULT_EMPTY_ARRAY.each do |instance_variable|
249
+ instance_variable_set("@#{instance_variable}", UNSET_VALUE)
250
+ end
251
+
252
+ @scheme = UNSET_VALUE
253
+ @api_key = UNSET_VALUE
254
+ @secret_key = UNSET_VALUE
255
+ @instance_ready_timeout = UNSET_VALUE
256
+ @network_type = UNSET_VALUE
257
+ @pf_private_rdp_port = UNSET_VALUE
258
+ @pf_public_port_randomrange = UNSET_VALUE
259
+ @pf_open_firewall = UNSET_VALUE
260
+ @expunge_on_destroy = UNSET_VALUE
261
+
262
+ # Internal state (prefix with __ so they aren't automatically
263
+ # merged)
264
+ @__compiled_domain_configs = {}
265
+ @__finalized = false
266
+ @__domain_config = {}
267
+ @__domain_specific = domain_specific
268
+ end
269
+
270
+ # Allows domain-specific overrides of any of the settings on this
271
+ # configuration object. This allows the user to override things like
272
+ # template and keypair name for domains. Example:
273
+ #
274
+ # cosmic.domain_config "abcd-ef01-2345-6789" do |domain|
275
+ # domain.template_id = "1234-5678-90ab-cdef"
276
+ # domain.keypair_name = "company-east"
277
+ # end
278
+ #
279
+ # @param [String] domain The Domain name to configure.
280
+ # @param [Hash] attributes Direct attributes to set on the configuration
281
+ # as a shortcut instead of specifying a full block.
282
+ # @yield [config] Yields a new domain configuration.
283
+ def domain_config(domain, attributes=nil, &block)
284
+ # Append the block to the list of domain configs for that domain.
285
+ # We'll evaluate these upon finalization.
286
+ @__domain_config[domain] ||= []
287
+
288
+ # Append a block that sets attributes if we got one
289
+ if attributes
290
+ attr_block = lambda do |config|
291
+ config.set_options(attributes)
292
+ end
293
+
294
+ @__domain_config[domain] << attr_block
295
+ end
296
+
297
+ # Append a block if we got one
298
+ @__domain_config[domain] << block if block_given?
299
+ end
300
+
301
+ #-------------------------------------------------------------------
302
+ # Internal methods.
303
+ #-------------------------------------------------------------------
304
+
305
+ def merge(other)
306
+ super.tap do |result|
307
+ # Copy over the domain specific flag. "True" is retained if either
308
+ # has it.
309
+ new_domain_specific = other.instance_variable_get(:@__domain_specific)
310
+ result.instance_variable_set(
311
+ :@__domain_specific, new_domain_specific || @__domain_specific)
312
+
313
+ # Go through all the domain configs and prepend ours onto
314
+ # theirs.
315
+ new_domain_config = other.instance_variable_get(:@__domain_config)
316
+ @__domain_config.each do |key, value|
317
+ new_domain_config[key] ||= []
318
+ new_domain_config[key] = value + new_domain_config[key]
319
+ end
320
+
321
+ # Set it
322
+ result.instance_variable_set(:@__domain_config, new_domain_config)
323
+
324
+ # Merge in the tags
325
+ result.tags.merge!(self.tags)
326
+ result.tags.merge!(other.tags)
327
+ end
328
+ end
329
+
330
+ def finalize!
331
+ INSTANCE_VAR_DEFAULT_NIL.each do |instance_variable|
332
+ # ... must be nil, since we can't default that
333
+ instance_variable_set("@#{instance_variable}", nil) if
334
+ instance_variable_get("@#{instance_variable}") == UNSET_VALUE
335
+ end
336
+
337
+ INSTANCE_VAR_DEFAULT_EMPTY_ARRAY.each do |instance_variable|
338
+ # ... must be empty array
339
+ instance_variable_set("@#{instance_variable}", []) if
340
+ instance_variable_get("@#{instance_variable}") == UNSET_VALUE
341
+ end
342
+
343
+ # We default the scheme to whatever the user has specifid in the .fog file
344
+ # *OR* whatever is default for the provider in the fog library
345
+ @scheme = nil if @scheme == UNSET_VALUE
346
+
347
+ # Try to get access keys from environment variables, they will
348
+ # default to nil if the environment variables are not present
349
+ @api_key = ENV['COSMIC_API_KEY'] if @api_key == UNSET_VALUE
350
+ @secret_key = ENV['COSMIC_SECRET_KEY'] if @secret_key == UNSET_VALUE
351
+
352
+ # Set the default timeout for waiting for an instance to be ready
353
+ @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
354
+
355
+ # NetworkType is 'Advanced' by default
356
+ @network_type = "Advanced" if @network_type == UNSET_VALUE
357
+
358
+ # Private rdp port defaults to 3389
359
+ @pf_private_rdp_port = 3389 if @pf_private_rdp_port == UNSET_VALUE
360
+
361
+ # Public port random-range, default to rfc6335 'Dynamic Ports'; "(never assigned)"
362
+ @pf_public_port_randomrange = {:start=>49152, :end=>65535} if @pf_public_port_randomrange == UNSET_VALUE
363
+
364
+ # Open firewall is true by default (for backwards compatibility)
365
+ @pf_open_firewall = true if @pf_open_firewall == UNSET_VALUE
366
+
367
+ # expunge on destroy is nil by default
368
+ @expunge_on_destroy = false if @expunge_on_destroy == UNSET_VALUE
369
+
370
+ # Compile our domain specific configurations only within
371
+ # NON-DOMAIN-SPECIFIC configurations.
372
+ unless @__domain_specific
373
+ @__domain_config.each do |domain, blocks|
374
+ config = self.class.new(true).merge(self)
375
+
376
+ # Execute the configuration for each block
377
+ blocks.each { |b| b.call(config) }
378
+
379
+ # The domain name of the configuration always equals the domain config name:
380
+ config.domain = domain
381
+
382
+ # Finalize the configuration
383
+ config.finalize!
384
+
385
+ # Store it for retrieval
386
+ @__compiled_domain_configs[domain] = config
387
+ end
388
+ end
389
+
390
+ # Mark that we finalized
391
+ @__finalized = true
392
+ end
393
+
394
+ def validate(machine)
395
+ errors = []
396
+
397
+ if @domain
398
+ # Get the configuration for the domain we're using and validate only that domain.
399
+ config = get_domain_config(@domain)
400
+
401
+ unless config.use_fog_profile
402
+ errors << I18n.t("vagrant_cosmic.config.api_key_required") if \
403
+ config.access_key_id.nil?
404
+ errors << I18n.t("vagrant_cosmic.config.secret_key_required") if \
405
+ config.secret_access_key.nil?
406
+ end
407
+ end
408
+
409
+ {"Cosmic Provider" => errors}
410
+ end
411
+
412
+ # This gets the configuration for a specific domain. It shouldn't
413
+ # be called by the general public and is only used internally.
414
+ def get_domain_config(name)
415
+ raise 'Configuration must be finalized before calling this method.' unless @__finalized
416
+
417
+ # Return the compiled domain config
418
+ @__compiled_domain_configs[name] || self
419
+ end
420
+ end
421
+ end
422
+ end
@@ -0,0 +1,27 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module Cosmic
5
+ module Errors
6
+ class VagrantCosmicError < Vagrant::Errors::VagrantError
7
+ error_namespace("vagrant_cosmic.errors")
8
+ end
9
+
10
+ class FogError < VagrantCosmicError
11
+ error_key(:fog_error)
12
+ end
13
+
14
+ class InstanceReadyTimeout < VagrantCosmicError
15
+ error_key(:instance_ready_timeout)
16
+ end
17
+
18
+ class RsyncError < VagrantCosmicError
19
+ error_key(:rsync_error)
20
+ end
21
+
22
+ class UserdataError < VagrantCosmicError
23
+ error_key(:user_data_error)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Exceptions
4
+ class IpNotFoundException < StandardError
5
+ end
6
+ class DuplicatePFRule < StandardError
7
+ end
8
+ class CosmicResourceNotFound < StandardError
9
+ def initialize(msg='Resource not found in cosmic')
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Model
4
+ class CosmicResource
5
+ attr_accessor :id, :name, :details
6
+ attr_reader :kind
7
+
8
+ def initialize(id, name, kind)
9
+ raise 'Resource must have a kind' if kind.nil? || kind.empty?
10
+ @id = id
11
+ @name = name
12
+ @kind = kind
13
+ end
14
+
15
+ def is_undefined?
16
+ is_id_undefined? and is_name_undefined?
17
+ end
18
+
19
+ def is_id_undefined?
20
+ id.nil? || id.empty?
21
+ end
22
+
23
+ def is_name_undefined?
24
+ name.nil? || name.empty?
25
+ end
26
+
27
+ def to_s
28
+ "#{kind} - #{id || '<unknown id>'}:#{name || '<unknown name>'}"
29
+ end
30
+
31
+ def self.create_list(ids, names, kind)
32
+ return create_id_list(ids, kind) unless ids.empty?
33
+ return create_name_list(names, kind) unless names.empty?
34
+ []
35
+ end
36
+
37
+ def self.create_id_list(ids, kind)
38
+ ids.each_with_object([]) do |id, resources|
39
+ resources << CosmicResource.new(id, nil, kind)
40
+ end
41
+ end
42
+
43
+ def self.create_name_list(names, kind)
44
+ names.each_with_object([]) do |name, resources|
45
+ resources << CosmicResource.new(nil, name, kind)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,82 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant Cosmic plugin must be run within Vagrant."
5
+ end
6
+
7
+ # This is a sanity check to make sure no one is attempting to install
8
+ # this into an early Vagrant version.
9
+ if Vagrant::VERSION < "2.2.0"
10
+ raise "The Vagrant Cosmic plugin is only compatible with Vagrant 2.2+"
11
+ end
12
+
13
+ module VagrantPlugins
14
+ module Cosmic
15
+ class Plugin < Vagrant.plugin("2")
16
+ name "Cosmic"
17
+ description <<-DESC
18
+ This plugin installs a provider that allows Vagrant to manage
19
+ machines in Cosmic.
20
+ DESC
21
+
22
+ config(:cosmic, :provider) do
23
+ require_relative "config"
24
+ Config
25
+ end
26
+
27
+ provider(:cosmic, { parallel: true, box_optional: true}) do # Setup logging and i18n
28
+ setup_logging
29
+ setup_i18n
30
+
31
+ # Return the provider
32
+ require_relative "provider"
33
+ Provider
34
+ end
35
+
36
+ provider_capability(:cosmic, :winrm_info) do
37
+ require_relative 'capabilities/winrm'
38
+ VagrantPlugins::Cosmic::Cap::WinRM
39
+ end
40
+
41
+ provider_capability(:cosmic, :rdp_info) do
42
+ require_relative 'capabilities/rdp'
43
+ VagrantPlugins::Cosmic::Cap::Rdp
44
+ end
45
+
46
+ # This initializes the internationalization strings.
47
+ def self.setup_i18n
48
+ I18n.load_path << File.expand_path("locales/en.yml", Cosmic.source_root)
49
+ I18n.reload!
50
+ end
51
+
52
+ # This sets up our log level to be whatever VAGRANT_LOG is.
53
+ def self.setup_logging
54
+ require "log4r"
55
+
56
+ level = nil
57
+ begin
58
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
59
+ rescue NameError
60
+ # This means that the logging constant wasn't found,
61
+ # which is fine. We just keep `level` as `nil`. But
62
+ # we tell the user.
63
+ level = nil
64
+ end
65
+
66
+ # Some constants, such as "true" resolve to booleans, so the
67
+ # above error checking doesn't catch it. This will check to make
68
+ # sure that the log level is an integer, as Log4r requires.
69
+ level = nil if !level.is_a?(Integer)
70
+
71
+ # Set the logging level on all "vagrant" namespaced
72
+ # logs as long as we have a valid level.
73
+ if level
74
+ logger = Log4r::Logger.new("vagrant_cosmic")
75
+ logger.outputters = Log4r::Outputter.stderr
76
+ logger.level = level
77
+ logger = nil
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,58 @@
1
+ require "log4r"
2
+ require "vagrant"
3
+
4
+ module VagrantPlugins
5
+ module Cosmic
6
+ class Provider < Vagrant.plugin("2", :provider)
7
+ def initialize(machine)
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ # Attempt to get the action method from the Action class if it
13
+ # exists, otherwise return nil to show that we don't support the
14
+ # given action.
15
+ action_method = "action_#{name}"
16
+ return Action.send(action_method) if Action.respond_to?(action_method)
17
+ nil
18
+ end
19
+
20
+ def ssh_info
21
+ # Run a custom action called "read_ssh_info" which does what it
22
+ # says and puts the resulting SSH info into the `:machine_ssh_info`
23
+ # key in the environment.
24
+ env = @machine.action("read_ssh_info")
25
+ env[:machine_ssh_info]
26
+ end
27
+
28
+ def winrm_info
29
+ # Run a custom action called "read_winrm_info" which does what it
30
+ # says and puts the resulting WinRM info into the `:machine_winrm_info`
31
+ # key in the environment.
32
+ env = @machine.action("read_winrm_info")
33
+ env[:machine_winrm_info]
34
+ end
35
+
36
+ def state
37
+ # Run a custom action we define called "read_state" which does
38
+ # what it says. It puts the state in the `:machine_state_id`
39
+ # key in the environment.
40
+ env = @machine.action("read_state")
41
+
42
+ state_id = env[:machine_state_id]
43
+
44
+ # Get the short and long description
45
+ short = I18n.t("vagrant_cosmic.states.short_#{state_id}")
46
+ long = I18n.t("vagrant_cosmic.states.long_#{state_id}")
47
+
48
+ # Return the MachineState object
49
+ Vagrant::MachineState.new(state_id, short, long)
50
+ end
51
+
52
+ def to_s
53
+ id = @machine.id.nil? ? "new" : @machine.id
54
+ "Cosmic (#{id})"
55
+ end
56
+ end
57
+ end
58
+ end