vagrant-openstack-illuin-provider 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +40 -0
  4. data/CHANGELOG.md +282 -0
  5. data/Gemfile +18 -0
  6. data/RELEASE.md +15 -0
  7. data/Rakefile +25 -0
  8. data/Vagrantfile +20 -0
  9. data/dummy.box +0 -0
  10. data/example_box/README.md +13 -0
  11. data/example_box/metadata.json +3 -0
  12. data/functional_tests/Vagrantfile +58 -0
  13. data/functional_tests/keys/vagrant-openstack +27 -0
  14. data/functional_tests/keys/vagrant-openstack.pub +1 -0
  15. data/functional_tests/run_tests.sh +142 -0
  16. data/lib/vagrant-openstack-illuin-provider.rb +29 -0
  17. data/lib/vagrant-openstack-illuin-provider/action.rb +344 -0
  18. data/lib/vagrant-openstack-illuin-provider/action/abstract_action.rb +22 -0
  19. data/lib/vagrant-openstack-illuin-provider/action/connect_openstack.rb +60 -0
  20. data/lib/vagrant-openstack-illuin-provider/action/create_server.rb +187 -0
  21. data/lib/vagrant-openstack-illuin-provider/action/create_stack.rb +76 -0
  22. data/lib/vagrant-openstack-illuin-provider/action/delete_server.rb +53 -0
  23. data/lib/vagrant-openstack-illuin-provider/action/delete_stack.rb +73 -0
  24. data/lib/vagrant-openstack-illuin-provider/action/message.rb +19 -0
  25. data/lib/vagrant-openstack-illuin-provider/action/provision.rb +60 -0
  26. data/lib/vagrant-openstack-illuin-provider/action/read_ssh_info.rb +74 -0
  27. data/lib/vagrant-openstack-illuin-provider/action/read_state.rb +43 -0
  28. data/lib/vagrant-openstack-illuin-provider/action/resume.rb +24 -0
  29. data/lib/vagrant-openstack-illuin-provider/action/snapshot_cleanup.rb +32 -0
  30. data/lib/vagrant-openstack-illuin-provider/action/snapshot_delete.rb +32 -0
  31. data/lib/vagrant-openstack-illuin-provider/action/snapshot_list.rb +22 -0
  32. data/lib/vagrant-openstack-illuin-provider/action/snapshot_restore.rb +29 -0
  33. data/lib/vagrant-openstack-illuin-provider/action/snapshot_save.rb +51 -0
  34. data/lib/vagrant-openstack-illuin-provider/action/start_server.rb +24 -0
  35. data/lib/vagrant-openstack-illuin-provider/action/stop_server.rb +25 -0
  36. data/lib/vagrant-openstack-illuin-provider/action/suspend.rb +24 -0
  37. data/lib/vagrant-openstack-illuin-provider/action/sync_folders.rb +138 -0
  38. data/lib/vagrant-openstack-illuin-provider/action/wait_active.rb +33 -0
  39. data/lib/vagrant-openstack-illuin-provider/action/wait_stop.rb +33 -0
  40. data/lib/vagrant-openstack-illuin-provider/cap/snapshot_list.rb +15 -0
  41. data/lib/vagrant-openstack-illuin-provider/catalog/openstack_catalog.rb +90 -0
  42. data/lib/vagrant-openstack-illuin-provider/client/cinder.rb +39 -0
  43. data/lib/vagrant-openstack-illuin-provider/client/domain.rb +163 -0
  44. data/lib/vagrant-openstack-illuin-provider/client/glance.rb +65 -0
  45. data/lib/vagrant-openstack-illuin-provider/client/heat.rb +49 -0
  46. data/lib/vagrant-openstack-illuin-provider/client/http_utils.rb +116 -0
  47. data/lib/vagrant-openstack-illuin-provider/client/keystone.rb +128 -0
  48. data/lib/vagrant-openstack-illuin-provider/client/neutron.rb +48 -0
  49. data/lib/vagrant-openstack-illuin-provider/client/nova.rb +303 -0
  50. data/lib/vagrant-openstack-illuin-provider/client/openstack.rb +59 -0
  51. data/lib/vagrant-openstack-illuin-provider/client/request_logger.rb +23 -0
  52. data/lib/vagrant-openstack-illuin-provider/client/rest_utils.rb +28 -0
  53. data/lib/vagrant-openstack-illuin-provider/command/abstract_command.rb +51 -0
  54. data/lib/vagrant-openstack-illuin-provider/command/flavor_list.rb +24 -0
  55. data/lib/vagrant-openstack-illuin-provider/command/floatingip_list.rb +32 -0
  56. data/lib/vagrant-openstack-illuin-provider/command/image_list.rb +29 -0
  57. data/lib/vagrant-openstack-illuin-provider/command/main.rb +52 -0
  58. data/lib/vagrant-openstack-illuin-provider/command/network_list.rb +25 -0
  59. data/lib/vagrant-openstack-illuin-provider/command/openstack_command.rb +16 -0
  60. data/lib/vagrant-openstack-illuin-provider/command/reset.rb +20 -0
  61. data/lib/vagrant-openstack-illuin-provider/command/subnet_list.rb +22 -0
  62. data/lib/vagrant-openstack-illuin-provider/command/utils.rb +22 -0
  63. data/lib/vagrant-openstack-illuin-provider/command/volume_list.rb +25 -0
  64. data/lib/vagrant-openstack-illuin-provider/config.rb +505 -0
  65. data/lib/vagrant-openstack-illuin-provider/config/http.rb +39 -0
  66. data/lib/vagrant-openstack-illuin-provider/config_resolver.rb +334 -0
  67. data/lib/vagrant-openstack-illuin-provider/errors.rb +187 -0
  68. data/lib/vagrant-openstack-illuin-provider/logging.rb +39 -0
  69. data/lib/vagrant-openstack-illuin-provider/plugin.rb +58 -0
  70. data/lib/vagrant-openstack-illuin-provider/provider.rb +50 -0
  71. data/lib/vagrant-openstack-illuin-provider/utils.rb +81 -0
  72. data/lib/vagrant-openstack-illuin-provider/version.rb +15 -0
  73. data/lib/vagrant-openstack-illuin-provider/version_checker.rb +76 -0
  74. data/locales/en.yml +412 -0
  75. data/spec/vagrant-openstack-illuin-provider/action/connect_openstack_spec.rb +770 -0
  76. data/spec/vagrant-openstack-illuin-provider/action/create_server_spec.rb +260 -0
  77. data/spec/vagrant-openstack-illuin-provider/action/create_stack_spec.rb +99 -0
  78. data/spec/vagrant-openstack-illuin-provider/action/delete_server_spec.rb +89 -0
  79. data/spec/vagrant-openstack-illuin-provider/action/delete_stack_spec.rb +63 -0
  80. data/spec/vagrant-openstack-illuin-provider/action/message_spec.rb +33 -0
  81. data/spec/vagrant-openstack-illuin-provider/action/provision_spec.rb +97 -0
  82. data/spec/vagrant-openstack-illuin-provider/action/read_ssh_info_spec.rb +202 -0
  83. data/spec/vagrant-openstack-illuin-provider/action/read_state_spec.rb +81 -0
  84. data/spec/vagrant-openstack-illuin-provider/action/resume_server_spec.rb +49 -0
  85. data/spec/vagrant-openstack-illuin-provider/action/start_server_spec.rb +49 -0
  86. data/spec/vagrant-openstack-illuin-provider/action/stop_server_spec.rb +49 -0
  87. data/spec/vagrant-openstack-illuin-provider/action/suspend_server_spec.rb +49 -0
  88. data/spec/vagrant-openstack-illuin-provider/action/sync_folders_spec.rb +155 -0
  89. data/spec/vagrant-openstack-illuin-provider/action/wait_active_spec.rb +53 -0
  90. data/spec/vagrant-openstack-illuin-provider/action/wait_stop_spec.rb +53 -0
  91. data/spec/vagrant-openstack-illuin-provider/action_spec.rb +120 -0
  92. data/spec/vagrant-openstack-illuin-provider/client/cinder_spec.rb +129 -0
  93. data/spec/vagrant-openstack-illuin-provider/client/glance_spec.rb +145 -0
  94. data/spec/vagrant-openstack-illuin-provider/client/heat_spec.rb +130 -0
  95. data/spec/vagrant-openstack-illuin-provider/client/keystone_spec.rb +226 -0
  96. data/spec/vagrant-openstack-illuin-provider/client/neutron_spec.rb +173 -0
  97. data/spec/vagrant-openstack-illuin-provider/client/nova_spec.rb +760 -0
  98. data/spec/vagrant-openstack-illuin-provider/client/utils_spec.rb +176 -0
  99. data/spec/vagrant-openstack-illuin-provider/command/flavor_list_spec.rb +43 -0
  100. data/spec/vagrant-openstack-illuin-provider/command/floatingip_list_spec.rb +74 -0
  101. data/spec/vagrant-openstack-illuin-provider/command/image_list_spec.rb +95 -0
  102. data/spec/vagrant-openstack-illuin-provider/command/network_list_spec.rb +65 -0
  103. data/spec/vagrant-openstack-illuin-provider/command/reset_spec.rb +24 -0
  104. data/spec/vagrant-openstack-illuin-provider/command/subnet_list_spec.rb +45 -0
  105. data/spec/vagrant-openstack-illuin-provider/command/volume_list_spec.rb +40 -0
  106. data/spec/vagrant-openstack-illuin-provider/config_resolver_spec.rb +879 -0
  107. data/spec/vagrant-openstack-illuin-provider/config_spec.rb +416 -0
  108. data/spec/vagrant-openstack-illuin-provider/e2e_spec.rb.save +27 -0
  109. data/spec/vagrant-openstack-illuin-provider/provider_spec.rb +13 -0
  110. data/spec/vagrant-openstack-illuin-provider/spec_helper.rb +37 -0
  111. data/spec/vagrant-openstack-illuin-provider/utils_spec.rb +197 -0
  112. data/spec/vagrant-openstack-illuin-provider/version_checker_spec.rb +39 -0
  113. data/stackrc +25 -0
  114. data/vagrant-openstack-illuin-provider.gemspec +35 -0
  115. metadata +379 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "openstack_illuin"
