Skip to content

Commit

Permalink
Merge pull request fog#3629 from Ladas/openstack_model_base_class_for…
Browse files Browse the repository at this point in the history
…_all_openstack_models

Fog::OpenStack::Model base class for all openstack models
  • Loading branch information
geemus committed Jul 15, 2015
2 parents a6064b3 + 21fa428 commit 41b327a
Show file tree
Hide file tree
Showing 56 changed files with 141 additions and 397 deletions.
17 changes: 3 additions & 14 deletions lib/fog/openstack/models/baremetal/chassis.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Baremetal
class OpenStack
class Chassis < Fog::Model
class Chassis < Fog::OpenStack::Model
identity :uuid

attribute :description
Expand All @@ -14,25 +14,14 @@ class Chassis < Fog::Model
attribute :updated_at
attribute :extra

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save
requires :description
identity ? update : create
end

def create
requires :description
merge_attributes(service.create_chassis(self.attributes).body)
self
end

def update(patch=nil)
requires :uuid
requires :uuid, :description
if patch
merge_attributes(service.patch_chassis(uuid, patch).body)
else
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/baremetal/driver.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Baremetal
class OpenStack
class Driver < Fog::Model
class Driver < Fog::OpenStack::Model
identity :name

attribute :name
attribute :hosts

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def properties
requires :name
service.get_driver_properties(self.name).body
Expand Down
17 changes: 3 additions & 14 deletions lib/fog/openstack/models/baremetal/node.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Baremetal
class OpenStack
class Node < Fog::Model
class Node < Fog::OpenStack::Model
identity :uuid

attribute :instance_uuid
Expand All @@ -29,25 +29,14 @@ class Node < Fog::Model
attribute :target_power_state
attribute :target_provision_state

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save
requires :driver
identity ? update : create
end

def create
requires :driver
merge_attributes(service.create_node(self.attributes).body)
self
end

def update(patch=nil)
requires :uuid
requires :uuid, :driver
if patch
merge_attributes(service.patch_node(uuid, patch).body)
else
Expand Down
17 changes: 3 additions & 14 deletions lib/fog/openstack/models/baremetal/port.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Baremetal
class OpenStack
class Port < Fog::Model
class Port < Fog::OpenStack::Model
identity :uuid

attribute :address
Expand All @@ -15,25 +15,14 @@ class Port < Fog::Model
attribute :extra
attribute :node_uuid

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save
requires :address, :node_uuid
identity ? update : create
end

def create
requires :address, :node_uuid
merge_attributes(service.create_port(self.attributes).body)
self
end

def update(patch=nil)
requires :uuid
requires :uuid, :address, :node_uuid
if patch
merge_attributes(service.patch_port(uuid, patch).body)
else
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/address.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Address < Fog::Model
class Address < Fog::OpenStack::Model
identity :id

attribute :ip
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/aggregate.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Aggregate < Fog::Model
class Aggregate < Fog::OpenStack::Model
identity :id

attribute :availability_zone
Expand All @@ -17,12 +17,6 @@ class Aggregate < Fog::Model
# Detailed
attribute :hosts

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save
requires :name
identity ? update : create
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/flavor.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Flavor < Fog::Model
class Flavor < Fog::OpenStack::Model
identity :id

attribute :name
Expand All @@ -18,12 +18,6 @@ class Flavor < Fog::Model
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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/openstack/models/compute/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Fog
module Compute
class OpenStack
class Host < Fog::Model
class Host < Fog::OpenStack::Model
attribute :host_name
attribute :service_name
attribute :details
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/image.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/openstack/models/model'
require 'fog/openstack/models/compute/metadata'

module Fog
module Compute
class OpenStack
class Image < Fog::Model
class Image < Fog::OpenStack::Model
identity :id

attribute :name
Expand All @@ -18,12 +18,6 @@ class Image < Fog::Model
attribute :metadata
attribute :links

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def metadata
@metadata ||= begin
Fog::Compute::OpenStack::Metadata.new({
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/key_pair.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class KeyPair < Fog::Model
class KeyPair < Fog::OpenStack::Model
identity :name

attribute :fingerprint
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/metadatum.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/openstack/models/model'
require 'fog/openstack/models/meta_parent'

module Fog
module Compute
class OpenStack
class Metadatum < Fog::Model
class Metadatum < Fog::OpenStack::Model
include Fog::Compute::OpenStack::MetaParent

identity :key
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/network.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Network < Fog::Model
class Network < Fog::OpenStack::Model
identity :id
attribute :name
attribute :addresses
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/security_group.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class SecurityGroup < Fog::Model
class SecurityGroup < Fog::OpenStack::Model
identity :id

attribute :name
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/security_group_rule.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class SecurityGroupRule < Fog::Model
class SecurityGroupRule < Fog::OpenStack::Model
identity :id

attribute :from_port
Expand Down
4 changes: 4 additions & 0 deletions lib/fog/openstack/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Server < Fog::Compute::Server
attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints
attr_accessor :block_device_mapping, :block_device_mapping_v2

# In some cases it's handy to be able to store the project for the record, e.g. swift doesn't contain project info
# in the result, so we can track it in this attribute based on what project was used in the request
attr_accessor :project

def initialize(attributes={})
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/service.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Service < Fog::Model
class Service < Fog::OpenStack::Model
identity :id

attribute :binary
Expand All @@ -16,12 +16,6 @@ class Service < Fog::Model
#detailed
attribute :disabled_reason

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def enable
requires :binary, :host
service.enable_service(self.host, self.binary)
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/snapshot.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/openstack/models/model'
require 'fog/openstack/models/compute/metadata'

module Fog
module Compute
class OpenStack
class Snapshot < Fog::Model
class Snapshot < Fog::OpenStack::Model
identity :id

attribute :name, :aliases => 'displayName'
Expand All @@ -14,12 +14,6 @@ class Snapshot < Fog::Model
attribute :size
attribute :created_at, :aliases => 'createdAt'

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save(force=false)
requires :volume_id, :name, :description
data = service.create_volume_snapshot(volume_id, name, description, force)
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/openstack/models/compute/tenant.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fog/core/model'
require 'fog/openstack/models/model'

module Fog
module Compute
class OpenStack
class Tenant < Fog::Model
class Tenant < Fog::OpenStack::Model
identity :id

attribute :description
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/openstack/models/compute/volume.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/openstack/models/model'
require 'fog/openstack/models/compute/metadata'

module Fog
module Compute
class OpenStack
class Volume < Fog::Model
class Volume < Fog::OpenStack::Model
identity :id

attribute :name, :aliases => 'displayName'
Expand All @@ -17,12 +17,6 @@ class Volume < Fog::Model
attribute :created_at, :aliases => 'createdAt'
attribute :attachments

def initialize(attributes)
# Old 'connection' is renamed as service and should be used instead
prepare_service_value(attributes)
super
end

def save
requires :name, :description, :size
data = service.create_volume(name, description, size, attributes)
Expand Down
Loading

0 comments on commit 41b327a

Please sign in to comment.