Module: AMA
Instance Method Summary collapse
- #create_stack(conf) ⇒ Object
- #delete_stack(stack_name) ⇒ Object
- #get_default_network_ids ⇒ Object
- #info(stack_name) ⇒ Object
- #stack_status(stack_name) ⇒ Object
- #terminate(instance_id) ⇒ Object
Instance Method Details
#create_stack(conf) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aws/drupal_aws.rb', line 14 def create_stack conf parameters = get_default_network_ids().update conf[:create_params] paramlist = parameters.map {|k,v| {parameter_key: k.to_s, parameter_value: v.to_s}} create_params = conf[:create].update({parameters: paramlist}) #puts create_params; return ### cfn = Aws::CloudFormation::Client.new begin cfn.create_stack( create_params ) descr = cfn.wait_until(:stack_create_complete, {stack_name: conf[:create][:stack_name]}, { delay: 6, max_attempts: 150, # 15 min before_attempt: ->(*x) do print "." end }) puts rescue Aws::CloudFormation::Errors::ServiceError, \ Aws::Waiters::Errors::WaiterFailed, \ ArgumentError => e puts e return end shape_outputs( descr ) end |
#delete_stack(stack_name) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/aws/drupal_aws.rb', line 40 def delete_stack stack_name begin cfn = Aws::CloudFormation::Client.new cfn.delete_stack({stack_name: stack_name}) rescue Aws::CloudFormation::Errors::ServiceError => e puts e end end |
#get_default_network_ids ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/aws/drupal_aws.rb', line 88 def get_default_network_ids begin ec2 = Aws::EC2::Client.new descr = ec2.describe_vpcs def_vpc = descr.vpcs.select { |x| x.is_default } .first.vpc_id descr = ec2.describe_subnets({ filters: [ {name: "vpc-id", values: [def_vpc]} ] }) rescue Aws::EC2::Errors => e puts " *** #{e}" return end subnets = descr.subnets.map &:subnet_id { VpcId: def_vpc, SubnetA: subnets[0], SubnetB: subnets[1] } end |
#info(stack_name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aws/drupal_aws.rb', line 67 def info stack_name begin cfn = Aws::CloudFormation::Client.new descr = cfn.describe_stacks({stack_name: stack_name}) rescue Aws::CloudFormation::Errors::ServiceError, ArgumentError => e puts e return end shape_outputs( descr ) end |
#stack_status(stack_name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/aws/drupal_aws.rb', line 49 def stack_status stack_name begin cfn = Aws::CloudFormation::Client.new events = cfn.describe_stack_events({stack_name: stack_name}) rescue Aws::CloudFormation::Errors::ServiceError, ArgumentError => e puts e return end last_event = events.stack_events.first finished = ("AWS::CloudFormation::Stack" == last_event.resource_type) finished &= (stack_name == last_event.logical_resource_id) finished &= !("CREATE_IN_PROGRESS" == last_event.resource_status) success = ("CREATE_COMPLETE" == last_event.resource_status) finished ? (success ? :created : :failed) : :ongoing end |
#terminate(instance_id) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/aws/drupal_aws.rb', line 78 def terminate instance_id begin ec2 = Aws::EC2::Client.new ec2.terminate_instances({ instance_ids: [instance_id] }) rescue Aws::EC2::Errors => e puts " *** #{e}" end end |