vagrant-vcloudair 0.5.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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rubocop.yml +34 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +21 -0
  6. data/README.md +109 -0
  7. data/lib/vagrant-vcloudair.rb +63 -0
  8. data/lib/vagrant-vcloudair/action.rb +298 -0
  9. data/lib/vagrant-vcloudair/action/announce_ssh_exec.rb +22 -0
  10. data/lib/vagrant-vcloudair/action/build_vapp.rb +235 -0
  11. data/lib/vagrant-vcloudair/action/connect_vcloud.rb +54 -0
  12. data/lib/vagrant-vcloudair/action/destroy_vapp.rb +54 -0
  13. data/lib/vagrant-vcloudair/action/destroy_vm.rb +37 -0
  14. data/lib/vagrant-vcloudair/action/disconnect_vcloud.rb +31 -0
  15. data/lib/vagrant-vcloudair/action/forward_ports.rb +132 -0
  16. data/lib/vagrant-vcloudair/action/handle_nat_port_collisions.rb +153 -0
  17. data/lib/vagrant-vcloudair/action/inventory_check.rb +210 -0
  18. data/lib/vagrant-vcloudair/action/is_bridged.rb +29 -0
  19. data/lib/vagrant-vcloudair/action/is_created.rb +35 -0
  20. data/lib/vagrant-vcloudair/action/is_last_vm.rb +31 -0
  21. data/lib/vagrant-vcloudair/action/is_paused.rb +20 -0
  22. data/lib/vagrant-vcloudair/action/is_running.rb +20 -0
  23. data/lib/vagrant-vcloudair/action/message_already_running.rb +16 -0
  24. data/lib/vagrant-vcloudair/action/message_cannot_suspend.rb +16 -0
  25. data/lib/vagrant-vcloudair/action/message_not_created.rb +16 -0
  26. data/lib/vagrant-vcloudair/action/message_not_running.rb +16 -0
  27. data/lib/vagrant-vcloudair/action/message_will_not_destroy.rb +21 -0
  28. data/lib/vagrant-vcloudair/action/power_off.rb +33 -0
  29. data/lib/vagrant-vcloudair/action/power_off_vapp.rb +40 -0
  30. data/lib/vagrant-vcloudair/action/power_on.rb +39 -0
  31. data/lib/vagrant-vcloudair/action/read_ssh_info.rb +153 -0
  32. data/lib/vagrant-vcloudair/action/read_state.rb +51 -0
  33. data/lib/vagrant-vcloudair/action/resume.rb +25 -0
  34. data/lib/vagrant-vcloudair/action/suspend.rb +25 -0
  35. data/lib/vagrant-vcloudair/action/unmap_port_forwardings.rb +74 -0
  36. data/lib/vagrant-vcloudair/cap/forwarded_ports.rb +38 -0
  37. data/lib/vagrant-vcloudair/cap/public_address.rb +18 -0
  38. data/lib/vagrant-vcloudair/cap/rdp_info.rb +18 -0
  39. data/lib/vagrant-vcloudair/cap/winrm_info.rb +15 -0
  40. data/lib/vagrant-vcloudair/command.rb +285 -0
  41. data/lib/vagrant-vcloudair/config.rb +205 -0
  42. data/lib/vagrant-vcloudair/driver/base.rb +643 -0
  43. data/lib/vagrant-vcloudair/driver/meta.rb +202 -0
  44. data/lib/vagrant-vcloudair/driver/version_5_1.rb +2019 -0
  45. data/lib/vagrant-vcloudair/errors.rb +77 -0
  46. data/lib/vagrant-vcloudair/model/forwarded_port.rb +66 -0
  47. data/lib/vagrant-vcloudair/plugin.rb +111 -0
  48. data/lib/vagrant-vcloudair/provider.rb +41 -0
  49. data/lib/vagrant-vcloudair/util/compile_forwarded_ports.rb +34 -0
  50. data/lib/vagrant-vcloudair/version.rb +5 -0
  51. data/locales/en.yml +169 -0
  52. data/vagrant-vcloudair.gemspec +33 -0
  53. metadata +266 -0
