From 40c0cd7122b87c4814ef531269c82c9b027239da Mon Sep 17 00:00:00 2001 From: Paul Thornthwaite Date: Sun, 23 Dec 2012 02:45:05 +0000 Subject: [PATCH] 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 --- lib/fog/aws/models/cdn/invalidation.rb | 2 +- lib/fog/aws/models/compute/address.rb | 2 +- lib/fog/aws/models/compute/server.rb | 4 ++-- lib/fog/aws/models/compute/snapshot.rb | 2 +- lib/fog/aws/models/compute/volume.rb | 2 +- lib/fog/bluebox/models/compute/server.rb | 4 ++-- lib/fog/brightbox/models/compute/api_client.rb | 2 +- lib/fog/brightbox/models/compute/application.rb | 2 +- lib/fog/brightbox/models/compute/firewall_policy.rb | 2 +- lib/fog/brightbox/models/compute/firewall_rule.rb | 2 +- lib/fog/brightbox/models/compute/image.rb | 2 +- lib/fog/brightbox/models/compute/load_balancer.rb | 2 +- lib/fog/brightbox/models/compute/server.rb | 4 ++-- lib/fog/clodo/models/compute/server.rb | 2 +- lib/fog/go_grid/models/compute/image.rb | 2 +- lib/fog/go_grid/models/compute/password.rb | 2 +- lib/fog/go_grid/models/compute/server.rb | 2 +- lib/fog/hp/models/compute/address.rb | 2 +- lib/fog/hp/models/compute/server.rb | 2 +- lib/fog/ibm/models/storage/volume.rb | 2 +- lib/fog/linode/models/compute/disk.rb | 2 +- lib/fog/linode/models/compute/ip.rb | 2 +- lib/fog/linode/models/compute/server.rb | 2 +- lib/fog/openstack/models/compute/address.rb | 2 +- lib/fog/openstack/models/compute/server.rb | 2 +- lib/fog/openstack/models/identity/user.rb | 2 +- lib/fog/ovirt/models/compute/server.rb | 2 +- lib/fog/ovirt/models/compute/template.rb | 2 +- lib/fog/rackspace/models/block_storage/snapshot.rb | 2 +- lib/fog/rackspace/models/block_storage/volume.rb | 2 +- lib/fog/rackspace/models/compute/image.rb | 2 +- lib/fog/rackspace/models/compute/server.rb | 2 +- lib/fog/rackspace/models/compute_v2/server.rb | 2 +- lib/fog/rackspace/models/dns/record.rb | 2 +- lib/fog/rackspace/models/dns/zone.rb | 2 +- lib/fog/rackspace/models/identity/user.rb | 2 +- lib/fog/rackspace/models/load_balancers/access_rule.rb | 2 +- lib/fog/rackspace/models/load_balancers/load_balancer.rb | 2 +- lib/fog/rackspace/models/load_balancers/node.rb | 2 +- lib/fog/rackspace/models/load_balancers/virtual_ip.rb | 2 +- lib/fog/voxel/models/compute/server.rb | 2 +- lib/fog/vsphere/models/compute/server.rb | 2 +- lib/fog/zerigo/models/dns/record.rb | 2 +- 43 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/fog/aws/models/cdn/invalidation.rb b/lib/fog/aws/models/cdn/invalidation.rb index 53f3e2937..b9d3757dd 100644 --- a/lib/fog/aws/models/cdn/invalidation.rb +++ b/lib/fog/aws/models/cdn/invalidation.rb @@ -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 diff --git a/lib/fog/aws/models/compute/address.rb b/lib/fog/aws/models/compute/address.rb index 6bb4b23f8..39c45bd08 100644 --- a/lib/fog/aws/models/compute/address.rb +++ b/lib/fog/aws/models/compute/address.rb @@ -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) diff --git a/lib/fog/aws/models/compute/server.rb b/lib/fog/aws/models/compute/server.rb index e60a8fa86..e77d03505 100644 --- a/lib/fog/aws/models/compute/server.rb +++ b/lib/fog/aws/models/compute/server.rb @@ -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) diff --git a/lib/fog/aws/models/compute/snapshot.rb b/lib/fog/aws/models/compute/snapshot.rb index 84c842b1e..21d1078a9 100644 --- a/lib/fog/aws/models/compute/snapshot.rb +++ b/lib/fog/aws/models/compute/snapshot.rb @@ -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 diff --git a/lib/fog/aws/models/compute/volume.rb b/lib/fog/aws/models/compute/volume.rb index 825b05722..25300e5d9 100644 --- a/lib/fog/aws/models/compute/volume.rb +++ b/lib/fog/aws/models/compute/volume.rb @@ -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 diff --git a/lib/fog/bluebox/models/compute/server.rb b/lib/fog/bluebox/models/compute/server.rb index b51dd2682..145a58c9e 100644 --- a/lib/fog/bluebox/models/compute/server.rb +++ b/lib/fog/bluebox/models/compute/server.rb @@ -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 diff --git a/lib/fog/brightbox/models/compute/api_client.rb b/lib/fog/brightbox/models/compute/api_client.rb index cf2954099..615805ea5 100644 --- a/lib/fog/brightbox/models/compute/api_client.rb +++ b/lib/fog/brightbox/models/compute/api_client.rb @@ -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 diff --git a/lib/fog/brightbox/models/compute/application.rb b/lib/fog/brightbox/models/compute/application.rb index baea25d89..925a8a803 100644 --- a/lib/fog/brightbox/models/compute/application.rb +++ b/lib/fog/brightbox/models/compute/application.rb @@ -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 == "" } diff --git a/lib/fog/brightbox/models/compute/firewall_policy.rb b/lib/fog/brightbox/models/compute/firewall_policy.rb index aed146945..a628574e8 100644 --- a/lib/fog/brightbox/models/compute/firewall_policy.rb +++ b/lib/fog/brightbox/models/compute/firewall_policy.rb @@ -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, diff --git a/lib/fog/brightbox/models/compute/firewall_rule.rb b/lib/fog/brightbox/models/compute/firewall_rule.rb index 9ac5c0b83..263ecc567 100644 --- a/lib/fog/brightbox/models/compute/firewall_rule.rb +++ b/lib/fog/brightbox/models/compute/firewall_rule.rb @@ -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, diff --git a/lib/fog/brightbox/models/compute/image.rb b/lib/fog/brightbox/models/compute/image.rb index 5b8a01f01..ac2534b21 100644 --- a/lib/fog/brightbox/models/compute/image.rb +++ b/lib/fog/brightbox/models/compute/image.rb @@ -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, diff --git a/lib/fog/brightbox/models/compute/load_balancer.rb b/lib/fog/brightbox/models/compute/load_balancer.rb index 877d999bc..0042b477b 100644 --- a/lib/fog/brightbox/models/compute/load_balancer.rb +++ b/lib/fog/brightbox/models/compute/load_balancer.rb @@ -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, diff --git a/lib/fog/brightbox/models/compute/server.rb b/lib/fog/brightbox/models/compute/server.rb index 2c5177d04..10aaa57b9 100644 --- a/lib/fog/brightbox/models/compute/server.rb +++ b/lib/fog/brightbox/models/compute/server.rb @@ -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 diff --git a/lib/fog/clodo/models/compute/server.rb b/lib/fog/clodo/models/compute/server.rb index 3cfc15bee..b4ec4d98f 100644 --- a/lib/fog/clodo/models/compute/server.rb +++ b/lib/fog/clodo/models/compute/server.rb @@ -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']) diff --git a/lib/fog/go_grid/models/compute/image.rb b/lib/fog/go_grid/models/compute/image.rb index 5b3547a50..74841aa17 100644 --- a/lib/fog/go_grid/models/compute/image.rb +++ b/lib/fog/go_grid/models/compute/image.rb @@ -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) diff --git a/lib/fog/go_grid/models/compute/password.rb b/lib/fog/go_grid/models/compute/password.rb index 358ec32d9..183e430c7 100644 --- a/lib/fog/go_grid/models/compute/password.rb +++ b/lib/fog/go_grid/models/compute/password.rb @@ -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) diff --git a/lib/fog/go_grid/models/compute/server.rb b/lib/fog/go_grid/models/compute/server.rb index f73a30a8f..a7feae635 100644 --- a/lib/fog/go_grid/models/compute/server.rb +++ b/lib/fog/go_grid/models/compute/server.rb @@ -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, diff --git a/lib/fog/hp/models/compute/address.rb b/lib/fog/hp/models/compute/address.rb index a42e8a727..378cbe1e2 100644 --- a/lib/fog/hp/models/compute/address.rb +++ b/lib/fog/hp/models/compute/address.rb @@ -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) diff --git a/lib/fog/hp/models/compute/server.rb b/lib/fog/hp/models/compute/server.rb index 8901fa278..ab198e6ca 100644 --- a/lib/fog/hp/models/compute/server.rb +++ b/lib/fog/hp/models/compute/server.rb @@ -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, diff --git a/lib/fog/ibm/models/storage/volume.rb b/lib/fog/ibm/models/storage/volume.rb index 1fbed5761..4befcd48d 100644 --- a/lib/fog/ibm/models/storage/volume.rb +++ b/lib/fog/ibm/models/storage/volume.rb @@ -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) diff --git a/lib/fog/linode/models/compute/disk.rb b/lib/fog/linode/models/compute/disk.rb index 4deec6e62..fdeb20a6b 100644 --- a/lib/fog/linode/models/compute/disk.rb +++ b/lib/fog/linode/models/compute/disk.rb @@ -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 diff --git a/lib/fog/linode/models/compute/ip.rb b/lib/fog/linode/models/compute/ip.rb index 931d4191e..9db59e1db 100644 --- a/lib/fog/linode/models/compute/ip.rb +++ b/lib/fog/linode/models/compute/ip.rb @@ -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 } diff --git a/lib/fog/linode/models/compute/server.rb b/lib/fog/linode/models/compute/server.rb index 782652abe..ab4d1bc00 100644 --- a/lib/fog/linode/models/compute/server.rb +++ b/lib/fog/linode/models/compute/server.rb @@ -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 diff --git a/lib/fog/openstack/models/compute/address.rb b/lib/fog/openstack/models/compute/address.rb index 631e79bc9..5c71ed233 100644 --- a/lib/fog/openstack/models/compute/address.rb +++ b/lib/fog/openstack/models/compute/address.rb @@ -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) diff --git a/lib/fog/openstack/models/compute/server.rb b/lib/fog/openstack/models/compute/server.rb index 7b2e3d300..501519a57 100644 --- a/lib/fog/openstack/models/compute/server.rb +++ b/lib/fog/openstack/models/compute/server.rb @@ -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) } diff --git a/lib/fog/openstack/models/identity/user.rb b/lib/fog/openstack/models/identity/user.rb index ea5a24e4f..b75843ef0 100644 --- a/lib/fog/openstack/models/identity/user.rb +++ b/lib/fog/openstack/models/identity/user.rb @@ -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) diff --git a/lib/fog/ovirt/models/compute/server.rb b/lib/fog/ovirt/models/compute/server.rb index 22239039a..162889ad7 100644 --- a/lib/fog/ovirt/models/compute/server.rb +++ b/lib/fog/ovirt/models/compute/server.rb @@ -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 diff --git a/lib/fog/ovirt/models/compute/template.rb b/lib/fog/ovirt/models/compute/template.rb index d32733998..239cae5c3 100644 --- a/lib/fog/ovirt/models/compute/template.rb +++ b/lib/fog/ovirt/models/compute/template.rb @@ -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 diff --git a/lib/fog/rackspace/models/block_storage/snapshot.rb b/lib/fog/rackspace/models/block_storage/snapshot.rb index 781cb4e35..2d3af9bd5 100644 --- a/lib/fog/rackspace/models/block_storage/snapshot.rb +++ b/lib/fog/rackspace/models/block_storage/snapshot.rb @@ -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, diff --git a/lib/fog/rackspace/models/block_storage/volume.rb b/lib/fog/rackspace/models/block_storage/volume.rb index 2d153edc9..1e11dcb51 100644 --- a/lib/fog/rackspace/models/block_storage/volume.rb +++ b/lib/fog/rackspace/models/block_storage/volume.rb @@ -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, diff --git a/lib/fog/rackspace/models/compute/image.rb b/lib/fog/rackspace/models/compute/image.rb index 3850a498d..dbe64d947 100644 --- a/lib/fog/rackspace/models/compute/image.rb +++ b/lib/fog/rackspace/models/compute/image.rb @@ -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) diff --git a/lib/fog/rackspace/models/compute/server.rb b/lib/fog/rackspace/models/compute/server.rb index b4ad9a400..1d61bcba1 100644 --- a/lib/fog/rackspace/models/compute/server.rb +++ b/lib/fog/rackspace/models/compute/server.rb @@ -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, diff --git a/lib/fog/rackspace/models/compute_v2/server.rb b/lib/fog/rackspace/models/compute_v2/server.rb index 6a4f30b97..49db837d4 100644 --- a/lib/fog/rackspace/models/compute_v2/server.rb +++ b/lib/fog/rackspace/models/compute_v2/server.rb @@ -45,7 +45,7 @@ module Fog attr_reader :password def save - if identity + if persisted? update else create diff --git a/lib/fog/rackspace/models/dns/record.rb b/lib/fog/rackspace/models/dns/record.rb index fc6e5ce2c..8e9b80a7c 100644 --- a/lib/fog/rackspace/models/dns/record.rb +++ b/lib/fog/rackspace/models/dns/record.rb @@ -33,7 +33,7 @@ module Fog end def save - if identity + if persisted? update else create diff --git a/lib/fog/rackspace/models/dns/zone.rb b/lib/fog/rackspace/models/dns/zone.rb index d3fa67251..928fc7a09 100644 --- a/lib/fog/rackspace/models/dns/zone.rb +++ b/lib/fog/rackspace/models/dns/zone.rb @@ -35,7 +35,7 @@ module Fog end def save - if identity + if persisted? update else create diff --git a/lib/fog/rackspace/models/identity/user.rb b/lib/fog/rackspace/models/identity/user.rb index 84e6d134e..c61d67bbe 100644 --- a/lib/fog/rackspace/models/identity/user.rb +++ b/lib/fog/rackspace/models/identity/user.rb @@ -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) diff --git a/lib/fog/rackspace/models/load_balancers/access_rule.rb b/lib/fog/rackspace/models/load_balancers/access_rule.rb index 2ff10ec2a..b1cfb03fb 100644 --- a/lib/fog/rackspace/models/load_balancers/access_rule.rb +++ b/lib/fog/rackspace/models/load_balancers/access_rule.rb @@ -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) diff --git a/lib/fog/rackspace/models/load_balancers/load_balancer.rb b/lib/fog/rackspace/models/load_balancers/load_balancer.rb index 80ad5ea87..05cabbf1c 100644 --- a/lib/fog/rackspace/models/load_balancers/load_balancer.rb +++ b/lib/fog/rackspace/models/load_balancers/load_balancer.rb @@ -164,7 +164,7 @@ module Fog end def save - if identity + if persisted? update else create diff --git a/lib/fog/rackspace/models/load_balancers/node.rb b/lib/fog/rackspace/models/load_balancers/node.rb index 337602272..216f55e30 100644 --- a/lib/fog/rackspace/models/load_balancers/node.rb +++ b/lib/fog/rackspace/models/load_balancers/node.rb @@ -20,7 +20,7 @@ module Fog end def save - if identity + if persisted? update else create diff --git a/lib/fog/rackspace/models/load_balancers/virtual_ip.rb b/lib/fog/rackspace/models/load_balancers/virtual_ip.rb index 3d535efd9..8ceb6154a 100644 --- a/lib/fog/rackspace/models/load_balancers/virtual_ip.rb +++ b/lib/fog/rackspace/models/load_balancers/virtual_ip.rb @@ -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) diff --git a/lib/fog/voxel/models/compute/server.rb b/lib/fog/voxel/models/compute/server.rb index 5bbef0b62..cefa6758b 100644 --- a/lib/fog/voxel/models/compute/server.rb +++ b/lib/fog/voxel/models/compute/server.rb @@ -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({ diff --git a/lib/fog/vsphere/models/compute/server.rb b/lib/fog/vsphere/models/compute/server.rb index ef73a5951..60d060700 100644 --- a/lib/fog/vsphere/models/compute/server.rb +++ b/lib/fog/vsphere/models/compute/server.rb @@ -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 diff --git a/lib/fog/zerigo/models/dns/record.rb b/lib/fog/zerigo/models/dns/record.rb index 833008836..165137b93 100644 --- a/lib/fog/zerigo/models/dns/record.rb +++ b/lib/fog/zerigo/models/dns/record.rb @@ -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)