Module: UCB::Webfarm

Includes:
UnixEnvironment
Defined in:
lib/ucb_webfarm.rb

Overview

Module giving Ruby access to various attributes of the webfarm including environment (dev, qa, prod), user/group info and ports.

require 'ucb_ist_unix'

`domainname`               #=> "dev\n"

UCB::Webfarm.environment   #=> "dev"
UCB::Webfarm.dev_int?          #=> true
UCB::Webfarm.prod?         #=> false

Constant Summary collapse

DEV_INT_ENV =

Webfarm Environments

'dev'
QA_ENV =
'qa'
PROD_ENV =
'prod'
RAILS_DEV_INTEGRATION_ENV =

Rails Environments

'dev_integration'
RAILS_QUALITY_ASSURANCE_ENV =
'quality_assurance'
RAILS_PRODUCTION_ENV =
'production'
RAILS_DEV_INTEGRATION_MIGRATION_ENV =

Rails Migration Environments

'dev_integration_migration'
RAILS_QUALITY_ASSURANCE_MIGRATION_ENV =
'quality_assurance_migration'
RAILS_PRODUCTION_MIGRATION_ENV =
'production_migration'

Class Method Summary collapse

Methods included from UnixEnvironment

included

Class Method Details

.dev?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/ucb_webfarm.rb', line 67

def dev?
  environment.nil?  
end

.dev_int?Boolean

Returns true for dev webfarm instances

Returns:

  • (Boolean)


72
73
74
# File 'lib/ucb_webfarm.rb', line 72

def dev_int?
  environment == DEV_INT_ENV
end

.environmentObject Also known as: webfarm_environment

Returns webfarm environment.



41
42
43
# File 'lib/ucb_webfarm.rb', line 41

def environment
  webfarm_environments.include?(domain_name) ? domain_name : nil
end

.environmentsObject Also known as: webfarm_environments

Returns an Array of the Webfarm (not Rails) environments.



35
36
37
# File 'lib/ucb_webfarm.rb', line 35

def environments
  @webfarm_environments ||= [DEV_INT_ENV, QA_ENV, PROD_ENV]
end

.machinesObject

An Array of all machine names for the environment.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ucb_webfarm.rb', line 51

def machines
  return [] if win32?
  
  if dev?
    ['localhost']
  elsif dev_int?
    ['webfarm-dev-01', 'webfarm-dev-02']          
  elsif qa?
    ['webfarm-qa-01', 'webfarm-qa-02']          
  elsif prod?
    ['webfarm-prod-01', 'webfarm-prod-02', 'webfarm-prod-03', 'webfarm-prod-04']       
  else
    raise(Exception, "Unrecognized Environment")
  end
end

.prod?Boolean

Returns true for prod webfarm instances

Returns:

  • (Boolean)


82
83
84
# File 'lib/ucb_webfarm.rb', line 82

def prod?
  environment == PROD_ENV
end

.qa?Boolean

Returns true for qa webfarm instances

Returns:

  • (Boolean)


77
78
79
# File 'lib/ucb_webfarm.rb', line 77

def qa?
  environment == QA_ENV
end

.rails_environmentObject

Returns Rails environment corresponding to the Webfarm environment. Returns ENV_RAILS_DEVELOPMENT unless webfarm?

Raises RuntimeError for unknown environment.



90
91
92
93
94
95
# File 'lib/ucb_webfarm.rb', line 90

def rails_environment
  return RAILS_DEV_INTEGRATION_ENV if dev_int?
  return RAILS_QUALITY_ASSURANCE_ENV if qa?
  return RAILS_PRODUCTION_ENV if prod?
  raise "Unknown webfarm rails_environment '#{environment}'"
end

.rails_migration_environmentObject

Returns environment to use for migrations. Allows different credentials for migrations than for web app.



99
100
101
102
103
104
# File 'lib/ucb_webfarm.rb', line 99

def rails_migration_environment
  return RAILS_DEV_INTEGRATION_MIGRATION_ENV if dev_int?
  return RAILS_QUALITY_ASSURANCE_MIGRATION_ENV if qa?
  return RAILS_PRODUCTION_MIGRATION_ENV if prod?
  raise "Unknown webfarm rails_migration_environment '#{environment}'"
end

.webfarm?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ucb_webfarm.rb', line 46

def webfarm?
  machine_name.split('-').first == 'webfarm'  
end