Module: Capistrano::Configuration::RightScale
- Included in:
- Capistrano::Configuration
- Defined in:
- lib/cap-rightscale/configuration/rightscale.rb
Instance Attribute Summary collapse
-
#rs_confpath ⇒ Object
Returns the value of attribute rs_confpath.
-
#rs_domain ⇒ Object
Returns the value of attribute rs_domain.
-
#rs_lifetime ⇒ Object
Returns the value of attribute rs_lifetime.
-
#use_nickname ⇒ Object
writeonly
Sets the attribute use_nickname.
-
#use_public_ip ⇒ Object
writeonly
Sets the attribute use_public_ip.
-
#use_rs_cache ⇒ Object
writeonly
Sets the attribute use_rs_cache.
-
#validate_echo ⇒ Object
writeonly
Sets the attribute validate_echo.
-
#validate_resolv ⇒ Object
writeonly
Sets the attribute validate_resolv.
Instance Method Summary collapse
-
#nickname(role, params) ⇒ Object
Get servers in deployment === Parameters * role - Capistrano role symbol (ex. :app, :web, :db) * params[:name_prefix] - ex.
- #rs_array_number_format(format) ⇒ Object
-
#server_array(role, params) ⇒ Object
Get RightScale Server Array RightScale nickname registerd deploy host’s /etc/hosts OR dns record(replace ‘s/ #/-000/’ to ServerArray name) === Parameters * role - Capistrano role symbol (ex. :app, :web, :db) * params[:array_id] - ex.
-
#tag(role, params) ⇒ Object
Get servers matching tags in deployment === Parameters * role - Capistrano role symbol (ex. :app, :web, :db) * params[:deployment] - ex.
Instance Attribute Details
#rs_confpath ⇒ Object
Returns the value of attribute rs_confpath.
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def rs_confpath @rs_confpath end |
#rs_domain ⇒ Object
Returns the value of attribute rs_domain.
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def rs_domain @rs_domain end |
#rs_lifetime ⇒ Object
Returns the value of attribute rs_lifetime.
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def rs_lifetime @rs_lifetime end |
#use_nickname=(value) ⇒ Object
Sets the attribute use_nickname
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def use_nickname=(value) @use_nickname = value end |
#use_public_ip=(value) ⇒ Object
Sets the attribute use_public_ip
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def use_public_ip=(value) @use_public_ip = value end |
#use_rs_cache=(value) ⇒ Object
Sets the attribute use_rs_cache
4 5 6 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 4 def use_rs_cache=(value) @use_rs_cache = value end |
#validate_echo=(value) ⇒ Object
Sets the attribute validate_echo
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def validate_echo=(value) @validate_echo = value end |
#validate_resolv=(value) ⇒ Object
Sets the attribute validate_resolv
5 6 7 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 5 def validate_resolv=(value) @validate_resolv = value end |
Instance Method Details
#nickname(role, params) ⇒ Object
Get servers in deployment
Parameters
-
role - Capistrano role symbol (ex. :app, :web, :db)
-
params[:name_prefix] - ex. :name_prefix => “db” (RightScale instance nickname)
-
params[:deployment] - ex. :deployment => 1
-
params[:domain] domain name(user defined) - ex. :domain => “example.com”
-
params[:except_tags] except servers matching tags
-
ex. :except_tags => [“xx_app:state=broken”, “xx_app:state=out_of_service”]
-
-
params[:xxx] - ex. :user => “www”, :port => 2345, etc…
Examples
deployment_id = 1
nickname :db, :name_prefix => "db", :deployment => deployment_id, :user => "mysql"
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 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 85 def nickname(role, params) start = Time.now _init unless initialized? return [] unless check_role(role) raise ArgumentError, ":deployment is not included in params!![#{params}]" unless params.has_key?(:deployment) @caller ||= File.basename(caller.map {|x| /(.*?):(\d+)/ =~ x; $1 }.first, ".*") @rs_server_keys ||= [:array_id, :name_prefix, :domain, :except_tags] logger.debug("SETTING ROLE: #{role}") servers = use_rs_cache ? role_with_load_cache(role, @rs_server_keys, params) : [] if servers.size == 0 # Request RightScale API deployment = rs_instance.deployment(params[:deployment], :server_settings => 'true') logger.debug( "querying rightscale for servers #{params[:name_prefix]} in deployment #{deployment.nickname}...") servers = deployment.servers.select {|s| s[:state] == "operational" } servers = servers.select {|s| /#{params[:name_prefix]}/ =~ s[:nickname] } if params[:name_prefix] servers = ( params[:deployment], servers, params[:except_tags], :minus) if params.include?(:except_tags) servers = servers.map do |server| hostname = server[:nickname] dom = params[:domain] || rs_domain hostname += ".#{dom}" if dom ip = use_public_ip ? server[:settings][:ip_address] : server[:settings][:private_ip_address] logger.debug("Found server: #{server[:nickname]}(#{ip})") use_nickname ? hostname : ip end servers = RSUtils.valid_resolv(servers, logger) if validate_resolv && use_nickname servers = RSUtils.valid_echo(servers, logger) if validate_echo role_with_dump_cache(role, servers, @rs_server_keys, params, use_rs_cache) if servers.size > 0 end logger.trace("Time: #{Time.now - start}") servers || [] end |
#rs_array_number_format(format) ⇒ Object
7 8 9 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 7 def rs_array_number_format(format) @array_num_format = format end |
#server_array(role, params) ⇒ Object
Get RightScale Server Array RightScale nickname registerd deploy host’s /etc/hosts OR dns record(replace ‘s/ #/-000/’ to ServerArray name)
Parameters
-
role - Capistrano role symbol (ex. :app, :web, :db)
-
params[:array_id] - ex. :array_id => 1
-
params[:domain] domain name(user defined) - ex. :domain => “example.com”
-
params[:except_tags] except servers matching tags
-
ex. :except_tags => [“xx_app:state=broken”, “xx_app:state=out_of_service”]
-
-
params[:xxx] - ex. :user => “www”, :port => 2345, etc…
Examples
array_id = 1
server_array :app, :array_id => array_id, :port => 1234
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 31 def server_array(role, params) start = Time.now _init unless initialized? return [] unless check_role(role) raise ArgumentError, ":array_id is not included in params!![#{params}]" unless params.has_key?(:array_id) @caller ||= File.basename(caller.map {|x| /(.*?):(\d+)/ =~ x; $1}.first, ".*") @rs_array_keys ||= [:array_id, :domain, :except_tags] logger.debug("SETTING ROLE: #{role}") servers = use_rs_cache ? role_with_load_cache(role, @rs_array_keys, params) : [] if servers.size == 0 # Request RightScale API array = rs_instance.array(params[:array_id]) logger.debug("querying rightscale for server_array #{array.nickname}...") deployment = rs_instance.deployment(array.deployment_href.match(/[0-9]+$/).to_s, :server_settings => 'true') deployment_name = deployment.nickname logger.debug("Deployment #{deployment_name}:") servers = rs_instance.array_instances(array.id).select {|i| i[:state] == "operational" } servers = ( deployment.id, servers, params[:except_tags], :minus) if params.include?(:except_tags) servers = servers.map do |instance| hostname = instance[:nickname].sub( / #[0-9]+$/, array_number_format % instance[:nickname].match(/[0-9]+$/).to_s.to_i) dom = params[:domain] || rs_domain hostname += ".#{dom}" if dom ip = use_public_ip ? instance[:ip_address] : instance[:private_ip_address] logger.debug("Found server: #{instance[:nickname]}(#{ip})") use_nickname ? hostname : ip end servers = RSUtils.valid_resolv(servers, logger) if validate_resolv && use_nickname servers = RSUtils.valid_echo(servers, logger) if validate_echo role_with_dump_cache(role, servers, @rs_array_keys, params, use_rs_cache) if servers.size > 0 end logger.trace("Time: #{Time.now - start}") servers || [] end |
#tag(role, params) ⇒ Object
Get servers matching tags in deployment
Parameters
-
role - Capistrano role symbol (ex. :app, :web, :db)
-
params[:deployment] - ex. :deployment => 1
-
params[:tags] - ex. :tags => “xx_db:role=master”,
"xx_web:role", "xx_lb" (RightScale tags partial matchs 'namespece:predicate=value')
-
params[:name_prefix] - ex. :name_prefix => “db” (RightScale instance nickname)
-
params[:domain] domain name(user defined) - ex. :domain => “example.com”
-
params[:except_tags] except servers matching tags
-
ex. :except_tags => [“xx_app:state=broken”, “xx_app:state=out_of_service”]
-
-
params[:xxx] - ex. :user => “www”, :port => 2345, etc…
Examples
deployment_id = 1
nickname :db, :name_prefix => "db", :tags => "xx_db:role", :deployment => deployment_id, :port => 3306
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cap-rightscale/configuration/rightscale.rb', line 139 def tag(role, params) start = Time.now _init unless initialized? return [] unless check_role(role) raise ArgumentError, ":tags is not included in params!![#{params}]" unless params.has_key?(:tags) raise ArgumentError, ":deployment is not included in params!![#{params}]" unless params.has_key?(:deployment) @caller ||= File.basename(caller.map {|x| /(.*?):(\d+)/ =~ x; $1 }.first, ".*") @rs_tag_keys ||= [:deployment, :tags, :name_prefix, :domain, :except_tags] logger.debug("SETTING ROLE: #{role}") servers = use_rs_cache ? role_with_load_cache(role, @rs_tag_keys, params) : [] if servers.size == 0 # Request RightScale API deployment = rs_instance.deployment(params[:deployment], :server_settings => 'true') logger.debug("querying rightscale for servers #{params[:name_prefix]} " + "matching tags #{params[:tags]} in deployment #{deployment.nickname}...") servers = deployment.servers.select {|s| s[:state] == "operational" } servers = servers.select {|s| /#{params[:name_prefix]}/ =~ s[:nickname] } if params[:name_prefix] servers = (params[:deployment], servers, params[:tags], :intersect) if params.include?(:except_tags) && servers.size > 0 servers = (params[:deployment], servers, params[:except_tags], :minus) end servers = servers.map do |server| hostname = server[:nickname] dom = params[:domain] || rs_domain hostname += ".#{dom}" if dom ip = use_public_ip ? server[:settings][:ip_address] : server[:settings][:private_ip_address] logger.debug("Found server: #{server[:nickname]}(#{ip})") use_nickname ? hostname : ip end servers = RSUtils.valid_resolv(servers, logger) if validate_resolv && use_nickname servers = RSUtils.valid_echo(servers, logger) if validate_echo role_with_dump_cache(role, servers, @rs_tag_keys, params, use_rs_cache) if servers.size > 0 end logger.trace("Time: #{Time.now - start}") servers || [] end |