wakame-vdc-webui 10.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL.txt +21 -0
- data/LICENSE +202 -0
- data/NOTICE +1 -0
- data/README +256 -0
- data/Rakefile +42 -0
- data/app/controllers/accounts_controller.rb +15 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/dialog_controller.rb +80 -0
- data/app/controllers/home_controller.rb +5 -0
- data/app/controllers/host_pools_controller.rb +26 -0
- data/app/controllers/images_controller.rb +28 -0
- data/app/controllers/information_controller.rb +10 -0
- data/app/controllers/instances_controller.rb +59 -0
- data/app/controllers/keypairs_controller.rb +64 -0
- data/app/controllers/security_groups_controller.rb +59 -0
- data/app/controllers/sessions_controller.rb +25 -0
- data/app/controllers/snapshots_controller.rb +48 -0
- data/app/controllers/storage_pools_controller.rb +27 -0
- data/app/controllers/users_controller.rb +3 -0
- data/app/controllers/volumes_controller.rb +86 -0
- data/app/helpers/accounts_helper.rb +2 -0
- data/app/helpers/application_helper.rb +23 -0
- data/app/helpers/dialog_helper.rb +2 -0
- data/app/helpers/home_helper.rb +2 -0
- data/app/helpers/host_pools_helper.rb +2 -0
- data/app/helpers/images_helper.rb +2 -0
- data/app/helpers/information_helper.rb +2 -0
- data/app/helpers/instances_helper.rb +2 -0
- data/app/helpers/keypairs_helper.rb +2 -0
- data/app/helpers/security_groups_helper.rb +2 -0
- data/app/helpers/sessions_helper.rb +2 -0
- data/app/helpers/snapshots_helper.rb +2 -0
- data/app/helpers/storage_pools_helper.rb +2 -0
- data/app/helpers/users_helper.rb +2 -0
- data/app/helpers/volumes_helper.rb +2 -0
- data/app/models/account.rb +104 -0
- data/app/models/authz.rb +102 -0
- data/app/models/base_new.rb +311 -0
- data/app/models/dcmgr_resource/account.rb +5 -0
- data/app/models/dcmgr_resource/base.rb +51 -0
- data/app/models/dcmgr_resource/host_pool.rb +11 -0
- data/app/models/dcmgr_resource/image.rb +11 -0
- data/app/models/dcmgr_resource/instance.rb +37 -0
- data/app/models/dcmgr_resource/mock.rb +15 -0
- data/app/models/dcmgr_resource/netfilter_group.rb +29 -0
- data/app/models/dcmgr_resource/ssh_key_pair.rb +25 -0
- data/app/models/dcmgr_resource/storage_pool.rb +11 -0
- data/app/models/dcmgr_resource/volume.rb +48 -0
- data/app/models/dcmgr_resource/volume_snapshot.rb +35 -0
- data/app/models/information.rb +9 -0
- data/app/models/schema.rb +51 -0
- data/app/models/tag.rb +121 -0
- data/app/models/tag_mapping.rb +25 -0
- data/app/models/user.rb +46 -0
- data/app/views/accounts/index.html.erb +68 -0
- data/app/views/dialog/attach_volume.html.erb +13 -0
- data/app/views/dialog/create_and_edit_security_group.html.erb +32 -0
- data/app/views/dialog/create_snapshot.html.erb +7 -0
- data/app/views/dialog/create_ssh_keypair.html.erb +15 -0
- data/app/views/dialog/create_volume.html.erb +18 -0
- data/app/views/dialog/create_volume_from_snapshot.html.erb +7 -0
- data/app/views/dialog/delete_security_group.html.erb +4 -0
- data/app/views/dialog/delete_snapshot.html.erb +7 -0
- data/app/views/dialog/delete_ssh_keypair.html.erb +4 -0
- data/app/views/dialog/delete_volume.html.erb +7 -0
- data/app/views/dialog/detach_volume.html.erb +7 -0
- data/app/views/dialog/launch_instance.html.erb +70 -0
- data/app/views/dialog/reboot_instances.html.erb +7 -0
- data/app/views/dialog/start_instances.html.erb +8 -0
- data/app/views/dialog/stop_instances.html.erb +7 -0
- data/app/views/dialog/terminate_instances.html.erb +7 -0
- data/app/views/home/index.html.erb +55 -0
- data/app/views/host_pools/index.html.erb +103 -0
- data/app/views/images/index.html.erb +126 -0
- data/app/views/information/index.html.erb +25 -0
- data/app/views/instances/index.html.erb +134 -0
- data/app/views/keypairs/index.html.erb +104 -0
- data/app/views/layouts/_footer.html.erb +4 -0
- data/app/views/layouts/_header.html.erb +14 -0
- data/app/views/layouts/_informationarea.html.erb +18 -0
- data/app/views/layouts/_login_header.erb +4 -0
- data/app/views/layouts/_service_health.erb +27 -0
- data/app/views/layouts/_sidemenu.html.erb +58 -0
- data/app/views/layouts/application.html.erb +34 -0
- data/app/views/layouts/login.html.erb +25 -0
- data/app/views/security_groups/index.html.erb +114 -0
- data/app/views/sessions/new.html.erb +27 -0
- data/app/views/snapshots/index.html.erb +110 -0
- data/app/views/storage_pools/index.html.erb +98 -0
- data/app/views/volumes/index.html.erb +117 -0
- data/config.ru +4 -0
- data/config/application.rb +48 -0
- data/config/boot.rb +13 -0
- data/config/database.yml +20 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +28 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +35 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/dcmgr_gui.rb +14 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +7 -0
- data/config/initializers/session_store.rb +8 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +109 -0
- data/db/seeds.rb +7 -0
- data/extras/authentication.rb +94 -0
- data/extras/util.rb +5 -0
- data/lib/tasks/dcmgr_gui.rake +51 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/images/app_active.gif +0 -0
- data/public/images/app_passive.gif +0 -0
- data/public/images/body_bg.gif +0 -0
- data/public/images/btn_change.gif +0 -0
- data/public/images/btn_create_security_group.gif +0 -0
- data/public/images/btn_create_snapshot.gif +0 -0
- data/public/images/btn_create_volume.gif +0 -0
- data/public/images/btn_createkey.gif +0 -0
- data/public/images/btn_de_register.gif +0 -0
- data/public/images/btn_delete_security_group.gif +0 -0
- data/public/images/btn_delete_snapshot.gif +0 -0
- data/public/images/btn_delete_volume.gif +0 -0
- data/public/images/btn_deletekey.gif +0 -0
- data/public/images/btn_healthdetail.gif +0 -0
- data/public/images/btn_hide.gif +0 -0
- data/public/images/btn_launch.gif +0 -0
- data/public/images/btn_next.gif +0 -0
- data/public/images/btn_prev.gif +0 -0
- data/public/images/btn_refresh.gif +0 -0
- data/public/images/btn_register_new_ami.gif +0 -0
- data/public/images/btn_savechange.gif +0 -0
- data/public/images/btn_show.gif +0 -0
- data/public/images/btn_show_accesskey.png +0 -0
- data/public/images/bup_btn_healthdetail.gif +0 -0
- data/public/images/bup_btn_refresh.gif +0 -0
- data/public/images/clear.gif +0 -0
- data/public/images/content_bg.png +0 -0
- data/public/images/content_foot_bg.gif +0 -0
- data/public/images/content_head_bg.gif +0 -0
- data/public/images/footer_bg.gif +0 -0
- data/public/images/head_gradation_bg.gif +0 -0
- data/public/images/header_logo.gif +0 -0
- data/public/images/icon_blockstore.gif +0 -0
- data/public/images/icon_caution.gif +0 -0
- data/public/images/icon_health.gif +0 -0
- data/public/images/icon_images.gif +0 -0
- data/public/images/icon_information.gif +0 -0
- data/public/images/icon_instances.gif +0 -0
- data/public/images/icon_resource.gif +0 -0
- data/public/images/icon_resource01.gif +0 -0
- data/public/images/icon_resource02.gif +0 -0
- data/public/images/icon_resource03.gif +0 -0
- data/public/images/icon_resource04.gif +0 -0
- data/public/images/icon_rss.gif +0 -0
- data/public/images/icon_security.gif +0 -0
- data/public/images/icon_service.gif +0 -0
- data/public/images/icon_service_stat.gif +0 -0
- data/public/images/icon_stop.gif +0 -0
- data/public/images/icon_summary.gif +0 -0
- data/public/images/icon_ttl_accskey.gif +0 -0
- data/public/images/icon_ttl_detail.gif +0 -0
- data/public/images/icon_ttl_instance.gif +0 -0
- data/public/images/icon_ttl_personal_inf.gif +0 -0
- data/public/images/infra_active.gif +0 -0
- data/public/images/infra_passive.gif +0 -0
- data/public/images/lastelement_bg.gif +0 -0
- data/public/images/lastelement_bg.png +0 -0
- data/public/images/listicon_useast.gif +0 -0
- data/public/images/loader_ball.gif +0 -0
- data/public/images/loader_boxes.gif +0 -0
- data/public/images/loading.gif +0 -0
- data/public/images/mainarea_bottom_bg.gif +0 -0
- data/public/images/mainarea_content_bg.gif +0 -0
- data/public/images/mainarea_h3_bg.gif +0 -0
- data/public/images/mainarea_wide_bottom_bg.gif +0 -0
- data/public/images/mainarea_wide_content_bg.gif +0 -0
- data/public/images/mainarea_wide_h3_bg.gif +0 -0
- data/public/images/menu_list_header.gif +0 -0
- data/public/images/menu_list_header_current.gif +0 -0
- data/public/images/plat_active.gif +0 -0
- data/public/images/plat_passive.gif +0 -0
- data/public/images/regionselect_bg.gif +0 -0
- data/public/images/select_bg_126.gif +0 -0
- data/public/images/select_bg_139.gif +0 -0
- data/public/images/sidemenu_bg.gif +0 -0
- data/public/images/sidemenu_bottom.gif +0 -0
- data/public/images/sidemenu_top.gif +0 -0
- data/public/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/public/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/public/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/public/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/public/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/public/images/ui-bg_glass_55_fcf0ba_1x400.png +0 -0
- data/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/images/ui-bg_gloss-wave_100_ece8da_500x100.png +0 -0
- data/public/images/ui-bg_gloss-wave_35_f6a828_500x100.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-hard_15_459e00_1x100.png +0 -0
- data/public/images/ui-bg_highlight-hard_95_cccccc_1x100.png +0 -0
- data/public/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/public/images/ui-bg_highlight-soft_25_67b021_1x100.png +0 -0
- data/public/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/public/images/ui-bg_highlight-soft_95_ffedad_1x100.png +0 -0
- data/public/images/ui-bg_inset-soft_15_2b2922_1x100.png +0 -0
- data/public/images/ui-icons_222222_256x240.png +0 -0
- data/public/images/ui-icons_228ef1_256x240.png +0 -0
- data/public/images/ui-icons_808080_256x240.png +0 -0
- data/public/images/ui-icons_847e71_256x240.png +0 -0
- data/public/images/ui-icons_8dc262_256x240.png +0 -0
- data/public/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/images/ui-icons_eeeeee_256x240.png +0 -0
- data/public/images/ui-icons_ef8c08_256x240.png +0 -0
- data/public/images/ui-icons_ffd27a_256x240.png +0 -0
- data/public/images/ui-icons_ffffff_256x240.png +0 -0
- data/public/images/vtip_arrow.png +0 -0
- data/public/javascripts/controls.js +965 -0
- data/public/javascripts/dcmgr_gui/application.js +91 -0
- data/public/javascripts/dcmgr_gui/core.js +539 -0
- data/public/javascripts/dcmgr_gui/dashboard_panel.js +34 -0
- data/public/javascripts/dcmgr_gui/host_pool_panel.js +83 -0
- data/public/javascripts/dcmgr_gui/image_panel.js +242 -0
- data/public/javascripts/dcmgr_gui/instance_panel.js +197 -0
- data/public/javascripts/dcmgr_gui/security_group_panel.js +196 -0
- data/public/javascripts/dcmgr_gui/snapshot_panel.js +168 -0
- data/public/javascripts/dcmgr_gui/sshkeypair_panel.js +161 -0
- data/public/javascripts/dcmgr_gui/storage_pool_panel.js +99 -0
- data/public/javascripts/dcmgr_gui/volume_panel.js +311 -0
- data/public/javascripts/dragdrop.js +974 -0
- data/public/javascripts/effects.js +1123 -0
- data/public/javascripts/jquery-1.4.2.min.js +154 -0
- data/public/javascripts/jquery-ui-1.8.4.custom.min.js +763 -0
- data/public/javascripts/jquery.loadmask.min.js +10 -0
- data/public/javascripts/jquery.tmpl.js +486 -0
- data/public/javascripts/jsdeferred.jquery.js +385 -0
- data/public/javascripts/prototype.js +6001 -0
- data/public/javascripts/rails.js +175 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/common.css +1236 -0
- data/public/stylesheets/dialog.css +67 -0
- data/public/stylesheets/jquery-ui-1.8.4.custom.css +572 -0
- data/public/stylesheets/jquery.loadmask.css +40 -0
- data/public/stylesheets/reset.css +71 -0
- data/public/stylesheets/style.css +7 -0
- data/public/stylesheets/vtip.css +28 -0
- data/script/rails +6 -0
- data/test/functional/accounts_controller_test.rb +8 -0
- data/test/functional/dialog_controller_test.rb +8 -0
- data/test/functional/home_controller_test.rb +8 -0
- data/test/functional/host_pools_controller_test.rb +8 -0
- data/test/functional/images_controller_test.rb +8 -0
- data/test/functional/information_controller_test.rb +8 -0
- data/test/functional/instances_controller_test.rb +8 -0
- data/test/functional/keypairs_controller_test.rb +8 -0
- data/test/functional/security_groups_controller_test.rb +8 -0
- data/test/functional/sessions_controller_test.rb +8 -0
- data/test/functional/snapshots_controller_test.rb +8 -0
- data/test/functional/storage_pools_controller_test.rb +8 -0
- data/test/functional/users_controller_test.rb +8 -0
- data/test/functional/volumes_controller_test.rb +8 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +13 -0
- data/test/unit/helpers/accounts_helper_test.rb +4 -0
- data/test/unit/helpers/dialog_helper_test.rb +4 -0
- data/test/unit/helpers/home_helper_test.rb +4 -0
- data/test/unit/helpers/host_pools_helper_test.rb +4 -0
- data/test/unit/helpers/images_helper_test.rb +4 -0
- data/test/unit/helpers/information_helper_test.rb +4 -0
- data/test/unit/helpers/instances_helper_test.rb +4 -0
- data/test/unit/helpers/keypairs_helper_test.rb +4 -0
- data/test/unit/helpers/security_groups_helper_test.rb +4 -0
- data/test/unit/helpers/sessions_helper_test.rb +4 -0
- data/test/unit/helpers/snapshots_helper_test.rb +4 -0
- data/test/unit/helpers/storage_pools_helper_test.rb +4 -0
- data/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/unit/helpers/volumes_helper_test.rb +4 -0
- metadata +399 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class Base < ActiveResource::Base
|
3
|
+
|
4
|
+
# self.site = 'http://your.dcmgr.api.server'
|
5
|
+
self.timeout = 30
|
6
|
+
self.format = :json
|
7
|
+
self.prefix = '/api/'
|
8
|
+
|
9
|
+
@@debug = false
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def total_resource
|
14
|
+
result = self.find(:first,:params => {:start => 0,:limit => 1})
|
15
|
+
result.owner_total
|
16
|
+
end
|
17
|
+
# If headers are not defined in a given subclass, then obtain
|
18
|
+
# headers from the superclass.
|
19
|
+
|
20
|
+
def set_debug(debug = true)
|
21
|
+
@@debug = debug
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ActiveResource::Connection.class_eval do
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_header
|
30
|
+
@default_header = {
|
31
|
+
'X-VDC-ACCOUNT-UUID' => self.class.send(:class_variable_get,:@@vdc_account_uuid)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure_http(http)
|
36
|
+
http = apply_ssl_options(http)
|
37
|
+
|
38
|
+
#add debug
|
39
|
+
http.set_debug_output($stderr) if @@debug
|
40
|
+
|
41
|
+
# Net::HTTP timeouts default to 60 seconds.
|
42
|
+
if @timeout
|
43
|
+
http.open_timeout = @timeout
|
44
|
+
http.read_timeout = @timeout
|
45
|
+
end
|
46
|
+
|
47
|
+
http
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class Instance < Base
|
3
|
+
def self.list(params = {})
|
4
|
+
self.find(:all,:params => params)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.show(instance_id)
|
8
|
+
self.get(instance_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create(params)
|
12
|
+
instance = self.new
|
13
|
+
instance.image_id = params[:image_id]
|
14
|
+
instance.instance_spec_id = params[:instance_spec_id]
|
15
|
+
instance.host_pool_id = params[:host_pool_id]
|
16
|
+
instance.host_name = params[:host_name]
|
17
|
+
instance.user_data = params[:user_data]
|
18
|
+
instance.nf_group = params[:nf_group]
|
19
|
+
instance.ssh_key = params[:ssh_key]
|
20
|
+
instance.save
|
21
|
+
instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.destroy(instance_id)
|
25
|
+
self.delete(instance_id).body
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.reboot(instance_id)
|
29
|
+
@collection ||= self.collection_name
|
30
|
+
self.collection_name = File.join(@collection,instance_id)
|
31
|
+
result = self.put(:reboot)
|
32
|
+
self.collection_name = @collection
|
33
|
+
result.body
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class Mock
|
3
|
+
def self.load(load)
|
4
|
+
root = File.expand_path('../')
|
5
|
+
load = File::split(load)
|
6
|
+
namespace = load[0]
|
7
|
+
file = load[1] + '.json'
|
8
|
+
dir = File.join(root,'common','data','mock',namespace)
|
9
|
+
jsonfile = File.join(dir,file)
|
10
|
+
json = ''
|
11
|
+
open(jsonfile) {|f| json = f.read }
|
12
|
+
json
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class NetfilterGroup < Base
|
3
|
+
|
4
|
+
def self.create(params)
|
5
|
+
netfilter_group = self.new
|
6
|
+
netfilter_group.name = params[:name]
|
7
|
+
netfilter_group.description = params[:description]
|
8
|
+
netfilter_group.rule = params[:rule]
|
9
|
+
netfilter_group.save
|
10
|
+
netfilter_group
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.list(params = {})
|
14
|
+
self.find(:all,:params => params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.show(uuid)
|
18
|
+
self.get(uuid)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(uuid,params)
|
22
|
+
self.put(uuid,params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.destroy(uuid)
|
26
|
+
self.delete(uuid).body
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class SshKeyPair < Base
|
3
|
+
|
4
|
+
def self.list(params = {})
|
5
|
+
self.find(:all,:params => params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.show(uuid)
|
9
|
+
self.get(uuid)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(params)
|
13
|
+
ssh_key_pair = self.new
|
14
|
+
ssh_key_pair.name = params[:name]
|
15
|
+
ssh_key_pair.download_once = params[:download_once]
|
16
|
+
ssh_key_pair.save
|
17
|
+
ssh_key_pair
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.destroy(uuid)
|
21
|
+
self.delete(uuid).body
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class Volume < Base
|
3
|
+
def self.list(params = {})
|
4
|
+
self.find(:all,:params => params)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.create(params)
|
8
|
+
volume = self.new
|
9
|
+
volume.volume_size = params[:volume_size]
|
10
|
+
volume.snapshot_id = params[:snapshot_id]
|
11
|
+
volume.storage_pool_id = params[:storage_pool_id]
|
12
|
+
volume.save
|
13
|
+
volume
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.destroy(volume_id)
|
17
|
+
self.delete(volume_id).body
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.attach(volume_id, instance_id)
|
21
|
+
@collection ||= self.collection_name
|
22
|
+
self.collection_name = File.join(@collection,volume_id)
|
23
|
+
result = self.put(:attach, {:volume_id => volume_id,:instance_id => instance_id})
|
24
|
+
self.collection_name = @collection
|
25
|
+
result.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.detach(volume_id)
|
29
|
+
@collection ||= self.collection_name
|
30
|
+
self.collection_name = File.join(@collection,volume_id)
|
31
|
+
result = self.put(:detach, {:volume_id => volume_id})
|
32
|
+
self.collection_name = @collection
|
33
|
+
result.body
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.status(account_id)
|
37
|
+
@collection ||= self.collection_name
|
38
|
+
self.collection_name = File.join(@collection,account_id)
|
39
|
+
result = self.get(:status)
|
40
|
+
self.collection_name = @collection
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.show(volume_id)
|
45
|
+
self.get(volume_id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DcmgrResource
|
2
|
+
class VolumeSnapshot < Base
|
3
|
+
|
4
|
+
def self.list(params = {})
|
5
|
+
data = self.find(:all, :params => params)
|
6
|
+
results = []
|
7
|
+
data.each { |row|
|
8
|
+
results << row.attributes
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.show(snapshot_id)
|
13
|
+
self.get(snapshot_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create(params)
|
17
|
+
snapshot = self.new
|
18
|
+
snapshot.volume_id = params[:volume_id]
|
19
|
+
snapshot.save
|
20
|
+
snapshot
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.destroy(snapshot_id)
|
24
|
+
self.delete(snapshot_id).body
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.status(account_id)
|
28
|
+
@collection ||= self.collection_name
|
29
|
+
self.collection_name = File.join(@collection,account_id)
|
30
|
+
result = self.get(:status)
|
31
|
+
self.collection_name = @collection
|
32
|
+
result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'sequel'
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module Schema
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def connect(str)
|
10
|
+
@db = Sequel.connect(str)
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_connect
|
14
|
+
@db
|
15
|
+
end
|
16
|
+
|
17
|
+
def config(env,file)
|
18
|
+
YAML::load(ERB.new(IO.read(file)).result)[env]
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :db
|
22
|
+
def table_exists?(table_name)
|
23
|
+
@db.table_exists? table_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def create!
|
27
|
+
Sequel::MySQL.default_charset = 'utf8'
|
28
|
+
Sequel::MySQL.default_engine = 'InnoDB'
|
29
|
+
|
30
|
+
models.each { |model|
|
31
|
+
model.create_table!
|
32
|
+
}
|
33
|
+
@db.create_table? :users_accounts do
|
34
|
+
primary_key :id, :type=>Integer
|
35
|
+
Fixnum :user_id, :null => false
|
36
|
+
Fixnum :account_id, :null => false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def drop!
|
41
|
+
models.each { |model|
|
42
|
+
@db.drop_table(model.table_name)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def models
|
47
|
+
@models ||= [Account, User,
|
48
|
+
Authz,Tag,TagMapping,Information
|
49
|
+
].freeze
|
50
|
+
end
|
51
|
+
end
|
data/app/models/tag.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class Tag < BaseNew
|
3
|
+
taggable('tag')
|
4
|
+
with_timestamps
|
5
|
+
plugin :single_table_inheritance, :type_id, :model_map=>{}
|
6
|
+
plugin :subclasses
|
7
|
+
|
8
|
+
inheritable_schema do
|
9
|
+
primary_key :id, :type=>Integer
|
10
|
+
Fixnum :account_id, :null=>false # if 0 system tag
|
11
|
+
index :account_id
|
12
|
+
Fixnum :owner_id, :null=>false
|
13
|
+
String :name, :fixed=>true, :size=>32, :null=>false
|
14
|
+
end
|
15
|
+
|
16
|
+
TYPE_NORMAL = 0
|
17
|
+
TYPE_AUTH = 1
|
18
|
+
|
19
|
+
many_to_one :account
|
20
|
+
|
21
|
+
#one_to_many :tag_mappings, :dataset=>proc{ TagMapping.dataset.filter(:tag_id=>self.id) } do
|
22
|
+
one_to_many :mapped_uuids, :class=>TagMapping do |ds|
|
23
|
+
ds.instance_eval {
|
24
|
+
def exists?(canonical_uuid)
|
25
|
+
!self.filter(:uuid=>canonical_uuid).empty?
|
26
|
+
end
|
27
|
+
}
|
28
|
+
ds
|
29
|
+
end
|
30
|
+
|
31
|
+
class UnacceptableTagType < StandardError
|
32
|
+
def initialize(msg, tag, taggable)
|
33
|
+
super(msg)
|
34
|
+
|
35
|
+
raise ArgumentError, "Expected #{Tag.class}: #{tag.class}" unless tag.is_a?(Tag)
|
36
|
+
raise ArgumentError, "Expected #{Taggable.class}: #{tag.class}" unless taggable.is_a?(Taggable)
|
37
|
+
@tag = tag
|
38
|
+
@taggable = taggable
|
39
|
+
end
|
40
|
+
#TODO: show @tag and @taggable info to the error message.
|
41
|
+
end
|
42
|
+
class TagAlreadyLabeled < StandardError; end
|
43
|
+
class TagAlreadyUnlabeled < StandardError; end
|
44
|
+
|
45
|
+
def labeled?(canonical_uuid)
|
46
|
+
# TODO: check if the uuid exists
|
47
|
+
|
48
|
+
!TagMapping.filter(:uuid=>canonical_uuid, :tag_id=>self.pk).empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def label(canonical_uuid)
|
52
|
+
tgt = Taggable.find(canonical_uuid)
|
53
|
+
|
54
|
+
raise(UnacceptableTagType, self, tgt) if accept_mapping?(tgt)
|
55
|
+
raise(TagAlreadyLabeled) if labeled?(canonical_uuid)
|
56
|
+
TagMapping.create(:uuid=>canonical_uuid, :tag_id=>self.pk)
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
def unlabel(canonical_uuid)
|
61
|
+
t = TagMapping.find(:uuid=>canonical_uuid, :tag_id=>self.pk) || raise(TagAlreadyUnlabeled)
|
62
|
+
t.delete
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
#many_to_many :tags, :join_table=>:tag_mappings, :left_key=>:target_id, :conditions=>{:target_type=>TagMapping::TYPE_TAG}
|
67
|
+
|
68
|
+
#many_to_one :owner, :class=>:User
|
69
|
+
|
70
|
+
#one_to_many :tag_attributes, :one_to_one=>true
|
71
|
+
|
72
|
+
def self.find_tag_class(name)
|
73
|
+
self.subclasses.find { |m|
|
74
|
+
m.to_s.sub(/^#{self.class}::/, '') == name
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
# STI class variable setter, getter methods.
|
79
|
+
class << self
|
80
|
+
|
81
|
+
# Declare the integer number for the tag.
|
82
|
+
#
|
83
|
+
# Also set the value to sti map in class Tag.
|
84
|
+
# class Tag1 < Tag
|
85
|
+
# type_id 123456
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# puts Tag1.type_id # == 123456
|
89
|
+
def type_id(type_id=nil)
|
90
|
+
if type_id.is_a?(Fixnum)
|
91
|
+
@type_id = type_id
|
92
|
+
Tag.sti_model_map[type_id] = self
|
93
|
+
Tag.sti_key_map[self.to_s] = type_id
|
94
|
+
end
|
95
|
+
@type_id || raise("#{self}.type_id is unset. Please set the unique number for the tag instance.")
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# Set or read description of the Tag class.
|
100
|
+
def description(desc=nil)
|
101
|
+
if desc
|
102
|
+
@description = desc
|
103
|
+
end
|
104
|
+
@description
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
# Check the object class type before associating to the Tag.
|
110
|
+
# Child class must implement this method.
|
111
|
+
# @param taggable_obj any object kind_of?(Model::Taggable)
|
112
|
+
def accept_mapping?(taggable_obj)
|
113
|
+
raise NotImplementedError
|
114
|
+
end
|
115
|
+
|
116
|
+
def after_initialize
|
117
|
+
super
|
118
|
+
self[:type_id] = self.class.type_id
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|