wakame-vdc-webui 10.12.0 → 11.06.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL-API.txt +14 -0
- data/Rakefile +5 -1
- data/app/api/config/environment.rb +9 -0
- data/app/controllers/accounts_controller.rb +39 -1
- data/app/controllers/application_controller.rb +73 -1
- data/app/controllers/instance_specs_controller.rb +11 -0
- data/app/controllers/instances_controller.rb +7 -3
- data/app/controllers/{images_controller.rb → machine_images_controller.rb} +2 -3
- data/app/controllers/sessions_controller.rb +6 -3
- data/app/controllers/snapshots_controller.rb +17 -6
- data/app/controllers/volumes_controller.rb +6 -2
- data/app/helpers/application_helper.rb +9 -5
- data/app/helpers/machine_images_helper.rb +2 -0
- data/app/models/account.rb +22 -4
- data/app/models/base_new.rb +11 -2
- data/app/models/dcmgr_resource/base.rb +13 -0
- data/app/models/dcmgr_resource/instance_spec.rb +7 -0
- data/app/models/dcmgr_resource/volume_snapshot.rb +6 -0
- data/app/models/information.rb +1 -1
- data/app/models/oauth_consumer.rb +15 -0
- data/app/models/oauth_token.rb +10 -0
- data/app/models/user.rb +34 -1
- data/app/views/accounts/index.html.erb +42 -67
- data/app/views/accounts/password.html.erb +35 -0
- data/app/views/dialog/attach_volume.html.erb +2 -2
- data/app/views/dialog/create_and_edit_security_group.html.erb +61 -28
- data/app/views/dialog/create_snapshot.html.erb +11 -4
- data/app/views/dialog/create_ssh_keypair.html.erb +2 -2
- data/app/views/dialog/create_volume.html.erb +3 -4
- data/app/views/dialog/create_volume_from_snapshot.html.erb +1 -1
- data/app/views/dialog/delete_security_group.html.erb +1 -1
- data/app/views/dialog/delete_snapshot.html.erb +1 -1
- data/app/views/dialog/delete_ssh_keypair.html.erb +1 -1
- data/app/views/dialog/delete_volume.html.erb +1 -1
- data/app/views/dialog/detach_volume.html.erb +1 -1
- data/app/views/dialog/launch_instance.html.erb +10 -14
- data/app/views/dialog/reboot_instances.html.erb +1 -1
- data/app/views/dialog/terminate_instances.html.erb +1 -1
- data/app/views/home/index.html.erb +11 -11
- data/app/views/host_pools/index.html.erb +87 -92
- data/app/views/instances/index.html.erb +50 -52
- data/app/views/keypairs/index.html.erb +16 -16
- data/app/views/layouts/_header.html.erb +6 -6
- data/app/views/layouts/_informationarea.html.erb +5 -5
- data/app/views/layouts/_login_header.erb +1 -1
- data/app/views/layouts/_sidemenu.html.erb +30 -28
- data/app/views/layouts/application.html.erb +19 -3
- data/app/views/layouts/login.html.erb +4 -4
- data/app/views/{images → machine_images}/index.html.erb +20 -39
- data/app/views/security_groups/index.html.erb +20 -23
- data/app/views/sessions/new.html.erb +10 -5
- data/app/views/snapshots/index.html.erb +28 -26
- data/app/views/storage_pools/index.html.erb +17 -22
- data/app/views/volumes/index.html.erb +32 -34
- data/config/application-cli.rb +33 -0
- data/config/{application-api.rb → cli_token.rb} +0 -0
- data/config/environment-cli.rb +4 -0
- data/config/environments/development.rb +19 -0
- data/config/initializers/dcmgr_gui.rb +8 -3
- data/config/initializers/sequel.rb +4 -0
- data/config/initializers/site.rb +8 -0
- data/config/locales/en.yml +307 -1
- data/config/locales/ja-JP.yml +4 -0
- data/config/locales/ja.yml +309 -0
- data/config/routes.rb +16 -9
- data/lib/cli/account.rb +264 -0
- data/lib/cli/base.rb +74 -0
- data/lib/cli/errors.rb +59 -0
- data/lib/cli/user.rb +226 -0
- data/lib/tasks/dcmgr_api.rake +65 -12
- data/lib/tasks/dcmgr_gui.rake +96 -4
- data/lib/tasks/dcmgr_oauth.rake +39 -0
- data/public/i18n/Messages.properties +0 -0
- data/public/images/Chevron.gif +0 -0
- data/public/images/ChevronOverlay.png +0 -0
- data/public/images/IconHome.gif +0 -0
- data/public/images/bg-box-body.gif +0 -0
- data/public/images/bg-box-body.png +0 -0
- data/public/images/bg-box-bottom.gif +0 -0
- data/public/images/bg-box-bottom.png +0 -0
- data/public/images/bg-box-top.gif +0 -0
- data/public/images/bg-box-top.png +0 -0
- data/public/images/cluetip/arrowdown.gif +0 -0
- data/public/images/cluetip/arrowleft.gif +0 -0
- data/public/images/cluetip/arrowright.gif +0 -0
- data/public/images/cluetip/arrowup.gif +0 -0
- data/public/images/cluetip/bl.gif +0 -0
- data/public/images/cluetip/bl.png +0 -0
- data/public/images/cluetip/br.gif +0 -0
- data/public/images/cluetip/br.png +0 -0
- data/public/images/cluetip/darrowdown.gif +0 -0
- data/public/images/cluetip/darrowleft.gif +0 -0
- data/public/images/cluetip/darrowright.gif +0 -0
- data/public/images/cluetip/darrowup.gif +0 -0
- data/public/images/cluetip/itunes.png +0 -0
- data/public/images/cluetip/rarrowdown.gif +0 -0
- data/public/images/cluetip/rarrowleft.gif +0 -0
- data/public/images/cluetip/rarrowright.gif +0 -0
- data/public/images/cluetip/rarrowup.gif +0 -0
- data/public/images/cluetip/tl.gif +0 -0
- data/public/images/cluetip/tl.png +0 -0
- data/public/images/cluetip/tr.gif +0 -0
- data/public/images/cluetip/tr.png +0 -0
- data/public/images/cluetip/wait.gif +0 -0
- data/public/images/dialog-error.png +0 -0
- data/public/images/dialog-help.png +0 -0
- data/public/images/dialog-information.png +0 -0
- data/public/images/dialog-warning.png +0 -0
- data/public/images/ui-bg_flat_55_fcf0ba_40x100.png +0 -0
- data/public/images/ui-bg_glass_10_136d76_1x400.png +0 -0
- data/public/images/ui-bg_glass_10_458845_1x400.png +0 -0
- data/public/images/ui-bg_highlight-hard_100_f5f3e5_1x100.png +0 -0
- data/public/images/ui-bg_highlight-hard_100_fafaf4_1x100.png +0 -0
- data/public/images/ui-bg_highlight-soft_50_136d76_1x100.png +0 -0
- data/public/images/ui-bg_inset-soft_15_386b3d_1x100.png +0 -0
- data/public/images/ui-icons_4c9052_256x240.png +0 -0
- data/public/images/ui-icons_847e71_256x240.png +0 -0
- data/public/javascripts/dcmgr_gui/account_panel.js +6 -0
- data/public/javascripts/dcmgr_gui/application.js +78 -5
- data/public/javascripts/dcmgr_gui/core.js +409 -102
- data/public/javascripts/dcmgr_gui/dashboard_panel.js +12 -3
- data/public/javascripts/dcmgr_gui/host_pool_panel.js +1 -1
- data/public/javascripts/dcmgr_gui/image_panel.js +119 -65
- data/public/javascripts/dcmgr_gui/instance_panel.js +86 -44
- data/public/javascripts/dcmgr_gui/security_group_panel.js +135 -77
- data/public/javascripts/dcmgr_gui/snapshot_panel.js +119 -61
- data/public/javascripts/dcmgr_gui/sshkeypair_panel.js +71 -47
- data/public/javascripts/dcmgr_gui/storage_pool_panel.js +10 -10
- data/public/javascripts/dcmgr_gui/volume_panel.js +311 -155
- data/public/javascripts/jquery.cluetip.min.js +33 -0
- data/public/javascripts/jquery.easing.1.3.js +205 -0
- data/public/javascripts/jquery.hoverIntent.js +114 -0
- data/public/javascripts/jquery.i18n.properties-min.js +7 -0
- data/public/javascripts/jquery.jBreadCrumb.1.1.js +240 -0
- data/public/javascripts/sexyalertbox.v1.2.jquery.js +414 -0
- data/public/javascripts/ui.selectmenu.js +541 -0
- data/public/stylesheets/BreadCrumb.css +109 -0
- data/public/stylesheets/common.css +146 -86
- data/public/stylesheets/dialog.css +7 -7
- data/public/stylesheets/jquery-ui-1.8.4.custom.css +41 -40
- data/public/stylesheets/jquery.cluetip.css +179 -0
- data/public/stylesheets/sexyalertbox.css +67 -0
- data/public/stylesheets/ui.selectmenu.css +24 -0
- data/test/functional/{images_controller_test.rb → machine_images_controller_test.rb} +1 -1
- data/test/unit/helpers/machine_images_helper_test.rb +4 -0
- metadata +350 -221
- data/README +0 -256
- data/app/api/auth_server.rb +0 -28
- data/app/helpers/images_helper.rb +0 -2
- data/app/views/information/index.html.erb +0 -25
- data/app/views/layouts/_service_health.erb +0 -27
- data/test/unit/helpers/images_helper_test.rb +0 -4
data/INSTALL-API.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Edit './config/initializers/proxy.rb'.
|
2
|
+
|
3
|
+
# Configuration:
|
4
|
+
#
|
5
|
+
# config/initializers/proxy.rb
|
6
|
+
|
7
|
+
# Start the nginx proxy server.
|
8
|
+
> rake api:create_proxy_config
|
9
|
+
> rake api:start_proxy
|
10
|
+
|
11
|
+
# Start the auth server.
|
12
|
+
> rackup -D -o localhost -p 8081 config-api.ru
|
13
|
+
# or...
|
14
|
+
> rake api:start_auth
|
data/Rakefile
CHANGED
@@ -21,6 +21,7 @@ task :gem do
|
|
21
21
|
s.email = ['dev@axsh.net']
|
22
22
|
s.name = 'wakame-vdc-webui'
|
23
23
|
s.summary = "Datacenter management toolkit for IaaS Cloud: UI frontend"
|
24
|
+
s.description = ''
|
24
25
|
s.required_ruby_version = '>= 1.8.7'
|
25
26
|
|
26
27
|
s.files = Dir['app/**/*.{rb,erb}','lib/**/*.rb',
|
@@ -29,12 +30,15 @@ task :gem do
|
|
29
30
|
'lib/**/*.{rb,rake}', 'test/**/*.rb',
|
30
31
|
'vendor/plugins/**/*.*', 'tmp/',
|
31
32
|
'script/*', 'test/**/*.rb', 'doc/**/*.*'] +
|
32
|
-
%w(Rakefile config.ru
|
33
|
+
%w(Rakefile config.ru LICENSE NOTICE INSTALL.txt INSTALL-API.txt tmp)
|
33
34
|
|
34
35
|
s.add_dependency "rails", '3.0.0'
|
35
36
|
s.add_dependency 'mysql','2.8.1'
|
36
37
|
s.add_dependency 'sequel','3.15.0'
|
37
38
|
s.add_dependency 'json','1.4.6'
|
39
|
+
s.add_dependency 'oauth','0.4.1'
|
40
|
+
s.add_dependency 'i18n', '0.4.2'
|
41
|
+
s.add_dependency 'nokogiri', '1.4.4'
|
38
42
|
end
|
39
43
|
|
40
44
|
File.open("#{spec.name}.gemspec", 'w'){|f| f.write(spec.to_ruby) }
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Load the rails application
|
2
|
+
require File.expand_path('../../../../config/application', __FILE__)
|
3
|
+
|
4
|
+
# Initialize the rails application
|
5
|
+
DcmgrGui::Application.initialize!
|
6
|
+
|
7
|
+
$stdout.reopen(File.expand_path("log/auth_server.log", Rails.root) , "a")
|
8
|
+
$stdout.sync = true
|
9
|
+
$stderr.reopen($stdout)
|
@@ -10,6 +10,44 @@ class AccountsController < ApplicationController
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def index
|
13
|
-
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_settings
|
17
|
+
account = params[:account]
|
18
|
+
if account
|
19
|
+
|
20
|
+
setting_params = {
|
21
|
+
:time_zone => account[:time_zone],
|
22
|
+
:locale => account[:locale],
|
23
|
+
}
|
24
|
+
|
25
|
+
User.update_settings(@current_user.id, setting_params)
|
26
|
+
end
|
27
|
+
redirect_to :action => 'index'
|
28
|
+
end
|
29
|
+
|
30
|
+
def password
|
31
|
+
@error_message = ''
|
32
|
+
if request.get?
|
33
|
+
#nop
|
34
|
+
elsif request.post?
|
35
|
+
password = params[:password]
|
36
|
+
new_password = params[:new_password]
|
37
|
+
confirm_password = params[:confirm_password]
|
38
|
+
unless new_password == confirm_password
|
39
|
+
@error_message = I18n.t('error_message.change_password1')
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
|
43
|
+
user = User.find(:uuid => @current_user.uuid, :password => User.encrypt_password(password))
|
44
|
+
if user
|
45
|
+
user.password = User.encrypt_password(new_password)
|
46
|
+
user.save
|
47
|
+
redirect_to :action => 'index'
|
48
|
+
else
|
49
|
+
@error_message = I18n.t('error_message.change_password2')
|
50
|
+
end
|
51
|
+
end
|
14
52
|
end
|
15
53
|
end
|
@@ -1,5 +1,77 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
class ApplicationController < ActionController::Base
|
2
4
|
protect_from_forgery
|
3
5
|
include Authentication
|
4
6
|
before_filter :login_required
|
5
|
-
|
7
|
+
before_filter :set_locale
|
8
|
+
before_filter :set_application
|
9
|
+
|
10
|
+
|
11
|
+
def set_application
|
12
|
+
@site = DCMGR_GUI_SITE
|
13
|
+
end
|
14
|
+
|
15
|
+
def dispatch(name, request)
|
16
|
+
begin
|
17
|
+
super
|
18
|
+
rescue Sequel::DatabaseConnectionError => e
|
19
|
+
response.status = 500
|
20
|
+
response.body = 'Database connection faild.'
|
21
|
+
rescue ActiveResource::ConnectionError => e
|
22
|
+
if is_dcmgr?(e)
|
23
|
+
response.status = e.response.code
|
24
|
+
response.body = e.response.body
|
25
|
+
response['X-Vdc-Request-Id'] = e.response['X-Vdc-Request-Id']
|
26
|
+
else
|
27
|
+
raise
|
28
|
+
end
|
29
|
+
end
|
30
|
+
to_a
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_dcmgr?(response_data)
|
34
|
+
if response_data.response['X-Vdc-Request-Id']
|
35
|
+
true
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_locale
|
42
|
+
language = params[:select_language] if params[:select_language]
|
43
|
+
if language
|
44
|
+
I18n.locale = language[:locale]
|
45
|
+
session[:locale] = I18n.locale
|
46
|
+
else
|
47
|
+
if session[:locale]
|
48
|
+
I18n.locale = session[:locale]
|
49
|
+
elsif @current_user
|
50
|
+
I18n.locale = @current_user.locale
|
51
|
+
else
|
52
|
+
I18n.locale = I18n.default_locale.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@locales = get_locales
|
57
|
+
@locale = I18n.locale
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_locales
|
61
|
+
locales = Array.new
|
62
|
+
locales.push(['English','en'])
|
63
|
+
locales.push(['日本語','ja'])
|
64
|
+
locales
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def extract_locale_from_accept_language_header
|
69
|
+
if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
70
|
+
nil
|
71
|
+
else
|
72
|
+
parsed_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
|
73
|
+
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : I18n.default_locale.to_s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -52,8 +52,12 @@ class InstancesController < ApplicationController
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def total
|
55
|
-
|
56
|
-
|
55
|
+
all_resource_count = DcmgrResource::Instance.total_resource
|
56
|
+
all_resources = DcmgrResource::Instance.find(:all,:params => {:start => 0, :limit => all_resource_count})
|
57
|
+
resources = all_resources[0].results
|
58
|
+
terminated_resource_count = DcmgrResource::Instance.get_resource_state_count(resources, 'terminated')
|
59
|
+
total = all_resource_count - terminated_resource_count
|
60
|
+
render :json => total
|
57
61
|
end
|
58
62
|
|
59
|
-
end
|
63
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
class
|
1
|
+
class MachineImagesController < ApplicationController
|
2
2
|
respond_to :json
|
3
3
|
|
4
4
|
def index
|
5
5
|
end
|
6
6
|
|
7
|
-
# images/show/1.json
|
8
7
|
def show
|
9
8
|
image_id = params[:id]
|
10
9
|
detail = DcmgrResource::Image.show(image_id)
|
@@ -25,4 +24,4 @@ class ImagesController < ApplicationController
|
|
25
24
|
total_resource = DcmgrResource::Image.total_resource
|
26
25
|
render :json => total_resource
|
27
26
|
end
|
28
|
-
end
|
27
|
+
end
|
@@ -8,12 +8,15 @@ class SessionsController < ApplicationController
|
|
8
8
|
|
9
9
|
def create
|
10
10
|
user = User.authenticate(params[:login], params[:password])
|
11
|
+
@error_message = ''
|
12
|
+
|
11
13
|
if user
|
12
14
|
self.current_user = user
|
15
|
+
User.update_last_login(user.id)
|
13
16
|
redirect_back_or_default('/', :notice => "Logged in successfully")
|
14
17
|
else
|
15
|
-
|
16
|
-
@login
|
18
|
+
@error_message = I18n.t('error_message.sign_in')
|
19
|
+
@login = params[:login]
|
17
20
|
render :action => 'new'
|
18
21
|
end
|
19
22
|
end
|
@@ -22,4 +25,4 @@ class SessionsController < ApplicationController
|
|
22
25
|
logout_killing_session!
|
23
26
|
redirect_back_or_default('/', :notice => "You have been logged out.")
|
24
27
|
end
|
25
|
-
end
|
28
|
+
end
|
@@ -7,14 +7,16 @@ class SnapshotsController < ApplicationController
|
|
7
7
|
|
8
8
|
def create
|
9
9
|
volume_ids = params[:ids]
|
10
|
-
|
10
|
+
destination = params[:destination]
|
11
|
+
res = []
|
11
12
|
volume_ids.each do |volume_id|
|
12
13
|
data = {
|
13
|
-
:volume_id => volume_id
|
14
|
+
:volume_id => volume_id,
|
15
|
+
:destination => destination
|
14
16
|
}
|
15
|
-
|
17
|
+
res << DcmgrResource::VolumeSnapshot.create(data)
|
16
18
|
end
|
17
|
-
render :json =>
|
19
|
+
render :json => res
|
18
20
|
end
|
19
21
|
|
20
22
|
def destroy
|
@@ -42,7 +44,16 @@ class SnapshotsController < ApplicationController
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def total
|
45
|
-
|
46
|
-
|
47
|
+
all_resource_count = DcmgrResource::VolumeSnapshot.total_resource
|
48
|
+
all_resources = DcmgrResource::VolumeSnapshot.find(:all,:params => {:start => 0, :limit => all_resource_count})
|
49
|
+
resources = all_resources[0].results
|
50
|
+
deleted_resource_count = DcmgrResource::VolumeSnapshot.get_resource_state_count(resources, 'deleted')
|
51
|
+
total = all_resource_count - deleted_resource_count
|
52
|
+
render :json => total
|
53
|
+
end
|
54
|
+
|
55
|
+
def upload_destination
|
56
|
+
destinations = DcmgrResource::VolumeSnapshot.upload_destination
|
57
|
+
render :json => destinations[0]
|
47
58
|
end
|
48
59
|
end
|
@@ -80,7 +80,11 @@ class VolumesController < ApplicationController
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def total
|
83
|
-
|
84
|
-
|
83
|
+
all_resource_count = DcmgrResource::Volume.total_resource
|
84
|
+
all_resources = DcmgrResource::Volume.find(:all,:params => {:start => 0, :limit => all_resource_count})
|
85
|
+
resources = all_resources[0].results
|
86
|
+
deleted_resource_count = DcmgrResource::Volume.get_resource_state_count(resources, 'deleted')
|
87
|
+
total = all_resource_count - deleted_resource_count
|
88
|
+
render :json => total
|
85
89
|
end
|
86
90
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ApplicationHelper
|
2
2
|
|
3
|
-
def li_link_to_current(name,
|
4
|
-
if current_page?(:controller =>
|
5
|
-
str = '<li class="current">' + link_to(name,controller) + '</li>'
|
3
|
+
def li_link_to_current(name, controller_name, action_name)
|
4
|
+
if current_page?(:controller => controller_name)
|
5
|
+
str = '<li class="current">' + link_to(name, {:controller => controller_name, :action => action_name}) + '</li>'
|
6
6
|
else
|
7
|
-
str = '<li>' + link_to(name,controller) + '</li>'
|
7
|
+
str = '<li>' + link_to(name, {:controller => controller_name, :action => action_name}) + '</li>'
|
8
8
|
end
|
9
9
|
str.html_safe
|
10
10
|
end
|
@@ -20,4 +20,8 @@ module ApplicationHelper
|
|
20
20
|
def nl2br(text)
|
21
21
|
text.gsub(/(<.*?>)/, '').gsub(/\n/, '<br />').html_safe
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
|
+
def user_last_login_at
|
25
|
+
@current_user.last_login_at.utc.iso8601
|
26
|
+
end
|
27
|
+
end
|
data/app/models/account.rb
CHANGED
@@ -13,7 +13,8 @@ class Account < BaseNew
|
|
13
13
|
|
14
14
|
inheritable_schema do
|
15
15
|
primary_key :id, :type=>Integer
|
16
|
-
String :name
|
16
|
+
String :name, :null=>false
|
17
|
+
String :description, :default=>""
|
17
18
|
Boolean :enable, :default=>true
|
18
19
|
DateTime :deleted_at, :null=>true
|
19
20
|
Boolean :is_deleted, :default=>false
|
@@ -23,11 +24,11 @@ class Account < BaseNew
|
|
23
24
|
many_to_many :users,:join_table => :users_accounts
|
24
25
|
|
25
26
|
def disable?
|
26
|
-
self.
|
27
|
+
not self.enable
|
27
28
|
end
|
28
29
|
|
29
30
|
def enable?
|
30
|
-
self.
|
31
|
+
self.enable
|
31
32
|
end
|
32
33
|
|
33
34
|
def to_hash_document
|
@@ -36,6 +37,23 @@ class Account < BaseNew
|
|
36
37
|
h
|
37
38
|
end
|
38
39
|
|
40
|
+
# Delete relations before setting an account to deleted
|
41
|
+
def before_destroy
|
42
|
+
relations = self.users
|
43
|
+
for ss in 0...relations.length do
|
44
|
+
self.remove_user(relations[0])
|
45
|
+
end
|
46
|
+
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
# override Sequel::Model#_delete not to delete rows but to set
|
51
|
+
# delete flags.
|
52
|
+
def _delete
|
53
|
+
self.deleted_at ||= Time.now
|
54
|
+
self.is_deleted = true
|
55
|
+
self.save
|
56
|
+
end
|
39
57
|
|
40
58
|
# STI class variable setter, getter methods.
|
41
59
|
class << self
|
@@ -53,7 +71,7 @@ class Account < BaseNew
|
|
53
71
|
def uuid(uuid=nil)
|
54
72
|
if uuid.is_a?(String)
|
55
73
|
uuid = uuid.downcase
|
56
|
-
|
74
|
+
unless self.check_trimmed_uuid_format(uuid)
|
57
75
|
raise "Invalid syntax of uuid: #{uuid}"
|
58
76
|
end
|
59
77
|
default_values[:uuid] = uuid
|
data/app/models/base_new.rb
CHANGED
@@ -149,7 +149,12 @@ module Taggable
|
|
149
149
|
if p_uuid and p_uuid =~ regex
|
150
150
|
return p_uuid.sub(regex, '')
|
151
151
|
end
|
152
|
-
raise
|
152
|
+
raise "Invalid uuid or unsupported uuid: #{p_uuid} in #{self}"
|
153
|
+
end
|
154
|
+
|
155
|
+
# Checks the general uuid syntax
|
156
|
+
def check_trimmed_uuid_format(uuid)
|
157
|
+
uuid.match(/^[a-z0-9 ]*$/) && uuid.length <= 8
|
153
158
|
end
|
154
159
|
|
155
160
|
# Checks the uuid syntax if it is for the Taggable class.
|
@@ -245,6 +250,10 @@ class BaseNew < Sequel::Model
|
|
245
250
|
s
|
246
251
|
end
|
247
252
|
|
253
|
+
# Returns true if this Model has time stamps
|
254
|
+
def with_timestamps?
|
255
|
+
self.columns.include?(:created_at) && self.columns.include?(:updated_at)
|
256
|
+
end
|
248
257
|
|
249
258
|
# Callback when the initial data is setup to the database.
|
250
259
|
def self.install_data
|
@@ -308,4 +317,4 @@ class BaseNew < Sequel::Model
|
|
308
317
|
}
|
309
318
|
|
310
319
|
end
|
311
|
-
end
|
320
|
+
end
|
@@ -20,6 +20,19 @@ module DcmgrResource
|
|
20
20
|
def set_debug(debug = true)
|
21
21
|
@@debug = debug
|
22
22
|
end
|
23
|
+
|
24
|
+
def get_resource_state_count(resources, state)
|
25
|
+
resource_count = 0
|
26
|
+
unless resources.empty?
|
27
|
+
resources.each do |item|
|
28
|
+
if item.state == state
|
29
|
+
resource_count += 1;
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
resource_count
|
34
|
+
end
|
35
|
+
|
23
36
|
end
|
24
37
|
|
25
38
|
ActiveResource::Connection.class_eval do
|