Skip to content

Commit 643f73c

Browse files
committed
Merge pull request #27 from zhitongLBN/create_volume_with_additional_option
add volume type and metadata options in create_volume
2 parents 988ccdc + d4e9a08 commit 643f73c

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

lib/fog/openstack/requests/compute/create_volume.rb

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#
12
module Fog
23
module Compute
34
class OpenStack
5+
#
46
class Real
5-
def create_volume(name, description, size, options={})
7+
def create_volume(name, description, size, options = {})
68
data = {
79
'volume' => {
810
'display_name' => name,
@@ -11,38 +13,43 @@ def create_volume(name, description, size, options={})
1113
}
1214
}
1315

14-
vanilla_options = [:snapshot_id, :availability_zone]
15-
vanilla_options.select{|o| options[o]}.each do |key|
16+
vanilla_options = [
17+
:snapshot_id,
18+
:availability_zone,
19+
:volume_type,
20+
:metadata]
21+
22+
vanilla_options.select { |o| options[o] }.each do |key|
1623
data['volume'][key] = options[key]
1724
end
25+
1826
request(
19-
:body => Fog::JSON.encode(data),
20-
:expects => [200, 202],
21-
:method => 'POST',
22-
:path => "os-volumes"
27+
:body => Fog::JSON.encode(data),
28+
:expects => [200, 202],
29+
:method => 'POST',
30+
:path => 'os-volumes'
2331
)
2432
end
2533
end
2634

35+
#
2736
class Mock
28-
def create_volume(name, description, size, options={})
37+
def create_volume(name, description, size, options = {})
2938
response = Excon::Response.new
3039
response.status = 202
31-
data = {
32-
'id' => Fog::Mock.random_numbers(2),
33-
'displayName' => name,
34-
'displayDescription' => description,
35-
'size' => size,
36-
'status' => 'creating',
37-
'snapshotId' => options[:snapshot_id],
38-
'volumeType' => 'None',
39-
'availabilityZone' => options[:availability_zone] || 'nova',
40-
'createdAt' => Time.now.strftime('%FT%T.%6N'),
41-
'attachments' => [],
42-
'metadata' => {}
40+
data = {'id' => Fog::Mock.random_numbers(2),
41+
'displayName' => name,
42+
'displayDescription' => description,
43+
'size' => size,
44+
'status' => 'creating',
45+
'snapshotId' => options[:snapshot_id],
46+
'volumeType' => options[:volume_type] || 'None',
47+
'availabilityZone' => options[:availability_zone] || 'nova',
48+
'createdAt' => Time.now.strftime('%FT%T.%6N'),
49+
'attachments' => [], 'metadata' => options[:metadata] || {}
4350
}
4451
self.data[:volumes][data['id']] = data
45-
response.body = { 'volume' => data }
52+
response.body = {'volume' => data}
4653
response
4754
end
4855
end

0 commit comments

Comments
 (0)