Class: Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/cluster/instance.rb

Direct Known Subclasses

AmazonInstance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Instance

Returns a new instance of Instance.



16
17
18
19
20
21
22
23
24
# File 'lib/cluster/instance.rb', line 16

def initialize(*args)
  options = args.extract_options!
  options.each do |key, value|
    func = "#{key}="
    if self.respond_to? func
      self.send func, value
    end
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def address
  @address
end

#disabled_servicesObject

Returns the value of attribute disabled_services.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def disabled_services
  @disabled_services
end

#friendly_nameObject

Returns the value of attribute friendly_name.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def friendly_name
  @friendly_name
end

#groupsObject

Returns the value of attribute groups.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def groups
  @groups
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def id
  @id
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def label
  @label
end

#servicesObject

Returns the value of attribute services.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def services
  @services
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def size
  @size
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def start_time
  @start_time
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/cluster/instance.rb', line 5

def state
  @state
end

Class Method Details

.create(*args) ⇒ Object



95
96
97
# File 'lib/cluster/instance.rb', line 95

def create(*args)
  new(*args).start!
end

Instance Method Details

#disable(service_list) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/cluster/instance.rb', line 62

def disable(service_list)
  for service in service_list
    unless disabled_services.include? service
      @disabled_services = disabled_services << service
    end
  end

  @disabled_services
end

#enable(service_list) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cluster/instance.rb', line 50

def enable(service_list)
  for service in service_list
    @disabled_services.delete(service) if disabled_services.include? service

    unless services.include? service
      @services = services << service
    end
  end

  @services
end

#identified_by?(arg) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/cluster/instance.rb', line 37

def identified_by?(arg)
  arg = arg.downcase
  self.id == arg or self.label == arg or self.dns == arg or self.friendly_name == arg
end

#to_s(format = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cluster/instance.rb', line 72

def to_s(format = nil)
  case format
  when :long
    svs = if services.empty?
            '(N/S)'
          else
            services.map {|s|
              disabled_services.include?(s) ? "!#{s}" : s
            }.join(',')
          end
    conn = dns
    conn = ip if !conn or conn.empty?
    conn = "(#{private_ip_address})" if !conn or conn.empty?

    nm = friendly_name
    nm = '(N/N)' if !nm or nm.empty?
    "#{nm}\t#{svs}\t#{state}\t#{id}\t#{conn}"
  else
    label or id
  end
end