mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
![Paul Thornthwaite](/assets/img/avatar_default.png)
The 'connection' accessor in collections and models actually refered to a subclassed instance of Fog::Service which creates confusion in the code. References to 'connection' could have meant the service or the Fog::Connection held within that service. This deprecates the connection accessor and replaces it with `#service` as a read only value. When a collection or model is initalised then service should be passed. This commit also updates all the changes to @connection made by providers in model initialisers since these depending on the presence of the 'connection' key. The key is still accepted by outputs a warning.
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
require 'fog/core/model'
|
|
|
|
module Fog
|
|
module Compute
|
|
class OpenStack
|
|
class Flavor < Fog::Model
|
|
identity :id
|
|
|
|
attribute :name
|
|
attribute :ram
|
|
attribute :disk
|
|
attribute :vcpus
|
|
attribute :links
|
|
attribute :swap
|
|
attribute :rxtx_factor
|
|
attribute :ephemeral, :aliases => 'OS-FLV-EXT-DATA:ephemeral'
|
|
attribute :is_public, :aliases => 'os-flavor-access:is_public'
|
|
attribute :disabled, :aliases => 'OS-FLV-DISABLED:disabled'
|
|
|
|
def initialize(attributes)
|
|
# Old 'connection' is renamed as service and should be used instead
|
|
prepare_service_value(attributes)
|
|
super
|
|
end
|
|
|
|
def save
|
|
requires :name, :ram, :vcpus, :disk
|
|
attributes[:ephemeral] = self.ephemeral || 0
|
|
attributes[:is_public] = self.is_public || false
|
|
attributes[:disabled] = self.disabled || false
|
|
attributes[:swap] = self.swap || 0
|
|
attributes[:rxtx_factor] = self.rxtx_factor || 1.0
|
|
merge_attributes(connection.create_flavor(self.attributes).body['flavor'])
|
|
self
|
|
end
|
|
|
|
def destroy
|
|
requires :id
|
|
connection.delete_flavor(self.id)
|
|
true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|