wakame-vdc-webui 10.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/INSTALL.txt +21 -0
  2. data/LICENSE +202 -0
  3. data/NOTICE +1 -0
  4. data/README +256 -0
  5. data/Rakefile +42 -0
  6. data/app/controllers/accounts_controller.rb +15 -0
  7. data/app/controllers/application_controller.rb +5 -0
  8. data/app/controllers/dialog_controller.rb +80 -0
  9. data/app/controllers/home_controller.rb +5 -0
  10. data/app/controllers/host_pools_controller.rb +26 -0
  11. data/app/controllers/images_controller.rb +28 -0
  12. data/app/controllers/information_controller.rb +10 -0
  13. data/app/controllers/instances_controller.rb +59 -0
  14. data/app/controllers/keypairs_controller.rb +64 -0
  15. data/app/controllers/security_groups_controller.rb +59 -0
  16. data/app/controllers/sessions_controller.rb +25 -0
  17. data/app/controllers/snapshots_controller.rb +48 -0
  18. data/app/controllers/storage_pools_controller.rb +27 -0
  19. data/app/controllers/users_controller.rb +3 -0
  20. data/app/controllers/volumes_controller.rb +86 -0
  21. data/app/helpers/accounts_helper.rb +2 -0
  22. data/app/helpers/application_helper.rb +23 -0
  23. data/app/helpers/dialog_helper.rb +2 -0
  24. data/app/helpers/home_helper.rb +2 -0
  25. data/app/helpers/host_pools_helper.rb +2 -0
  26. data/app/helpers/images_helper.rb +2 -0
  27. data/app/helpers/information_helper.rb +2 -0
  28. data/app/helpers/instances_helper.rb +2 -0
  29. data/app/helpers/keypairs_helper.rb +2 -0
  30. data/app/helpers/security_groups_helper.rb +2 -0
  31. data/app/helpers/sessions_helper.rb +2 -0
  32. data/app/helpers/snapshots_helper.rb +2 -0
  33. data/app/helpers/storage_pools_helper.rb +2 -0
  34. data/app/helpers/users_helper.rb +2 -0
  35. data/app/helpers/volumes_helper.rb +2 -0
  36. data/app/models/account.rb +104 -0
  37. data/app/models/authz.rb +102 -0
  38. data/app/models/base_new.rb +311 -0
  39. data/app/models/dcmgr_resource/account.rb +5 -0
  40. data/app/models/dcmgr_resource/base.rb +51 -0
  41. data/app/models/dcmgr_resource/host_pool.rb +11 -0
  42. data/app/models/dcmgr_resource/image.rb +11 -0
  43. data/app/models/dcmgr_resource/instance.rb +37 -0
  44. data/app/models/dcmgr_resource/mock.rb +15 -0
  45. data/app/models/dcmgr_resource/netfilter_group.rb +29 -0
  46. data/app/models/dcmgr_resource/ssh_key_pair.rb +25 -0
  47. data/app/models/dcmgr_resource/storage_pool.rb +11 -0
  48. data/app/models/dcmgr_resource/volume.rb +48 -0
  49. data/app/models/dcmgr_resource/volume_snapshot.rb +35 -0
  50. data/app/models/information.rb +9 -0
  51. data/app/models/schema.rb +51 -0
  52. data/app/models/tag.rb +121 -0
  53. data/app/models/tag_mapping.rb +25 -0
  54. data/app/models/user.rb +46 -0
  55. data/app/views/accounts/index.html.erb +68 -0
  56. data/app/views/dialog/attach_volume.html.erb +13 -0
  57. data/app/views/dialog/create_and_edit_security_group.html.erb +32 -0
  58. data/app/views/dialog/create_snapshot.html.erb +7 -0
  59. data/app/views/dialog/create_ssh_keypair.html.erb +15 -0
  60. data/app/views/dialog/create_volume.html.erb +18 -0
  61. data/app/views/dialog/create_volume_from_snapshot.html.erb +7 -0
  62. data/app/views/dialog/delete_security_group.html.erb +4 -0
  63. data/app/views/dialog/delete_snapshot.html.erb +7 -0
  64. data/app/views/dialog/delete_ssh_keypair.html.erb +4 -0
  65. data/app/views/dialog/delete_volume.html.erb +7 -0
  66. data/app/views/dialog/detach_volume.html.erb +7 -0
  67. data/app/views/dialog/launch_instance.html.erb +70 -0
  68. data/app/views/dialog/reboot_instances.html.erb +7 -0
  69. data/app/views/dialog/start_instances.html.erb +8 -0
  70. data/app/views/dialog/stop_instances.html.erb +7 -0
  71. data/app/views/dialog/terminate_instances.html.erb +7 -0
  72. data/app/views/home/index.html.erb +55 -0
  73. data/app/views/host_pools/index.html.erb +103 -0
  74. data/app/views/images/index.html.erb +126 -0
  75. data/app/views/information/index.html.erb +25 -0
  76. data/app/views/instances/index.html.erb +134 -0
  77. data/app/views/keypairs/index.html.erb +104 -0
  78. data/app/views/layouts/_footer.html.erb +4 -0
  79. data/app/views/layouts/_header.html.erb +14 -0
  80. data/app/views/layouts/_informationarea.html.erb +18 -0
  81. data/app/views/layouts/_login_header.erb +4 -0
  82. data/app/views/layouts/_service_health.erb +27 -0
  83. data/app/views/layouts/_sidemenu.html.erb +58 -0
  84. data/app/views/layouts/application.html.erb +34 -0
  85. data/app/views/layouts/login.html.erb +25 -0
  86. data/app/views/security_groups/index.html.erb +114 -0
  87. data/app/views/sessions/new.html.erb +27 -0
  88. data/app/views/snapshots/index.html.erb +110 -0
  89. data/app/views/storage_pools/index.html.erb +98 -0
  90. data/app/views/volumes/index.html.erb +117 -0
  91. data/config.ru +4 -0
  92. data/config/application.rb +48 -0
  93. data/config/boot.rb +13 -0
  94. data/config/database.yml +20 -0
  95. data/config/environment.rb +5 -0
  96. data/config/environments/development.rb +28 -0
  97. data/config/environments/production.rb +49 -0
  98. data/config/environments/test.rb +35 -0
  99. data/config/initializers/backtrace_silencers.rb +7 -0
  100. data/config/initializers/dcmgr_gui.rb +14 -0
  101. data/config/initializers/inflections.rb +10 -0
  102. data/config/initializers/mime_types.rb +5 -0
  103. data/config/initializers/secret_token.rb +7 -0
  104. data/config/initializers/session_store.rb +8 -0
  105. data/config/locales/en.yml +5 -0
  106. data/config/routes.rb +109 -0
  107. data/db/seeds.rb +7 -0
  108. data/extras/authentication.rb +94 -0
  109. data/extras/util.rb +5 -0
  110. data/lib/tasks/dcmgr_gui.rake +51 -0
  111. data/public/404.html +26 -0
  112. data/public/422.html +26 -0
  113. data/public/500.html +26 -0
  114. data/public/favicon.ico +0 -0
  115. data/public/images/app_active.gif +0 -0
  116. data/public/images/app_passive.gif +0 -0
  117. data/public/images/body_bg.gif +0 -0
  118. data/public/images/btn_change.gif +0 -0
  119. data/public/images/btn_create_security_group.gif +0 -0
  120. data/public/images/btn_create_snapshot.gif +0 -0
  121. data/public/images/btn_create_volume.gif +0 -0
  122. data/public/images/btn_createkey.gif +0 -0
  123. data/public/images/btn_de_register.gif +0 -0
  124. data/public/images/btn_delete_security_group.gif +0 -0
  125. data/public/images/btn_delete_snapshot.gif +0 -0
  126. data/public/images/btn_delete_volume.gif +0 -0
  127. data/public/images/btn_deletekey.gif +0 -0
  128. data/public/images/btn_healthdetail.gif +0 -0
  129. data/public/images/btn_hide.gif +0 -0
  130. data/public/images/btn_launch.gif +0 -0
  131. data/public/images/btn_next.gif +0 -0
  132. data/public/images/btn_prev.gif +0 -0
  133. data/public/images/btn_refresh.gif +0 -0
  134. data/public/images/btn_register_new_ami.gif +0 -0
  135. data/public/images/btn_savechange.gif +0 -0
  136. data/public/images/btn_show.gif +0 -0
  137. data/public/images/btn_show_accesskey.png +0 -0
  138. data/public/images/bup_btn_healthdetail.gif +0 -0
  139. data/public/images/bup_btn_refresh.gif +0 -0
  140. data/public/images/clear.gif +0 -0
  141. data/public/images/content_bg.png +0 -0
  142. data/public/images/content_foot_bg.gif +0 -0
  143. data/public/images/content_head_bg.gif +0 -0
  144. data/public/images/footer_bg.gif +0 -0
  145. data/public/images/head_gradation_bg.gif +0 -0
  146. data/public/images/header_logo.gif +0 -0
  147. data/public/images/icon_blockstore.gif +0 -0
  148. data/public/images/icon_caution.gif +0 -0
  149. data/public/images/icon_health.gif +0 -0
  150. data/public/images/icon_images.gif +0 -0
  151. data/public/images/icon_information.gif +0 -0
  152. data/public/images/icon_instances.gif +0 -0
  153. data/public/images/icon_resource.gif +0 -0
  154. data/public/images/icon_resource01.gif +0 -0
  155. data/public/images/icon_resource02.gif +0 -0
  156. data/public/images/icon_resource03.gif +0 -0
  157. data/public/images/icon_resource04.gif +0 -0
  158. data/public/images/icon_rss.gif +0 -0
  159. data/public/images/icon_security.gif +0 -0
  160. data/public/images/icon_service.gif +0 -0
  161. data/public/images/icon_service_stat.gif +0 -0
  162. data/public/images/icon_stop.gif +0 -0
  163. data/public/images/icon_summary.gif +0 -0
  164. data/public/images/icon_ttl_accskey.gif +0 -0
  165. data/public/images/icon_ttl_detail.gif +0 -0
  166. data/public/images/icon_ttl_instance.gif +0 -0
  167. data/public/images/icon_ttl_personal_inf.gif +0 -0
  168. data/public/images/infra_active.gif +0 -0
  169. data/public/images/infra_passive.gif +0 -0
  170. data/public/images/lastelement_bg.gif +0 -0
  171. data/public/images/lastelement_bg.png +0 -0
  172. data/public/images/listicon_useast.gif +0 -0
  173. data/public/images/loader_ball.gif +0 -0
  174. data/public/images/loader_boxes.gif +0 -0
  175. data/public/images/loading.gif +0 -0
  176. data/public/images/mainarea_bottom_bg.gif +0 -0
  177. data/public/images/mainarea_content_bg.gif +0 -0
  178. data/public/images/mainarea_h3_bg.gif +0 -0
  179. data/public/images/mainarea_wide_bottom_bg.gif +0 -0
  180. data/public/images/mainarea_wide_content_bg.gif +0 -0
  181. data/public/images/mainarea_wide_h3_bg.gif +0 -0
  182. data/public/images/menu_list_header.gif +0 -0
  183. data/public/images/menu_list_header_current.gif +0 -0
  184. data/public/images/plat_active.gif +0 -0
  185. data/public/images/plat_passive.gif +0 -0
  186. data/public/images/regionselect_bg.gif +0 -0
  187. data/public/images/select_bg_126.gif +0 -0
  188. data/public/images/select_bg_139.gif +0 -0
  189. data/public/images/sidemenu_bg.gif +0 -0
  190. data/public/images/sidemenu_bottom.gif +0 -0
  191. data/public/images/sidemenu_top.gif +0 -0
  192. data/public/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  193. data/public/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  194. data/public/images/ui-bg_flat_10_000000_40x100.png +0 -0
  195. data/public/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  196. data/public/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  197. data/public/images/ui-bg_glass_55_fcf0ba_1x400.png +0 -0
  198. data/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  199. data/public/images/ui-bg_gloss-wave_100_ece8da_500x100.png +0 -0
  200. data/public/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  201. data/public/images/ui-bg_highlight-hard_100_f5f3e5_1x100.png +0 -0
  202. data/public/images/ui-bg_highlight-hard_100_fafaf4_1x100.png +0 -0
  203. data/public/images/ui-bg_highlight-hard_15_459e00_1x100.png +0 -0
  204. data/public/images/ui-bg_highlight-hard_95_cccccc_1x100.png +0 -0
  205. data/public/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  206. data/public/images/ui-bg_highlight-soft_25_67b021_1x100.png +0 -0
  207. data/public/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  208. data/public/images/ui-bg_highlight-soft_95_ffedad_1x100.png +0 -0
  209. data/public/images/ui-bg_inset-soft_15_2b2922_1x100.png +0 -0
  210. data/public/images/ui-icons_222222_256x240.png +0 -0
  211. data/public/images/ui-icons_228ef1_256x240.png +0 -0
  212. data/public/images/ui-icons_808080_256x240.png +0 -0
  213. data/public/images/ui-icons_847e71_256x240.png +0 -0
  214. data/public/images/ui-icons_8dc262_256x240.png +0 -0
  215. data/public/images/ui-icons_cd0a0a_256x240.png +0 -0
  216. data/public/images/ui-icons_eeeeee_256x240.png +0 -0
  217. data/public/images/ui-icons_ef8c08_256x240.png +0 -0
  218. data/public/images/ui-icons_ffd27a_256x240.png +0 -0
  219. data/public/images/ui-icons_ffffff_256x240.png +0 -0
  220. data/public/images/vtip_arrow.png +0 -0
  221. data/public/javascripts/controls.js +965 -0
  222. data/public/javascripts/dcmgr_gui/application.js +91 -0
  223. data/public/javascripts/dcmgr_gui/core.js +539 -0
  224. data/public/javascripts/dcmgr_gui/dashboard_panel.js +34 -0
  225. data/public/javascripts/dcmgr_gui/host_pool_panel.js +83 -0
  226. data/public/javascripts/dcmgr_gui/image_panel.js +242 -0
  227. data/public/javascripts/dcmgr_gui/instance_panel.js +197 -0
  228. data/public/javascripts/dcmgr_gui/security_group_panel.js +196 -0
  229. data/public/javascripts/dcmgr_gui/snapshot_panel.js +168 -0
  230. data/public/javascripts/dcmgr_gui/sshkeypair_panel.js +161 -0
  231. data/public/javascripts/dcmgr_gui/storage_pool_panel.js +99 -0
  232. data/public/javascripts/dcmgr_gui/volume_panel.js +311 -0
  233. data/public/javascripts/dragdrop.js +974 -0
  234. data/public/javascripts/effects.js +1123 -0
  235. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  236. data/public/javascripts/jquery-ui-1.8.4.custom.min.js +763 -0
  237. data/public/javascripts/jquery.loadmask.min.js +10 -0
  238. data/public/javascripts/jquery.tmpl.js +486 -0
  239. data/public/javascripts/jsdeferred.jquery.js +385 -0
  240. data/public/javascripts/prototype.js +6001 -0
  241. data/public/javascripts/rails.js +175 -0
  242. data/public/robots.txt +5 -0
  243. data/public/stylesheets/common.css +1236 -0
  244. data/public/stylesheets/dialog.css +67 -0
  245. data/public/stylesheets/jquery-ui-1.8.4.custom.css +572 -0
  246. data/public/stylesheets/jquery.loadmask.css +40 -0
  247. data/public/stylesheets/reset.css +71 -0
  248. data/public/stylesheets/style.css +7 -0
  249. data/public/stylesheets/vtip.css +28 -0
  250. data/script/rails +6 -0
  251. data/test/functional/accounts_controller_test.rb +8 -0
  252. data/test/functional/dialog_controller_test.rb +8 -0
  253. data/test/functional/home_controller_test.rb +8 -0
  254. data/test/functional/host_pools_controller_test.rb +8 -0
  255. data/test/functional/images_controller_test.rb +8 -0
  256. data/test/functional/information_controller_test.rb +8 -0
  257. data/test/functional/instances_controller_test.rb +8 -0
  258. data/test/functional/keypairs_controller_test.rb +8 -0
  259. data/test/functional/security_groups_controller_test.rb +8 -0
  260. data/test/functional/sessions_controller_test.rb +8 -0
  261. data/test/functional/snapshots_controller_test.rb +8 -0
  262. data/test/functional/storage_pools_controller_test.rb +8 -0
  263. data/test/functional/users_controller_test.rb +8 -0
  264. data/test/functional/volumes_controller_test.rb +8 -0
  265. data/test/performance/browsing_test.rb +9 -0
  266. data/test/test_helper.rb +13 -0
  267. data/test/unit/helpers/accounts_helper_test.rb +4 -0
  268. data/test/unit/helpers/dialog_helper_test.rb +4 -0
  269. data/test/unit/helpers/home_helper_test.rb +4 -0
  270. data/test/unit/helpers/host_pools_helper_test.rb +4 -0
  271. data/test/unit/helpers/images_helper_test.rb +4 -0
  272. data/test/unit/helpers/information_helper_test.rb +4 -0
  273. data/test/unit/helpers/instances_helper_test.rb +4 -0
  274. data/test/unit/helpers/keypairs_helper_test.rb +4 -0
  275. data/test/unit/helpers/security_groups_helper_test.rb +4 -0
  276. data/test/unit/helpers/sessions_helper_test.rb +4 -0
  277. data/test/unit/helpers/snapshots_helper_test.rb +4 -0
  278. data/test/unit/helpers/storage_pools_helper_test.rb +4 -0
  279. data/test/unit/helpers/users_helper_test.rb +4 -0
  280. data/test/unit/helpers/volumes_helper_test.rb +4 -0
  281. metadata +399 -0
@@ -0,0 +1,5 @@
1
+ module DcmgrResource
2
+ class Account < Base
3
+ #DcmgrResource::Account.get('a-00000000')
4
+ end
5
+ end
@@ -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,11 @@
1
+ module DcmgrResource
2
+ class HostPool < Base
3
+ def self.list(params = {})
4
+ self.find(:all,:params => params)
5
+ end
6
+
7
+ def self.show(host_pool_id)
8
+ self.get(host_pool_id)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module DcmgrResource
2
+ class Image < Base
3
+ def self.list(params = {})
4
+ self.find(:all,:params => params)
5
+ end
6
+
7
+ def self.show(image_id)
8
+ self.get(image_id)
9
+ end
10
+ end
11
+ 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,11 @@
1
+ module DcmgrResource
2
+ class StoragePool < Base
3
+ def self.list(params = {})
4
+ self.find(:all,:params => params)
5
+ end
6
+
7
+ def self.show(storage_pool_id)
8
+ self.get(storage_pool_id)
9
+ end
10
+ end
11
+ 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,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ class Information < BaseNew
3
+ with_timestamps
4
+ inheritable_schema do
5
+ String :title, :size=>255
6
+ String :description, :text=>true
7
+ end
8
+
9
+ 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