3
+ }
@@ -0,0 +1,58 @@
1
+ require 'vagrant-openstack-provider'
2
+
3
+ Vagrant.configure('2') do |config|
4
+
5
+ config.vm.box = 'openstack'
6
+ config.vm.box_url = 'https://github.com/ggiamarchi/vagrant-openstack/raw/master/source/dummy.box'
7
+ config.vm.boot_timeout = ENV['OS_SSH_TIMEOUT'].to_i
8
+
9
+ config.ssh.private_key_path = ENV['OS_KEYPAIR_PRIVATE_KEY']
10
+ config.ssh.pty = true
11
+ config.ssh.shell = ENV['OS_SSH_SHELL']
12
+
13
+ config.vm.provider :openstack do |os|
14
+ os.username = ENV['OS_USERNAME']
15
+ os.password = ENV['OS_PASSWORD']
16
+ os.openstack_auth_url = ENV['OS_AUTH_URL']
17
+ os.openstack_compute_url = ENV['OS_COMPUTE_URL']
18
+ os.openstack_network_url = ENV['OS_NETWORK_URL']
19
+ os.tenant_name = ENV['OS_TENANT_NAME']
20
+ os.sync_method = ENV['OS_SYNC_METHOD']
21
+ os.flavor = ENV['OS_FLAVOR']
22
+ os.image = ENV['OS_IMAGE']
23
+ os.ssh_username = ENV['OS_SSH_USERNAME']
24
+ os.keypair_name = ENV['OS_KEYPAIR_NAME']
25
+ os.floating_ip_pool = ENV['OS_FLOATING_IP_POOL']
26
+ end
27
+
28
+ config.vm.define 'test-basic' do |test|
29
+ test.vm.provider :openstack do |os|
30
+ os.floating_ip = ENV['OS_FLOATING_IP']
31
+ os.floating_ip_pool = nil
32
+ end
33
+ test.vm.provision 'shell', inline: 'echo "SUCCESS" > /tmp/test_shell_provision'
34
+ end
35
+
36
+ config.vm.define 'test-floating-ip-pool' do |test|
37
+ test.vm.provider :openstack do |os|
38
+ os.floating_ip = nil
39
+ os.floating_ip_pool = ENV['OS_FLOATING_IP_POOL']
40
+ end
41
+ test.vm.provision 'shell', inline: 'echo "SUCCESS" > /tmp/test_shell_provision'
42
+ end
43
+
44
+ config.vm.define 'test-ssh-public-key-path' do |test|
45
+ test.vm.provider :openstack do |os|
46
+ os.keypair_name = nil
47
+ os.public_key_path = ENV['OS_PUBLIC_KEY_PATH']
48
+ end
49
+ test.vm.provision 'shell', inline: 'echo "SUCCESS" > /tmp/test_shell_provision'
50
+ end
51
+
52
+ config.vm.define 'test-availabilty-zone' do |test|
53
+ test.vm.provider :openstack do |os|
54
+ os.availability_zone = ENV['OS_AZ']
55
+ end
56
+ test.vm.provision 'shell', inline: 'echo "SUCCESS" > /tmp/test_shell_provision'
57
+ end
58
+ end
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEowIBAAKCAQEArKPKCXfOr8pjInYeDfGOfKC5JS8jWGgf5OqD0SlvRpdWEKa6
3
+ KR6gDL6rVVFU4z7T5lECzeCp+P4uXwYhqXM4TodEccjPkMLDgR5jt+Fd9ixtlVYR
4
+ Gj5vuAv1a7gk4zVr4M82oOKnTriTqTrFGZL3YG3XyxKftoTZyDWsI4nAbfMoup/e
5
+ d54zHY6gApgDGBg+XlJz5Ai4AJT2YtCwWyu4v/zuDcEtMBDbioI8jpWkKTycFMDw
6
+ W8f5Cwxe3bMCw9sasC6+FUI97ac5itvnE6/LZvcftYjXQF0oakz3ujZ0/gN0rhpe
7
+ pswU2ODSkXWxOMBYS0PXZz9N2r3jzGXa5h1EfwIDAQABAoIBACGaL7TwENa+edU3
8
+ UFo+bhFr5x2Js0N94NdZnhaUDgibZDERgqKGR3izk/2jOvaQQAZQNk+ELxE7yCLO
9
+ uraUqpz+TyAmieAPSKZVF+uufe9wblPm0KVfCbe0/CvfR67BsyGqs2NVOmNkIbmK
10
+ qtpzdJrcRmhMU7He4dTKPZsdMMs1esmWK3+uGgtfQTSaCi7rTxsCMn+Ob+lxvfvG
11
+ QS2Ehb63jyb+8L8PyRqnunK9iBpdhuLHN8tGeDzmrCVz/ziRenslfXq1Ng7pxhUQ
12
+ gyXWjlMoRibt9bcsSt1LcaqZMAeiiRnyUlaqyvtkhSb+yzZyHQZs90DgxRVH40Ya
13
+ ebq9FcECgYEA5eXApNgi2iLDWMIGISO9uPDxzR5i4aDjIyHGv1uos/hWwJiX864K
14
+ N23WLLna2LyIAZaEzUi76cPReFza7lxDtl/OeRDgf7yCPWZdH9OhyAeAtVVOu4eN
15
+ iX5dee/GW5Mmu5xBUXo4z0TETqbey1fWHeJNqaA5W9mWkBKrKnT2aIcCgYEAwD3F
16
+ /yUb8fS/Tj02oh2qb3clIwEIgdh6C38/d2J1OduICVzLoMhq0nZnZ1zMPNtLA/g2
17
+ TjZ70EY1VyDAOWaIo+FGU/HIuLsP2jWKvDSKhJUx/oBBPWpCxqBZefoQhKZLkbmO
18
+ Tw+SrUBQM7r8pL/5ptocW0HDwjL8Sbs4KfSWWkkCgYBSLuPDChDLcgnrPND8H86+
19
+ wkNuVCJ9DgqkkHqABcA1Nd2tU99eGSVF01nw+y+ksyDbkHdA+3NRidLj+C27b/g0
20
+ xeMFnGbkwvq8AE/iBMGcxDHaoPhYSYjrUeUQpgp+ygfaoW0oN0z/q1GR3E1g27GL
21
+ VU72CHT4xLvyHPpbXxyHGQKBgAXO1/iJanq45j664rerJccQVnLkSRmDLMzEH2q/
22
+ 8sK4uzdtMkm9RFzvbthUmWcNSQrpqNpcEwmL1Xi4aJZTXrV0zOckWugZ3rS9AWAG
23
+ RlkTGNuTjGUKnNHbblidEXqwe3//lykUU14gn0uwzok7s5My68BmEEABwlWH7n52
24
+ AUThAoGBANwwj2WKKu6l66fyQPFZu0cJTfjhiZt1WH17mHAAtL2TpLnDJiPZYbzJ
25
+ 8WRqCWrww+IVq1yxBS6LhAGMuHTfxFWZGKSPxf9jOM87RKJbPkiBDHoFXznjkjsn
26
+ tXk6jmn+6bCmwkgfzVypN3GTyEMhVgQPMJNqlMO9Op5ZAAKuyi31
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCso8oJd86vymMidh4N8Y58oLklLyNYaB/k6oPRKW9Gl1YQpropHqAMvqtVUVTjPtPmUQLN4Kn4/i5fBiGpczhOh0RxyM+QwsOBHmO34V32LG2VVhEaPm+4C/VruCTjNWvgzzag4qdOuJOpOsUZkvdgbdfLEp+2hNnINawjicBt8yi6n953njMdjqACmAMYGD5eUnPkCLgAlPZi0LBbK7i//O4NwS0wENuKgjyOlaQpPJwUwPBbx/kLDF7dswLD2xqwLr4VQj3tpzmK2+cTr8tm9x+1iNdAXShqTPe6NnT+A3SuGl6mzBTY4NKRdbE4wFhLQ9dnP03avePMZdrmHUR/ julienvey@MacBook-Air-de-Julien.local
@@ -0,0 +1,142 @@
1
+ #!/bin/bash
2
+
3
+ export VAGRANT_OPENSTACK_LOG=debug
4
+
5
+ export OS_SSH_TIMEOUT=600
6
+ export OS_SYNC_METHOD=none
7
+ export OS_SSH_SHELL=bash
8
+ export OS_SSH_USERNAME=
9
+ export OS_SERVER_NAME=
10
+ export OS_IMAGE=
11
+
12
+ ERROR_STATE=0
13
+
14
+ cat > /tmp/images_with_ssh_user <<EOL
15
+ ubuntu-12.04_x86_64_HWE;stack
16
+ ubuntu-14.04_x86_64_LVM;stack
17
+ debian7_x86_64_LVM;stack
18
+ centos65_x86_64_LVM;stack
19
+ EOL
20
+
21
+ cat > /tmp/vagrant_machines <<EOL
22
+ test-basic
23
+ test-floating-ip-pool
24
+ test-ssh-public-key-path
25
+ test-availabilty-zone
26
+ EOL
27
+
28
+ #
29
+ # $1 - Log level
30
+ # $2 - Action (e.g. UP, SSH, DESTROY)
31
+ # $* - Text
32
+ #
33
+ function log() {
34
+ [ $# -lt 3 ] && echo "Logger error..." >&2 && exit 1
35
+ level=$1 ; shift
36
+ action=$1 ; shift
37
+ printf "$(date '+%Y-%m-%d %H:%M:%S') | %10s | %10s | %s\n" "${level}" "${action}" "$*" | tee -a test.log
38
+ }
39
+
40
+ #
41
+ # $1 - Action (e.g. UP, SSH, DESTROY)
42
+ # $* - Text
43
+ #
44
+ function logInfo() {
45
+ action=$1
46
+ shift
47
+ log INFO "${action}" "$*"
48
+ }
49
+
50
+ #
51
+ # $1 - Action (e.g. UP, SSH, DESTROY)
52
+ # $* - Text
53
+ #
54
+ function logError() {
55
+ action=$1
56
+ shift
57
+ log ERROR "${action}" "$*"
58
+ ERROR_STATE=1
59
+ }
60
+
61
+ #
62
+ # $1 - Action (e.g. UP, SSH, DESTROY)
63
+ # $* - Text
64
+ #
65
+ function logSuccess() {
66
+ action=$1
67
+ shift
68
+ log SUCCESS "${action}" "$*"
69
+ }
70
+
71
+ runSingleTest() {
72
+ if [ -d ".vagrant" ]; then
73
+ rm -rf .vagrant
74
+ fi
75
+ machine=${1}
76
+
77
+ testSummary="${OS_SERVER_NAME} - ${OS_IMAGE} - ${OS_SSH_USERNAME}"
78
+
79
+ logInfo 'START' "${testSummary}"
80
+
81
+ bundle exec vagrant up "${machine}" --provider openstack 2>&1 | tee -a "${OS_SERVER_NAME}_up.log"
82
+ if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
83
+ logError 'UP' "${testSummary}"
84
+ else
85
+ logSuccess 'UP' "${testSummary}"
86
+ bundle exec vagrant ssh "${machine}" -c "cat /tmp/test_shell_provision" 2>&1 | tee -a "${OS_SERVER_NAME}_ssh.log"
87
+ if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
88
+ logError 'SSH' "${testSummary}"
89
+ else
90
+ logSuccess 'SSH' "${testSummary}"
91
+ fi
92
+ fi
93
+
94
+ bundle exec vagrant destroy "${machine}" 2>&1 | tee -a "${OS_SERVER_NAME}_destroy.log"
95
+ if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
96
+ logError 'DESTROY' "${testSummary}"
97
+ else
98
+ logSuccess 'DESTROY' "${testSummary}"
99
+ fi
100
+
101
+ logInfo 'END' "${testSummary}"
102
+
103
+ }
104
+
105
+ #
106
+ # $1 - Instance name prefix
107
+ # $2 - Floating IP tu use
108
+ #
109
+ function runAllTests() {
110
+ ip=${1}
111
+ i=1
112
+ rm -f test.log "${name}_*.log"
113
+ touch test.log
114
+ nbTests=$(wc -l < /tmp/images_with_ssh_user)
115
+ for (( i=1 ; i<=nbTests ; i++ )) ; do
116
+ #TODO(vagrant status does not support providers, see https://github.com/mitchellh/vagrant/issues/4173)
117
+ #for machine in $(bundle exec vagrant status | tail -n +8 | head -n -4 | awk '{print $1}') ; do
118
+ while IFS= read -r machine
119
+ do
120
+ currentTest=$(head -n ${i} < /tmp/images_with_ssh_user | tail -n 1)
121
+ export OS_SERVER_NAME="${machine}_${i}"
122
+ export OS_IMAGE=$(echo "${currentTest}" | cut -f1 -d";")
123
+ export OS_FLOATING_IP="${ip}"
124
+ export OS_SSH_USERNAME=$(echo "${currentTest}" | cut -f2 -d";")
125
+ runSingleTest "${machine}"
126
+ done < /tmp/vagrant_machines
127
+ done
128
+ }
129
+
130
+ runAllTests "${OS_FLOATING_IP}"
131
+
132
+ echo ''
133
+ echo '################################################################################################'
134
+ echo '# Report summary #'
135
+ echo '################################################################################################'
136
+ echo ''
137
+ cat test.log
138
+ echo ''
139
+ echo '################################################################################################'
140
+ echo ''
141
+
142
+ exit ${ERROR_STATE}
@@ -0,0 +1,29 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant-openstack-illuin-provider/plugin'
4
+ require 'vagrant-openstack-illuin-provider/logging'
5
+
6
+ module VagrantPlugins
7
+ module Openstack
8
+ lib_path = Pathname.new(File.expand_path('../vagrant-openstack-illuin-provider', __FILE__))
9
+ autoload :Errors, lib_path.join('errors')
10
+
11
+ # This initializes the i18n load path so that the plugin-specific
12
+ # translations work.
13
+ def self.init_i18n
14
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
15
+ I18n.reload!
16
+ end
17
+
18
+ def self.init_logging
19
+ Logging.init
20
+ end
21
+
22
+ # This returns the path to the source of this plugin.
23
+ #
24
+ # @return [Pathname]
25
+ def self.source_root
26
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,344 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant/action/builder'
4
+
5
+ module VagrantPlugins
6
+ module Openstack
7
+ module Action
8
+ # Include the built-in modules so we can use them as top-level things.
9
+ include Vagrant::Action::Builtin
10
+
11
+ # This action is called to destroy the remote machine.
12
+ def self.action_destroy
13
+ new_builder.tap do |b|
14
+ b.use ConfigValidate
15
+ b.use ConnectOpenstack
16
+ b.use Call, ReadState do |env, b2|
17
+ if env[:machine_state_id] == :not_created
18
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
19
+ else
20
+ b2.use(ProvisionerCleanup, :before)
21
+ b2.use SnapshotCleanup if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
22
+ b2.use DeleteServer
23
+ b2.use DeleteStack
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ # This action is called when `vagrant provision` is called.
30
+ def self.action_provision
31
+ new_builder.tap do |b|
32
+ b.use ConfigValidate
33
+ b.use ConnectOpenstack
34
+ b.use Call, ReadState do |env, b2|
35
+ if env[:machine_state_id] == :not_created
36
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
37
+ else
38
+ if env[:machine].provider_config.meta_args_support
39
+ b2.use ProvisionWrapper
40
+ else
41
+ b2.use Provision
42
+ end
43
+ if env[:machine].provider_config.use_legacy_synced_folders
44
+ env[:machine].ui.warn I18n.t('vagrant_openstack.config.sync_folders_deprecated')
45
+ b2.use SyncFolders
46
+ else
47
+ # Standard Vagrant implementation.
48
+ b2.use SyncedFolders
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # This action is called to read the SSH info of the machine. The
56
+ # resulting state is expected to be put into the `:machine_ssh_info`
57
+ # key.
58
+ def self.action_read_ssh_info
59
+ new_builder.tap do |b|
60
+ b.use ConfigValidate
61
+ b.use ConnectOpenstack
62
+ b.use ReadSSHInfo
63
+ end
64
+ end
65
+
66
+ # This action is called to read the state of the machine. The
67
+ # resulting state is expected to be put into the `:machine_state_id`
68
+ # key.
69
+ def self.action_read_state
70
+ new_builder.tap do |b|
71
+ b.use HandleBox
72
+ b.use ConfigValidate
73
+ b.use ConnectOpenstack
74
+ b.use ReadState
75
+ end
76
+ end
77
+
78
+ def self.action_ssh
79
+ new_builder.tap do |b|
80
+ b.use ConfigValidate
81
+ b.use ConnectOpenstack
82
+ b.use Call, ReadState do |env, b2|
83
+ if env[:machine_state_id] == :not_created
84
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
85
+ else
86
+ b2.use SSHExec
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ def self.action_ssh_run
93
+ new_builder.tap do |b|
94
+ b.use ConfigValidate
95
+ b.use ConnectOpenstack
96
+ b.use Call, ReadState do |env, b2|
97
+ if env[:machine_state_id] == :not_created
98
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
99
+ else
100
+ b2.use SSHRun
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def self.action_up
107
+ new_builder.tap do |b|
108
+ b.use HandleBox
109
+ b.use ConfigValidate
110
+ b.use ConnectOpenstack
111
+
112
+ b.use Call, ReadState do |env, b2|
113
+ case env[:machine_state_id]
114
+ when :not_created
115
+ ssh_disabled = env[:machine].provider_config.ssh_disabled
116
+ unless ssh_disabled
117
+ if env[:machine].provider_config.meta_args_support
118
+ b2.use ProvisionWrapper
119
+ else
120
+ b2.use Provision
121
+ end
122
+ end
123
+
124
+ if env[:machine].provider_config.use_legacy_synced_folders
125
+ env[:machine].ui.warn I18n.t('vagrant_openstack.config.sync_folders_deprecated')
126
+ b2.use SyncFolders
127
+ else
128
+ # Standard Vagrant implementation.
129
+ b2.use SyncedFolders
130
+ end
131
+
132
+ b2.use CreateStack
133
+ b2.use CreateServer
134
+ b2.use Message, I18n.t('vagrant_openstack.ssh_disabled_provisioning') if ssh_disabled
135
+ unless ssh_disabled
136
+ # Handle legacy ssh_timeout option
137
+ timeout = env[:machine].provider_config.ssh_timeout
138
+ unless timeout.nil?
139
+ env[:machine].ui.warn I18n.t('vagrant_openstack.config.ssh_timeout_deprecated')
140
+ env[:machine].config.vm.boot_timeout = timeout
141
+ end
142
+
143
+ b2.use WaitForCommunicator
144
+ end
145
+ when :shutoff
146
+ b2.use StartServer
147
+ when :suspended
148
+ b2.use Resume
149
+ else
150
+ b2.use Message, I18n.t('vagrant_openstack.already_created')
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ def self.action_halt
157
+ new_builder.tap do |b|
158
+ b.use ConfigValidate
159
+ b.use ConnectOpenstack
160
+ b.use Call, ReadState do |env, b2|
161
+ if env[:machine_state_id] == :not_created
162
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
163
+ else
164
+ b2.use StopServer
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ # This is the action that is primarily responsible for suspending
171
+ # the virtual machine.
172
+ # Vm cannot be suspended when the machine_state_id is not "active" (typically a task is ongoing)
173
+ def self.action_suspend
174
+ new_builder.tap do |b|
175
+ b.use ConfigValidate
176
+ b.use ConnectOpenstack
177
+ b.use Call, ReadState do |env, b2|
178
+ case env[:machine_state_id]
179
+ when :not_created
180
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
181
+ when :suspended
182
+ b2.use Message, I18n.t('vagrant_openstack.already_suspended')
183
+ when :active
184
+ b2.use Suspend
185
+ else
186
+ b2.use Message, I18n.t('vagrant_openstack.ongoing_task')
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ # This is the action that is primarily responsible for resuming
193
+ # suspended machines.
194
+ # Vm cannot be resumed when the machine_state_id is not suspended.
195
+ def self.action_resume
196
+ new_builder.tap do |b|
197
+ b.use ConfigValidate
198
+ b.use ConnectOpenstack
199
+ b.use Call, ReadState do |env, b2|
200
+ case env[:machine_state_id]
201
+ when :not_created
202
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
203
+ when :suspended
204
+ b2.use Resume
205
+ else
206
+ b2.use Message, I18n.t('vagrant_openstack.not_suspended')
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ def self.action_reload
213
+ new_builder.tap do |b|
214
+ b.use ConfigValidate
215
+ b.use ConnectOpenstack
216
+ b.use Call, ReadState do |env, b2|
217
+ case env[:machine_state_id]
218
+ when :not_created
219
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
220
+ when :suspended
221
+ b2.use Resume
222
+ b2.use WaitForServerToBeActive
223
+ b2.use StopServer
224
+ b2.use WaitForServerToStop
225
+ b2.use StartServer
226
+ when :shutoff
227
+ b2.use StartServer
228
+ else
229
+ b2.use StopServer
230
+ b2.use WaitForServerToStop
231
+ b2.use StartServer
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+ # TODO: Remove the if guard when Vagrant 1.8.0 is the minimum version.
238
+ # rubocop:disable IndentationWidth
239
+ if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
240
+ def self.action_snapshot_delete
241
+ new_builder.tap do |b|
242
+ b.use ConfigValidate
243
+ b.use ConnectOpenstack
244
+ b.use Call, IsState, :not_created do |env, b2|
245
+ if env[:result]
246
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
247
+ else
248
+ b2.use SnapshotDelete
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ def self.action_snapshot_list
255
+ new_builder.tap do |b|
256
+ b.use ConfigValidate
257
+ b.use ConnectOpenstack
258
+ b.use Call, IsState, :not_created do |env, b2|
259
+ if env[:result]
260
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
261
+ else
262
+ b2.use SnapshotList
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ def self.action_snapshot_restore
269
+ new_builder.tap do |b|
270
+ b.use ConfigValidate
271
+ b.use ConnectOpenstack
272
+ b.use Call, IsState, :not_created do |env, b2|
273
+ if env[:result]
274
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
275
+ next
276
+ end
277
+
278
+ b2.use SnapshotRestore
279
+ b2.use WaitForServerToBeActive
280
+ b2.use WaitForCommunicator
281
+
282
+ b2.use Call, IsEnvSet, :snapshot_delete do |env2, b3|
283
+ # Used by vagrant push/pop
284
+ b3.use action_snapshot_delete if env2[:result]
285
+ end
286
+
287
+ b2.use action_provision
288
+ end
289
+ end
290
+ end
291
+
292
+ def self.action_snapshot_save
293
+ new_builder.tap do |b|
294
+ b.use ConfigValidate
295
+ b.use ConnectOpenstack
296
+ b.use Call, IsState, :not_created do |env, b2|
297
+ if env[:result]
298
+ b2.use Message, I18n.t('vagrant_openstack.not_created')
299
+ else
300
+ b2.use SnapshotSave
301
+ end
302
+ end
303
+ end
304
+ end
305
+ end # Vagrant > 1.8.0 guard
306
+ # rubocop:enable IndentationWidth
307
+
308
+ # The autoload farm
309
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
310
+ autoload :Message, action_root.join('message')
311
+ autoload :ConnectOpenstack, action_root.join('connect_openstack')
312
+ autoload :CreateServer, action_root.join('create_server')
313
+ autoload :CreateStack, action_root.join('create_stack')
314
+ autoload :DeleteStack, action_root.join('delete_stack')
315
+ autoload :DeleteServer, action_root.join('delete_server')
316
+ autoload :StopServer, action_root.join('stop_server')
317
+ autoload :StartServer, action_root.join('start_server')
318
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
319
+ autoload :ReadState, action_root.join('read_state')
320
+ autoload :SyncFolders, action_root.join('sync_folders')
321
+ autoload :Suspend, action_root.join('suspend')
322
+ autoload :Resume, action_root.join('resume')
323
+ autoload :ProvisionWrapper, action_root.join('provision')
324
+ autoload :WaitForServerToStop, action_root.join('wait_stop')
325
+ autoload :WaitForServerToBeActive, action_root.join('wait_active')
326
+ # TODO: Remove the if guard when Vagrant 1.8.0 is the minimum version.
327
+ # rubocop:disable IndentationWidth
328
+ if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
329
+ autoload :SnapshotCleanup, action_root.join('snapshot_cleanup')
330
+ autoload :SnapshotDelete, action_root.join('snapshot_delete')
331
+ autoload :SnapshotList, action_root.join('snapshot_list')
332
+ autoload :SnapshotRestore, action_root.join('snapshot_restore')
333
+ autoload :SnapshotSave, action_root.join('snapshot_save')
334
+ end
335
+ # rubocop:enable IndentationWidth
336
+
337
+ private
338
+
339
+ def self.new_builder
340
+ Vagrant::Action::Builder.new
341
+ end
342
+ end
343
+ end
344
+ end