Class: OpsWorks::Stack

Inherits:
Resource show all
Defined in:
lib/opsworks/stack.rb

Constant Summary collapse

AVAILABLE_CHEF_VERSIONS =
%w(0.9 11.4 11.10)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

account, client, #initialize

Constructor Details

This class inherits a constructor from OpsWorks::Resource

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/opsworks/stack.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/opsworks/stack.rb', line 8

def name
  @name
end

Class Method Details

.activeObject



18
19
20
# File 'lib/opsworks/stack.rb', line 18

def self.active
  all.select(&:active?)
end

.allObject



12
13
14
15
16
# File 'lib/opsworks/stack.rb', line 12

def self.all
  client.describe_stacks.data[:stacks].map do |hash|
    new(id: hash[:stack_id], name: hash[:name])
  end
end

.find_by_name(name) ⇒ Object



22
23
24
# File 'lib/opsworks/stack.rb', line 22

def self.find_by_name(name)
  all.find { |stack| stack.name == name }
end

.latest_chef_versionObject



26
27
28
# File 'lib/opsworks/stack.rb', line 26

def self.latest_chef_version
  AVAILABLE_CHEF_VERSIONS.last
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/opsworks/stack.rb', line 76

def active?
  instances.any?(&:online?)
end

#appsObject



30
31
32
# File 'lib/opsworks/stack.rb', line 30

def apps
  @apps ||= initialize_apps
end

#deploy_app(app) ⇒ Object



71
72
73
74
# File 'lib/opsworks/stack.rb', line 71

def deploy_app(app)
  fail 'App not found' unless app && app.id
  create_deployment(app_id: app.id, command: { name: 'deploy' })
end

#execute_recipe(recipe) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/opsworks/stack.rb', line 62

def execute_recipe(recipe)
  create_deployment(
    command: {
      name: 'execute_recipes',
      args: { 'recipes' => [recipe] }
    }
  )
end

#find_app_by_name(name) ⇒ Object



42
43
44
# File 'lib/opsworks/stack.rb', line 42

def find_app_by_name(name)
  apps.find { |app| app.name == name }
end

#find_permission_by_user(name) ⇒ Object



38
39
40
# File 'lib/opsworks/stack.rb', line 38

def find_permission_by_user(name)
  permissions.find { |permission| permission.user == name }
end

#instancesObject



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

def instances
  @instances ||= initialize_instances
end

#permissionsObject



34
35
36
# File 'lib/opsworks/stack.rb', line 34

def permissions
  @permissions ||= initialize_permissions
end

#update_custom_cookbooksObject



58
59
60
# File 'lib/opsworks/stack.rb', line 58

def update_custom_cookbooks
  create_deployment(command: { name: 'update_custom_cookbooks' })
end

#upgrade_chef(version, options = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/opsworks/stack.rb', line 50

def upgrade_chef(version, options = {})
  self.class.client.update_stack(
    stack_id: id,
    configuration_manager: { name: 'Chef', version: version },
    chef_configuration: { manage_berkshelf: options[:manage_berkshelf] }
  )
end