Class: Opsup::StackOperator
- Inherits:
-
Object
- Object
- Opsup::StackOperator
- Defined in:
- lib/opsup/stack_operator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opsworks:, logger:) ⇒ StackOperator
constructor
A new instance of StackOperator.
- #run_commands(commands, stack_name:, mode:, dryrun: false) ⇒ Object
Constructor Details
#initialize(opsworks:, logger:) ⇒ StackOperator
Returns a new instance of StackOperator.
14 15 16 17 |
# File 'lib/opsup/stack_operator.rb', line 14 def initialize(opsworks:, logger:) @opsworks = opsworks @logger = logger end |
Class Method Details
.create(opsworks:) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/opsup/stack_operator.rb', line 7 def self.create(opsworks:) new( opsworks: opsworks, logger: Opsup::Logger.instance, ) end |
Instance Method Details
#run_commands(commands, stack_name:, mode:, dryrun: false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 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 |
# File 'lib/opsup/stack_operator.rb', line 19 def run_commands(commands, stack_name:, mode:, dryrun: false) # Find the target stack. @logger.debug('Verifying the specified stack exists...') stacks = @opsworks.describe_stacks.stacks stack = stacks.find { |s| s.name == stack_name } raise Opsup::Error, "Stack #{stack_name} does not exist" if stack.nil? # Find the stack's apps. @logger.debug('Verifying the stack has at least one app...') apps = @opsworks.describe_apps(stack_id: stack.stack_id).apps raise Opsup::Error, "#{stack_name} has no apps" if apps.empty? # Find the instances to be updated. @logger.debug('Finding all working instances in the stack...') instances = @opsworks.describe_instances(stack_id: stack.stack_id).instances instances = instances.reject { |inst| inst.status == 'stopped' } @logger.debug( "#{instances.size} #{instances.size == 1 ? 'instance is' : 'instances are'} found", ) # Currently Opsup deploys only the first app by default. app = apps.first instance_ids = instances.map(&:instance_id) # Run the commands sequentially. commands.each do |command| @logger.info("Running #{command} command in #{mode} mode...") run_command( command, dryrun: dryrun, mode: mode, stack: stack, app: app, instance_ids: instance_ids, ) end end |