cfn_manage 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/cfn_manage.rb DELETED
@@ -1,108 +0,0 @@
1
- require 'optparse'
2
- require_relative '../lib/cf_common'
3
- require_relative '../lib/cf_start_stop_environment'
4
- require 'logger'
5
-
6
- # exit with usage information
7
- def print_usage_exit(code)
8
- STDERR.puts(File.open("#{File.expand_path(File.dirname(__FILE__))}/usage.txt").read)
9
- exit code
10
- end
11
-
12
- # global options
13
- $options = {}
14
- $options['SOURCE_BUCKET'] = ENV['SOURCE_BUCKET']
15
- $options['AWS_ASSUME_ROLE'] = ENV['AWS_ASSUME_ROLE']
16
-
17
- # global logger
18
- $log = Logger.new(STDOUT)
19
-
20
- # always flush output
21
- STDOUT.sync = true
22
-
23
- # parse command line options
24
- OptionParser.new do |opts|
25
-
26
- opts.banner = 'Usage: cfn_manage [command] [options]'
27
-
28
- opts.on('--source-bucket [BUCKET]') do |bucket|
29
- $options['SOURCE_BUCKET'] = bucket
30
- ENV['SOURCE_BUCKET'] = bucket
31
- end
32
-
33
- opts.on('--aws-role [ROLE]') do |role|
34
- ENV['AWS_ASSUME_ROLE'] = role
35
- end
36
-
37
- opts.on('--stack-name [STACK_NAME]') do |stack|
38
- $options['STACK'] = stack
39
- end
40
-
41
- opts.on('--asg-name [ASG]') do |asg|
42
- $options['ASG'] = asg
43
- end
44
-
45
- opts.on('--rds-instance-id [RDS_INSTANCE_ID]') do |asg|
46
- $options['RDS_INSTANCE_ID'] = asg
47
- end
48
-
49
- opts.on('--aurora-cluster-id [AURORA_CLUSTER_ID]') do |asg|
50
- $options['AURORA_CLUSTER_ID'] = asg
51
- end
52
-
53
- opts.on('--stack-name [STACK_NAME]') do |asg|
54
- $options['STACK_NAME'] = asg
55
- end
56
-
57
- opts.on('-r [AWS_REGION]', '--region [AWS_REGION]') do |region|
58
- ENV['AWS_REGION'] = region
59
- end
60
-
61
- opts.on('-p [AWS_PROFILE]', '--profile [AWS_PROFILE]') do |profile|
62
- ENV['CFN_AWS_PROFILE'] = profile
63
- end
64
-
65
- opts.on('--dry-run') do
66
- ENV['DRY_RUN'] = '1'
67
- end
68
-
69
- opts.on('--continue-on-error') do
70
- ENV['CFN_CONTINUE_ON_ERROR'] = '1'
71
- end
72
-
73
- end.parse!
74
-
75
- command = ARGV[0]
76
-
77
- if command.nil?
78
- print_usage_exit(-1)
79
- end
80
-
81
- # execute action based on command
82
- case command
83
- when 'help'
84
- print_usage_exit(0)
85
- # asg commands
86
- when 'stop-asg'
87
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_asg('stop', $options['ASG'])
88
- when 'start-asg'
89
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_asg('start', $options['ASG'])
90
-
91
- # rds commands
92
- when 'stop-rds'
93
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_rds('stop', $options['RDS_INSTANCE_ID'])
94
- when 'start-rds'
95
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_rds('start', $options['RDS_INSTANCE_ID'])
96
-
97
- # aurora cluster commands
98
- when 'stop-aurora-cluster'
99
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_aurora_cluster('stop', $options['AURORA_CLUSTER_ID'])
100
- when 'start-aurora-cluster'
101
- Base2::CloudFormation::EnvironmentRunStop.new().start_stop_aurora_cluster('start', $options['AURORA_CLUSTER_ID'])
102
-
103
- # stack commands
104
- when 'stop-environment'
105
- Base2::CloudFormation::EnvironmentRunStop.new().stop_environment($options['STACK_NAME'])
106
- when 'start-environment'
107
- Base2::CloudFormation::EnvironmentRunStop.new().start_environment($options['STACK_NAME'])
108
- end
@@ -1,39 +0,0 @@
1
- require_relative '../lib/asg_start_stop_handler'
2
- require_relative '../lib/ec2_start_stop_handler'
3
- require_relative '../lib/rds_start_stop_handler'
4
- require_relative '../lib/aurora_cluster_start_stop_handler'
5
- require_relative '../lib/alarm_start_stop_handler'
6
- require_relative '../lib/spot_fleet_start_stop_handler'
7
-
8
- module Base2
9
-
10
- class StartStopHandlerFactory
11
-
12
- # Factory method to get start/stop handler based on CloudFormation
13
- # resource type. If resource_id passed in does not exist, it is
14
- # very likely that exception will be raised
15
- def self.get_start_stop_handler(resource_type, resource_id)
16
- case resource_type
17
- when 'AWS::AutoScaling::AutoScalingGroup'
18
- return Base2::AsgStartStopHandler.new(resource_id)
19
-
20
- when 'AWS::EC2::Instance'
21
- return Base2::Ec2StartStopHandler.new(resource_id)
22
-
23
- when 'AWS::RDS::DBInstance'
24
- return Base2::RdsStartStopHandler.new(resource_id)
25
-
26
- when 'AWS::RDS::DBCluster'
27
- return Base2::AuroraClusterStartStopHandler.new(resource_id)
28
-
29
- when 'AWS::CloudWatch::Alarm'
30
- return Base2::AlarmStartStopHandler.new(resource_id)
31
-
32
- when 'AWS::EC2::SpotFleet'
33
- return Base2::SpotFleetStartStopHandler.new(resource_id)
34
- else
35
- return nil
36
- end
37
- end
38
- end
39
- end