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/config/routes.rb
CHANGED
@@ -5,8 +5,11 @@ DcmgrGui::Application.routes.draw do
|
|
5
5
|
|
6
6
|
#account
|
7
7
|
post 'accounts/switch' ,:to => 'accounts#switch'
|
8
|
-
get 'accounts' ,:to => '
|
9
|
-
|
8
|
+
get 'accounts' ,:to => 'accounts#index'
|
9
|
+
get 'accounts/password' ,:to => 'accounts#password'
|
10
|
+
post 'accounts/password' ,:to => 'accounts#password'
|
11
|
+
post 'accounts/update_settings', :to => 'accounts#update_settings'
|
12
|
+
|
10
13
|
#dialog
|
11
14
|
get 'dialog/create_volume', :to => 'dialog#create_volume'
|
12
15
|
post 'dialog/create_volume_from_snapshot', :to => 'dialog#create_volume_from_snapshot'
|
@@ -25,7 +28,7 @@ DcmgrGui::Application.routes.draw do
|
|
25
28
|
post 'dialog/launch_instance', :to => 'dialog#launch_instance'
|
26
29
|
get 'dialog/create_ssh_keypair', :to => 'dialog#create_ssh_keypair'
|
27
30
|
post 'dialog/delete_ssh_keypair', :to => 'dialog#delete_ssh_keypair'
|
28
|
-
|
31
|
+
|
29
32
|
#home
|
30
33
|
get 'home' ,:to => 'home#index'
|
31
34
|
|
@@ -35,11 +38,11 @@ DcmgrGui::Application.routes.draw do
|
|
35
38
|
get 'host_pools/show/:id' ,:to => 'host_pools#show'
|
36
39
|
get 'host_pools/show_host_pools' ,:to => 'host_pools#show_host_pools'
|
37
40
|
|
38
|
-
#
|
39
|
-
get '
|
40
|
-
get '
|
41
|
-
get '
|
42
|
-
get '
|
41
|
+
#machine_images
|
42
|
+
get 'machine_images' ,:to => 'machine_images#index'
|
43
|
+
get 'machine_images/total',:to => 'machine_images#total'
|
44
|
+
get 'machine_images/list/:id' ,:to => 'machine_images#list'
|
45
|
+
get 'machine_images/show/:id' ,:to => 'machine_images#show'
|
43
46
|
|
44
47
|
|
45
48
|
#information
|
@@ -55,6 +58,9 @@ DcmgrGui::Application.routes.draw do
|
|
55
58
|
post 'instances' ,:to => 'instances#create'
|
56
59
|
get 'instances/show/:id' ,:to => 'instances#show'
|
57
60
|
|
61
|
+
#instance_specs
|
62
|
+
get 'instance_specs/all' ,:to => 'instance_specs#show_instance_specs'
|
63
|
+
|
58
64
|
#kepairs
|
59
65
|
get 'keypairs' ,:to => 'keypairs#index'
|
60
66
|
get 'keypairs/list/:id' ,:to => 'keypairs#list'
|
@@ -82,7 +88,8 @@ DcmgrGui::Application.routes.draw do
|
|
82
88
|
get 'snapshots/show/:id' ,:to => 'snapshots#show'
|
83
89
|
post 'snapshots' ,:to => 'snapshots#create'
|
84
90
|
delete 'snapshots/:id' ,:to => 'snapshots#destroy'
|
85
|
-
|
91
|
+
get 'snapshots/upload_destination',:to => 'snapshots#upload_destination'
|
92
|
+
|
86
93
|
#sessions
|
87
94
|
get 'login' => 'sessions#new', :as => :login
|
88
95
|
get 'logout' => 'sessions#destroy', :as => :logout
|
data/lib/cli/account.rb
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'sequel'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
#TODO: Make sure :desc is filled in for every option
|
7
|
+
module Cli
|
8
|
+
class AccountCli < Base
|
9
|
+
namespace :account
|
10
|
+
#M=Dcmgr::Models
|
11
|
+
|
12
|
+
#no_tasks {
|
13
|
+
#def before_task
|
14
|
+
## Setup DB connections and load paths for dcmgr_gui
|
15
|
+
#root_dir = File.expand_path('../../../', __FILE__)
|
16
|
+
|
17
|
+
##get the database details
|
18
|
+
##TODO:get this path in a less hard-coded way?
|
19
|
+
#content = File.new(File.expand_path('../../frontend/dcmgr_gui/config/database.yml', root_dir)).read
|
20
|
+
#settings = YAML::load content
|
21
|
+
|
22
|
+
##load the database variables
|
23
|
+
##TODO: get environment from RAILS_ENV
|
24
|
+
#db_environment = 'development'
|
25
|
+
#db_adapter = settings[db_environment]['adapter']
|
26
|
+
#db_host = settings[db_environment]['host']
|
27
|
+
#db_name = settings[db_environment]['database']
|
28
|
+
#db_user = settings[db_environment]['user']
|
29
|
+
#db_pwd = settings[db_environment]['password']
|
30
|
+
|
31
|
+
##Connect to the database
|
32
|
+
#url = "#{db_adapter}://#{db_host}/#{db_name}?user=#{db_user}&password=#{db_pwd}"
|
33
|
+
#db = Sequel.connect(url)
|
34
|
+
|
35
|
+
##load the cli environment
|
36
|
+
#$LOAD_PATH.unshift File.expand_path('../../frontend/dcmgr_gui/config', root_dir)
|
37
|
+
#$LOAD_PATH.unshift File.expand_path('../../frontend/dcmgr_gui/app/models', root_dir)
|
38
|
+
##require 'account'
|
39
|
+
#require 'environment-cli'
|
40
|
+
|
41
|
+
##Associate the models with their respective database
|
42
|
+
#Account.db = db
|
43
|
+
#User.db = db
|
44
|
+
#end
|
45
|
+
#}
|
46
|
+
|
47
|
+
desc "add [options]", "Create a new account."
|
48
|
+
method_option :name, :type => :string, :aliases => "-n", :required => true, :desc => "The name for the new account." #Maximum size: 255
|
49
|
+
method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new account."
|
50
|
+
method_option :description, :type => :string, :aliases => "-d", :default => "", :desc => "The description for this account."
|
51
|
+
#method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
52
|
+
def add
|
53
|
+
#Check if the data we got is valid
|
54
|
+
if options[:name] != nil && options[:name].length > 255
|
55
|
+
raise "Account name can not be longer than 255 characters."
|
56
|
+
end
|
57
|
+
if options[:description] != nil && options[:description].length > 100
|
58
|
+
raise "Account description can not be longer than 100 chracters."
|
59
|
+
end
|
60
|
+
|
61
|
+
#Put them in the backend
|
62
|
+
#fields = {:description => options[:description], :enabled => M::Account::ENABLED}
|
63
|
+
#fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
|
64
|
+
|
65
|
+
#new_uuid = super(M::Account,fields)
|
66
|
+
|
67
|
+
##This should never happen as long as the databases remain synchronized.
|
68
|
+
#begin
|
69
|
+
#raise "A uuid collision occurred. This means the account databases are not synchronized." if Account[new_uuid] != nil
|
70
|
+
#rescue
|
71
|
+
#M::Account[new_uuid].delete
|
72
|
+
#raise
|
73
|
+
#end
|
74
|
+
|
75
|
+
#Put them in the frontend
|
76
|
+
#super(Account,{:uuid => new_uuid,:name => options[:name],:description => options[:description]})
|
77
|
+
|
78
|
+
#puts new_uuid
|
79
|
+
fields = {:name => options[:name],:description => options[:description], :enable => Account::ENABLED}
|
80
|
+
fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
|
81
|
+
puts super(Account,fields)
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "show [UUID] [options]", "Show all accounts currently in the database"
|
85
|
+
method_option :deleted, :type => :boolean, :default => false, :aliases => "-d", :desc => "Show deleted accounts."
|
86
|
+
def show(uuid = nil)
|
87
|
+
if uuid
|
88
|
+
#back_acc = M::Account[uuid] || raise(Thor::Error, "Unknown Account UUID: #{uuid}")
|
89
|
+
acc = Account[uuid] || raise(Thor::Error, "Unknown Account UUID: #{uuid}")
|
90
|
+
puts ERB.new(<<__END, nil, '-').result(binding)
|
91
|
+
Account UUID:
|
92
|
+
<%- if acc.class == Account -%>
|
93
|
+
<%= acc.canonical_uuid %>
|
94
|
+
<%- else -%>
|
95
|
+
<%= Account.uuid_prefix%>-<%= acc.uuid %>
|
96
|
+
<%- end -%>
|
97
|
+
Enabled:
|
98
|
+
<%- if acc.enable? -%>
|
99
|
+
Yes
|
100
|
+
<%- else -%>
|
101
|
+
No
|
102
|
+
<%- end -%>
|
103
|
+
<%- if acc.name -%>
|
104
|
+
Name:
|
105
|
+
<%= acc.name %>
|
106
|
+
<%- end -%>
|
107
|
+
<%- if acc.description -%>
|
108
|
+
Description:
|
109
|
+
<%= acc.description %>
|
110
|
+
<%- end -%>
|
111
|
+
<%- if acc.is_deleted -%>
|
112
|
+
Deleted at:
|
113
|
+
<%= acc.deleted_at %>
|
114
|
+
<%- end -%>
|
115
|
+
<%- unless acc.users.empty? -%>
|
116
|
+
Associated users:
|
117
|
+
<%- acc.users.each { |row| -%>
|
118
|
+
<%= row.canonical_uuid %>\t<%= row.name %>
|
119
|
+
<%- } -%>
|
120
|
+
<%- end -%>
|
121
|
+
__END
|
122
|
+
else
|
123
|
+
#This needs an "|| false" because options[:deleted] is usually nil which isn't the same as false
|
124
|
+
acc = Account.filter(:is_deleted => (options[:deleted] || false )).all
|
125
|
+
puts ERB.new(<<__END, nil, '-').result(binding)
|
126
|
+
<%- acc.each { |row| -%>
|
127
|
+
<%- if row.class == Account -%>
|
128
|
+
<%= row.canonical_uuid %>\t<%= row.name %>
|
129
|
+
<%- else -%>
|
130
|
+
<%= Account.uuid_prefix%>-<%= row.uuid %>\t<%= row.name %>
|
131
|
+
<%- end -%>
|
132
|
+
<%- } -%>
|
133
|
+
__END
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "modify UUID [options]", "Modify an existing account."
|
138
|
+
method_option :name, :type => :string, :aliases => "-n", :desc => "The new name for the account." #Maximum size: 200
|
139
|
+
method_option :description, :type => :string, :aliases => "-d", :desc => "The new description for the account."
|
140
|
+
#method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
141
|
+
def modify(uuid)
|
142
|
+
raise "Account name can not be longer than 255 characters." if options[:name] != nil && options[:name].length > 255
|
143
|
+
raise "Description can not be longer than 100 characters." if options[:description] != nil && options[:description].length > 100
|
144
|
+
super(Account,uuid,{:name => options[:name],:description => options[:description]})
|
145
|
+
#super(M::Account,uuid,{:description => options[:description]})
|
146
|
+
end
|
147
|
+
|
148
|
+
#TODO: show account to confirm deletion
|
149
|
+
desc "del UUID [options]", "Deletes an existing account."
|
150
|
+
method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
151
|
+
def del(uuid)
|
152
|
+
super(Account,uuid)
|
153
|
+
#super(M::Account,uuid)
|
154
|
+
|
155
|
+
puts "Account #{uuid} has been deleted." if options[:verbose]
|
156
|
+
end
|
157
|
+
|
158
|
+
desc "enable UUID [options]", "Enable an account."
|
159
|
+
method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
160
|
+
def enable(uuid)
|
161
|
+
to_enable = Account[uuid]
|
162
|
+
Error.raise("Unknown frontend account UUID: #{uuid}", 100) if to_enable == nil or to_enable.is_deleted
|
163
|
+
#to_enable_back = M::Account[uuid] || Error.raise("Unknown backend account UUID: #{uuid}", 100)
|
164
|
+
|
165
|
+
if to_enable.enable?# && to_enable_back.enable?
|
166
|
+
puts "Account #{uuid} is already enabled." if options[:verbose]
|
167
|
+
else
|
168
|
+
to_enable.enable = Account::ENABLED
|
169
|
+
to_enable.updated_at = Time.now.utc.iso8601
|
170
|
+
to_enable.save
|
171
|
+
|
172
|
+
#to_enable_back.enabled = Dcmgr::Models::Account::ENABLED
|
173
|
+
#to_enable_back.updated_at = Time.now.utc.iso8601
|
174
|
+
#to_enable_back.save
|
175
|
+
|
176
|
+
puts "Account #{uuid} has been enabled." if options[:verbose]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
desc "disable UUID [options]", "Disable an account."
|
181
|
+
method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
182
|
+
def disable(uuid)
|
183
|
+
to_disable = Account[uuid]
|
184
|
+
UnknownUUIDError.raise(uuid) if to_disable == nil or to_disable.is_deleted
|
185
|
+
#to_disable_back = M::Account[uuid] || Error.raise("Unknown backend account UUID: #{uuid}", 100)
|
186
|
+
|
187
|
+
if to_disable.disable? #&& to_disable_back.disable?
|
188
|
+
puts "Account #{id} is already disabled." if options[:verbose]
|
189
|
+
else
|
190
|
+
to_disable.enable = Account::DISABLED
|
191
|
+
to_disable.updated_at = Time.now.utc.iso8601
|
192
|
+
to_disable.save
|
193
|
+
|
194
|
+
#to_disable_back.enabled = M::Account::DISABLED
|
195
|
+
#to_disable_back.updated_at = Time.now.utc.iso8601
|
196
|
+
#to_disable_back.save
|
197
|
+
|
198
|
+
puts "Account #{uuid} has been disabled." if options[:verbose]
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
desc "associate UUID", "Associate an account with a user or multiple users."
|
203
|
+
method_option :users, :type => :array, :required => true, :aliases => "-u", :desc => "The uuid of the users to associate with the account. Any non-existing uuid will be ignored"
|
204
|
+
method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
205
|
+
def associate(uuid)
|
206
|
+
account = Account[uuid] || UnknownUUIDError.raise(uuid)
|
207
|
+
|
208
|
+
options[:users].each { |u|
|
209
|
+
if User[u].nil?
|
210
|
+
puts "Unknown user UUID: #{u}" if options[:verbose]
|
211
|
+
elsif !account.users.index(User[u]).nil?
|
212
|
+
puts "Account #{uuid} is already associated with user #{u}." if options[:verbose]
|
213
|
+
else
|
214
|
+
user = User[u]
|
215
|
+
account.add_user(user)
|
216
|
+
if user.primary_account_id.nil?
|
217
|
+
user.primary_account_id = account.uuid
|
218
|
+
user.save
|
219
|
+
end
|
220
|
+
|
221
|
+
puts "Account #{uuid} successfully associated with user #{u}." if options[:verbose]
|
222
|
+
end
|
223
|
+
}
|
224
|
+
end
|
225
|
+
|
226
|
+
desc "dissociate UUID", "Dissociate an account from a user or multiple users."
|
227
|
+
method_option :users, :type => :array, :required => true, :aliases => "-u", :desc => "The uuid of the users to dissociate from the account. Any non-existing or non numeral id will be ignored"
|
228
|
+
method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "Print feedback on what is happening."
|
229
|
+
def dissociate(uuid)
|
230
|
+
account = Account[uuid] || UnknownUUIDError.raise(uuid)
|
231
|
+
|
232
|
+
options[:users].each { |u|
|
233
|
+
user = User[u]
|
234
|
+
if user.nil?
|
235
|
+
puts "Unknown user UUID: #{u}" if options[:verbose]
|
236
|
+
elsif account.users.index(User[u]).nil?
|
237
|
+
puts "Account #{uuid} is not associated with user #{u}." if options[:verbose]
|
238
|
+
else
|
239
|
+
account.remove_user(user)
|
240
|
+
|
241
|
+
puts "Account #{uuid} successfully dissociated from user #{u}." if options[:verbose]
|
242
|
+
|
243
|
+
if account.uuid == user.primary_account_id
|
244
|
+
user.primary_account_id = nil
|
245
|
+
user.save
|
246
|
+
puts "This was user #{u}'s primary account. Has been set to Null now." if options[:verbose]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
}
|
250
|
+
end
|
251
|
+
|
252
|
+
#desc "quota UUID [options]","Set quota settings for an account."
|
253
|
+
#method_option :weight, :type => :numeric, :aliases => "-w", :desc => "The instance total weight to set this account's quota to."
|
254
|
+
#method_option :size, :type => :numeric, :aliases => "-s", :desc => "The volume total size to set this account's quota to."
|
255
|
+
#def quota(uuid)
|
256
|
+
#account = M::Account[uuid] || UnknownUUIDError.raise(uuid)
|
257
|
+
#account.quota.instance_total_weight = options[:weight] unless options[:weight].nil?
|
258
|
+
#account.quota.volume_total_size = options[:size] unless options[:size].nil?
|
259
|
+
#account.quota.updated_at = Time.now.utc.iso8601
|
260
|
+
#account.quota.save
|
261
|
+
#end
|
262
|
+
|
263
|
+
end
|
264
|
+
end
|
data/lib/cli/base.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Cli
|
6
|
+
class Base < Thor
|
7
|
+
protected
|
8
|
+
def self.basename
|
9
|
+
"#{super()} #{namespace}"
|
10
|
+
end
|
11
|
+
|
12
|
+
no_tasks {
|
13
|
+
public
|
14
|
+
# add before/after task hook.
|
15
|
+
def invoke_task(task, *args)
|
16
|
+
BaseNew.db.transaction do
|
17
|
+
before_task
|
18
|
+
super(task, *args)
|
19
|
+
after_task
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def before_task
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_task
|
28
|
+
end
|
29
|
+
}
|
30
|
+
|
31
|
+
def add(model,options)
|
32
|
+
raise ArgumentError unless options.is_a? Hash
|
33
|
+
#TODO: Make this check a little tighter by checking that the model is either from the wakame backend or frontend
|
34
|
+
#UnknownModelError.raise(model) unless model < Dcmgr::Models::BaseNew
|
35
|
+
UnknownModelError.raise(model) unless model < Sequel::Model
|
36
|
+
|
37
|
+
fields = options.dup
|
38
|
+
|
39
|
+
if fields.has_key?("uuid") || fields.has_key?(:uuid)
|
40
|
+
fields[:uuid] = model.trim_uuid(fields[:uuid]) if model.check_uuid_format(fields[:uuid])
|
41
|
+
Error.raise("UUID syntax invalid: #{fields[:uuid]}",100) unless model.check_trimmed_uuid_format(fields[:uuid])
|
42
|
+
end
|
43
|
+
|
44
|
+
#Create database fields
|
45
|
+
new_record = model.create(fields)
|
46
|
+
|
47
|
+
#Return uuid if there is one
|
48
|
+
new_record.canonical_uuid #if model.respond_to? "canonical_uuid"
|
49
|
+
end
|
50
|
+
|
51
|
+
def del(model,uuid)
|
52
|
+
#UnknownModelError.raise(model) unless model < Dcmgr::Models::BaseNew
|
53
|
+
UnknownModelError.raise(model) unless model < Sequel::Model
|
54
|
+
to_delete = model[uuid] || UnknownUUIDError.raise(uuid)
|
55
|
+
to_delete.destroy
|
56
|
+
end
|
57
|
+
|
58
|
+
def modify(model,uuid,fields)
|
59
|
+
#UnknownModelError.raise(model) unless model < Dcmgr::Models::BaseNew
|
60
|
+
UnknownModelError.raise(model) unless model < Sequel::Model
|
61
|
+
raise ArgumentError unless fields.is_a? Hash
|
62
|
+
to_modify = model[uuid] || UnknownUUIDError.raise(uuid)
|
63
|
+
|
64
|
+
#Use a copy of the fields hash so this method can work with frozen hashes
|
65
|
+
fields_nonil = fields.merge({})
|
66
|
+
#Don't update empty fields
|
67
|
+
fields_nonil.delete_if {|key,value| value.nil?}
|
68
|
+
|
69
|
+
to_modify.set(fields_nonil)
|
70
|
+
to_modify.updated_at = Time.now.utc.iso8601 if to_modify.with_timestamps?
|
71
|
+
to_modify.save_changes
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/cli/errors.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Cli
|
4
|
+
class Error < StandardError
|
5
|
+
attr_reader :exit_code
|
6
|
+
def initialize(msg, exit_code=1)
|
7
|
+
super(msg)
|
8
|
+
@exit_code = exit_code
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.raise(msg, exit_code)
|
12
|
+
Kernel.raise(if msg.is_a?(self)
|
13
|
+
msg
|
14
|
+
else
|
15
|
+
self.new(msg, exit_code)
|
16
|
+
end)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class UnknownUUIDError < Error
|
21
|
+
def initialize(uuid,exit_code=100)
|
22
|
+
super("Unknown UUID: '#{uuid}'.")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.raise(uuid,exit_code=100)
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class UnsupportedArchError < Error
|
31
|
+
def initialize(arch,exit_code=100)
|
32
|
+
super("Unsupported arch type: '#{arch}'.")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.raise(arch,exit_code=100)
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class UnknownModelError < Error
|
41
|
+
def initialize(model,exit_code=100)
|
42
|
+
super("Not a sequel model: '#{model}'.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.raise(model,exit_code=100)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class UnsupportedHypervisorError < Error
|
51
|
+
def initialize(arch,exit_code=100)
|
52
|
+
super("Unsupported hypervisor type: '#{arch}'.")
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.raise(arch,exit_code=100)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|