mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Make use of #persisted? method
In many places we were checking for identity which was the shorthand for checking if the resource had been saved by the service. The #persisted? method was added to show a clearer intent and also offer minimal ActiveModel interface
This commit is contained in:
parent
3c6bf2d552
commit
40c0cd7122
43 changed files with 46 additions and 46 deletions
|
@ -29,7 +29,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :paths, :caller_reference
|
||||
raise "Submitted invalidation cannot be submitted again" if identity
|
||||
raise "Submitted invalidation cannot be submitted again" if persisted?
|
||||
response = connection.post_invalidation(distribution.identity, paths, caller_reference)
|
||||
merge_attributes(invalidation_to_attributes(response.body))
|
||||
true
|
||||
|
|
|
@ -39,7 +39,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
data = connection.allocate_address(domain).body
|
||||
new_attributes = data.reject {|key,value| key == 'requestId'}
|
||||
merge_attributes(new_attributes)
|
||||
|
|
|
@ -130,7 +130,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :image_id
|
||||
|
||||
options = {
|
||||
|
@ -224,7 +224,7 @@ module Fog
|
|||
#but in #save a merge_attribute is called after run_instance
|
||||
#thus making an un-necessary request. Use this until finding a clever solution
|
||||
def monitor=(new_monitor)
|
||||
if identity
|
||||
if persisted?
|
||||
case new_monitor
|
||||
when true
|
||||
response = connection.monitor_instances(identity)
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :volume_id
|
||||
|
||||
data = connection.create_snapshot(volume_id, description).body
|
||||
|
|
|
@ -39,7 +39,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :availability_zone
|
||||
requires_one :size, :snapshot_id
|
||||
|
||||
|
|
|
@ -71,11 +71,11 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :flavor_id, :image_id, :location_id
|
||||
options = {}
|
||||
|
||||
if identity.nil? # new record
|
||||
unless persisted? # new record
|
||||
raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
|
||||
options['ssh_public_key'] = public_key if public_key
|
||||
options['password'] = password if @password
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
attribute :account_id
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
options = {
|
||||
:name => name,
|
||||
:description => description
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
attribute :secret
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
options = {
|
||||
:name => name
|
||||
}.delete_if {|k,v| v.nil? || v == "" }
|
||||
|
|
|
@ -21,7 +21,7 @@ module Fog
|
|||
|
||||
# Sticking with existing Fog behaviour, save does not update but creates a new resource
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
options = {
|
||||
:server_group => server_group_id,
|
||||
:name => name,
|
||||
|
|
|
@ -24,7 +24,7 @@ module Fog
|
|||
|
||||
# Sticking with existing Fog behaviour, save does not update but creates a new resource
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :firewall_policy_id
|
||||
options = {
|
||||
:firewall_policy => firewall_policy_id,
|
||||
|
|
|
@ -39,7 +39,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :source, :arch
|
||||
options = {
|
||||
:source => source,
|
||||
|
|
|
@ -32,7 +32,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :nodes, :listeners, :healthcheck
|
||||
options = {
|
||||
:nodes => nodes,
|
||||
|
|
|
@ -156,7 +156,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :image_id
|
||||
options = {
|
||||
:image => image_id,
|
||||
|
@ -190,7 +190,7 @@ module Fog
|
|||
# FIXME Using side effect of wait_for's (evaluated block) to detect timeouts
|
||||
begin
|
||||
wait_for(20) { ! ready? }
|
||||
start
|
||||
start
|
||||
rescue Fog::Errors::Timeout => e
|
||||
false
|
||||
end
|
||||
|
|
|
@ -88,7 +88,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :image_id
|
||||
data = connection.create_server(image_id, attributes)
|
||||
merge_attributes(data.body['server'])
|
||||
|
|
|
@ -45,7 +45,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :server_id
|
||||
|
||||
data = connection.grid_server_add(server_id, 'name' => name)
|
||||
|
|
|
@ -35,7 +35,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :password_id
|
||||
data = connection.support_password_list()
|
||||
merge_attributes(data.body)
|
||||
|
|
|
@ -58,7 +58,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :name, :image_id, :memory, :public_ip_address
|
||||
options = {
|
||||
'isSandbox' => sandbox,
|
||||
|
|
|
@ -34,7 +34,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
data = connection.allocate_address.body['floating_ip']
|
||||
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
|
||||
merge_attributes(new_attributes)
|
||||
|
|
|
@ -161,7 +161,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :flavor_id, :image_id, :name
|
||||
options = {
|
||||
'metadata' => metadata,
|
||||
|
|
|
@ -81,7 +81,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :name, :offering_id, :format, :location_id, :size
|
||||
data = connection.create_volume(name, offering_id, format, location_id, size)
|
||||
merge_attributes(data.body)
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :server
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
@type, @image, @stack_script, @name, @password, @size =
|
||||
attributes.values_at :type, :image, :stack_script, :name, :password, :size
|
||||
create_disk
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :server
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
|
||||
connection.linode_ip_addprivate server.id
|
||||
server.ips.all.find { |ip| !ip.public }
|
||||
|
|
|
@ -43,7 +43,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
@data_center, @flavor, @image, @kernel, @type, @payment_terms, @stack_script, @name, @password, @callback =
|
||||
attributes.values_at :data_center, :flavor, :image, :kernel, :type, :payment_terms, :stack_script, :name, :password, :callback
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
data = connection.allocate_address(pool).body['floating_ip']
|
||||
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
|
||||
merge_attributes(new_attributes)
|
||||
|
|
|
@ -226,7 +226,7 @@ module Fog
|
|||
|
||||
# TODO: Implement /os-volumes-boot support with 'block_device_mapping'
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :flavor_ref, :image_ref, :name
|
||||
meta_hash = {}
|
||||
metadata.each { |meta| meta_hash.store(meta.key, meta.value) }
|
||||
|
|
|
@ -25,7 +25,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :name, :tenant_id, :password
|
||||
enabled = true if enabled.nil?
|
||||
data = connection.create_user(name, password, email, tenant_id, enabled)
|
||||
|
|
|
@ -116,7 +116,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
connection.update_vm(attributes)
|
||||
else
|
||||
self.id = connection.create_vm(attributes).id
|
||||
|
|
|
@ -45,7 +45,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
connection.client.create_template(attributes)
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
|||
|
||||
def save(force = false)
|
||||
requires :volume_id
|
||||
raise IdentifierTaken.new('Resaving may cause a duplicate snapshot to be created') if identity
|
||||
raise IdentifierTaken.new('Resaving may cause a duplicate snapshot to be created') if persisted?
|
||||
data = connection.create_snapshot(volume_id, {
|
||||
:display_name => display_name,
|
||||
:display_description => display_description,
|
||||
|
|
|
@ -42,7 +42,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :size
|
||||
raise IdentifierTaken.new('Resaving may cause a duplicate volume to be created') if identity
|
||||
raise IdentifierTaken.new('Resaving may cause a duplicate volume to be created') if persisted?
|
||||
data = connection.create_volume(size, {
|
||||
:display_name => display_name,
|
||||
:display_description => display_description,
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :server_id
|
||||
|
||||
data = connection.create_image(server_id, 'name' => name)
|
||||
|
|
|
@ -66,7 +66,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :flavor_id, :image_id
|
||||
options = {
|
||||
'metadata' => metadata,
|
||||
|
|
|
@ -45,7 +45,7 @@ module Fog
|
|||
attr_reader :password
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
update
|
||||
else
|
||||
create
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
update
|
||||
else
|
||||
create
|
||||
|
|
|
@ -35,7 +35,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
update
|
||||
else
|
||||
create
|
||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :username, :email, :enabled
|
||||
if identity.nil?
|
||||
unless persisted?
|
||||
data = connection.create_user(username, email, enabled, :password => password)
|
||||
else
|
||||
data = connection.update_user(identity, username, email, enabled, :password => password)
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :load_balancer, :address, :type
|
||||
connection.create_access_rule(load_balancer.id, address, type)
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
update
|
||||
else
|
||||
create
|
||||
|
|
|
@ -20,7 +20,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
if identity
|
||||
if persisted?
|
||||
update
|
||||
else
|
||||
create
|
||||
|
|
|
@ -18,7 +18,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :load_balancer, :type
|
||||
data = connection.create_virtual_ip(load_balancer.id, type)
|
||||
merge_attributes(data.body)
|
||||
|
|
|
@ -54,7 +54,7 @@ module Fog
|
|||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :name, :image_id, :processing_cores, :facility, :disk_size
|
||||
|
||||
data = connection.voxcloud_create({
|
||||
|
|
|
@ -165,7 +165,7 @@ module Fog
|
|||
|
||||
def save
|
||||
requires :name, :cluster, :datacenter
|
||||
if identity
|
||||
if persisted?
|
||||
raise "update is not supported yet"
|
||||
# connection.update_vm(attributes)
|
||||
else
|
||||
|
|
|
@ -45,7 +45,7 @@ module Fog
|
|||
options[:priority] = priority if priority
|
||||
options[:ttl] = ttl if ttl
|
||||
|
||||
if identity
|
||||
if persisted?
|
||||
options[:host_type] = type
|
||||
options[:data] = value
|
||||
connection.update_host(identity, options)
|
||||
|
|
Loading…
Add table
Reference in a new issue