vagrant-vmware-appcatalyst 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +38 -0
  3. data/.rubocop.yml +34 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +177 -0
  6. data/README.md +72 -0
  7. data/lib/vagrant-vmware-appcatalyst.rb +30 -0
  8. data/lib/vagrant-vmware-appcatalyst/action.rb +249 -0
  9. data/lib/vagrant-vmware-appcatalyst/action/connect_appcatalyst.rb +45 -0
  10. data/lib/vagrant-vmware-appcatalyst/action/destroy_vm.rb +33 -0
  11. data/lib/vagrant-vmware-appcatalyst/action/import.rb +101 -0
  12. data/lib/vagrant-vmware-appcatalyst/action/is_created.rb +34 -0
  13. data/lib/vagrant-vmware-appcatalyst/action/is_paused.rb +33 -0
  14. data/lib/vagrant-vmware-appcatalyst/action/is_running.rb +32 -0
  15. data/lib/vagrant-vmware-appcatalyst/action/message_already_running.rb +29 -0
  16. data/lib/vagrant-vmware-appcatalyst/action/message_not_created.rb +29 -0
  17. data/lib/vagrant-vmware-appcatalyst/action/message_not_running.rb +29 -0
  18. data/lib/vagrant-vmware-appcatalyst/action/message_not_supported.rb +29 -0
  19. data/lib/vagrant-vmware-appcatalyst/action/message_will_not_destroy.rb +30 -0
  20. data/lib/vagrant-vmware-appcatalyst/action/power_off.rb +40 -0
  21. data/lib/vagrant-vmware-appcatalyst/action/power_on.rb +34 -0
  22. data/lib/vagrant-vmware-appcatalyst/action/read_ssh_info.rb +56 -0
  23. data/lib/vagrant-vmware-appcatalyst/action/read_state.rb +72 -0
  24. data/lib/vagrant-vmware-appcatalyst/action/resume.rb +31 -0
  25. data/lib/vagrant-vmware-appcatalyst/action/suspend.rb +31 -0
  26. data/lib/vagrant-vmware-appcatalyst/cap/mount_appcatalyst_shared_folder.rb +100 -0
  27. data/lib/vagrant-vmware-appcatalyst/cap/public_address.rb +31 -0
  28. data/lib/vagrant-vmware-appcatalyst/config.rb +40 -0
  29. data/lib/vagrant-vmware-appcatalyst/driver/base.rb +131 -0
  30. data/lib/vagrant-vmware-appcatalyst/driver/meta.rb +106 -0
  31. data/lib/vagrant-vmware-appcatalyst/driver/version_1_0.rb +223 -0
  32. data/lib/vagrant-vmware-appcatalyst/errors.rb +44 -0
  33. data/lib/vagrant-vmware-appcatalyst/plugin.rb +111 -0
  34. data/lib/vagrant-vmware-appcatalyst/provider.rb +60 -0
  35. data/lib/vagrant-vmware-appcatalyst/synced_folder.rb +123 -0
  36. data/lib/vagrant-vmware-appcatalyst/version.rb +18 -0
  37. data/locales/en.yml +29 -0
  38. data/vagrant-vmware-appcatalyst.gemspec +40 -0
  39. metadata +165 -0
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class ConnectAppCatalyst
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_appcatalyst::action::connect_appcatalyst')
21
+ end
22
+
23
+ def call(env)
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info('Connecting to AppCatalyst...')
27
+
28
+ @logger.debug("config.rest_port: #{config.rest_port}") unless config.rest_port.nil?
29
+
30
+ if config.rest_port.nil?
31
+ endpoint = 'http://localhost:8080'
32
+ else
33
+ endpoint = "http://localhost:#{config.rest_port}"
34
+ end
35
+
36
+ env[:appcatalyst_cnx] = Driver::Meta.new(endpoint)
37
+
38
+ @logger.info('Logging into AppCatalyst...')
39
+
40
+ @app.call env
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class DestroyVM
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_appcatalyst::action::destroy_vm')
21
+ end
22
+
23
+ def call(env)
24
+ env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
25
+ env[:appcatalyst_cnx].delete_vm(env[:machine].id)
26
+ env[:machine].id = nil
27
+
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ require 'securerandom'
15
+
16
+ module VagrantPlugins
17
+ module AppCatalyst
18
+ module Action
19
+ class Import
20
+ def initialize(app, _env)
21
+ @app = app
22
+ @logger = Log4r::Logger.new('vagrant_appcatalyst::action::import')
23
+ end
24
+
25
+ def call(env)
26
+ env[:ui].info I18n.t('vagrant.actions.vm.import.importing',
27
+ name: env[:machine].box.name)
28
+
29
+ # Generate a random UUID for our box
30
+ uuid = "vagrant-#{SecureRandom.uuid}"
31
+
32
+ env[:ui].detail I18n.t('vagrant_appcatalyst.vm.cloning')
33
+
34
+ env[:appcatalyst_cnx].clone_vm_in_directory(
35
+ env[:machine].box.directory,
36
+ "#{env[:machine].data_dir}/#{uuid}"
37
+ )
38
+
39
+ vmx_file = Dir.glob(
40
+ "#{env[:machine].data_dir}/#{uuid}/*.vmx"
41
+ ).first
42
+
43
+ # Make sure we use Virtual HW 11
44
+ env[:appcatalyst_cnx].set_vmx_value(vmx_file, 'virtualHW.version', '11')
45
+
46
+ # Make sure we use VGA only...
47
+ env[:appcatalyst_cnx].set_vmx_value(vmx_file, 'svga.vgaOnly', 'true')
48
+
49
+ # Reconfigure VM with additional parameters specified in the
50
+ # Vagrantfile.
51
+ unless env[:machine].provider_config.vmx.empty?
52
+ @logger.debug(
53
+ "Adding parameters to VMX: #{env[:machine].provider_config.vmx}"
54
+ )
55
+ env[:machine].provider_config.vmx.each do |k, v|
56
+ env[:appcatalyst_cnx].set_vmx_value(vmx_file, k, v)
57
+ end
58
+ end
59
+
60
+ env[:appcatalyst_cnx].import_vm(
61
+ uuid,
62
+ "Vagrant: #{env[:machine].name}",
63
+ vmx_file,
64
+ 'vagrant'
65
+ )
66
+
67
+ # If import has succeded, let's set machine id.
68
+ env[:machine].id = uuid
69
+
70
+ # If we got interrupted, then the import could have been
71
+ # interrupted and its not a big deal. Just return out.
72
+ return if env[:interrupted]
73
+
74
+ # Flag as erroneous and return if import failed
75
+ # TODO: raise correct error
76
+ fail Vagrant::Errors::VMImportFailure unless env[:machine].id
77
+
78
+ # Import completed successfully. Continue the chain
79
+ @app.call(env)
80
+ end
81
+
82
+ def recover(env)
83
+ if env[:machine].state.id != :not_created
84
+ return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
85
+
86
+ # If we're not supposed to destroy on error then just return
87
+ return unless env[:destroy_on_error]
88
+
89
+ # Interrupted, destroy the VM. We note that we don't want to
90
+ # validate the configuration here, and we don't want to confirm
91
+ # we want to destroy.
92
+ destroy_env = env.clone
93
+ destroy_env[:config_validate] = false
94
+ destroy_env[:force_confirm_destroy] = true
95
+ env[:action_runner].run(Action.action_destroy, destroy_env)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class IsCreated
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_appcatalyst::action::is_created')
21
+ end
22
+
23
+ def call(env)
24
+ # Set the result to be true if the machine is created.
25
+ env[:result] = env[:machine].state.id != :not_created
26
+
27
+ # Call the next if we have one (but we shouldn't, since this
28
+ # middleware is built to run with the Call-type middlewares)
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class IsPaused
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ # Set the result to be true if the machine is suspended.
24
+ env[:result] = env[:machine].state.id == :suspended
25
+
26
+ # Call the next if we have one (but we shouldn't, since this
27
+ # middleware is built to run with the Call-type middlewares)
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software distributed
9
+ # under the License is distributed on an "AS IS" BASIS, without warranties or
10
+ # conditions of any kind, EITHER EXPRESS OR IMPLIED. See the License for the
11
+ # specific language governing permissions and limitations under the License.
12
+
13
+ module VagrantPlugins
14
+ module AppCatalyst
15
+ module Action
16
+ class IsRunning
17
+ def initialize(app, env)
18
+ @app = app
19
+ end
20
+
21
+ def call(env)
22
+ # Set the result to be true if the machine is running.
23
+ env[:result] = env[:machine].state.id == :running
24
+
25
+ # Call the next if we have one (but we shouldn't, since this
26
+ # middleware is built to run with the Call-type middlewares)
27
+ @app.call(env)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class MessageAlreadyRunning
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ env[:ui].info I18n.t("vagrant.commands.common.vm_already_running")
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class MessageNotCreated
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ env[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class MessageNotRunning
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ env[:ui].info I18n.t("vagrant.commands.common.vm_not_running")
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class MessageNotSupported
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ env[:ui].error(I18n.t('vagrant_appcatalyst.errors.violations.operation_not_supported'))
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class MessageWillNotDestroy
18
+ def initialize(app, env)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
24
+ name: env[:machine].name)
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ # use this file except in compliance with the License. You may obtain a copy of
6
+ # the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, without
10
+ # warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
11
+ # License for the specific language governing permissions and limitations under
12
+ # the License.
13
+
14
+ module VagrantPlugins
15
+ module AppCatalyst
16
+ module Action
17
+ class PowerOff
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_appcatalyst::action::poweroff')
21
+ end
22
+
23
+ def call(env)
24
+ current_state = env[:machine].state.id
25
+ if current_state == :running
26
+ env[:ui].info(I18n.t("vagrant.actions.vm.halt.graceful"))
27
+ begin
28
+ env[:appcatalyst_cnx].set_vm_power(env[:machine].id, 'shutdown')
29
+ rescue Errors::UnattendedCodeError
30
+ env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
31
+ env[:appcatalyst_cnx].set_vm_power(env[:machine].id, 'off')
32
+ end
33
+ end
34
+
35
+ @app.call(env)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end