=begin #Linstor REST API #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 The version of the OpenAPI document: 1.0.13 Contact: rene.peinthor@linbit.com Generated by: https://openapi-generator.tech OpenAPI Generator version: 5.3.1 =end require 'spec_helper' describe LinstorClient::ApiClient do context 'initialization' do context 'URL stuff' do context 'host' do it 'removes http from host' do LinstorClient.configure { |c| c.host = 'http://example.com' } expect(LinstorClient::Configuration.default.host).to eq('example.com') end it 'removes https from host' do LinstorClient.configure { |c| c.host = 'https://wookiee.com' } expect(LinstorClient::ApiClient.default.config.host).to eq('wookiee.com') end it 'removes trailing path from host' do LinstorClient.configure { |c| c.host = 'hobo.com/v4' } expect(LinstorClient::Configuration.default.host).to eq('hobo.com') end end context 'base_path' do it "prepends a slash to base_path" do LinstorClient.configure { |c| c.base_path = 'v4/dog' } expect(LinstorClient::Configuration.default.base_path).to eq('/v4/dog') end it "doesn't prepend a slash if one is already there" do LinstorClient.configure { |c| c.base_path = '/v4/dog' } expect(LinstorClient::Configuration.default.base_path).to eq('/v4/dog') end it "ends up as a blank string if nil" do LinstorClient.configure { |c| c.base_path = nil } expect(LinstorClient::Configuration.default.base_path).to eq('') end end end end describe '#deserialize' do it "handles Array" do api_client = LinstorClient::ApiClient.new headers = { 'Content-Type' => 'application/json' } response = double('response', headers: headers, body: '[12, 34]') data = api_client.deserialize(response, 'Array') expect(data).to be_instance_of(Array) expect(data).to eq([12, 34]) end it 'handles Array>' do api_client = LinstorClient::ApiClient.new headers = { 'Content-Type' => 'application/json' } response = double('response', headers: headers, body: '[[12, 34], [56]]') data = api_client.deserialize(response, 'Array>') expect(data).to be_instance_of(Array) expect(data).to eq([[12, 34], [56]]) end it 'handles Hash' do api_client = LinstorClient::ApiClient.new headers = { 'Content-Type' => 'application/json' } response = double('response', headers: headers, body: '{"message": "Hello"}') data = api_client.deserialize(response, 'Hash') expect(data).to be_instance_of(Hash) expect(data).to eq(:message => 'Hello') end end describe "#object_to_hash" do it 'ignores nils and includes empty arrays' do # uncomment below to test object_to_hash for model # api_client = LinstorClient::ApiClient.new # _model = LinstorClient::ModelName.new # update the model attribute below # _model.id = 1 # update the expected value (hash) below # expected = {id: 1, name: '', tags: []} # expect(api_client.object_to_hash(_model)).to eq(expected) end end describe '#build_collection_param' do let(:param) { ['aa', 'bb', 'cc'] } let(:api_client) { LinstorClient::ApiClient.new } it 'works for csv' do expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc') end it 'works for ssv' do expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc') end it 'works for tsv' do expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc") end it 'works for pipes' do expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc') end it 'works for multi' do expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc']) end it 'fails for invalid collection format' do expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID') end end describe '#json_mime?' do let(:api_client) { LinstorClient::ApiClient.new } it 'works' do expect(api_client.json_mime?(nil)).to eq false expect(api_client.json_mime?('')).to eq false expect(api_client.json_mime?('application/json')).to eq true expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true expect(api_client.json_mime?('APPLICATION/JSON')).to eq true expect(api_client.json_mime?('application/xml')).to eq false expect(api_client.json_mime?('text/plain')).to eq false expect(api_client.json_mime?('application/jsonp')).to eq false end end describe '#select_header_accept' do let(:api_client) { LinstorClient::ApiClient.new } it 'works' do expect(api_client.select_header_accept(nil)).to be_nil expect(api_client.select_header_accept([])).to be_nil expect(api_client.select_header_accept(['application/json'])).to eq('application/json') expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml') expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml') end end describe '#select_header_content_type' do let(:api_client) { LinstorClient::ApiClient.new } it 'works' do expect(api_client.select_header_content_type(nil)).to be_nil expect(api_client.select_header_content_type([])).to be_nil expect(api_client.select_header_content_type(['application/json'])).to eq('application/json') expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml') expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain') end end describe '#sanitize_filename' do let(:api_client) { LinstorClient::ApiClient.new } it 'works' do expect(api_client.sanitize_filename('sun')).to eq('sun') expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif') expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif') end end end