lib/dcmgr/models/account.rb in wakame-vdc-agents-10.12.0 vs lib/dcmgr/models/account.rb in wakame-vdc-agents-11.06.0
- old
+ new
@@ -14,10 +14,11 @@
Fixnum :enabled, :default=>ENABLED, :null=>false
end
with_timestamps
one_to_many :tags, :dataset=>lambda { Tag.filter(:account_id=>self.canonical_uuid); }
+ one_to_one :quota, :class=>Quota, :key=>:account_id
# sti plugin has to be loaded at lower position.
plugin :subclasses
plugin :single_table_inheritance, :uuid, :model_map=>{}
@@ -28,10 +29,21 @@
def enable?
self.enabled == ENABLED
end
+ def after_create
+ self.quota = Quota.create
+ super
+ end
+
+ def before_destroy
+ self.quota.destroy unless self.quota.nil?
+ super
+ end
+
+
# STI class variable setter, getter methods.
class << self
def default_values
@default_values ||= {}
end
@@ -44,16 +56,17 @@
end
def uuid(uuid=nil)
if uuid.is_a?(String)
uuid = uuid.downcase
- if uuid !~ /^[a-z0-9]{8}$/
+ unless self.check_trimmed_uuid_format(uuid)
raise "Invalid syntax of uuid: #{uuid}"
end
default_values[:uuid] = uuid
end
- default_values[:uuid] || raise("#{self}.uuid is unset. Set the unique number")
+ raise("#{self}.uuid is unset. Set the unique number") unless default_values[:uuid]
+ "#{uuid_prefix}-#{default_values[:uuid]}"
end
def description(description=nil)
if description
default_values[:description] = description
@@ -78,11 +91,22 @@
install_data_hooks do
Account.subclasses.each { |m|
Account.create(m.default_values.dup)
}
- end
+ # create shared resource pool tags
+ Dcmgr::Tags::HostPool.create(:account_id=>SystemAccount::SharedPoolAccount.uuid,
+ :uuid=>'shhost',
+ :name=>"default_shared_hosts")
+ Dcmgr::Tags::NetworkPool.create(:account_id=>SystemAccount::SharedPoolAccount.uuid,
+ :uuid=>'shnet',
+ :name=>"default_shared_networks")
+ Dcmgr::Tags::StoragePool.create(:account_id=>SystemAccount::SharedPoolAccount.uuid,
+ :uuid=>'shstor',
+ :name=>"default_shared_storages")
+ end
+
SystemAccount.define_account(:DatacenterAccount) do
pk 100
uuid '00000000'
description 'datacenter system account'