ruby-linstor-client 1.0.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.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +86 -0
- data/LICENSE +21 -0
- data/README.md +21 -0
- data/Rakefile +10 -0
- data/codegen.sh +22 -0
- data/generator/custom/one_of_drbd_resource_definition_layer.rb +7 -0
- data/generator/custom/one_of_drbd_volume_definition.rb +7 -0
- data/generator/custom/one_of_drbd_volume_luks_volume_storage_nvme_volme_writecache_volume.rb +11 -0
- data/generator/openapi-generator.yaml +11 -0
- data/generator/template/Gemfile.mustache +9 -0
- data/generator/template/README.mustache +148 -0
- data/generator/template/Rakefile.mustache +10 -0
- data/generator/template/api.mustache +209 -0
- data/generator/template/api_client.mustache +264 -0
- data/generator/template/api_client_faraday_partial.mustache +136 -0
- data/generator/template/api_client_spec.mustache +220 -0
- data/generator/template/api_client_typhoeus_partial.mustache +153 -0
- data/generator/template/api_doc.mustache +118 -0
- data/generator/template/api_error.mustache +49 -0
- data/generator/template/api_info.mustache +12 -0
- data/generator/template/api_test.mustache +47 -0
- data/generator/template/base_object.mustache +120 -0
- data/generator/template/configuration.mustache +385 -0
- data/generator/template/configuration_spec.mustache +34 -0
- data/generator/template/configuration_tls_faraday_partial.mustache +29 -0
- data/generator/template/configuration_tls_typhoeus_partial.mustache +34 -0
- data/generator/template/gem.mustache +53 -0
- data/generator/template/gemspec.mustache +35 -0
- data/generator/template/git_push.sh.mustache +57 -0
- data/generator/template/gitignore.mustache +39 -0
- data/generator/template/model.mustache +26 -0
- data/generator/template/model_doc.mustache +12 -0
- data/generator/template/model_test.mustache +77 -0
- data/generator/template/partial_model_enum_class.mustache +20 -0
- data/generator/template/partial_model_generic.mustache +371 -0
- data/generator/template/partial_model_generic_doc.mustache +28 -0
- data/generator/template/partial_oneof_module.mustache +137 -0
- data/generator/template/partial_oneof_module_doc.mustache +92 -0
- data/generator/template/rspec.mustache +2 -0
- data/generator/template/rubocop.mustache +148 -0
- data/generator/template/spec_helper.mustache +103 -0
- data/generator/template/travis.mustache +14 -0
- data/generator/template/version.mustache +7 -0
- data/lib/ruby-linstor-client/api/developers_api.rb +5856 -0
- data/lib/ruby-linstor-client/api_client.rb +393 -0
- data/lib/ruby-linstor-client/api_error.rb +57 -0
- data/lib/ruby-linstor-client/configuration.rb +298 -0
- data/lib/ruby-linstor-client/models/api_call_rc.rb +293 -0
- data/lib/ruby-linstor-client/models/auto_place_request.rb +245 -0
- data/lib/ruby-linstor-client/models/auto_select_filter.rb +305 -0
- data/lib/ruby-linstor-client/models/candidate.rb +248 -0
- data/lib/ruby-linstor-client/models/controller_props_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/controller_version.rb +245 -0
- data/lib/ruby-linstor-client/models/drbd_proxy_enable.rb +219 -0
- data/lib/ruby-linstor-client/models/drbd_proxy_modify.rb +288 -0
- data/lib/ruby-linstor-client/models/drbd_resource.rb +276 -0
- data/lib/ruby-linstor-client/models/drbd_resource_definition_layer.rb +283 -0
- data/lib/ruby-linstor-client/models/drbd_volume.rb +285 -0
- data/lib/ruby-linstor-client/models/drbd_volume_definition.rb +236 -0
- data/lib/ruby-linstor-client/models/error_report.rb +252 -0
- data/lib/ruby-linstor-client/models/key_value_store.rb +231 -0
- data/lib/ruby-linstor-client/models/key_value_store_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/layer_type.rb +40 -0
- data/lib/ruby-linstor-client/models/luks_resource.rb +220 -0
- data/lib/ruby-linstor-client/models/luks_volume.rb +275 -0
- data/lib/ruby-linstor-client/models/max_volume_sizes.rb +229 -0
- data/lib/ruby-linstor-client/models/net_interface.rb +309 -0
- data/lib/ruby-linstor-client/models/node.rb +381 -0
- data/lib/ruby-linstor-client/models/node_modify.rb +252 -0
- data/lib/ruby-linstor-client/models/nvme_resource.rb +220 -0
- data/lib/ruby-linstor-client/models/nvme_volume.rb +266 -0
- data/lib/ruby-linstor-client/models/one_of_drbd_resource_definition_layer.rb +7 -0
- data/lib/ruby-linstor-client/models/one_of_drbd_volume_definition.rb +7 -0
- data/lib/ruby-linstor-client/models/one_of_drbd_volume_luks_volume_storage_nvme_volme_writecache_volume.rb +11 -0
- data/lib/ruby-linstor-client/models/pass_phrase_create.rb +227 -0
- data/lib/ruby-linstor-client/models/physical_storage.rb +238 -0
- data/lib/ruby-linstor-client/models/physical_storage_create.rb +337 -0
- data/lib/ruby-linstor-client/models/physical_storage_device.rb +245 -0
- data/lib/ruby-linstor-client/models/physical_storage_storage_pool_create.rb +232 -0
- data/lib/ruby-linstor-client/models/provider_kind.rb +43 -0
- data/lib/ruby-linstor-client/models/resource.rb +278 -0
- data/lib/ruby-linstor-client/models/resource_connection.rb +261 -0
- data/lib/ruby-linstor-client/models/resource_connection_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/resource_create.rb +238 -0
- data/lib/ruby-linstor-client/models/resource_definition.rb +295 -0
- data/lib/ruby-linstor-client/models/resource_definition_create.rb +262 -0
- data/lib/ruby-linstor-client/models/resource_definition_layer.rb +228 -0
- data/lib/ruby-linstor-client/models/resource_definition_modify.rb +274 -0
- data/lib/ruby-linstor-client/models/resource_group.rb +262 -0
- data/lib/ruby-linstor-client/models/resource_group_modify.rb +261 -0
- data/lib/ruby-linstor-client/models/resource_group_spawn.rb +255 -0
- data/lib/ruby-linstor-client/models/resource_layer.rb +283 -0
- data/lib/ruby-linstor-client/models/resource_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/resource_state.rb +218 -0
- data/lib/ruby-linstor-client/models/resource_with_volumes.rb +297 -0
- data/lib/ruby-linstor-client/models/resource_with_volumes_all_of.rb +220 -0
- data/lib/ruby-linstor-client/models/snapshot.rb +282 -0
- data/lib/ruby-linstor-client/models/snapshot_restore.rb +236 -0
- data/lib/ruby-linstor-client/models/snapshot_volume_definition.rb +228 -0
- data/lib/ruby-linstor-client/models/storage_pool.rb +333 -0
- data/lib/ruby-linstor-client/models/storage_pool_definition.rb +230 -0
- data/lib/ruby-linstor-client/models/storage_pool_definition_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/storage_resource.rb +220 -0
- data/lib/ruby-linstor-client/models/storage_volume.rb +256 -0
- data/lib/ruby-linstor-client/models/volume.rb +327 -0
- data/lib/ruby-linstor-client/models/volume_definition.rb +277 -0
- data/lib/ruby-linstor-client/models/volume_definition_create.rb +232 -0
- data/lib/ruby-linstor-client/models/volume_definition_layer.rb +233 -0
- data/lib/ruby-linstor-client/models/volume_definition_modify.rb +264 -0
- data/lib/ruby-linstor-client/models/volume_group.rb +251 -0
- data/lib/ruby-linstor-client/models/volume_group_modify.rb +255 -0
- data/lib/ruby-linstor-client/models/volume_layer.rb +228 -0
- data/lib/ruby-linstor-client/models/volume_modify.rb +243 -0
- data/lib/ruby-linstor-client/models/volume_state.rb +218 -0
- data/lib/ruby-linstor-client/models/writecache_resource.rb +220 -0
- data/lib/ruby-linstor-client/models/writecache_volume.rb +266 -0
- data/lib/ruby-linstor-client/version.rb +15 -0
- data/lib/ruby-linstor-client.rb +109 -0
- data/pkg/ruby-linstor-client-1.0.0.gem +0 -0
- data/ruby-linstor-client.gemspec +39 -0
- data/spec/api/developers_api_spec.rb +1116 -0
- data/spec/api_client_spec.rb +188 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/api_call_rc_spec.rb +70 -0
- data/spec/models/auto_place_request_spec.rb +46 -0
- data/spec/models/auto_select_filter_spec.rb +82 -0
- data/spec/models/candidate_spec.rb +52 -0
- data/spec/models/controller_props_modify_spec.rb +46 -0
- data/spec/models/controller_version_spec.rb +52 -0
- data/spec/models/drbd_proxy_enable_spec.rb +34 -0
- data/spec/models/drbd_proxy_modify_spec.rb +56 -0
- data/spec/models/drbd_resource_definition_layer_spec.rb +76 -0
- data/spec/models/drbd_resource_spec.rb +70 -0
- data/spec/models/drbd_volume_definition_spec.rb +46 -0
- data/spec/models/drbd_volume_spec.rb +76 -0
- data/spec/models/error_report_spec.rb +52 -0
- data/spec/models/key_value_store_modify_spec.rb +46 -0
- data/spec/models/key_value_store_spec.rb +40 -0
- data/spec/models/layer_type_spec.rb +28 -0
- data/spec/models/luks_resource_spec.rb +34 -0
- data/spec/models/luks_volume_spec.rb +70 -0
- data/spec/models/max_volume_sizes_spec.rb +40 -0
- data/spec/models/net_interface_spec.rb +68 -0
- data/spec/models/node_modify_spec.rb +52 -0
- data/spec/models/node_spec.rb +102 -0
- data/spec/models/nvme_resource_spec.rb +34 -0
- data/spec/models/nvme_volume_spec.rb +64 -0
- data/spec/models/pass_phrase_create_spec.rb +40 -0
- data/spec/models/physical_storage_create_spec.rb +80 -0
- data/spec/models/physical_storage_device_spec.rb +52 -0
- data/spec/models/physical_storage_spec.rb +46 -0
- data/spec/models/physical_storage_storage_pool_create_spec.rb +40 -0
- data/spec/models/provider_kind_spec.rb +28 -0
- data/spec/models/resource_connection_modify_spec.rb +46 -0
- data/spec/models/resource_connection_spec.rb +58 -0
- data/spec/models/resource_create_spec.rb +46 -0
- data/spec/models/resource_definition_create_spec.rb +58 -0
- data/spec/models/resource_definition_layer_spec.rb +40 -0
- data/spec/models/resource_definition_modify_spec.rb +64 -0
- data/spec/models/resource_definition_spec.rb +76 -0
- data/spec/models/resource_group_modify_spec.rb +58 -0
- data/spec/models/resource_group_spawn_spec.rb +52 -0
- data/spec/models/resource_group_spec.rb +58 -0
- data/spec/models/resource_layer_spec.rb +76 -0
- data/spec/models/resource_modify_spec.rb +46 -0
- data/spec/models/resource_spec.rb +70 -0
- data/spec/models/resource_state_spec.rb +34 -0
- data/spec/models/resource_with_volumes_all_of_spec.rb +34 -0
- data/spec/models/resource_with_volumes_spec.rb +76 -0
- data/spec/models/snapshot_restore_spec.rb +40 -0
- data/spec/models/snapshot_spec.rb +70 -0
- data/spec/models/snapshot_volume_definition_spec.rb +40 -0
- data/spec/models/storage_pool_definition_modify_spec.rb +46 -0
- data/spec/models/storage_pool_definition_spec.rb +40 -0
- data/spec/models/storage_pool_spec.rb +94 -0
- data/spec/models/storage_resource_spec.rb +34 -0
- data/spec/models/storage_volume_spec.rb +58 -0
- data/spec/models/volume_definition_create_spec.rb +40 -0
- data/spec/models/volume_definition_layer_spec.rb +40 -0
- data/spec/models/volume_definition_modify_spec.rb +58 -0
- data/spec/models/volume_definition_spec.rb +64 -0
- data/spec/models/volume_group_modify_spec.rb +52 -0
- data/spec/models/volume_group_spec.rb +52 -0
- data/spec/models/volume_layer_spec.rb +40 -0
- data/spec/models/volume_modify_spec.rb +46 -0
- data/spec/models/volume_spec.rb +100 -0
- data/spec/models/volume_state_spec.rb +34 -0
- data/spec/models/writecache_resource_spec.rb +34 -0
- data/spec/models/writecache_volume_spec.rb +64 -0
- data/spec/spec_helper.rb +111 -0
- metadata +344 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#Linstor REST API
|
|
3
|
+
|
|
4
|
+
#Linstor REST API V1 The V1 rest api of Linstor should stay compatible and only additions are made to the API, If there are breaking changes or redesigned a new major REST API version will be issued. Server runs per default on port `3370` on `::` ipv6 and ipv4. To change the bind address or port you can use the following linstor client commands: ``` linstor controller set-property REST/bindAddress 127.0.0.1 linstor controller set-property REST/port 8080 ``` After setting this properties restart the controller and the new values should be used. Changelog: * 1.0.13 - Fixed broken volume definition modify `flags` handling - Added flags to volume groups (create/modify) * 1.0.12 - Added WritecacheResource and WritecacheVolume schemas. - Removed support for swordfish - Added `with_storage_pool` to PhysicalStorageCreate post request, allowing to create linstor storage pools too - Added `gross` flag for volume-definition size - Added flags to VolumeDefinitionModify (so that `gross` flag can be changed) - Added query-max-volume-size to resource-groups * 1.0.11 - Added /v1/physical-storage endpoint, that lets you query and create lvm/zfs pools - Extended Node with list of supported providers and layers as well as lists of reasons for unsupported providers and layers * 1.0.10 - Added `reports` array field to Volume object, contains ApiCallRcs for problems - Changed `ResourceDefinitions` can now include `VolumeDefinitions` in `volume_definitions` field - Added various filter query parameters * 1.0.9 - Added supports_snapshots to StoragePool * 1.0.8 - Added /v1/resource-groups - Added /v1/resource-groups/{rscgrp}/volume-groups - Moved AutoSelectFilter::place_count default indirectly to create resource implementation - Added diskless_on_remaining to AutoSelectFilter - Changed /v1/view/resources return type to ResourceWithVolumes ResourceWithVolumes is now a child type of Resource (removed volumes from Resource) * 1.0.7 - Added ext_meta_stor_pool to DrbdVolume - Added is_active field to the NetInterface type * 1.0.6 - Added /v1/resource-definitions/{rscName}/resources/{nodeName}/volumes/{vlmnr} PUT * 1.0.5 - Added `reports` field to StoragePool object * 1.0.4 - Added /v1/view/storage-pools overview path - Added uuid fields for objects * 1.0.3 - Added /v1/view/resources overview path - documentation schema extraction * 1.0.2 - Added /v1/storage-pool-definitions object path - added NVME layer object type * 1.0.1 - Documentation review and updates - no functional changes * 1.0.0 - Initial REST API v1
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 1.0.13
|
|
7
|
+
Contact: rene.peinthor@linbit.com
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
OpenAPI Generator version: 5.3.1
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require 'date'
|
|
14
|
+
require 'json'
|
|
15
|
+
require 'logger'
|
|
16
|
+
require 'tempfile'
|
|
17
|
+
require 'time'
|
|
18
|
+
require 'faraday'
|
|
19
|
+
|
|
20
|
+
module LinstorClient
|
|
21
|
+
class ApiClient
|
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
|
23
|
+
attr_accessor :config
|
|
24
|
+
|
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
|
26
|
+
#
|
|
27
|
+
# @return [Hash]
|
|
28
|
+
attr_accessor :default_headers
|
|
29
|
+
|
|
30
|
+
# Initializes the ApiClient
|
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
|
32
|
+
def initialize(config = Configuration.default)
|
|
33
|
+
@config = config
|
|
34
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
|
35
|
+
@default_headers = {
|
|
36
|
+
'Content-Type' => 'application/json',
|
|
37
|
+
'User-Agent' => @user_agent
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.default
|
|
42
|
+
@@default ||= ApiClient.new
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Call an API with given options.
|
|
46
|
+
#
|
|
47
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
|
48
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
|
49
|
+
def call_api(http_method, path, opts = {})
|
|
50
|
+
ssl_options = {
|
|
51
|
+
:ca_file => @config.ssl_ca_file,
|
|
52
|
+
:verify => @config.ssl_verify,
|
|
53
|
+
:verify_mode => @config.ssl_verify_mode,
|
|
54
|
+
:client_cert => @config.ssl_client_cert,
|
|
55
|
+
:client_key => @config.ssl_client_key
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
|
|
59
|
+
conn.request(:basic_auth, config.username, config.password)
|
|
60
|
+
@config.configure_middleware(conn)
|
|
61
|
+
if opts[:header_params]["Content-Type"] == "multipart/form-data"
|
|
62
|
+
conn.request :multipart
|
|
63
|
+
conn.request :url_encoded
|
|
64
|
+
end
|
|
65
|
+
conn.adapter(Faraday.default_adapter)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
begin
|
|
69
|
+
response = connection.public_send(http_method.to_sym.downcase) do |req|
|
|
70
|
+
build_request(http_method, path, req, opts)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if @config.debugging
|
|
74
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
unless response.success?
|
|
78
|
+
if response.status == 0
|
|
79
|
+
# Errors from libcurl will be made visible here
|
|
80
|
+
fail ApiError.new(:code => 0,
|
|
81
|
+
:message => response.return_message)
|
|
82
|
+
else
|
|
83
|
+
fail ApiError.new(:code => response.status,
|
|
84
|
+
:response_headers => response.headers,
|
|
85
|
+
:response_body => response.body),
|
|
86
|
+
response.reason_phrase
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
rescue Faraday::TimeoutError
|
|
90
|
+
fail ApiError.new('Connection timed out')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if opts[:return_type]
|
|
94
|
+
data = deserialize(response, opts[:return_type])
|
|
95
|
+
else
|
|
96
|
+
data = nil
|
|
97
|
+
end
|
|
98
|
+
return data, response.status, response.headers
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Builds the HTTP request
|
|
102
|
+
#
|
|
103
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
|
104
|
+
# @param [String] path URL path (e.g. /account/new)
|
|
105
|
+
# @option opts [Hash] :header_params Header parameters
|
|
106
|
+
# @option opts [Hash] :query_params Query parameters
|
|
107
|
+
# @option opts [Hash] :form_params Query parameters
|
|
108
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
|
109
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
|
110
|
+
def build_request(http_method, path, request, opts = {})
|
|
111
|
+
url = build_request_url(path, opts)
|
|
112
|
+
http_method = http_method.to_sym.downcase
|
|
113
|
+
|
|
114
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
|
115
|
+
query_params = opts[:query_params] || {}
|
|
116
|
+
form_params = opts[:form_params] || {}
|
|
117
|
+
|
|
118
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
|
119
|
+
|
|
120
|
+
req_opts = {
|
|
121
|
+
:params_encoding => @config.params_encoding,
|
|
122
|
+
:timeout => @config.timeout,
|
|
123
|
+
:verbose => @config.debugging
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
|
127
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
|
128
|
+
if @config.debugging
|
|
129
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
request.headers = header_params
|
|
133
|
+
request.body = req_body
|
|
134
|
+
request.options = OpenStruct.new(req_opts)
|
|
135
|
+
request.url url
|
|
136
|
+
request.params = query_params
|
|
137
|
+
download_file(request) if opts[:return_type] == 'File'
|
|
138
|
+
request
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Builds the HTTP request body
|
|
142
|
+
#
|
|
143
|
+
# @param [Hash] header_params Header parameters
|
|
144
|
+
# @param [Hash] form_params Query parameters
|
|
145
|
+
# @param [Object] body HTTP body (JSON/XML)
|
|
146
|
+
# @return [String] HTTP body data in the form of string
|
|
147
|
+
def build_request_body(header_params, form_params, body)
|
|
148
|
+
# http form
|
|
149
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
|
150
|
+
data = URI.encode_www_form(form_params)
|
|
151
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
|
152
|
+
data = {}
|
|
153
|
+
form_params.each do |key, value|
|
|
154
|
+
case value
|
|
155
|
+
when ::File, ::Tempfile
|
|
156
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
|
157
|
+
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
|
158
|
+
when ::Array, nil
|
|
159
|
+
# let Faraday handle Array and nil parameters
|
|
160
|
+
data[key] = value
|
|
161
|
+
else
|
|
162
|
+
data[key] = value.to_s
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
elsif body
|
|
166
|
+
data = body.is_a?(String) ? body : body.to_json
|
|
167
|
+
else
|
|
168
|
+
data = nil
|
|
169
|
+
end
|
|
170
|
+
data
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def download_file(request)
|
|
174
|
+
@stream = []
|
|
175
|
+
|
|
176
|
+
# handle streaming Responses
|
|
177
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
|
178
|
+
@stream << chunk
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Check if the given MIME is a JSON MIME.
|
|
183
|
+
# JSON MIME examples:
|
|
184
|
+
# application/json
|
|
185
|
+
# application/json; charset=UTF8
|
|
186
|
+
# APPLICATION/JSON
|
|
187
|
+
# */*
|
|
188
|
+
# @param [String] mime MIME
|
|
189
|
+
# @return [Boolean] True if the MIME is application/json
|
|
190
|
+
def json_mime?(mime)
|
|
191
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Deserialize the response to the given return type.
|
|
195
|
+
#
|
|
196
|
+
# @param [Response] response HTTP response
|
|
197
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
|
198
|
+
def deserialize(response, return_type)
|
|
199
|
+
body = response.body
|
|
200
|
+
|
|
201
|
+
# handle file downloading - return the File instance processed in request callbacks
|
|
202
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
|
203
|
+
if return_type == 'File'
|
|
204
|
+
content_disposition = response.headers['Content-Disposition']
|
|
205
|
+
if content_disposition && content_disposition =~ /filename=/i
|
|
206
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
|
207
|
+
prefix = sanitize_filename(filename)
|
|
208
|
+
else
|
|
209
|
+
prefix = 'download-'
|
|
210
|
+
end
|
|
211
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
|
212
|
+
encoding = body.encoding
|
|
213
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
|
214
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
|
215
|
+
@tempfile.close
|
|
216
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
|
217
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
|
218
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
|
219
|
+
"explicitly with `tempfile.delete`"
|
|
220
|
+
return @tempfile
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
return nil if body.nil? || body.empty?
|
|
224
|
+
|
|
225
|
+
# return response body directly for String return type
|
|
226
|
+
return body if return_type == 'String'
|
|
227
|
+
|
|
228
|
+
# ensuring a default content type
|
|
229
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
|
230
|
+
|
|
231
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
|
232
|
+
|
|
233
|
+
begin
|
|
234
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
|
235
|
+
rescue JSON::ParserError => e
|
|
236
|
+
if %w(String Date Time).include?(return_type)
|
|
237
|
+
data = body
|
|
238
|
+
else
|
|
239
|
+
raise e
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
convert_to_type data, return_type
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Convert data to the given return type.
|
|
247
|
+
# @param [Object] data Data to be converted
|
|
248
|
+
# @param [String] return_type Return type
|
|
249
|
+
# @return [Mixed] Data in a particular type
|
|
250
|
+
def convert_to_type(data, return_type)
|
|
251
|
+
return nil if data.nil?
|
|
252
|
+
case return_type
|
|
253
|
+
when 'String'
|
|
254
|
+
data.to_s
|
|
255
|
+
when 'Integer'
|
|
256
|
+
data.to_i
|
|
257
|
+
when 'Float'
|
|
258
|
+
data.to_f
|
|
259
|
+
when 'Boolean'
|
|
260
|
+
data == true
|
|
261
|
+
when 'Time'
|
|
262
|
+
# parse date time (expecting ISO 8601 format)
|
|
263
|
+
Time.parse data
|
|
264
|
+
when 'Date'
|
|
265
|
+
# parse date time (expecting ISO 8601 format)
|
|
266
|
+
Date.parse data
|
|
267
|
+
when 'Object'
|
|
268
|
+
# generic object (usually a Hash), return directly
|
|
269
|
+
data
|
|
270
|
+
when /\AArray<(.+)>\z/
|
|
271
|
+
# e.g. Array<Pet>
|
|
272
|
+
sub_type = $1
|
|
273
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
|
274
|
+
when /\AHash\<String, (.+)\>\z/
|
|
275
|
+
# e.g. Hash<String, Integer>
|
|
276
|
+
sub_type = $1
|
|
277
|
+
{}.tap do |hash|
|
|
278
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
|
279
|
+
end
|
|
280
|
+
else
|
|
281
|
+
# models (e.g. Pet) or oneOf
|
|
282
|
+
klass = LinstorClient.const_get(return_type)
|
|
283
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Sanitize filename by removing path.
|
|
288
|
+
# e.g. ../../sun.gif becomes sun.gif
|
|
289
|
+
#
|
|
290
|
+
# @param [String] filename the filename to be sanitized
|
|
291
|
+
# @return [String] the sanitized filename
|
|
292
|
+
def sanitize_filename(filename)
|
|
293
|
+
filename.gsub(/.*[\/\\]/, '')
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def build_request_url(path, opts = {})
|
|
297
|
+
# Add leading and trailing slashes to path
|
|
298
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
|
299
|
+
@config.base_url(opts[:operation]) + path
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Update header and query params based on authentication settings.
|
|
303
|
+
#
|
|
304
|
+
# @param [Hash] header_params Header parameters
|
|
305
|
+
# @param [Hash] query_params Query parameters
|
|
306
|
+
# @param [String] auth_names Authentication scheme name
|
|
307
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
|
308
|
+
Array(auth_names).each do |auth_name|
|
|
309
|
+
auth_setting = @config.auth_settings[auth_name]
|
|
310
|
+
next unless auth_setting
|
|
311
|
+
case auth_setting[:in]
|
|
312
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
|
313
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
|
314
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# Sets user agent in HTTP header
|
|
320
|
+
#
|
|
321
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
|
322
|
+
def user_agent=(user_agent)
|
|
323
|
+
@user_agent = user_agent
|
|
324
|
+
@default_headers['User-Agent'] = @user_agent
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Return Accept header based on an array of accepts provided.
|
|
328
|
+
# @param [Array] accepts array for Accept
|
|
329
|
+
# @return [String] the Accept header (e.g. application/json)
|
|
330
|
+
def select_header_accept(accepts)
|
|
331
|
+
return nil if accepts.nil? || accepts.empty?
|
|
332
|
+
# use JSON when present, otherwise use all of the provided
|
|
333
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
|
334
|
+
json_accept || accepts.join(',')
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# Return Content-Type header based on an array of content types provided.
|
|
338
|
+
# @param [Array] content_types array for Content-Type
|
|
339
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
|
340
|
+
def select_header_content_type(content_types)
|
|
341
|
+
# return nil by default
|
|
342
|
+
return if content_types.nil? || content_types.empty?
|
|
343
|
+
# use JSON when present, otherwise use the first one
|
|
344
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
|
345
|
+
json_content_type || content_types.first
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
|
349
|
+
# @param [Object] model object to be converted into JSON string
|
|
350
|
+
# @return [String] JSON string representation of the object
|
|
351
|
+
def object_to_http_body(model)
|
|
352
|
+
return model if model.nil? || model.is_a?(String)
|
|
353
|
+
local_body = nil
|
|
354
|
+
if model.is_a?(Array)
|
|
355
|
+
local_body = model.map { |m| object_to_hash(m) }
|
|
356
|
+
else
|
|
357
|
+
local_body = object_to_hash(model)
|
|
358
|
+
end
|
|
359
|
+
local_body.to_json
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# Convert object(non-array) to hash.
|
|
363
|
+
# @param [Object] obj object to be converted into JSON string
|
|
364
|
+
# @return [String] JSON string representation of the object
|
|
365
|
+
def object_to_hash(obj)
|
|
366
|
+
if obj.respond_to?(:to_hash)
|
|
367
|
+
obj.to_hash
|
|
368
|
+
else
|
|
369
|
+
obj
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# Build parameter value according to the given collection format.
|
|
374
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
|
375
|
+
def build_collection_param(param, collection_format)
|
|
376
|
+
case collection_format
|
|
377
|
+
when :csv
|
|
378
|
+
param.join(',')
|
|
379
|
+
when :ssv
|
|
380
|
+
param.join(' ')
|
|
381
|
+
when :tsv
|
|
382
|
+
param.join("\t")
|
|
383
|
+
when :pipes
|
|
384
|
+
param.join('|')
|
|
385
|
+
when :multi
|
|
386
|
+
# return the array directly as typhoeus will handle it as expected
|
|
387
|
+
param
|
|
388
|
+
else
|
|
389
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#Linstor REST API
|
|
3
|
+
|
|
4
|
+
#Linstor REST API V1 The V1 rest api of Linstor should stay compatible and only additions are made to the API, If there are breaking changes or redesigned a new major REST API version will be issued. Server runs per default on port `3370` on `::` ipv6 and ipv4. To change the bind address or port you can use the following linstor client commands: ``` linstor controller set-property REST/bindAddress 127.0.0.1 linstor controller set-property REST/port 8080 ``` After setting this properties restart the controller and the new values should be used. Changelog: * 1.0.13 - Fixed broken volume definition modify `flags` handling - Added flags to volume groups (create/modify) * 1.0.12 - Added WritecacheResource and WritecacheVolume schemas. - Removed support for swordfish - Added `with_storage_pool` to PhysicalStorageCreate post request, allowing to create linstor storage pools too - Added `gross` flag for volume-definition size - Added flags to VolumeDefinitionModify (so that `gross` flag can be changed) - Added query-max-volume-size to resource-groups * 1.0.11 - Added /v1/physical-storage endpoint, that lets you query and create lvm/zfs pools - Extended Node with list of supported providers and layers as well as lists of reasons for unsupported providers and layers * 1.0.10 - Added `reports` array field to Volume object, contains ApiCallRcs for problems - Changed `ResourceDefinitions` can now include `VolumeDefinitions` in `volume_definitions` field - Added various filter query parameters * 1.0.9 - Added supports_snapshots to StoragePool * 1.0.8 - Added /v1/resource-groups - Added /v1/resource-groups/{rscgrp}/volume-groups - Moved AutoSelectFilter::place_count default indirectly to create resource implementation - Added diskless_on_remaining to AutoSelectFilter - Changed /v1/view/resources return type to ResourceWithVolumes ResourceWithVolumes is now a child type of Resource (removed volumes from Resource) * 1.0.7 - Added ext_meta_stor_pool to DrbdVolume - Added is_active field to the NetInterface type * 1.0.6 - Added /v1/resource-definitions/{rscName}/resources/{nodeName}/volumes/{vlmnr} PUT * 1.0.5 - Added `reports` field to StoragePool object * 1.0.4 - Added /v1/view/storage-pools overview path - Added uuid fields for objects * 1.0.3 - Added /v1/view/resources overview path - documentation schema extraction * 1.0.2 - Added /v1/storage-pool-definitions object path - added NVME layer object type * 1.0.1 - Documentation review and updates - no functional changes * 1.0.0 - Initial REST API v1
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 1.0.13
|
|
7
|
+
Contact: rene.peinthor@linbit.com
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
OpenAPI Generator version: 5.3.1
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module LinstorClient
|
|
14
|
+
class ApiError < StandardError
|
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
|
16
|
+
|
|
17
|
+
# Usage examples:
|
|
18
|
+
# ApiError.new
|
|
19
|
+
# ApiError.new("message")
|
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
|
22
|
+
def initialize(arg = nil)
|
|
23
|
+
if arg.is_a? Hash
|
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
|
25
|
+
super(arg[:message] || arg['message'])
|
|
26
|
+
else
|
|
27
|
+
super arg
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
arg.each do |k, v|
|
|
31
|
+
instance_variable_set "@#{k}", v
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
super arg
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Override to_s to display a friendly error message
|
|
39
|
+
def to_s
|
|
40
|
+
message
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def message
|
|
44
|
+
if @message.nil?
|
|
45
|
+
msg = "Error message: the server returns an error"
|
|
46
|
+
else
|
|
47
|
+
msg = @message
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
msg += "\nHTTP status code: #{code}" if code
|
|
51
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
|
52
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
|
53
|
+
|
|
54
|
+
msg
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|