vagrant-conoha 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 (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +35 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +19 -0
  6. data/LICENSE +23 -0
  7. data/Rakefile +25 -0
  8. data/Vagrantfile +71 -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-conoha.rb +29 -0
  17. data/lib/vagrant-conoha/action.rb +227 -0
  18. data/lib/vagrant-conoha/action/abstract_action.rb +22 -0
  19. data/lib/vagrant-conoha/action/connect_openstack.rb +60 -0
  20. data/lib/vagrant-conoha/action/create_server.rb +154 -0
  21. data/lib/vagrant-conoha/action/create_stack.rb +68 -0
  22. data/lib/vagrant-conoha/action/delete_server.rb +53 -0
  23. data/lib/vagrant-conoha/action/delete_stack.rb +73 -0
  24. data/lib/vagrant-conoha/action/message.rb +19 -0
  25. data/lib/vagrant-conoha/action/provision.rb +60 -0
  26. data/lib/vagrant-conoha/action/read_ssh_info.rb +72 -0
  27. data/lib/vagrant-conoha/action/read_state.rb +43 -0
  28. data/lib/vagrant-conoha/action/resume.rb +24 -0
  29. data/lib/vagrant-conoha/action/start_server.rb +24 -0
  30. data/lib/vagrant-conoha/action/stop_server.rb +25 -0
  31. data/lib/vagrant-conoha/action/suspend.rb +24 -0
  32. data/lib/vagrant-conoha/action/sync_folders.rb +129 -0
  33. data/lib/vagrant-conoha/action/wait_accessible.rb +61 -0
  34. data/lib/vagrant-conoha/action/wait_active.rb +33 -0
  35. data/lib/vagrant-conoha/action/wait_stop.rb +33 -0
  36. data/lib/vagrant-conoha/catalog/openstack_catalog.rb +67 -0
  37. data/lib/vagrant-conoha/client/cinder.rb +39 -0
  38. data/lib/vagrant-conoha/client/domain.rb +159 -0
  39. data/lib/vagrant-conoha/client/glance.rb +65 -0
  40. data/lib/vagrant-conoha/client/heat.rb +49 -0
  41. data/lib/vagrant-conoha/client/http_utils.rb +116 -0
  42. data/lib/vagrant-conoha/client/keystone.rb +77 -0
  43. data/lib/vagrant-conoha/client/neutron.rb +48 -0
  44. data/lib/vagrant-conoha/client/nova.rb +212 -0
  45. data/lib/vagrant-conoha/client/openstack.rb +59 -0
  46. data/lib/vagrant-conoha/client/request_logger.rb +23 -0
  47. data/lib/vagrant-conoha/client/rest_utils.rb +25 -0
  48. data/lib/vagrant-conoha/command/abstract_command.rb +51 -0
  49. data/lib/vagrant-conoha/command/flavor_list.rb +24 -0
  50. data/lib/vagrant-conoha/command/image_list.rb +29 -0
  51. data/lib/vagrant-conoha/command/main.rb +51 -0
  52. data/lib/vagrant-conoha/command/network_list.rb +25 -0
  53. data/lib/vagrant-conoha/command/openstack_command.rb +16 -0
  54. data/lib/vagrant-conoha/command/reset.rb +20 -0
  55. data/lib/vagrant-conoha/command/subnet_list.rb +22 -0
  56. data/lib/vagrant-conoha/command/utils.rb +22 -0
  57. data/lib/vagrant-conoha/command/volume_list.rb +25 -0
  58. data/lib/vagrant-conoha/config.rb +390 -0
  59. data/lib/vagrant-conoha/config/http.rb +39 -0
  60. data/lib/vagrant-conoha/config_resolver.rb +285 -0
  61. data/lib/vagrant-conoha/errors.rb +187 -0
  62. data/lib/vagrant-conoha/logging.rb +39 -0
  63. data/lib/vagrant-conoha/plugin.rb +48 -0
  64. data/lib/vagrant-conoha/provider.rb +50 -0
  65. data/lib/vagrant-conoha/utils.rb +26 -0
  66. data/lib/vagrant-conoha/version.rb +15 -0
  67. data/lib/vagrant-conoha/version_checker.rb +76 -0
  68. data/locales/en.yml +393 -0
  69. data/spec/vagrant-conoha/action/connect_openstack_spec.rb +695 -0
  70. data/spec/vagrant-conoha/action/create_server_spec.rb +225 -0
  71. data/spec/vagrant-conoha/action/create_stack_spec.rb +99 -0
  72. data/spec/vagrant-conoha/action/delete_server_spec.rb +89 -0
  73. data/spec/vagrant-conoha/action/delete_stack_spec.rb +63 -0
  74. data/spec/vagrant-conoha/action/message_spec.rb +33 -0
  75. data/spec/vagrant-conoha/action/provision_spec.rb +104 -0
  76. data/spec/vagrant-conoha/action/read_ssh_info_spec.rb +190 -0
  77. data/spec/vagrant-conoha/action/read_state_spec.rb +81 -0
  78. data/spec/vagrant-conoha/action/resume_server_spec.rb +49 -0
  79. data/spec/vagrant-conoha/action/start_server_spec.rb +49 -0
  80. data/spec/vagrant-conoha/action/stop_server_spec.rb +49 -0
  81. data/spec/vagrant-conoha/action/suspend_server_spec.rb +49 -0
  82. data/spec/vagrant-conoha/action/sync_folders_spec.rb +155 -0
  83. data/spec/vagrant-conoha/action/wait_accessible_spec.rb +67 -0
  84. data/spec/vagrant-conoha/action/wait_active_spec.rb +53 -0
  85. data/spec/vagrant-conoha/action/wait_stop_spec.rb +53 -0
  86. data/spec/vagrant-conoha/action_spec.rb +120 -0
  87. data/spec/vagrant-conoha/client/cinder_spec.rb +127 -0
  88. data/spec/vagrant-conoha/client/glance_spec.rb +143 -0
  89. data/spec/vagrant-conoha/client/heat_spec.rb +128 -0
  90. data/spec/vagrant-conoha/client/keystone_spec.rb +150 -0
  91. data/spec/vagrant-conoha/client/neutron_spec.rb +171 -0
  92. data/spec/vagrant-conoha/client/nova_spec.rb +757 -0
  93. data/spec/vagrant-conoha/client/utils_spec.rb +176 -0
  94. data/spec/vagrant-conoha/command/flavor_list_spec.rb +43 -0
  95. data/spec/vagrant-conoha/command/image_list_spec.rb +95 -0
  96. data/spec/vagrant-conoha/command/network_list_spec.rb +65 -0
  97. data/spec/vagrant-conoha/command/reset_spec.rb +24 -0
  98. data/spec/vagrant-conoha/command/subnet_list_spec.rb +45 -0
  99. data/spec/vagrant-conoha/command/volume_list_spec.rb +40 -0
  100. data/spec/vagrant-conoha/config_resolver_spec.rb +860 -0
  101. data/spec/vagrant-conoha/config_spec.rb +373 -0
  102. data/spec/vagrant-conoha/e2e_spec.rb.save +27 -0
  103. data/spec/vagrant-conoha/provider_spec.rb +13 -0
  104. data/spec/vagrant-conoha/spec_helper.rb +37 -0
  105. data/spec/vagrant-conoha/utils_spec.rb +129 -0
  106. data/spec/vagrant-conoha/version_checker_spec.rb +39 -0
  107. data/stackrc +25 -0
  108. data/vagrant-conoha.gemspec +32 -0
  109. metadata +343 -0
@@ -0,0 +1,25 @@
1
+ require 'log4r'
2
+
3
+ require 'vagrant-conoha/action/abstract_action'
4
+
5
+ module VagrantPlugins
6
+ module ConoHa
7
+ module Action
8
+ class StopServer < AbstractAction
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_openstack::action::stop_server')
12
+ end
13
+
14
+ def execute(env)
15
+ if env[:machine].id
16
+ @logger.info "Stopping server #{env[:machine].id}..."
17
+ env[:ui].info(I18n.t('vagrant_openstack.stopping_server'))
18
+ env[:openstack_client].nova.stop_server(env, env[:machine].id)
19
+ end
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-conoha/action/abstract_action'
2
+
3
+ module VagrantPlugins
4
+ module ConoHa
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,129 @@
1
+ require 'log4r'
2
+ require 'rbconfig'
3
+ require 'vagrant/util/subprocess'
4
+
5
+ require 'vagrant-conoha/action/abstract_action'
6
+
7
+ module VagrantPlugins
8
+ module ConoHa
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
+ # Rsync over to the guest path using the SSH info. add
86
+ # .hg/ and .git/ to exclude list as that isn't covered in
87
+ # --cvs-exclude
88
+ command = [
89
+ 'rsync', '--verbose', '--archive', '-z',
90
+ '--cvs-exclude',
91
+ '--exclude', '.hg/',
92
+ '--exclude', '.git/',
93
+ '--chmod', 'ugo=rwX',
94
+ *includes,
95
+ '-e', "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
96
+ hostpath,
97
+ "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
98
+ command.compact!
99
+
100
+ # during rsync, ignore files specified in list of files containing exclude patterns
101
+ # ex: rsync_ignore_files = ['.hgignore', '.gitignore']
102
+ ignore_files = []
103
+ ignore_files = env[:machine].provider_config.rsync_ignore_files unless env[:machine].provider_config.rsync_ignore_files.nil?
104
+ ignore_files.each do |ignore_file|
105
+ abs_ignore_file = env[:root_path].to_s + '/' + ignore_file
106
+ command += ['--exclude-from', abs_ignore_file] if File.exist?(abs_ignore_file)
107
+ end
108
+ r = Vagrant::Util::Subprocess.execute(*command)
109
+ next if r.exit_code == 0
110
+ fail Errors::RsyncError, guestpath: guestpath, hostpath: hostpath, stderr: r.stderr
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def ssh_key_options(ssh_info)
117
+ # Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
118
+ Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
119
+ end
120
+
121
+ def add_cygdrive_prefix_to_path(hostpath)
122
+ hostpath.downcase.sub(/^([a-z]):\//) do
123
+ "/cygdrive/#{Regexp.last_match[1]}/"
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,61 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module ConoHa
5
+ module Action
6
+ class WaitForServerToBeAccessible < AbstractAction
7
+ def initialize(app, env, resolver = nil, ssh = nil)
8
+ @logger = Log4r::Logger.new('vagrant_openstack::action::wait_accessible')
9
+ @app = app
10
+ @ssh = ssh || Vagrant::Action::Builtin::SSHRun.new(app, env)
11
+ @resolver = resolver || VagrantPlugins::ConoHa::ConfigResolver.new
12
+ end
13
+
14
+ def execute(env)
15
+ waiting_for_server_to_be_reachable(env)
16
+ @logger.info 'The server is ready'
17
+ env[:ui].info(I18n.t('vagrant_openstack.ready'))
18
+ @app.call(env)
19
+ end
20
+
21
+ private
22
+
23
+ def waiting_for_server_to_be_reachable(env)
24
+ return if env[:interrupted]
25
+ ssh_timeout = env[:machine].provider_config.ssh_timeout
26
+ return if server_is_reachable?(env, ssh_timeout)
27
+ env[:ui].error(I18n.t('vagrant_openstack.timeout'))
28
+ fail Errors::SshUnavailable, host: @resolver.resolve_floating_ip(env), timeout: ssh_timeout
29
+ end
30
+
31
+ def server_is_reachable?(env, timeout)
32
+ start_time = Time.now
33
+ current_time = start_time
34
+ nb_retry = 0
35
+
36
+ while (current_time - start_time) <= timeout
37
+ @logger.debug "Checking if SSH port is open... Attempt number #{nb_retry}"
38
+ if nb_retry % 5 == 0
39
+ @logger.info 'Waiting for SSH to become available...'
40
+ env[:ui].info(I18n.t('vagrant_openstack.waiting_for_ssh'))
41
+ end
42
+
43
+ env[:ssh_run_command] = 'exit 0'
44
+ env[:ssh_opts] = {
45
+ extra_args: ['-o', 'BatchMode=yes']
46
+ }
47
+ @ssh.call(env)
48
+ return true if env[:ssh_run_exit_status] == 0
49
+
50
+ @logger.debug 'SSH not yet available... new retry in in 1 second'
51
+ nb_retry += 1
52
+ sleep 1
53
+ current_time = Time.now
54
+ end
55
+
56
+ false
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,33 @@
1
+ require 'log4r'
2
+ require 'timeout'
3
+
4
+ require 'vagrant-conoha/action/abstract_action'
5
+
6
+ module VagrantPlugins
7
+ module ConoHa
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(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-conoha/action/abstract_action'
5
+
6
+ module VagrantPlugins
7
+ module ConoHa
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(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,67 @@
1
+ module VagrantPlugins
2
+ module ConoHa
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
+ endpoint_type = config.endpoint_type
14
+ @logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints'))
15
+ @logger.info("Selecting endpoints matching region '#{config.region}'") unless config.region.nil?
16
+
17
+ catalog.each do |service|
18
+ se = service['endpoints']
19
+ if config.region.nil?
20
+ if se.size > 1
21
+ env[:ui].warn I18n.t('vagrant_openstack.client.multiple_endpoint', size: se.size, type: service['type'])
22
+ env[:ui].warn " => #{service['endpoints'][0][endpoint_type]}"
23
+ end
24
+ url = se[0][endpoint_type].strip
25
+ else
26
+ se.each do |endpoint|
27
+ url = endpoint[endpoint_type].strip if endpoint['region'].eql? config.region
28
+ end
29
+ end
30
+ endpoints[service['type'].to_sym] = url unless url.nil? || url.empty?
31
+ end
32
+
33
+ endpoints[:network] = choose_api_version('Neutron', 'openstack_network_url', 'v2') do
34
+ client.neutron.get_api_version_list(env, :network)
35
+ end if config.openstack_network_url.nil? && !endpoints[:network].nil?
36
+
37
+ endpoints[:image] = choose_api_version('Glance', 'openstack_image_url', nil, false) do
38
+ client.glance.get_api_version_list(env)
39
+ end if config.openstack_image_url.nil? && !endpoints[:image].nil?
40
+ end
41
+
42
+ private
43
+
44
+ def choose_api_version(service_name, url_property, version_prefix = nil, fail_if_not_found = true)
45
+ versions = yield
46
+
47
+ return versions.first['links'].first['href'] if version_prefix.nil?
48
+
49
+ if versions.size == 1
50
+ return versions.first['links'].first['href'] if versions.first['id'].start_with?(version_prefix)
51
+ fail Errors::NoMatchingApiVersion, api_name: service_name, url_property: url_property, version_list: version_list if fail_if_not_found
52
+ end
53
+
54
+ version_list = ''
55
+ versions.each do |version|
56
+ return version['links'].first['href'] if version['id'].start_with?(version_prefix)
57
+ links = version['links'].map { |l| l['href'] }
58
+ version_list << "#{version['id'].ljust(6)} #{version['status'].ljust(10)} #{links}\n"
59
+ end
60
+
61
+ fail Errors::NoMatchingApiVersion, api_name: service_name, url_property: url_property, version_list: version_list if fail_if_not_found
62
+ nil
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,39 @@
1
+ require 'log4r'
2
+ require 'json'
3
+
4
+ require 'vagrant-conoha/client/http_utils'
5
+ require 'vagrant-conoha/client/domain'
6
+
7
+ module VagrantPlugins
8
+ module ConoHa
9
+ class CinderClient
10
+ include Singleton
11
+ include VagrantPlugins::ConoHa::HttpUtils
12
+ include VagrantPlugins::ConoHa::Domain
13
+
14
+ def initialize
15
+ @logger = Log4r::Logger.new('vagrant_openstack::cinder')
16
+ @session = VagrantPlugins::ConoHa.session
17
+ end
18
+
19
+ def get_all_volumes(env)
20
+ volumes_json = get(env, "#{@session.endpoints[:volumev2]}/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,159 @@
1
+ require 'log4r'
2
+ require 'json'
3
+
4
+ module VagrantPlugins
5
+ module ConoHa
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
+
29
+ def initialize(id, name, visibility = nil, size = nil, min_ram = nil, min_disk = nil)
30
+ @visibility = visibility
31
+ @size = size
32
+ @min_ram = min_ram
33
+ @min_disk = min_disk
34
+ super(id, name)
35
+ end
36
+
37
+ protected
38
+
39
+ def state
40
+ [@id, @name, @visibility, @size, @min_ram, @min_disk]
41
+ end
42
+ end
43
+
44
+ class Flavor < Item
45
+ #
46
+ # The number of vCPU
47
+ #
48
+ attr_accessor :vcpus
49
+
50
+ #
51
+ # The amount of RAM in Megaoctet
52
+ #
53
+ attr_accessor :ram
54
+
55
+ #
56
+ # The size of root disk in Gigaoctet
57
+ #
58
+ attr_accessor :disk
59
+
60
+ def initialize(id, name, vcpus, ram, disk)
61
+ @vcpus = vcpus
62
+ @ram = ram
63
+ @disk = disk
64
+ super(id, name)
65
+ end
66
+
67
+ protected
68
+
69
+ def state
70
+ [@id, @name, @vcpus, @ram, @disk]
71
+ end
72
+ end
73
+
74
+ class FloatingIP
75
+ attr_accessor :ip, :pool, :instance_id
76
+ def initialize(ip, pool, instance_id)
77
+ @ip = ip
78
+ @pool = pool
79
+ @instance_id = instance_id
80
+ end
81
+ end
82
+
83
+ class Volume < Item
84
+ #
85
+ # Size in Gigaoctet
86
+ #
87
+ attr_accessor :size
88
+
89
+ #
90
+ # Status (e.g. 'Available', 'In-use')
91
+ #
92
+ attr_accessor :status
93
+
94
+ #
95
+ # Whether volume is bootable or not
96
+ #
97
+ attr_accessor :bootable
98
+
99
+ #
100
+ # instance id volume is attached to
101
+ #
102
+ attr_accessor :instance_id
103
+
104
+ #
105
+ # device (e.g. /dev/sdb) if attached
106
+ #
107
+ attr_accessor :device
108
+
109
+ # rubocop:disable Metrics/ParameterLists
110
+ def initialize(id, name, size, status, bootable, instance_id, device)
111
+ @size = size
112
+ @status = status
113
+ @bootable = bootable
114
+ @instance_id = instance_id
115
+ @device = device
116
+ super(id, name)
117
+ end
118
+ # rubocop:enable Metrics/ParameterLists
119
+
120
+ def to_s
121
+ {
122
+ id: @id,
123
+ name: @name,
124
+ size: @size,
125
+ status: @status,
126
+ bootable: @bootable,
127
+ instance_id: @instance_id,
128
+ device: @device
129
+ }.to_json
130
+ end
131
+
132
+ protected
133
+
134
+ def state
135
+ [@id, @name, @size, @status, @bootable, @instance_id, @device]
136
+ end
137
+ end
138
+
139
+ class Subnet < Item
140
+ attr_accessor :cidr
141
+ attr_accessor :enable_dhcp
142
+ attr_accessor :network_id
143
+
144
+ def initialize(id, name, cidr, enable_dhcp, network_id)
145
+ @cidr = cidr
146
+ @enable_dhcp = enable_dhcp
147
+ @network_id = network_id
148
+ super(id, name)
149
+ end
150
+
151
+ protected
152
+
153
+ def state
154
+ [@id, @name, @cidr, @enable_dhcp, @network_id]
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end