Class: CapistranoProvisioning::Cluster
- Inherits:
-
Object
- Object
- CapistranoProvisioning::Cluster
- Defined in:
- lib/capistrano-provisioning/cluster.rb
Instance Attribute Summary collapse
-
#bootstrap ⇒ Object
Returns the value of attribute bootstrap.
-
#config ⇒ Object
Returns the value of attribute config.
-
#name ⇒ Object
Returns the value of attribute name.
-
#servers ⇒ Object
Returns the value of attribute servers.
Instance Method Summary collapse
- #add_users(users, opts = {}) ⇒ Object
- #ensure_users ⇒ Object
-
#initialize(name, opts = {}) ⇒ Cluster
constructor
A new instance of Cluster.
- #install_users(specified_users = []) ⇒ Object
- #preview_users(specified_users = []) ⇒ Object
- #unique_name ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(name, opts = {}) ⇒ Cluster
Returns a new instance of Cluster.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/capistrano-provisioning/cluster.rb', line 5 def initialize(name, opts = {}) self.name = name self.servers = opts[:servers] self.bootstrap = opts[:bootstrap] self.config = opts[:config] @users = [] add_cluster_cap_task end |
Instance Attribute Details
#bootstrap ⇒ Object
Returns the value of attribute bootstrap.
3 4 5 |
# File 'lib/capistrano-provisioning/cluster.rb', line 3 def bootstrap @bootstrap end |
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/capistrano-provisioning/cluster.rb', line 3 def config @config end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/capistrano-provisioning/cluster.rb', line 3 def name @name end |
#servers ⇒ Object
Returns the value of attribute servers.
3 4 5 |
# File 'lib/capistrano-provisioning/cluster.rb', line 3 def servers @servers end |
Instance Method Details
#add_users(users, opts = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/capistrano-provisioning/cluster.rb', line 48 def add_users(users, opts = {}) @users += users.collect do |user| if user.is_a? CapistranoProvisioning::User user.config = self.config user else opts.merge!(:name => user, :config => self.config) CapistranoProvisioning::User.new(opts) # This dependency should be injected, really. end end end |
#ensure_users ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/capistrano-provisioning/cluster.rb', line 40 def ensure_users if @users.empty? and config.respond_to?(:default_users) @users = config.default_users end abort "No users found" unless @users end |
#install_users(specified_users = []) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/capistrano-provisioning/cluster.rb', line 16 def install_users(specified_users = []) ensure_users self.servers.each do |server| self.users.each do |user| next unless specified_users.empty? or specified_users.include?(user.name) user.install(:server => server) end end end |
#preview_users(specified_users = []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/capistrano-provisioning/cluster.rb', line 27 def preview_users(specified_users = []) ensure_users self.servers.each do |server| puts "#{server}: " self.users.each do |user| next unless specified_users.empty? or specified_users.include?(user.name) groups = user.groups.empty? ? '' : "(#{user.groups.join(', ')})" puts "\t#{user.name} #{groups}" end end end |
#unique_name ⇒ Object
60 61 62 |
# File 'lib/capistrano-provisioning/cluster.rb', line 60 def unique_name self.config.send(:unique_name) + ":" + self.name.to_s end |
#users ⇒ Object
64 65 66 67 |
# File 'lib/capistrano-provisioning/cluster.rb', line 64 def users ensure_users @users end |