Class: Fog::Brightbox::Compute::Volume

Inherits:
Model
  • Object
show all
Includes:
ResourceLocking
Defined in:
lib/fog/brightbox/models/compute/volume.rb

Instance Method Summary collapse

Methods included from ResourceLocking

#lock!, #locked?, #unlock!

Methods included from ModelHelper

#collection_name, #resource_name

Instance Method Details

#attach(server) ⇒ Object



37
38
39
40
41
42
# File 'lib/fog/brightbox/models/compute/volume.rb', line 37

def attach(server)
  requires :identity
  data = service.attach_volume(identity, server: server.id)
  merge_attributes(data)
  true
end

#attached?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fog/brightbox/models/compute/volume.rb', line 44

def attached?
  state == "attached"
end

#copy(options = {}) ⇒ Fog::Compute::Volume

Returns a new model for the copy.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :delete_with_server (Boolean)

    Set true the volume will be removed if attached to a server that is deleted

  • :description (String)
  • :name (String)
  • :serial (String)

Returns:

  • (Fog::Compute::Volume)

    a new model for the copy



55
56
57
58
59
# File 'lib/fog/brightbox/models/compute/volume.rb', line 55

def copy(options = {})
  requires :identity
  data = service.copy_volume(identity, options)
  service.volumes.new(data)
end

#creating?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/fog/brightbox/models/compute/volume.rb', line 61

def creating?
  state == "creating"
end

#deleted?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fog/brightbox/models/compute/volume.rb', line 65

def deleted?
  state == "deleted"
end

#deleting?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fog/brightbox/models/compute/volume.rb', line 69

def deleting?
  state == "deleting"
end

#destroyObject



143
144
145
146
147
148
# File 'lib/fog/brightbox/models/compute/volume.rb', line 143

def destroy
  requires :identity
  data = service.delete_volume(identity)
  merge_attributes(data)
  true
end

#detachObject



73
74
75
76
77
78
# File 'lib/fog/brightbox/models/compute/volume.rb', line 73

def detach
  requires :identity
  data = service.detach_volume(identity)
  merge_attributes(data)
  true
end

#detached?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/fog/brightbox/models/compute/volume.rb', line 80

def detached?
  state == "detached"
end

#failed?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/fog/brightbox/models/compute/volume.rb', line 84

def failed?
  state == "failed"
end

#finished?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fog/brightbox/models/compute/volume.rb', line 88

def finished?
  deleted? || failed?
end

#ready?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/fog/brightbox/models/compute/volume.rb', line 92

def ready?
  attached? || detached?
end

#resize(options) ⇒ Object

Parameters:

  • options (Hash)

Options Hash (options):

  • :to (Integer)

    The new size in MiB to change the volume to



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fog/brightbox/models/compute/volume.rb', line 98

def resize(options)
  requires :identity

  # The API requires the old "from" size to avoid acting on stale data
  # We can merge this and if the API rejects the request, the model was out of sync
  options.merge!(:from => size)

  data = service.resize_volume(identity, options)
  merge_attributes(data)
  true
end

#saveObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fog/brightbox/models/compute/volume.rb', line 110

def save
  if persisted?
    options = {
      :delete_with_server => delete_with_server,
      :description => description,
      :name => name,
      :serial => serial
    }.delete_if { |_k, v| v.nil? || v == "" }

    data = service.update_volume(identity, options)
  else
    raise Fog::Errors::Error.new("'image_id' and 'filesystem_type' are mutually exclusive") if image_id && filesystem_type
    raise Fog::Errors::Error.new("'image_id' or 'filesystem_type' is required") unless image_id || filesystem_type

    options = {
      :delete_with_server => delete_with_server,
      :description => description,
      :filesystem_label => filesystem_label,
      :filesystem_type => filesystem_type,
      :name => name,
      :serial => serial,
      :size => size
    }.delete_if { |_k, v| v.nil? || v == "" }

    options.merge!(:image => image_id) unless image_id.nil? || image_id == ""

    data = service.create_volume(options)
  end

  merge_attributes(data)
  true
end