openstack 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -1
- data/VERSION +1 -1
- data/lib/openstack.rb +1 -0
- data/lib/openstack/connection.rb +3 -1
- data/lib/openstack/image/connection.rb +16 -0
- data/lib/openstack/volume/connection.rb +41 -8
- data/lib/openstack/volume/snapshot.rb +25 -0
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -195,7 +195,7 @@ See the class definitions for documentation on specific methods and operations.
|
|
195
195
|
>> os.detach_volume(704289, 90805)
|
196
196
|
=> true
|
197
197
|
|
198
|
-
== Examples for Volumes:
|
198
|
+
== Examples for Volumes and Snaphots:
|
199
199
|
|
200
200
|
#NOTE - attach/detach operations are implemented for the compute service as the OS API defines these operations as extensions to Openstack Compute.
|
201
201
|
|
@@ -227,6 +227,21 @@ See the class definitions for documentation on specific methods and operations.
|
|
227
227
|
>> vs.delete_volume(90805)
|
228
228
|
=> true
|
229
229
|
|
230
|
+
# Create a snapshot: - must specify display_name and volume_id parameters... optionally also :display_description
|
231
|
+
>> vs.create_snapshot({:volume_id=>"3b38b570-a4ff-4444-984a-3566cbdc8ab2", :display_name=>"marios_snapshot"})
|
232
|
+
=> #<OpenStack::Volume::Snapshot:0xa0cfea4 @id=223, @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23 14:25:02.654217">
|
233
|
+
|
234
|
+
# List snapshots: - aliased as just 'snapshots' ... vs.snapshots
|
235
|
+
>> vs.list_snapshots
|
236
|
+
=> [#<OpenStack::Volume::Snapshot:0x9a6e4fc @id="0e76dacb-2fcf-4565-84a3-aa3d7bd16224", @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23T14:18:13.000000">]
|
237
|
+
|
238
|
+
# Get a specific snapshot: - aliased as 'snapshot'
|
239
|
+
>> vs.get_snapshot("0e76dacb-2fcf-4565-84a3-aa3d7bd16224")
|
240
|
+
=> #<OpenStack::Volume::Snapshot:0x9a890b8 @id="0e76dacb-2fcf-4565-84a3-aa3d7bd16224", @display_name="marios_snapshot", @display_description=nil, @volume_id="3b38b570-a4ff-4444-984a-3566cbdc8ab2", @status="creating", @size=1, @created_at="2013-01-23T14:18:13.000000">
|
241
|
+
|
242
|
+
# Delete a snapshot:
|
243
|
+
>> vs.delete_snapshot("0e76dacb-2fcf-4565-84a3-aa3d7bd16224")
|
244
|
+
=> true
|
230
245
|
|
231
246
|
== Examples for Object-Store:
|
232
247
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.8
|
data/lib/openstack.rb
CHANGED
data/lib/openstack/connection.rb
CHANGED
@@ -65,7 +65,9 @@ class Connection
|
|
65
65
|
OpenStack::Swift::Connection.new(connection)
|
66
66
|
when "volume"
|
67
67
|
OpenStack::Volume::Connection.new(connection)
|
68
|
-
|
68
|
+
when "image"
|
69
|
+
OpenStack::Image::Connection.new(connection)
|
70
|
+
else
|
69
71
|
raise Exception::InvalidArgument, "Invalid :service_type parameter: #{@service_type}"
|
70
72
|
end
|
71
73
|
end
|
@@ -9,7 +9,8 @@ module Volume
|
|
9
9
|
def initialize(connection)
|
10
10
|
@connection = connection
|
11
11
|
OpenStack::Authentication.init(@connection)
|
12
|
-
@volumes_native, @volume_path = check_if_native
|
12
|
+
@volumes_native, @volume_path = check_if_native("volumes")
|
13
|
+
@snapshots_native, @snapshot_path = check_if_native("snapshots")
|
13
14
|
end
|
14
15
|
|
15
16
|
# Returns true if the authentication was successful and returns false otherwise.
|
@@ -27,6 +28,7 @@ module Volume
|
|
27
28
|
raise OpenStack::Exception::MissingArgument, ":display_name and :size must be specified to create a volume" unless (options[:display_name] && options[:size])
|
28
29
|
data = JSON.generate(:volume => options)
|
29
30
|
response = @connection.csreq("POST",@connection.service_host,"#{@connection.service_path}/#{@volume_path}",@connection.service_port,@connection.service_scheme,{'content-type' => 'application/json'},data)
|
31
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
30
32
|
volume_info = JSON.parse(response.body)["volume"]
|
31
33
|
volume = OpenStack::Volume::Volume.new(volume_info)
|
32
34
|
end
|
@@ -53,32 +55,63 @@ module Volume
|
|
53
55
|
true
|
54
56
|
end
|
55
57
|
|
56
|
-
|
58
|
+
def list_snapshots
|
59
|
+
response = @connection.req("GET", "/#{@snapshot_path}")
|
60
|
+
snapshot_hash = JSON.parse(response.body)["snapshots"]
|
61
|
+
snapshot_hash.inject([]){|res, current| res << OpenStack::Volume::Snapshot.new(current); res}
|
62
|
+
end
|
63
|
+
alias :snapshots :list_snapshots
|
64
|
+
|
65
|
+
def get_snapshot(snap_id)
|
66
|
+
response = @connection.req("GET", "/#{@snapshot_path}/#{snap_id}")
|
67
|
+
snapshot_hash = JSON.parse(response.body)["snapshot"]
|
68
|
+
OpenStack::Volume::Snapshot.new(snapshot_hash)
|
69
|
+
end
|
70
|
+
alias :snapshot :get_snapshot
|
71
|
+
|
72
|
+
#require params: {:display_name, :volume_id}
|
73
|
+
#optional params: {:display_description, :metadata=>{:key=>val, ...}, :availability_zone, :volume_type }
|
74
|
+
#returns OpenStack::Volume::Snapshot object
|
75
|
+
def create_snapshot(options)
|
76
|
+
raise OpenStack::Exception::MissingArgument, ":volume_id and :display_name must be specified to create a snapshot" unless (options[:display_name] && options[:volume_id])
|
77
|
+
#:force documented in API but not explained... clarify (fails without)
|
78
|
+
options.merge!({:force=>"true"})
|
79
|
+
data = JSON.generate(:snapshot => options)
|
80
|
+
response = @connection.csreq("POST",@connection.service_host,"#{@connection.service_path}/#{@snapshot_path}",@connection.service_port,@connection.service_scheme,{'content-type' => 'application/json'},data)
|
81
|
+
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
|
82
|
+
snapshot_info = JSON.parse(response.body)["snapshot"]
|
83
|
+
OpenStack::Volume::Snapshot.new(snapshot_info)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_snapshot(snap_id)
|
87
|
+
@connection.req("DELETE", "/#{@snapshot_path}/#{snap_id}")
|
88
|
+
true
|
89
|
+
end
|
57
90
|
|
58
91
|
private
|
59
92
|
|
60
93
|
#fudge... not clear if volumes support is available as 'native' volume API or
|
61
94
|
#as the os-volumes extension. Need to probe to find out (for now)
|
62
95
|
#see https://lists.launchpad.net/openstack/msg16601.html
|
63
|
-
def check_if_native
|
96
|
+
def check_if_native(entity) #volumes or snapshots
|
64
97
|
native = extension = false
|
65
98
|
#check if 'native' volume API present:
|
66
99
|
begin
|
67
|
-
response = @connection.req("GET", "
|
100
|
+
response = @connection.req("GET", "/#{entity}")
|
68
101
|
native = true if response.code.match(/^20.$/)
|
69
|
-
return true,
|
102
|
+
return true, entity
|
70
103
|
rescue OpenStack::Exception::ItemNotFound => not_found
|
71
104
|
native = false
|
72
105
|
end
|
73
106
|
#check if available as extension:
|
74
107
|
begin
|
75
|
-
response = @connection.req("GET", "/os
|
108
|
+
response = @connection.req("GET", "/os-#{entity}")
|
76
109
|
extension = true if response.code.match(/^20.$/)
|
77
|
-
return false, "os
|
110
|
+
return false, "os-#{entity}"
|
78
111
|
rescue OpenStack::Exception::ItemNotFound => not_found
|
79
112
|
extension = false
|
80
113
|
end
|
81
|
-
raise OpenStack::Exception::NotImplemented.new("No Volumes support for this provider", 501, "No
|
114
|
+
raise OpenStack::Exception::NotImplemented.new("No Volumes support for this provider", 501, "No #{entity} Support") unless (native || extension)
|
82
115
|
end
|
83
116
|
|
84
117
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenStack
|
2
|
+
module Volume
|
3
|
+
class Snapshot
|
4
|
+
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :display_name
|
7
|
+
attr_reader :display_description
|
8
|
+
attr_reader :volume_id
|
9
|
+
attr_reader :status
|
10
|
+
attr_reader :size
|
11
|
+
attr_reader :created_at
|
12
|
+
|
13
|
+
def initialize(snap_info)
|
14
|
+
@id = snap_info["id"]
|
15
|
+
@display_name = snap_info["display_name"] || snap_info["displayName"]
|
16
|
+
@display_description = snap_info["display_description"] || snap_info["displayDescription"]
|
17
|
+
@volume_id = snap_info["volume_id"] || snap_info["volumeId"]
|
18
|
+
@status = snap_info["status"]
|
19
|
+
@size = snap_info["size"]
|
20
|
+
@created_at = snap_info["created_at"] || snap_info["createdAt"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mocha
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/openstack/compute/personalities.rb
|
82
82
|
- lib/openstack/compute/server.rb
|
83
83
|
- lib/openstack/connection.rb
|
84
|
+
- lib/openstack/image/connection.rb
|
84
85
|
- lib/openstack/swift/connection.rb
|
85
86
|
- lib/openstack/swift/container.rb
|
86
87
|
- lib/openstack/swift/storage_object.rb
|