diff --git a/lib/aviator/openstack/compute/v2/public/list_addresses.rb b/lib/aviator/openstack/compute/v2/public/list_addresses.rb index 6e2b4a2..3cdaa31 100644 --- a/lib/aviator/openstack/compute/v2/public/list_addresses.rb +++ b/lib/aviator/openstack/compute/v2/public/list_addresses.rb @@ -1,5 +1,5 @@ module Aviator - + define_request :list_addresses do meta :provider, :openstack @@ -10,28 +10,37 @@ module Aviator link 'documentation', 'http://docs.openstack.org/api/openstack-compute/2/content/List_Addresses-d1e3014.html' - param :id, required: true + link 'documentation', + 'http://docs.openstack.org/api/openstack-compute/2/content/List_Addresses_by_Network-d1e3118.html' + + + param :id, required: true + param :networkID, required: false + def headers h = {} - + unless self.anonymous? h['X-Auth-Token'] = session_data[:access][:token][:id] end - + h end - - + + def http_method :get end - - + + def url service_spec = session_data[:access][:serviceCatalog].find{|s| s[:type] == service.to_s } - "#{ service_spec[:endpoints][0][:publicURL] }/servers/#{ params[:id] }/ips" + url = "#{ service_spec[:endpoints][0][:publicURL] }/servers/#{ params[:id] }/ips" + url += "/#{ params[:networkID] }" if params[:networkID] + + url end end diff --git a/test/aviator/openstack/compute/v2/public/list_addresses_test.rb b/test/aviator/openstack/compute/v2/public/list_addresses_test.rb index dc4f1ad..30acc6e 100644 --- a/test/aviator/openstack/compute/v2/public/list_addresses_test.rb +++ b/test/aviator/openstack/compute/v2/public/list_addresses_test.rb @@ -84,7 +84,9 @@ class Aviator::Test validate_attr :optional_params do - klass.optional_params.must_equal [] + klass.optional_params.must_equal [ + :networkID + ] end @@ -117,7 +119,7 @@ class Aviator::Test response.body.wont_be_nil response.body[:addresses].wont_be_nil response.headers.wont_be_nil - end + end validate_response 'an invalid server id is provided' do @@ -130,6 +132,28 @@ class Aviator::Test response.status.must_equal 404 response.body.wont_be_nil response.headers.wont_be_nil + end + + + validate_response 'a networkID parameter is provided' do + server_id = session.compute_service.request(:list_servers).body[:servers].first[:id] + + response = session.compute_service.request :list_addresses do |params| + params[:id] = server_id + end + + network_id = response.body[:addresses].keys.first + + response = session.compute_service.request :list_addresses do |params| + params[:id] = server_id + params[:networkID] = network_id + end + + + response.status.must_equal 200 + response.body.wont_be_nil + response.body.keys.wont_be_empty + response.headers.wont_be_nil end end diff --git a/test/cassettes/openstack/compute/v2/public/list_addresses/leads_to_a_valid_response_when_a_networkID_parameter_is_provided.yml b/test/cassettes/openstack/compute/v2/public/list_addresses/leads_to_a_valid_response_when_a_networkID_parameter_is_provided.yml new file mode 100644 index 0000000..295c9a6 --- /dev/null +++ b/test/cassettes/openstack/compute/v2/public/list_addresses/leads_to_a_valid_response_when_a_networkID_parameter_is_provided.yml @@ -0,0 +1,167 @@ +--- +http_interactions: +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"passwordCredentials":{"username":"","password":""},"tenantName":""}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '2701' + date: + - Sat, 07 Sep 2013 01:25:11 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-09-07T01:25:11.854217", + "expires": "2013-09-07T07:25:11Z", "id": "f92e36d540b541ab9346c9b9167f7e24", + "tenant": {"description": "", "enabled": true, + "id": "eb87dfa8fdec48678b0f0b0f80b44677", "name": ""}}, + "serviceCatalog": [{"endpoints": [{"adminURL": ":8774/v2/eb87dfa8fdec48678b0f0b0f80b44677", + "region": "RegionOne", "internalURL": ":8774/v2/eb87dfa8fdec48678b0f0b0f80b44677", + "id": "430279a1221947c3ae56339b069f1b34", "publicURL": ":8774/v2/eb87dfa8fdec48678b0f0b0f80b44677"}], + "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": + ":9292", "region": "RegionOne", "internalURL": ":9292", + "id": "0704bbb682c349cd8bad917183e7a7dd", "publicURL": ":9292"}], + "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": + ":8777", "region": "RegionOne", "internalURL": ":8777", + "id": "94a8dead81c34afbaa8ae5e163b8b0c5", "publicURL": ":8777"}], + "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": + [{"adminURL": ":8776/v1/eb87dfa8fdec48678b0f0b0f80b44677", + "region": "RegionOne", "internalURL": ":8776/v1/eb87dfa8fdec48678b0f0b0f80b44677", + "id": "2aedb2fe28114b86a13c48e8bef42b77", "publicURL": ":8776/v1/eb87dfa8fdec48678b0f0b0f80b44677"}], + "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": + [{"adminURL": ":8773/services/Admin", "region": + "RegionOne", "internalURL": ":8773/services/Cloud", + "id": "308574230d4a427a996d1f9c6e602e14", "publicURL": ":8773/services/Cloud"}], + "endpoints_links": [], "type": "ec2", "name": "nova_ec2"}, {"endpoints": [{"adminURL": + ":35357/v2.0", "region": "RegionOne", "internalURL": + ":5000/v2.0", "id": "04e2c1aa204048529cd859b111362d46", + "publicURL": ":5000/v2.0"}], "endpoints_links": + [], "type": "identity", "name": "keystone"}], "user": {"username": "", + "roles_links": [], "id": "400351b4991d40d79434539b4cee9d36", "roles": [{"name": + "_member_"}, {"name": "Member"}], "name": ""}, + "metadata": {"is_admin": 0, "roles": ["9fe2ff9ee4384b1894a90878d3e92bab", + "972b832749e5458cafe44d40d5b0e895"]}}}' + http_version: + recorded_at: Sat, 07 Sep 2013 01:25:12 GMT +- request: + method: get + uri: :8774/v2/eb87dfa8fdec48678b0f0b0f80b44677/servers + body: + encoding: US-ASCII + string: '' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + X-Auth-Token: + - f92e36d540b541ab9346c9b9167f7e24 + response: + status: + code: 200 + message: + headers: + x-compute-request-id: + - req-44b04237-2da3-45de-982d-e70a8f8eacd7 + content-type: + - application/json + content-length: + - '390' + date: + - Sat, 07 Sep 2013 01:25:13 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"servers": [{"id": "7ff01c2a-325d-4c05-ac77-5f76df18962a", "links": + [{"href": ":8774/v2/eb87dfa8fdec48678b0f0b0f80b44677/servers/7ff01c2a-325d-4c05-ac77-5f76df18962a", + "rel": "self"}, {"href": ":8774/eb87dfa8fdec48678b0f0b0f80b44677/servers/7ff01c2a-325d-4c05-ac77-5f76df18962a", + "rel": "bookmark"}], "name": "Aviator Testing"}]}' + http_version: + recorded_at: Sat, 07 Sep 2013 01:25:13 GMT +- request: + method: get + uri: :8774/v2/eb87dfa8fdec48678b0f0b0f80b44677/servers/7ff01c2a-325d-4c05-ac77-5f76df18962a/ips + body: + encoding: US-ASCII + string: '' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + X-Auth-Token: + - f92e36d540b541ab9346c9b9167f7e24 + response: + status: + code: 200 + message: + headers: + x-compute-request-id: + - req-458cab2e-e23c-4bc6-93ff-9e50ab8833aa + content-type: + - application/json + content-length: + - '108' + date: + - Sat, 07 Sep 2013 01:25:14 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"addresses": {"novanetwork_5": [{"version": 4, "addr": "10.3.5.3"}, + {"version": 4, "addr": "10.50.3.43"}]}}' + http_version: + recorded_at: Sat, 07 Sep 2013 01:25:15 GMT +- request: + method: get + uri: :8774/v2/eb87dfa8fdec48678b0f0b0f80b44677/servers/7ff01c2a-325d-4c05-ac77-5f76df18962a/ips/novanetwork_5 + body: + encoding: US-ASCII + string: '' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + X-Auth-Token: + - f92e36d540b541ab9346c9b9167f7e24 + response: + status: + code: 200 + message: + headers: + x-compute-request-id: + - req-c27e1e00-8843-4664-b6a3-68bae4075f1e + content-type: + - application/json + content-length: + - '93' + date: + - Sat, 07 Sep 2013 01:25:15 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"novanetwork_5": [{"version": 4, "addr": "10.3.5.3"}, {"version": + 4, "addr": "10.50.3.43"}]}' + http_version: + recorded_at: Sat, 07 Sep 2013 01:25:15 GMT +recorded_with: VCR 2.5.0