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



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

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

#attached?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fog/brightbox/models/compute/volume.rb', line 46

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



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

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

#creating?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/fog/brightbox/models/compute/volume.rb', line 63

def creating?
  state == "creating"
end

#deleted?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/fog/brightbox/models/compute/volume.rb', line 67

def deleted?
  state == "deleted"
end

#deleting?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fog/brightbox/models/compute/volume.rb', line 71

def deleting?
  state == "deleting"
end

#destroyObject



146
147
148
149
150
151
# File 'lib/fog/brightbox/models/compute/volume.rb', line 146

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

#detachObject



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

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

#detached?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/fog/brightbox/models/compute/volume.rb', line 82

def detached?
  state == "detached"
end

#failed?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/fog/brightbox/models/compute/volume.rb', line 86

def failed?
  state == "failed"
end

#finished?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/fog/brightbox/models/compute/volume.rb', line 90

def finished?
  deleted? || failed?
end

#ready?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/fog/brightbox/models/compute/volume.rb', line 94

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



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

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[:from] = size

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

#saveObject



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
142
143
144
# File 'lib/fog/brightbox/models/compute/volume.rb', line 112

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, "'image_id' and 'filesystem_type' are mutually exclusive" if image_id && filesystem_type
    raise Fog::Errors::Error, "'image_id' or 'filesystem_type' is required" unless image_id || filesystem_type

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

    options[:image] = image_id unless image_id.nil? || image_id == ""

    data = service.create_volume(options)
  end

  merge_attributes(data)
  true
end