class ProfitBricks::Volume
Volume
class
Public Class Methods
Create a new volume.
Parameters¶ ↑
-
options
<Hash>:-
name
<String> - Optional, name of the volume -
size
<Integer> - Required, size of the volume in GB -
type
<String> - Required, the volume type (HDD or SSD) -
bus
<String> - Optional, the bus type of the volume-
VIRTIO
- Default -
IDE
-
-
image
<String> - Optional, image or snapshot ID -
sshKeys
<Array> - Optional, a list of public SSH keys
-
Returns¶ ↑
-
id
<String> - Universally unique identifer of resource -
type
<String> -Resource
type -
href
<String> -Resource
URL representation -
metadata
<Hash>:-
lastModifiedDate
-
lastModifiedBy
-
createdDate
-
createdBy
-
state
-
etag
-
-
properties
<Hash>:-
name
<String> -
size
<Integer> -
bus
<String> -
image
<String> -
imagePassword
<String> -
type
<String> -
licenseType
<String> -
cpuHotPlug
<Boolean> -
cpuHotUnPlug
<Boolean> -
ramHotPlug
<Boolean> -
ramHotUnPlug
<Boolean> -
nicHotPlug
<Boolean> -
nicHotUnPlug
<Boolean> -
discVirtioHotPlug
<Boolean> -
discVirtioHotUnPlug
<Boolean> -
discScsiHotPlug
<Boolean> -
discScsiHotUnPlug
<Boolean> -
sshKeys
<Array>
-
# File lib/profitbricks/volume.rb, line 158 def create(datacenter_id, options = {}) response = ProfitBricks.request( method: :post, path: "/datacenters/#{datacenter_id}/volumes", expects: 202, body: { properties: options }.to_json ) add_parent_identities(response) instantiate_objects(response) end
Retrieve a datacenter volume.
# File lib/profitbricks/volume.rb, line 186 def get(datacenter_id, server_id = nil, volume_id) path = if server_id.nil? "/datacenters/#{datacenter_id}/volumes/#{volume_id}" else "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes/#{volume_id}" end response = ProfitBricks.request( method: :get, path: path, expects: 200 ) add_parent_identities(response) instantiate_objects(response) end
List all datacenter volumes.
# File lib/profitbricks/volume.rb, line 170 def list(datacenter_id, server_id = nil) path = if server_id.nil? "/datacenters/#{datacenter_id}/volumes" else "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes" end response = ProfitBricks.request( method: :get, path: path, expects: 200 ) add_parent_identities(response) instantiate_objects(response) end
Public Instance Methods
Attach volume to server.
# File lib/profitbricks/volume.rb, line 31 def attach(server_id) ProfitBricks.request( method: :post, path: "/datacenters/#{datacenterId}/servers/#{server_id}/volumes", expects: 202, body: { id: id }.to_json ) self end
Create volume snapshot.
Parameters¶ ↑
-
options
<Hash>:-
name
<String> - Optional, name of the snapshot -
description
<String> - Optional, description of the snapshot
-
Returns¶ ↑
-
id
<String> - Universally unique identifer of resource -
type
<String> -Resource
type -
href
<String> -Resource
URL representation -
metadata
<Hash>:-
lastModifiedDate
-
lastModifiedBy
-
createdDate
-
createdBy
-
state
-
etag
-
-
properties
<Hash>:-
name
<Integer> -
description
<Array> -
location
<String> -
cpuHotPlug
<Boolean> -
cpuHotUnPlug
<Boolean> -
ramHotPlug
<Boolean> -
ramHotUnPlug
<Boolean> -
nicHotPlug
<Boolean> -
nicHotUnPlug
<Boolean> -
discVirtioHotPlug
<Boolean> -
discVirtioHotUnPlug
<Boolean> -
discScsiHotPlug
<Boolean> -
discScsiHotUnPlug
<Boolean> -
licenceType
<String>
-
# File lib/profitbricks/volume.rb, line 84 def create_snapshot(options = {}) response = ProfitBricks.request( method: :post, path: "/datacenters/#{datacenterId}/volumes/#{id}/create-snapshot", headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, expects: 202, body: URI.encode_www_form(options) ) ProfitBricks::Snapshot.new(response) end
Delete the volume.
# File lib/profitbricks/volume.rb, line 5 def delete response = ProfitBricks.request( method: :delete, path: "/datacenters/#{datacenterId}/volumes/#{id}", expects: 202 ) self.requestId = response[:requestId] self end
Detach volume from server.
# File lib/profitbricks/volume.rb, line 42 def detach(server_id) ProfitBricks.request( method: :delete, path: "/datacenters/#{datacenterId}/servers/#{server_id}/volumes/#{id}", expects: 202 ) end
Restore snapshot to volume.
Parameters¶ ↑
-
snapshot_id
<String>: Universally unique identifer of snapshot resource
Returns¶ ↑
-
true
<Boolean>
# File lib/profitbricks/volume.rb, line 103 def restore_snapshot(snapshot_id) ProfitBricks.request( method: :post, path: "/datacenters/#{datacenterId}/volumes/#{id}/restore-snapshot", headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, expects: 202, body: URI.encode_www_form(snapshotId: snapshot_id) ) end
Update the volume.
# File lib/profitbricks/volume.rb, line 16 def update(options = {}) response = ProfitBricks.request( method: :patch, path: "/datacenters/#{datacenterId}/volumes/#{id}", expects: 202, body: options.to_json ) if response self.requestId = response['requestId'] @properties = @properties.merge(response['properties']) end self end