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,24 @@
1
+ require 'vagrant-openstack-illuin-provider/action/abstract_action'
2
+
3
+ module VagrantPlugins
4
+ module Openstack
5
+ module Action
6
+ class Suspend < AbstractAction
7
+ def initialize(app, _env)
8
+ @app = app
9
+ @logger = Log4r::Logger.new('vagrant_openstack::action::suspend_server')
10
+ end
11
+
12
+ def execute(env)
13
+ if env[:machine].id
14
+ @logger.info "Saving VM #{env[:machine].id} state and suspending execution..."
15
+ env[:ui].info I18n.t('vagrant.actions.vm.suspend.suspending')
16
+ env[:openstack_client].nova.suspend_server(env, env[:machine].id)
17
+ end
18
+
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,138 @@
1
+ require 'log4r'
2
+ require 'rbconfig'
3
+ require 'vagrant/util/subprocess'
4
+
5
+ require 'vagrant-openstack-illuin-provider/action/abstract_action'
6
+
7
+ module VagrantPlugins
8
+ module Openstack
9
+ module Action
10
+ class SyncFolders < AbstractAction
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def execute(env)
16
+ sync_method = env[:machine].provider_config.sync_method
17
+ if sync_method == 'none'
18
+ NoSyncFolders.new(@app, env).call(env)
19
+ elsif sync_method == 'rsync'
20
+ RsyncFolders.new(@app, env).call(env)
21
+ else
22
+ fail Errors::SyncMethodError, sync_method_value: sync_method
23
+ end
24
+ end
25
+ end
26
+
27
+ class NoSyncFolders
28
+ def initialize(app, _env)
29
+ @app = app
30
+ end
31
+
32
+ def call(env)
33
+ @app.call(env)
34
+ env[:ui].info(I18n.t('vagrant_openstack.disabled_sync_folders'))
35
+ end
36
+ end
37
+
38
+ # This middleware uses `rsync` to sync the folders over to the
39
+ # remote instance.
40
+ class RsyncFolders
41
+ def initialize(app, _env)
42
+ @app = app
43
+ @logger = Log4r::Logger.new('vagrant_openstack::action::sync_folders')
44
+ @host_os = RbConfig::CONFIG['host_os']
45
+ end
46
+
47
+ def call(env)
48
+ @app.call(env)
49
+
50
+ if env[:machine].provider_config.ssh_disabled
51
+ env[:ui].info(I18n.t('vagrant_openstack.ssh_disabled_sync_folders'))
52
+ return
53
+ end
54
+
55
+ ssh_info = env[:machine].ssh_info
56
+
57
+ config = env[:machine].provider_config
58
+ rsync_includes = config.rsync_includes.to_a
59
+
60
+ env[:machine].config.vm.synced_folders.each do |_, data|
61
+ hostpath = File.expand_path(data[:hostpath], env[:root_path])
62
+ guestpath = data[:guestpath]
63
+
64
+ # Make sure there is a trailing slash on the host path to
65
+ # avoid creating an additional directory with rsync
66
+ hostpath = "#{hostpath}/" if hostpath !~ /\/$/
67
+
68
+ # If on Windows, modify the path to work with cygwin rsync
69
+ if @host_os =~ /mswin|mingw|cygwin/
70
+ hostpath = add_cygdrive_prefix_to_path(hostpath)
71
+ end
72
+
73
+ env[:ui].info(I18n.t('vagrant_openstack.rsync_folder', hostpath: hostpath, guestpath: guestpath))
74
+
75
+ # Create the guest path
76
+ env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
77
+ env[:machine].communicate.sudo("chown -R #{ssh_info[:username]} '#{guestpath}'")
78
+
79
+ # Generate rsync include commands
80
+ includes = rsync_includes.each_with_object([]) do |incl, incls|
81
+ incls << '--include'
82
+ incls << incl
83
+ end
84
+
85
+ # Create ssh params for rsync
86
+ # we need them as one string because rsync -e expects one string
87
+ ssh_params = [
88
+ "ssh -p #{ssh_info[:port]}",
89
+ '-o StrictHostKeyChecking=no',
90
+ '-o UserKnownHostsFile=/dev/null',
91
+ '-o IdentitiesOnly=yes',
92
+ "#{ssh_key_options(ssh_info)}"].join(' ')
93
+
94
+ # Rsync over to the guest path using the SSH info. add
95
+ # .hg/ and .git/ to exclude list as that isn't covered in
96
+ # --cvs-exclude
97
+ command = [
98
+ 'rsync', '--verbose', '--archive', '-z',
99
+ '--cvs-exclude',
100
+ '--exclude', '.hg/',
101
+ '--exclude', '.git/',
102
+ '--chmod', 'ugo=rwX',
103
+ *includes,
104
+ '-e', ssh_params,
105
+ hostpath,
106
+ "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
107
+ command.compact!
108
+
109
+ # during rsync, ignore files specified in list of files containing exclude patterns
110
+ # ex: rsync_ignore_files = ['.hgignore', '.gitignore']
111
+ ignore_files = []
112
+ ignore_files = env[:machine].provider_config.rsync_ignore_files unless env[:machine].provider_config.rsync_ignore_files.nil?
113
+ ignore_files.each do |ignore_file|
114
+ abs_ignore_file = env[:root_path].to_s + '/' + ignore_file
115
+ command += ['--exclude-from', abs_ignore_file] if File.exist?(abs_ignore_file)
116
+ end
117
+ r = Vagrant::Util::Subprocess.execute(*command)
118
+ next if r.exit_code == 0
119
+ fail Errors::RsyncError, guestpath: guestpath, hostpath: hostpath, stderr: r.stderr
120
+ end
121
+ end
122
+
123
+ private
124
+
125
+ def ssh_key_options(ssh_info)
126
+ # Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
127
+ Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
128
+ end
129
+
130
+ def add_cygdrive_prefix_to_path(hostpath)
131
+ hostpath.downcase.sub(/^([a-z]):\//) do
132
+ "/cygdrive/#{Regexp.last_match[1]}/"
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,33 @@
1
+ require 'log4r'
2
+ require 'timeout'
3
+
4
+ require 'vagrant-openstack-illuin-provider/action/abstract_action'
5
+
6
+ module VagrantPlugins
7
+ module Openstack
8
+ module Action
9
+ class WaitForServerToBeActive < AbstractAction
10
+ def initialize(app, _env, retry_interval = 3)
11
+ @app = app
12
+ @logger = Log4r::Logger.new('vagrant_openstack::action::start_server')
13
+ @retry_interval = retry_interval
14
+ end
15
+
16
+ def execute(env)
17
+ if env[:machine].id
18
+ env[:ui].info(I18n.t('vagrant_openstack.waiting_start'))
19
+ client = env[:openstack_client].nova
20
+ config = env[:machine].provider_config
21
+ Timeout.timeout(config.server_active_timeout, Errors::Timeout) do
22
+ while client.get_server_details(env, env[:machine].id)['status'] != 'ACTIVE'
23
+ sleep @retry_interval
24
+ @logger.info('Waiting for server to be active')
25
+ end
26
+ end
27
+ end
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'log4r'
2
+ require 'timeout'
3
+
4
+ require 'vagrant-openstack-illuin-provider/action/abstract_action'
5
+
6
+ module VagrantPlugins
7
+ module Openstack
8
+ module Action
9
+ class WaitForServerToStop < AbstractAction
10
+ def initialize(app, _env, retry_interval = 3)
11
+ @app = app
12
+ @logger = Log4r::Logger.new('vagrant_openstack::action::stop_server')
13
+ @retry_interval = retry_interval
14
+ end
15
+
16
+ def execute(env)
17
+ if env[:machine].id
18
+ env[:ui].info(I18n.t('vagrant_openstack.waiting_stop'))
19
+ client = env[:openstack_client].nova
20
+ config = env[:machine].provider_config
21
+ Timeout.timeout(config.server_stop_timeout, Errors::Timeout) do
22
+ while client.get_server_details(env, env[:machine].id)['status'] != 'SHUTOFF'
23
+ sleep @retry_interval
24
+ @logger.info('Waiting for server to stop')
25
+ end
26
+ end
27
+ end
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module Openstack
3
+ module Cap
4
+ module SnapshotList
5
+ # Returns a list of the snapshots that are taken on this machine.
6
+ #
7
+ # @return [Array<String>]
8
+ def self.snapshot_list(machine)
9
+ env = machine.action(:snapshot_list, lock: false)
10
+ env[:machine_snapshot_list]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,90 @@
1
+ module VagrantPlugins
2
+ module Openstack
3
+ module Catalog
4
+ class OpenstackCatalog
5
+ def initialize
6
+ @logger = Log4r::Logger.new('vagrant_openstack::action::openstack_reader')
7
+ end
8
+
9
+ def read(env, catalog)
10
+ config = env[:machine].provider_config
11
+ client = env[:openstack_client]
12
+ endpoints = client.session.endpoints
13
+ @logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints'))
14
+ @logger.info("Selecting endpoints matching region '#{config.region}'") unless config.region.nil?
15
+
16
+ catalog.each do |service|
17
+ se = service['endpoints']
18
+ if config.identity_api_version == '2'
19
+ get_endpoints_2(env, se, service, config, endpoints)
20
+ elsif config.identity_api_version == '3'
21
+ get_interfaces_3(se, service, config, endpoints)
22
+ end
23
+ end
24
+
25
+ endpoints[:network] = choose_api_version('Neutron', 'openstack_network_url', 'v2') do
26
+ client.neutron.get_api_version_list(env, :network)
27
+ end if config.openstack_network_url.nil? && !endpoints[:network].nil?
28
+
29
+ endpoints[:image] = choose_api_version('Glance', 'openstack_image_url', nil, false) do
30
+ client.glance.get_api_version_list(env)
31
+ end if config.openstack_image_url.nil? && !endpoints[:image].nil?
32
+ end
33
+
34
+ private
35
+
36
+ def get_endpoints_2(env, se, service, config, endpoints)
37
+ endpoint_type = config.endpoint_type
38
+ if config.region.nil?
39
+ if se.size > 1
40
+ env[:ui].warn I18n.t('vagrant_openstack.client.multiple_endpoint', size: se.size, type: service['type'])
41
+ env[:ui].warn " => #{service['endpoints'][0][endpoint_type]}"
42
+ end
43
+ url = se[0][endpoint_type].strip
44
+ else
45
+ se.each do |endpoint|
46
+ url = endpoint[endpoint_type].strip if endpoint['region'].eql? config.region
47
+ end
48
+ end
49
+ endpoints[service['type'].to_sym] = url unless url.nil? || url.empty?
50
+ end
51
+
52
+ def get_interfaces_3(se, service, config, endpoints)
53
+ url = nil
54
+ se.each do |endpoint|
55
+ next if endpoint['interface'] != config.interface_type
56
+ if config.region.nil?
57
+ url = endpoint['url']
58
+ break
59
+ elsif endpoint['region'] == config.region
60
+ url = endpoint['url']
61
+ break
62
+ end
63
+ end
64
+ endpoints[service['type'].to_sym] = url unless url.nil? || url.empty?
65
+ end
66
+
67
+ def choose_api_version(service_name, url_property, version_prefix = nil, fail_if_not_found = true)
68
+ versions = yield
69
+
70
+ return versions.first['links'].first['href'] if version_prefix.nil?
71
+
72
+ if versions.size == 1
73
+ return versions.first['links'].first['href'] if versions.first['id'].start_with?(version_prefix)
74
+ fail Errors::NoMatchingApiVersion, api_name: service_name, url_property: url_property, version_list: version_list if fail_if_not_found
75
+ end
76
+
77
+ version_list = ''
78
+ versions.each do |version|
79
+ return version['links'].first['href'] if version['id'].start_with?(version_prefix)
80
+ links = version['links'].map { |l| l['href'] }
81
+ version_list << "#{version['id'].ljust(6)} #{version['status'].ljust(10)} #{links}\n"
82
+ end
83
+
84
+ fail Errors::NoMatchingApiVersion, api_name: service_name, url_property: url_property, version_list: version_list if fail_if_not_found
85
+ nil
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,39 @@
1
+ require 'log4r'
2
+ require 'json'
3
+
4
+ require 'vagrant-openstack-illuin-provider/client/http_utils'
5
+ require 'vagrant-openstack-illuin-provider/client/domain'
6
+
7
+ module VagrantPlugins
8
+ module Openstack
9
+ class CinderClient
10
+ include Singleton
11
+ include VagrantPlugins::Openstack::HttpUtils
12
+ include VagrantPlugins::Openstack::Domain
13
+
14
+ def initialize
15
+ @logger = Log4r::Logger.new('vagrant_openstack::cinder')
16
+ @session = VagrantPlugins::Openstack.session
17
+ end
18
+
19
+ def get_all_volumes(env)
20
+ volumes_json = get(env, "#{@session.endpoints[:volume]}/volumes/detail")
21
+ JSON.parse(volumes_json)['volumes'].map do |volume|
22
+ name = volume['display_name']
23
+ name = volume['name'] if name.nil? # To be compatible with cinder api v1 and v2
24
+ case volume['attachments'].size
25
+ when 0
26
+ @logger.debug "No attachment found for volume #{volume['id']}"
27
+ else
28
+ attachment = volume['attachments'][0]
29
+ server_id = attachment['server_id']
30
+ device = attachment['device']
31
+ @logger.warn "Found #{attachment.size} attachments for volume #{volume['id']} : " if attachment.size > 1
32
+ @logger.debug "Attachment found for volume #{volume['id']} : #{attachment.to_json}"
33
+ end
34
+ Volume.new(volume['id'], name, volume['size'], volume['status'], volume['bootable'], server_id, device)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,163 @@
1
+ require 'log4r'
2
+ require 'json'
3
+
4
+ module VagrantPlugins
5
+ module Openstack
6
+ module Domain
7
+ class Item
8
+ attr_accessor :id, :name
9
+ def initialize(id, name)
10
+ @id = id
11
+ @name = name
12
+ end
13
+
14
+ def ==(other)
15
+ other.class == self.class && other.state == state
16
+ end
17
+
18
+ def state
19
+ [@id, @name]
20
+ end
21
+ end
22
+
23
+ class Image < Item
24
+ attr_accessor :visibility
25
+ attr_accessor :size
26
+ attr_accessor :min_ram
27
+ attr_accessor :min_disk
28
+ attr_accessor :metadata
29
+
30
+ # rubocop:disable Metrics/ParameterLists
31
+ def initialize(id, name, visibility = nil, size = nil, min_ram = nil, min_disk = nil, metadata = {})
32
+ @visibility = visibility
33
+ @size = size
34
+ @min_ram = min_ram
35
+ @min_disk = min_disk
36
+ @metadata = metadata
37
+ super(id, name)
38
+ end
39
+ # rubocop:enable Metrics/ParameterLists
40
+
41
+ protected
42
+
43
+ def state
44
+ [@id, @name, @visibility, @size, @min_ram, @min_disk, @metadata]
45
+ end
46
+ end
47
+
48
+ class Flavor < Item
49
+ #
50
+ # The number of vCPU
51
+ #
52
+ attr_accessor :vcpus
53
+
54
+ #
55
+ # The amount of RAM in Megaoctet
56
+ #
57
+ attr_accessor :ram
58
+
59
+ #
60
+ # The size of root disk in Gigaoctet
61
+ #
62
+ attr_accessor :disk
63
+
64
+ def initialize(id, name, vcpus, ram, disk)
65
+ @vcpus = vcpus
66
+ @ram = ram
67
+ @disk = disk
68
+ super(id, name)
69
+ end
70
+
71
+ protected
72
+
73
+ def state
74
+ [@id, @name, @vcpus, @ram, @disk]
75
+ end
76
+ end
77
+
78
+ class FloatingIP
79
+ attr_accessor :ip, :pool, :instance_id
80
+ def initialize(ip, pool, instance_id)
81
+ @ip = ip
82
+ @pool = pool
83
+ @instance_id = instance_id
84
+ end
85
+ end
86
+
87
+ class Volume < Item
88
+ #
89
+ # Size in Gigaoctet
90
+ #
91
+ attr_accessor :size
92
+
93
+ #
94
+ # Status (e.g. 'Available', 'In-use')
95
+ #
96
+ attr_accessor :status
97
+
98
+ #
99
+ # Whether volume is bootable or not
100
+ #
101
+ attr_accessor :bootable
102
+
103
+ #
104
+ # instance id volume is attached to
105
+ #
106
+ attr_accessor :instance_id
107
+
108
+ #
109
+ # device (e.g. /dev/sdb) if attached
110
+ #
111
+ attr_accessor :device
112
+
113
+ # rubocop:disable Metrics/ParameterLists
114
+ def initialize(id, name, size, status, bootable, instance_id, device)
115
+ @size = size
116
+ @status = status
117
+ @bootable = bootable
118
+ @instance_id = instance_id
119
+ @device = device
120
+ super(id, name)
121
+ end
122
+ # rubocop:enable Metrics/ParameterLists
123
+
124
+ def to_s
125
+ {
126
+ id: @id,
127
+ name: @name,
128
+ size: @size,
129
+ status: @status,
130
+ bootable: @bootable,
131
+ instance_id: @instance_id,
132
+ device: @device
133
+ }.to_json
134
+ end
135
+
136
+ protected
137
+
138
+ def state
139
+ [@id, @name, @size, @status, @bootable, @instance_id, @device]
140
+ end
141
+ end
142
+
143
+ class Subnet < Item
144
+ attr_accessor :cidr
145
+ attr_accessor :enable_dhcp
146
+ attr_accessor :network_id
147
+
148
+ def initialize(id, name, cidr, enable_dhcp, network_id)
149
+ @cidr = cidr
150
+ @enable_dhcp = enable_dhcp
151
+ @network_id = network_id
152
+ super(id, name)
153
+ end
154
+
155
+ protected
156
+
157
+ def state
158
+ [@id, @name, @cidr, @enable_dhcp, @network_id]
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end