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



93
94
95
# File 'lib/cluster/instance.rb', line 93

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

Instance Method Details

#disable(service_list) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/cluster/instance.rb', line 66

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



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cluster/instance.rb', line 54

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



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

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
    "#{friendly_name}\t#{svs}\t#{state}\t#{id}\t#{dns}"
  else
    label or id
  end
end