Skip to content

Commit

Permalink
Adding OpenStack volume availability_zones
Browse files Browse the repository at this point in the history
Adding OpenStack volume availability_zones
  • Loading branch information
Ladas committed Jul 29, 2015
1 parent 6e8760e commit 7d8e1dd
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/fog/openstack/models/volume/availability_zone.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions lib/fog/openstack/models/volume/availability_zones.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions lib/fog/openstack/requests/volume/list_zones.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/fog/openstack/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class OpenStack < Fog::Service
model :volume
collection :volumes

model :availability_zone
collection :availability_zones

model :volume_type
collection :volume_types

Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions tests/openstack/requests/volume/availability_zone_tests.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7d8e1dd

Please sign in to comment.