Class OpenShift::UnixUser
In: lib/openshift-origin-node/model/unix_user.rb
Parent: Model

Unix User

Represents a user account on the system.

Methods

Included Modules

OpenShift::Utils::ShellExec

Constants

DEFAULT_SKEL_DIR = File.join(OpenShift::Config::CONF_DIR,"skel")

Attributes

app_name  [R] 
application_uuid  [R] 
container_name  [R] 
container_uuid  [R] 
debug  [RW] 
gecos  [R] 
gid  [R] 
homedir  [R] 
namespace  [R] 
quota_blocks  [R] 
quota_files  [R] 
uid  [R] 
uuid  [R] 

Public Class methods

Public Instance methods

Public: Add broker authorization keys so gear can communicate with

        broker.

iv - A String value for the IV file. token - A String value for the token file.

Examples

  add_broker_auth('ivvalue', 'tokenvalue')
  # => ["/var/lib/openshift/UUID/.auth/iv",
        "/var/lib/openshift/UUID/.auth/token"]

Returns An Array of Strings for the newly created auth files

Public: Add an environment variable to a given gear.

key - The String value of target environment variable. value - The String value to place inside the environment variable. prefix_cloud_name - The String value to append in front of key.

Examples

 add_env_var('mysql-5.3')
 # => 36

Returns the Integer value for how many bytes got written or raises on failure.

Public: Append an SSH key to a users authorized_keys file

key - The String value of the ssh key. key_type - The String value of the key type ssh-(rsa|dss)). comment - The String value of the comment to append to the key.

Examples

  add_ssh_key('AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...',
              'ssh-rsa',
              'example@example.com')
  # => nil

Returns nil on Success or raises on Failure

Public: Create an empty gear.

Examples

  create
  # => nil
  # a user
  # Setup permissions

Returns nil on Success or raises on Failure

Public: Destroys a gear stopping all processes and removing all files

The order of the calls and gyrations done in this code is to prevent

  pam_namespace from locking polyinstantiated directories during
  their deletion. If you see "broken" gears, i.e. ~uuid/.tmp and
   ~/uuid/.sandbox after #destroy has been called, this method is broken.

See Bug 853582 for history.

Examples

  destroy
  # => nil

Returns nil on Success or raises on Failure

private: Determine the MCS label for a given uid

@param [Integer] The user ID @return [String] The SELinux MCS label

Private: Create and populate the users home dir.

Examples

  initialize_homedir
  # => nil
  # Creates:
  # ~
  # ~/.tmp/
  # ~/.sandbox/$uuid
  # ~/.env/
  # APP_UUID, GEAR_UUID, APP_NAME, APP_DNS, HOMEDIR, DATA_DIR,      #   #   GEAR_DNS, GEAR_NAME, PATH, REPO_DIR, TMP_DIR, HISTFILE
  # ~/app-root
  # ~/app-root/data
  # ~/app-root/runtime/repo
  # ~/app-root/repo -> runtime/repo
  # ~/app-root/runtime/data -> ../data

Returns nil on Success and raises on Failure.

Private: Initialize OpenShift Port Proxy for this gear

The port proxy range is determined by configuration and must produce identical results to the abstract cartridge provided range.

Examples: initialize_openshift_port_proxy

   => true
   service openshift_port_proxy setproxy 35000 delete 35001 delete etc...

Returns:

   true   - port proxy could be initialized properly
   false  - port proxy could not be initialized properly

Private: Kill all processes for a given gear

Kill all processes owned by the uid or uuid. No reason for graceful shutdown first, the directories and user are going

  to be removed from the system.

Examples: kill_gear_procs

   => true
   pkill -u id

Raises exception on error.

Public: list directories (cartridges) in home directory @param [String] home directory @return [String] comma separated list of directories

Private: Determine next available user id. This is usually determined

          and provided by the broker but is auto determined if not
          provided.

Examples:

  next_uid =>
  # => 504

Returns Integer value for next available uid.

Private: Purge IPC entities for a given gear

Enumerate and remove all IPC entities for a given user ID or user name.

Examples: purge_sysvipc

   => true
   ipcs -c
   ipcrm -s id
   ipcrm -m id

Raises exception on error.

private: Read ssh authorized_keys file

@param [String] authorized_keys_file ssh authorized_keys path @return [Hash] authorized keys with the comment field as the key

Public: Remove broker authentication keys from gear.

Examples

  remove_broker_auth
  # => nil

Returns nil on Success and false on Failure

Public: Remove an environment variable from a given gear.

key - String name of the environment variable to remove. prefix_cloud_name - String prefix to append to key.

Examples

  remove_env_var('OPENSHIFT_MONGODB_DB_URL')
  # => nil

Returns an nil on success and false on failure.

Public: Remove an SSH key from a users authorized_keys file.

key - The String value of the ssh key. comment - The String value of the comment associated with the key.

Examples

  remove_ssh_key('AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...',
              'example@example.com')
  # => nil

Returns nil on Success or raises on Failure

private: Set the SELinux context on a file or directory

@param [Integer] The user ID

private: Write ssh authorized_keys file

@param [String] authorized_keys_file ssh authorized_keys path @param [Hash] keys authorized keys with the comment field as the key @return [Hash] authorized keys with the comment field as the key

[Validate]