diff --git a/lib/fog/openstack/models/volume/availability_zone.rb b/lib/fog/openstack/models/volume/availability_zone.rb new file mode 100644 index 0000000000..f32a470eb7 --- /dev/null +++ b/lib/fog/openstack/models/volume/availability_zone.rb @@ -0,0 +1,13 @@ +require 'fog/openstack/models/model' + +module Fog + module Volume + class OpenStack + class AvailabilityZone < Fog::OpenStack::Model + identity :zoneName + + attribute :zoneState + end + end + end +end diff --git a/lib/fog/openstack/models/volume/availability_zones.rb b/lib/fog/openstack/models/volume/availability_zones.rb new file mode 100644 index 0000000000..cdabc821b8 --- /dev/null +++ b/lib/fog/openstack/models/volume/availability_zones.rb @@ -0,0 +1,17 @@ +require 'fog/openstack/models/collection' +require 'fog/openstack/models/volume/availability_zone' + +module Fog + module Volume + class OpenStack + class AvailabilityZones < Fog::OpenStack::Collection + model Fog::Volume::OpenStack::AvailabilityZone + + def all(options = {}) + data = service.list_zones(options) + load_response(data, 'availabilityZoneInfo') + end + end + end + end +end diff --git a/lib/fog/openstack/requests/volume/list_zones.rb b/lib/fog/openstack/requests/volume/list_zones.rb new file mode 100644 index 0000000000..9e92a5068d --- /dev/null +++ b/lib/fog/openstack/requests/volume/list_zones.rb @@ -0,0 +1,32 @@ +module Fog + module Volume + class OpenStack + class Real + def list_zones(options = {}) + request( + :expects => 200, + :method => 'GET', + :path => 'os-availability-zone.json', + :query => options + ) + end + end + + class Mock + def list_zones(options = {}) + Excon::Response.new( + :body => { + "availabilityZoneInfo" => [ + { + "zoneState" => { "available" => true }, + "zoneName" => "nova" + } + ] + }, + :status => 200 + ) + end + end + end + end +end diff --git a/lib/fog/openstack/volume.rb b/lib/fog/openstack/volume.rb index d54b6b7eb9..af3aa53af8 100644 --- a/lib/fog/openstack/volume.rb +++ b/lib/fog/openstack/volume.rb @@ -15,6 +15,9 @@ class OpenStack < Fog::Service model :volume collection :volumes + model :availability_zone + collection :availability_zones + model :volume_type collection :volume_types @@ -31,6 +34,8 @@ class OpenStack < Fog::Service request :extend_volume request :delete_volume + request :list_zones + request :list_volume_types request :get_volume_type_details diff --git a/tests/openstack/requests/volume/availability_zone_tests.rb b/tests/openstack/requests/volume/availability_zone_tests.rb new file mode 100644 index 0000000000..d9f6045601 --- /dev/null +++ b/tests/openstack/requests/volume/availability_zone_tests.rb @@ -0,0 +1,13 @@ +Shindo.tests('Fog::Volume[:openstack] | availability zone requests', ['openstack']) do + + @flavor_format = { + 'zoneName' => String, + 'zoneState' => Hash, + } + + tests('success') do + tests('#list_zones').data_matches_schema({'availabilityZoneInfo' => [@flavor_format]}) do + Fog::Volume[:openstack].list_zones.body + end + end +end