Class: CloudUser
- Inherits:
-
OpenShift::UserModel
- Object
- OpenShift::UserModel
- CloudUser
- Defined in:
- app/models/cloud_user.rb
Instance Attribute Summary collapse
-
#applications ⇒ Object
Returns the value of attribute applications.
-
#auth_method ⇒ Object
Returns the value of attribute auth_method.
-
#capabilities ⇒ Object
Returns the value of attribute capabilities.
-
#consumed_gears ⇒ Object
Returns the value of attribute consumed_gears.
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#env_vars ⇒ Object
Returns the value of attribute env_vars.
-
#gear_usage_records ⇒ Object
Returns the value of attribute gear_usage_records.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#max_gears ⇒ Object
Returns the value of attribute max_gears.
-
#parent_user_login ⇒ Object
Returns the value of attribute parent_user_login.
-
#pending_plan_id ⇒ Object
Returns the value of attribute pending_plan_id.
-
#pending_plan_uptime ⇒ Object
Returns the value of attribute pending_plan_uptime.
-
#plan_id ⇒ Object
Returns the value of attribute plan_id.
-
#save_jobs ⇒ Object
readonly
Returns the value of attribute save_jobs.
-
#ssh_keys ⇒ Object
Returns the value of attribute ssh_keys.
-
#system_ssh_keys ⇒ Object
Returns the value of attribute system_ssh_keys.
-
#usage_account_id ⇒ Object
Returns the value of attribute usage_account_id.
-
#usage_records ⇒ Object
Returns the value of attribute usage_records.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
- .find(login) ⇒ Object
- .find_all_logins(opts = nil) ⇒ Object
- .find_by_uuid(obj_type_of_uuid, uuid) ⇒ Object
- .find_subaccounts_by_parent_login(parent_login) ⇒ Object
- .hash_to_obj(hash) ⇒ Object
Instance Method Summary collapse
- #add_env_var(key, value) ⇒ Object
- #add_save_job(section, object, value) ⇒ Object
- #add_ssh_key(key_name, key, key_type = nil) ⇒ Object
- #add_system_ssh_key(app_name, key) ⇒ Object
- #delete ⇒ Object
- #force_delete ⇒ Object
- #get_ssh_key ⇒ Object
-
#initialize(login = nil, ssh = nil, ssh_type = nil, key_name = nil, capabilities = nil, parent_login = nil) ⇒ CloudUser
constructor
A new instance of CloudUser.
- #remove_env_var(key) ⇒ Object
- #remove_ssh_key(key_name) ⇒ Object
- #remove_system_ssh_key(app_name) ⇒ Object
- #save ⇒ Object
- #update_ssh_key(key, key_type = nil, key_name = nil) ⇒ Object
Constructor Details
#initialize(login = nil, ssh = nil, ssh_type = nil, key_name = nil, capabilities = nil, parent_login = nil) ⇒ CloudUser
Returns a new instance of CloudUser.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/cloud_user.rb', line 28 def initialize(login=nil, ssh=nil, ssh_type=nil, key_name=nil, capabilities=nil, parent_login=nil) super() if not ssh.nil? ssh_type = Key::DEFAULT_SSH_KEY_TYPE if ssh_type.to_s.strip.length == 0 self.ssh_keys = {} unless self.ssh_keys key_name = Key::DEFAULT_SSH_KEY_NAME if key_name.to_s.strip.length == 0 self.ssh_keys[key_name] = { "key" => ssh, "type" => ssh_type } else self.ssh_keys = {} unless self.ssh_keys end self.login = login self.domains = [] self.max_gears = Rails.configuration.openshift[:default_max_gears] self.capabilities = capabilities || {} unless self.capabilities.has_key?('gear_sizes') # set the user's gear capabilities to default if not specified self.capabilities['gear_sizes'] = Rails.application.config.openshift[:default_gear_capabilities] || [ Rails.application.config.openshift[:default_gear_size] ] end self.parent_user_login = parent_login self.consumed_gears = 0 end |
Instance Attribute Details
#applications ⇒ Object
Returns the value of attribute applications.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def applications @applications end |
#auth_method ⇒ Object
Returns the value of attribute auth_method.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def auth_method @auth_method end |
#capabilities ⇒ Object
Returns the value of attribute capabilities.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def capabilities @capabilities end |
#consumed_gears ⇒ Object
Returns the value of attribute consumed_gears.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def consumed_gears @consumed_gears end |
#domains ⇒ Object
Returns the value of attribute domains.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def domains @domains end |
#env_vars ⇒ Object
Returns the value of attribute env_vars.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def env_vars @env_vars end |
#gear_usage_records ⇒ Object
Returns the value of attribute gear_usage_records.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def gear_usage_records @gear_usage_records end |
#login ⇒ Object
Returns the value of attribute login.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def login @login end |
#max_gears ⇒ Object
Returns the value of attribute max_gears.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def max_gears @max_gears end |
#parent_user_login ⇒ Object
Returns the value of attribute parent_user_login.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def parent_user_login @parent_user_login end |
#pending_plan_id ⇒ Object
Returns the value of attribute pending_plan_id.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def pending_plan_id @pending_plan_id end |
#pending_plan_uptime ⇒ Object
Returns the value of attribute pending_plan_uptime.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def pending_plan_uptime @pending_plan_uptime end |
#plan_id ⇒ Object
Returns the value of attribute plan_id.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def plan_id @plan_id end |
#save_jobs ⇒ Object
Returns the value of attribute save_jobs.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def save_jobs @save_jobs end |
#ssh_keys ⇒ Object
Returns the value of attribute ssh_keys.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def ssh_keys @ssh_keys end |
#system_ssh_keys ⇒ Object
Returns the value of attribute system_ssh_keys.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def system_ssh_keys @system_ssh_keys end |
#usage_account_id ⇒ Object
Returns the value of attribute usage_account_id.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def usage_account_id @usage_account_id end |
#usage_records ⇒ Object
Returns the value of attribute usage_records.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def usage_records @usage_records end |
#uuid ⇒ Object
Returns the value of attribute uuid.
2 3 4 |
# File 'app/models/cloud_user.rb', line 2 def uuid @uuid end |
Class Method Details
.find(login) ⇒ Object
232 233 234 |
# File 'app/models/cloud_user.rb', line 232 def self.find(login) super(login,login) end |
.find_all_logins(opts = nil) ⇒ Object
236 237 238 |
# File 'app/models/cloud_user.rb', line 236 def self.find_all_logins(opts=nil) OpenShift::DataStore.instance.find_all_logins(opts) end |
.find_by_uuid(obj_type_of_uuid, uuid) ⇒ Object
157 158 159 160 161 |
# File 'app/models/cloud_user.rb', line 157 def self.find_by_uuid(obj_type_of_uuid, uuid) hash = OpenShift::DataStore.instance.find_by_uuid(obj_type_of_uuid, uuid) return nil unless hash hash_to_obj(hash) end |
.find_subaccounts_by_parent_login(parent_login) ⇒ Object
163 164 165 166 167 |
# File 'app/models/cloud_user.rb', line 163 def self.find_subaccounts_by_parent_login(parent_login) hash_list = OpenShift::DataStore.instance.find_subaccounts_by_parent_login(parent_login) return nil if hash_list.nil? or hash_list.empty? hash_list.map {|hash| hash_to_obj(hash) } end |
.hash_to_obj(hash) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'app/models/cloud_user.rb', line 169 def self.hash_to_obj(hash) apps = [] if hash["apps"] hash["apps"].each do |app_hash| app = Application.hash_to_obj(app_hash) apps.push(app) end hash.delete("apps") end domains = [] if hash["domains"] hash["domains"].each do |domain_hash| domain = Domain.hash_to_obj(domain_hash) domains.push(domain) end hash.delete("apps") end usage_records = [] if hash["usage_records"] hash["usage_records"].each do |usage_hash| usage_record = UsageRecord.hash_to_obj(usage_hash) usage_records.push(usage_record) end hash.delete("usage_records") end user = super(hash) user.applications = apps apps.each do |app| app.user = user app.reset_state end user.domains = domains domains.each do |domain| domain.user = user end user.usage_records = usage_records usage_records.each do |usage_record| usage_record.user = user end user end |
Instance Method Details
#add_env_var(key, value) ⇒ Object
284 285 286 287 288 |
# File 'app/models/cloud_user.rb', line 284 def add_env_var(key, value) self.env_vars = {} unless self.env_vars self.env_vars[key] = value add_save_job('adds', 'env_vars', [key, value]) end |
#add_save_job(section, object, value) ⇒ Object
296 297 298 299 300 301 |
# File 'app/models/cloud_user.rb', line 296 def add_save_job(section, object, value) self.save_jobs = {} unless self.save_jobs self.save_jobs[section] = {} unless self.save_jobs[section] self.save_jobs[section][object] = [] unless self.save_jobs[section][object] self.save_jobs[section][object] << value end |
#add_ssh_key(key_name, key, key_type = nil) ⇒ Object
254 255 256 257 258 259 |
# File 'app/models/cloud_user.rb', line 254 def add_ssh_key(key_name, key, key_type=nil) self.ssh_keys = {} unless self.ssh_keys key_type = Key::DEFAULT_SSH_KEY_TYPE if key_type.to_s.strip.length == 0 self.ssh_keys[key_name] = { "key" => key, "type" => key_type } add_save_job('adds', 'ssh_keys', [key, key_type, key_name]) end |
#add_system_ssh_key(app_name, key) ⇒ Object
240 241 242 243 244 |
# File 'app/models/cloud_user.rb', line 240 def add_system_ssh_key(app_name, key) self.system_ssh_keys = {} unless self.system_ssh_keys self.system_ssh_keys[app_name] = key add_save_job('adds', 'ssh_keys', [key, nil, app_name]) end |
#delete ⇒ Object
225 226 227 228 229 230 |
# File 'app/models/cloud_user.rb', line 225 def delete if (self.domains && !self.domains.empty?) or (self.applications && !self.applications.empty?) raise OpenShift::UserException.new("Error: User '#{@login}' has valid domain or applications.", 139) end super(@login) end |
#force_delete ⇒ Object
214 215 216 217 218 219 220 221 222 223 |
# File 'app/models/cloud_user.rb', line 214 def force_delete self.applications.each do |app| app.cleanup_and_delete() end if self.applications && !self.applications.empty? self.domains.each do |domain| domain.delete end if self.domains && !self.domains.empty? user = CloudUser.find(self.login) user.delete if user end |
#get_ssh_key ⇒ Object
277 278 279 280 281 282 |
# File 'app/models/cloud_user.rb', line 277 def get_ssh_key raise OpenShift::UserKeyException.new("ERROR: No ssh keys found for user #{self.login}", 123) if self.ssh_keys.nil? or not self.ssh_keys.kind_of?(Hash) key_name = (self.ssh_keys.key?(Key::DEFAULT_SSH_KEY_NAME)) ? Key::DEFAULT_SSH_KEY_NAME : self.ssh_keys.keys[0] self.ssh_keys[key_name] end |
#remove_env_var(key) ⇒ Object
290 291 292 293 294 |
# File 'app/models/cloud_user.rb', line 290 def remove_env_var(key) self.env_vars = {} unless self.env_vars self.env_vars.delete key add_save_job('removes', 'env_vars', [key]) end |
#remove_ssh_key(key_name) ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'app/models/cloud_user.rb', line 261 def remove_ssh_key(key_name) self.ssh_keys = {} unless self.ssh_keys # validations raise OpenShift::UserKeyException.new("ERROR: Key name '#{key_name}' doesn't exist for user #{self.login}", 118) if not self.ssh_keys.has_key?(key_name) add_save_job('removes', 'ssh_keys', [self.ssh_keys[key_name]["key"], key_name]) self.ssh_keys.delete key_name end |
#remove_system_ssh_key(app_name) ⇒ Object
246 247 248 249 250 251 252 |
# File 'app/models/cloud_user.rb', line 246 def remove_system_ssh_key(app_name) self.system_ssh_keys = {} unless self.system_ssh_keys key = self.system_ssh_keys[app_name] return unless key self.system_ssh_keys.delete app_name add_save_job('removes', 'ssh_keys', [key, app_name]) end |
#save ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/cloud_user.rb', line 54 def save resultIO = ResultIO.new unless persisted? #new user record resultIO.append(create()) end if applications && !applications.empty? && save_jobs gears = [] tag = "" applications.each do |app| app.gears.each do |gear| if !app.destroyed_gears || !app.destroyed_gears.include?(gear.uuid) gears << gear end end end handle = RemoteJob.create_parallel_job RemoteJob.run_parallel_on_gears(gears, handle) { |exec_handle, gear| if save_jobs['removes'] save_jobs['removes'].each do |action, values| case action when 'ssh_keys' values.each do |value| ssh_key = value[0] ssh_key_comment = value[1] job = gear.ssh_key_job_remove(ssh_key, ssh_key_comment) RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end when 'env_vars' values.each do |value| env_var_key = value[0] job = gear.env_var_job_remove(env_var_key) RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end when 'broker_auth_keys' values.each do |value| app_uuid = value[0] if app_uuid == gear.app.uuid job = gear.broker_auth_key_job_remove RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end end end end end if save_jobs['adds'] save_jobs['adds'].each do |action, values| case action when 'ssh_keys' values.each do |value| ssh_key = value[0] ssh_key_type = value[1] ssh_key_comment = value[2] job = gear.ssh_key_job_add(ssh_key, ssh_key_type, ssh_key_comment) RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end when 'env_vars' values.each do |value| env_var_key = value[0] env_var_value = value[1] job = gear.env_var_job_add(env_var_key, env_var_value) RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end when 'broker_auth_keys' values.each do |value| app_uuid = value[0] if app_uuid == gear.app.uuid iv = value[1] token = value[2] job = gear.broker_auth_key_job_add(iv, token) RemoteJob.add_parallel_job(exec_handle, tag, gear, job) end end end end end } RemoteJob.get_parallel_run_results(handle) { |tag, gear, output, status| if status != 0 raise OpenShift::NodeException.new("Error updating settings on gear: #{gear} with status: #{status} and output: #{output}", 143) end } save_jobs['removes'].clear if save_jobs['removes'] save_jobs['adds'].clear if save_jobs['adds'] end super(@login) resultIO end |
#update_ssh_key(key, key_type = nil, key_name = nil) ⇒ Object
271 272 273 274 275 |
# File 'app/models/cloud_user.rb', line 271 def update_ssh_key(key, key_type=nil, key_name=nil) key_name = Key::DEFAULT_SSH_KEY_NAME if key_name.to_s.strip.length == 0 remove_ssh_key(key_name) add_ssh_key(key_name, key, key_type) end |