@@ -0,0 +1,77 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module VCloudAir
5
+ module Errors
6
+ # Generic Errors during Vagrant execution
7
+ class VCloudAirGenericError < Vagrant::Errors::VagrantError
8
+ error_namespace('vagrant_vcloudair.errors')
9
+ end
10
+ class VCloudAirOldVersion < VCloudAirGenericError
11
+ error_key(:vcloud_old_version)
12
+ end
13
+ class CatalogAddError < VCloudAirGenericError
14
+ error_key(:catalog_add_error)
15
+ end
16
+ class UnauthorizedAccess < VCloudAirGenericError
17
+ error_key(:unauthorized_access)
18
+ end
19
+ class StopVAppError < VCloudAirGenericError
20
+ error_key(:stop_vapp_error)
21
+ end
22
+ class ComposeVAppError < VCloudAirGenericError
23
+ error_key(:compose_vapp_error)
24
+ end
25
+ class InvalidNetSpecification < VCloudAirGenericError
26
+ error_key(:invalid_network_specification)
27
+ end
28
+ class WontCreate < VCloudAirGenericError
29
+ error_key(:wont_create)
30
+ end
31
+ # Config Error that are caught during Vagrant execution
32
+ class VCloudAirConfigError < Vagrant::Errors::VagrantError
33
+ error_namespace('vagrant_vcloudair.errors.config')
34
+ end
35
+ class ServiceNotFound < VCloudAirConfigError
36
+ error_key(:service_not_found)
37
+ end
38
+ class VdcNotFound < VCloudAirConfigError
39
+ error_key(:vdc_not_found)
40
+ end
41
+ class EdgeGWNotFound < VCloudAirConfigError
42
+ error_key(:edgegw_not_found)
43
+ end
44
+ class EdgeGWIPNotFound < VCloudAirConfigError
45
+ error_key(:edgegw_ip_not_found)
46
+ end
47
+ class EdgeGWNotConnected < VCloudAirConfigError
48
+ error_key(:edgegw_not_connected)
49
+ end
50
+ class ForwardPortCollision < VCloudAirConfigError
51
+ error_key(:forward_port_collision)
52
+ end
53
+ # Errors in the REST API communication
54
+ class VCloudAirRestError < Vagrant::Errors::VagrantError
55
+ error_namespace('vagrant_vcloudair.errors.rest_errors')
56
+ end
57
+ class ObjectNotFound < VCloudAirRestError
58
+ error_key(:object_not_found)
59
+ end
60
+ class InvalidConfigError < VCloudAirRestError
61
+ error_key(:invalid_config_error)
62
+ end
63
+ class InvalidStateError < VCloudAirRestError
64
+ error_key(:invalid_state_error)
65
+ end
66
+ class InvalidRequestError < VCloudAirRestError
67
+ error_key(:invalid_request_error)
68
+ end
69
+ class UnattendedCodeError < VCloudAirRestError
70
+ error_key(:unattended_code_error)
71
+ end
72
+ class EndpointUnavailable < VCloudAirRestError
73
+ error_key(:endpoint_unavailable)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,66 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Model
4
+ # Represents a single forwarded port for VirtualBox. This has various
5
+ # helpers and defaults for a forwarded port.
6
+ class ForwardedPort
7
+ # If true, this port should be auto-corrected.
8
+ #
9
+ # @return [Boolean]
10
+ attr_reader :auto_correct
11
+
12
+ # The unique ID for the forwarded port.
13
+ #
14
+ # @return [String]
15
+ attr_reader :id
16
+
17
+ # The protocol to forward.
18
+ #
19
+ # @return [String]
20
+ attr_reader :protocol
21
+
22
+ # The IP that the forwarded port will connect to on the guest machine.
23
+ #
24
+ # @return [String]
25
+ attr_reader :guest_ip
26
+
27
+ # The port on the guest to be exposed on the host.
28
+ #
29
+ # @return [Integer]
30
+ attr_reader :guest_port
31
+
32
+ # The IP that the forwarded port will bind to on the host machine.
33
+ #
34
+ # @return [String]
35
+ attr_reader :host_ip
36
+
37
+ # The port on the host used to access the port on the guest.
38
+ #
39
+ # @return [Integer]
40
+ attr_reader :host_port
41
+
42
+ def initialize(id, host_port, guest_port, options)
43
+ @id = id
44
+ @guest_port = guest_port
45
+ @host_port = host_port
46
+
47
+ options ||= {}
48
+ @auto_correct = false
49
+ if options.key?(:auto_correct)
50
+ @auto_correct = options[:auto_correct]
51
+ end
52
+ @guest_ip = options[:guest_ip] || nil
53
+ @host_ip = options[:host_ip] || nil
54
+ @protocol = options[:protocol] || 'tcp'
55
+ end
56
+
57
+ # This corrects the host port and changes it to the given new port.
58
+ #
59
+ # @param [Integer] new_port The new port
60
+ def correct_host_port(new_port)
61
+ @host_port = new_port
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,111 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The Vagrant vCloud Air plugin must be run within Vagrant.'
5
+ end
6
+
7
+ if Vagrant::VERSION < '1.6.3'
8
+ fail 'The Vagrant vCloud Air plugin is only compatible with Vagrant 1.6.3+'
9
+ end
10
+
11
+ module VagrantPlugins
12
+ module VCloudAir
13
+ class Plugin < Vagrant.plugin('2')
14
+ name 'VMware vCloud Air Provider'
15
+ description 'Allows Vagrant to manage machines with VMware vCloud Air(R)'
16
+
17
+ config(:vcloudair, :provider) do
18
+ require_relative 'config'
19
+ Config
20
+ end
21
+
22
+ # We provide support for multiple box formats, including the new standard
23
+ # 'vmware_ovf' and the legacy 'vcloud' and 'vcenter'.
24
+ provider(:vcloudair, box_format: %w[vmware_ovf vcloud vcenter]) do
25
+ setup_logging
26
+ setup_i18n
27
+
28
+ # Return the provider
29
+ require_relative 'provider'
30
+ Provider
31
+ end
32
+
33
+ # Add vagrant share support
34
+ provider_capability('vcloudair', 'public_address') do
35
+ require_relative 'cap/public_address'
36
+ Cap::PublicAddress
37
+ end
38
+
39
+ provider_capability(:vcloudair, :forwarded_ports) do
40
+ require_relative 'cap/forwarded_ports'
41
+ Cap::ForwardedPorts
42
+ end
43
+
44
+ provider_capability(:vcloudair, :winrm_info) do
45
+ require_relative 'cap/winrm_info'
46
+ Cap::WinRM
47
+ end
48
+
49
+ provider_capability(:vcloudair, :rdp_info) do
50
+ require_relative 'cap/rdp_info'
51
+ Cap::RDP
52
+ end
53
+
54
+ # Added a vagrant vcloudair-status command to enhance troubleshooting and
55
+ # visibility.
56
+ command('vcloudair') do
57
+ require_relative 'command'
58
+ Command
59
+ end
60
+
61
+ def self.setup_i18n
62
+ I18n.load_path << File.expand_path('locales/en.yml', VCloudAir.source_root)
63
+ I18n.reload!
64
+ end
65
+
66
+ # This sets up our log level to be whatever VAGRANT_LOG is.
67
+ def self.setup_logging
68
+ require 'log4r'
69
+
70
+ level = nil
71
+ begin
72
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
73
+ rescue NameError
74
+ # This means that the logging constant wasn't found,
75
+ # which is fine. We just keep `level` as `nil`. But
76
+ # we tell the user.
77
+ level = nil
78
+ end
79
+
80
+ # Some constants, such as 'true' resolve to booleans, so the
81
+ # above error checking doesn't catch it. This will check to make
82
+ # sure that the log level is an integer, as Log4r requires.
83
+ level = nil unless level.is_a?(Integer)
84
+
85
+ # Set the logging level on all 'vagrant' namespaced
86
+ # logs as long as we have a valid level.
87
+ if level
88
+ logger = Log4r::Logger.new('vagrant_vcloudair')
89
+ logger.outputters = Log4r::Outputter.stderr
90
+ logger.level = level
91
+ # logger = nil
92
+ end
93
+ end
94
+ end
95
+
96
+ module Driver
97
+ autoload :Meta, File.expand_path('../driver/meta', __FILE__)
98
+ autoload :Version_5_1, File.expand_path('../driver/version_5_1', __FILE__)
99
+ end
100
+
101
+ module Model
102
+ autoload :ForwardedPort,
103
+ File.expand_path('../model/forwarded_port', __FILE__)
104
+ end
105
+
106
+ module Util
107
+ autoload :CompileForwardedPorts,
108
+ File.expand_path('../util/compile_forwarded_ports', __FILE__)
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,41 @@
1
+ require 'log4r'
2
+ require 'vagrant'
3
+
4
+ module VagrantPlugins
5
+ module VCloudAir
6
+ class Provider < Vagrant.plugin('2', :provider)
7
+ def initialize(machine)
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ action_method = "action_#{name}"
13
+ return Action.send(action_method) if Action.respond_to?(action_method)
14
+ nil
15
+ end
16
+
17
+ def ssh_info
18
+ env = @machine.action('read_ssh_info')
19
+ env[:machine_ssh_info]
20
+ end
21
+
22
+ def state
23
+ env = @machine.action('read_state')
24
+
25
+ state_id = env[:machine_state_id]
26
+
27
+ # Translate into short/long descriptions
28
+ short = state_id.to_s.gsub('_', ' ')
29
+ long = I18n.t("vagrant_vcloudair.vm.states.#{state_id}")
30
+
31
+ # Return the MachineState object
32
+ Vagrant::MachineState.new(state_id, short, long)
33
+ end
34
+
35
+ def to_s
36
+ id = @machine.id.nil? ? 'new' : @machine.id
37
+ "vCloud Air (#{id})"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require 'vagrant/util/scoped_hash_override'
2
+
3
+ module VagrantPlugins
4
+ module VCloudAir
5
+ module Util
6
+ module CompileForwardedPorts
7
+ include Vagrant::Util::ScopedHashOverride
8
+
9
+ # This method compiles the forwarded ports into {ForwardedPort}
10
+ # models.
11
+ def compile_forwarded_ports(config)
12
+ mappings = {}
13
+
14
+ config.vm.networks.each do |type, options|
15
+ if type == :forwarded_port
16
+ guest_port = options[:guest]
17
+ host_port = options[:host]
18
+ options = scoped_hash_override(options, :vcloud)
19
+ id = options[:id]
20
+
21
+ # skip forwarded rules already found in handle_nat_port_collisions
22
+ next if options[:already_exists]
23
+
24
+ mappings[host_port] =
25
+ Model::ForwardedPort.new(id, host_port, guest_port, options)
26
+ end
27
+ end
28
+
29
+ mappings.values
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ VERSION = '0.5.0'
4
+ end
5
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,169 @@
1
+ en:
2
+ vagrant_vcloudair:
3
+ vapp:
4
+ build_vapp: |-
5
+ Building vApp...
6
+ vapp_created: |-
7
+ vApp %{vapp_name} successfully created.
8
+ vapp_creation_failed: |-
9
+ vApp %{vapp_name} creation failed!
10
+ adding_vm: |-
11
+ Adding VM to existing vApp...
12
+ vm_add_failed: |-
13
+ VM %{vm_name} add to %{vapp_name} failed!
14
+ destroy_vapp: |-
15
+ Destroying vApp...
16
+ poweroff_vapp: |-
17
+ Single VM left in the vApp, Powering off vApp...
18
+ catalog:
19
+ create_catalog: |-
20
+ Catalog [%{catalog_name}] successfully created.
21
+ create_catalog_ask: |-
22
+ Would you like to create the [#{cfg.catalog_name}] catalog?
23
+ Choice (yes/no):
24
+ catalog_not_created: |-
25
+ Catalog not created, exiting...
26
+ add_to_catalog: |-
27
+ Adding [%{box_name}] to Catalog [%{catalog_name}]
28
+ nonexistant_catalog: |-
29
+ Catalog [%{catalog_name}] does not exist!
30
+ nonexistant_catalog_item: |-
31
+ Catalog item [%{catalog_item}] in Catalog [%{catalog_name}] does not exist!"
32
+ upload_ask: |-
33
+ Would you like to upload the [%{catalog_item}] box to [%{catalog_name}] Catalog?
34
+ Choice (yes/no):
35
+ uploading: |-
36
+ Uploading [%{catalog_item}]...
37
+ catalog_item_not_available: |-
38
+ Catalog item not available, exiting...
39
+ edge:
40
+ network_test: |-
41
+ Testing Network Configuration in vCloud Air...
42
+ removing_nat_rules: |-
43
+ Removing NAT rules on [%{vdc_edge_gateway}] for IP [%{vdc_edge_gateway_ip}].
44
+ port_forwarding: |-
45
+ Forwarding Ports: VM port %{guest_port} -> vShield Edge port %{host_port}
46
+ nat_rules_creation: |-
47
+ Creating NAT rules on [%{vdc_edge_gateway}] for IP [%{vapp_edge_ip}] port %{port}.
48
+ vm:
49
+ setting_vm_hardware: |-
50
+ Setting VM hardware...
51
+ poweron_vm: |-
52
+ Powering on VM...
53
+ suspend_vm: |-
54
+ Suspending VM...
55
+ vm_not_created: |-
56
+ The VM has not been created
57
+ will_not_destroy: |-
58
+ VM will not be destroyed
59
+ vm_already_running: |-
60
+ VM is already running
61
+ vm_not_running: |-
62
+ VM is not running
63
+ vm_halted_cannot_suspend: |-
64
+ VM is not running or already suspended, cannot suspend it.
65
+ ssh_announce: |-
66
+ External IP for %{machine_name}: %{ip}
67
+ destroy_vm: |-
68
+ Destroying VM...
69
+ poweroff_vm: |-
70
+ Powering off VM...
71
+ waiting_for_ssh: |-
72
+ Waiting for %{port_name} Access on %{external_ip}:%{external_port} ...
73
+ states:
74
+ not_created: |-
75
+ The environment has not yet been created. Run `vagrant up` to
76
+ create the environment. If a machine is not created, only the
77
+ default provider will be shown. So if a provider is not listed,
78
+ then the machine is not created for that environment.
79
+ suspended: |-
80
+ The VM is paused. To resume the VM, simply run `vagrant up`
81
+ or `vagrant resume`
82
+ stopped: |-
83
+ The VM is powered off. To restart the VM, simply run `vagrant up`
84
+ running: |-
85
+ The VM is running. To stop this VM, you can run `vagrant halt` to
86
+ shut it down forcefully, or you can run `vagrant suspend` to simply
87
+ suspend the virtual machine. In either case, to restart it again,
88
+ simply run `vagrant up`.
89
+ errors:
90
+ missing_compute_resource: |-
91
+ Configured compute resource not found
92
+ missing_datacenter: |-
93
+ Configured data center not found
94
+ missing_resource_pool: |-
95
+ Configured resource pool not found
96
+ missing_template: |-
97
+ Configured template VM could not be found
98
+ vcloud_old_version: |-
99
+ Sorry, VMware vCloud Air API version %{version} is not supported
100
+ unauthorized_access: |-
101
+ Access not authorized, please verify the username and password in your
102
+ Vagrantfile
103
+ catalog_add_error: |-
104
+ Impossible to add Box to Catalog, error: %{message}
105
+ invalid_network_specification: |-
106
+ Wrong Network specification in the Vagrantfile, make sure you have
107
+ access to the specified network.
108
+ wont_create: |-
109
+ User rejected creation/upload of %{item}, exiting...
110
+ stop_vapp_error: |-
111
+ Impossible to stop vApp, could be a transient error, please try again,
112
+ error: %{message}
113
+ compose_vapp_error: |-
114
+ Impossible to compose a vApp, error: %{message}
115
+ rest_errors:
116
+ object_not_found: |-
117
+ Object not found in vCloud Air, %{message}. Please report this Error.
118
+ invalid_config_error: |-
119
+ Invalid Guest Customization Specified
120
+ invalid_state_error: |-
121
+ Invalid vApp State %{message}
122
+ invalid_request_error: |-
123
+ Invalid request %{message}
124
+ unattended_code_error: |-
125
+ Unattended code received %{message}
126
+ endpoint_unavailable: |-
127
+ Can't connect to vCloud Air, please verify connectivity.
128
+ config:
129
+ username: |-
130
+ Configuration must specify a vCloud Air username
131
+ password: |-
132
+ Configuration must specify a vCloud Air password
133
+ dns_not_valid: |-
134
+ One or more DNS names specified are invalid
135
+ dns_specified_as_subnet: |-
136
+ One or more DNS names are specified as subnets
137
+ ip_dns: |-
138
+ DNS configuration must be specified as an Array type
139
+ edge_gateway_ip_not_valid: |-
140
+ The Edge Gateway IP specified is not invalid
141
+ edge_gateway_ip_specified_as_subnet: |-
142
+ The Edge Gateway IP specified is specified as subnet
143
+ ip_subnet_not_valid: |-
144
+ The specified subnet is invalid
145
+ ip_subnet_too_small: |-
146
+ The specified subnet is too small, must contain at least 2 usable IPs (/30 or 255.255.255.252)
147
+ catalog_name: |-
148
+ Configuration must specify a vCloud Air Catalog (for the VM templates images)
149
+ vdc_name: |-
150
+ Configuration must specify a vCloud Air Virtual Datacenter (Target Organization VDC)
151
+ vdc_network_name: |-
152
+ Configuration must specify a vCloud Air Network Name
153
+ mixed_bridge: |-
154
+ Configuration 'network_bridge' and 'vdc_edge_gateway'/'vdc_edge_gateway_ip' are mutually exclusive
155
+ wrong_edge_configuration: |-
156
+ Configuration 'vdc_edge_gateway' and 'vdc_edge_gateway_ip' must be both specified
157
+ service_not_found: |-
158
+ The specified Service cannot be found, please verify your 'cloud_id' and/or 'vdc_name' parameters.
159
+ vdc_not_found: |-
160
+ The Virtual Data Center %{message} cannot be found, please verify your 'vdc_name' parameter.
161
+ edgegw_not_found: |-
162
+ The specified Edge Gateway %{message} cannot be found, please verify your 'vdc_edge_gateway' parameter.
163
+ edgegw_ip_not_found: |-
164
+ The specified Edge Gateway IP %{message} cannot be found, please verify your 'vdc_edge_gateway_ip' parameter.
165
+ edgegw_not_connected: |-
166
+ The Edge Gateway %{edge} is not connected to network %{network}, please check your Vagrantfile parameters.
167
+ forward_port_collision: |-
168
+ Port collision detected, change it in the Vagrantfile or add auto_correct: true. %{guest_port} => %{host_port}
169
+