Class: Maestro::Cloud::Aws

Inherits:
Base
  • Object
show all
Defined in:
lib/maestro/cloud/aws.rb

Overview

Amazon Web Services cloud

Constant Summary collapse

MAESTRO_NODE_PREFIX =
"node."
MAESTRO_ROLE_PREFIX =
"role."
MAESTRO_DEFAULT_ROLE =
"default"
US_EAST_REGION =
"us-east"
US_WEST_REGION =
"us-west"
EU_REGION =
"eu"
ASIA_PACIFIC_REGION =
"asia-pacific"
REGIONS =
[US_EAST_REGION, US_WEST_REGION, EU_REGION, ASIA_PACIFIC_REGION]
EC2_ENDPOINTS =
{US_EAST_REGION => "ec2.us-east-1.amazonaws.com",
US_WEST_REGION => "ec2.us-west-1.amazonaws.com",
EU_REGION => "ec2.eu-west-1.amazonaws.com",
ASIA_PACIFIC_REGION => "ec2.ap-southeast-1.amazonaws.com"}
ELB_ENDPOINTS =
{US_EAST_REGION => "elasticloadbalancing.us-east-1.amazonaws.com",
US_WEST_REGION => "elasticloadbalancing.us-west-1.amazonaws.com",
EU_REGION => "elasticloadbalancing.eu-west-1.amazonaws.com",
ASIA_PACIFIC_REGION => "elasticloadbalancing.ap-southeast-1.amazonaws.com"}
RDS_ENDPOINTS =
{US_EAST_REGION => "rds.us-east-1.amazonaws.com",
US_WEST_REGION => "rds.us-west-1.amazonaws.com",
EU_REGION => "rds.eu-west-1.amazonaws.com",
ASIA_PACIFIC_REGION => "rds.ap-southeast-1.amazonaws.com"}

Instance Attribute Summary collapse

Attributes inherited from Base

#config_file, #configurable_nodes, #log_directory, #log_file, #name

Attributes included from Validator

#valid, #validation_errors

Instance Method Summary collapse

Methods inherited from Base

#chef_solo_installed?, #configure_chef_solo, create_from_file, #install_chef_solo, #method_missing, #nodes, #nodes=, #role, #roles, #roles=, #run_chef_solo

Methods included from Validator

#invalidate, #valid?, #validate

Constructor Details

#initialize(name, cfg_file = nil, &block) ⇒ Aws

Returns a new instance of Aws.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/maestro/cloud/aws.rb', line 67

def initialize(name, cfg_file=nil, &block)
  @ec2_nodes = Hash.new
  @elb_nodes = Hash.new
  @rds_nodes = Hash.new
  super(name, cfg_file, &block)
  @ec2_security_groups = Array.new
  @role_ec2_security_groups = Array.new
  @node_ec2_security_groups = Array.new
  @default_ec2_security_group = role_ec2_security_group_name(MAESTRO_DEFAULT_ROLE)
  @role_ec2_security_groups << @default_ec2_security_group
  @ec2_nodes.values.each {|ec2| ec2.set_default_security_group(@default_ec2_security_group)}
  @db_parameter_groups = Array.new
  @db_security_groups = Array.new
  @rds_nodes.values.each do |rds|
    @db_parameter_groups << rds.db_parameter_group_name
    @db_security_groups << rds.db_security_group_name
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Maestro::Cloud::Base

Instance Attribute Details

#db_parameter_groupsObject (readonly)

Array of all rds db parameter group names in this Cloud



56
57
58
# File 'lib/maestro/cloud/aws.rb', line 56

def db_parameter_groups
  @db_parameter_groups
end

#db_security_groupsObject (readonly)

Array of all rds db security group names in this Cloud



58
59
60
# File 'lib/maestro/cloud/aws.rb', line 58

def db_security_groups
  @db_security_groups
end

#default_ec2_security_groupObject (readonly)

the default ec2 security group name for this Cloud



54
55
56
# File 'lib/maestro/cloud/aws.rb', line 54

def default_ec2_security_group
  @default_ec2_security_group
end

#ec2_nodesObject (readonly)

Hash of Ec2 Nodes



60
61
62
# File 'lib/maestro/cloud/aws.rb', line 60

def ec2_nodes
  @ec2_nodes
end

#ec2_security_groupsObject (readonly)

Array of all ec2 security groups names in this Cloud



48
49
50
# File 'lib/maestro/cloud/aws.rb', line 48

def ec2_security_groups
  @ec2_security_groups
end

#elb_nodesObject (readonly)

Hash of Elb Nodes



62
63
64
# File 'lib/maestro/cloud/aws.rb', line 62

def elb_nodes
  @elb_nodes
end

#node_ec2_security_groupsObject (readonly)

Array of ec2 security group names for the Maestro::Node::Aws::Ec2 Nodes in this Cloud



52
53
54
# File 'lib/maestro/cloud/aws.rb', line 52

def node_ec2_security_groups
  @node_ec2_security_groups
end

#rds_nodesObject (readonly)

Hash of Rds Nodes



64
65
66
# File 'lib/maestro/cloud/aws.rb', line 64

def rds_nodes
  @rds_nodes
end

#role_ec2_security_groupsObject (readonly)

Array of ec2 security group names for the Roles in this Cloud



50
51
52
# File 'lib/maestro/cloud/aws.rb', line 50

def role_ec2_security_groups
  @role_ec2_security_groups
end

Instance Method Details

#chef_assets_urlObject

Returns the URL to the Chef assets tar ball



743
744
745
# File 'lib/maestro/cloud/aws.rb', line 743

def chef_assets_url
  AWS::S3::S3Object.url_for(MAESTRO_CHEF_ARCHIVE, chef_bucket, :expires_in => 600, :use_ssl => true)
end

#configureObject

Configures the Nodes in this Cloud



160
161
162
163
164
165
# File 'lib/maestro/cloud/aws.rb', line 160

def configure
  connect!
  get_configurable_node_hostnames
  upload_chef_assets
  super
end

#connect!Object

establishes a connection to Amazon



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/maestro/cloud/aws.rb', line 121

def connect!
  region.nil? || region.empty? ? region_name = US_EAST_REGION : region_name = region
  @ec2 = AWS::EC2::Base.new(:access_key_id => aws_access_key,
                            :secret_access_key => aws_secret_access_key,
                            :use_ssl => true,
                            :server => EC2_ENDPOINTS[region_name])
  @elb = AWS::ELB::Base.new(:access_key_id => aws_access_key,
                            :secret_access_key => aws_secret_access_key,
                            :use_ssl => true,
                            :server => ELB_ENDPOINTS[region_name])
  @rds = AWS::RDS::Base.new(:access_key_id => aws_access_key,
                            :secret_access_key => aws_secret_access_key,
                            :use_ssl => true,
                            :server => RDS_ENDPOINTS[region_name])
  s3_logger = Logger.new(STDOUT)
  s3_logger.level = Logger::FATAL
  AWS::S3::Base.establish_connection!(:access_key_id => aws_access_key, :secret_access_key => aws_secret_access_key, :use_ssl => true)
end

#ebs_volume_allocated?(volume_id) ⇒ Boolean

predicate indicating if the given EBS volume is allocated to this Cloud’s AWS account

Returns:

  • (Boolean)


625
626
627
628
629
630
631
632
633
# File 'lib/maestro/cloud/aws.rb', line 625

def ebs_volume_allocated?(volume_id)
  begin
    volume = @ec2.describe_volumes(:volume_id => [volume_id])
    return true if !volume.nil?
  rescue AWS::Error => aws_error
    return false if aws_error.message.eql? "The volume '#{volume_id}' does not exist."
  end
  return false
end

#ebs_volume_association(volume_id) ⇒ Object

returns the instance_id which the given EBS volume is associated with, or nil if it is not associated



636
637
638
639
640
641
642
643
644
645
646
# File 'lib/maestro/cloud/aws.rb', line 636

def ebs_volume_association(volume_id)
  begin
    volume = @ec2.describe_volumes(:volume_id => [volume_id])
    if !volume.nil? && !volume.volumeSet.nil? && !volume.volumeSet.item.nil? && !volume.volumeSet.item[0].attachmentSet.nil?
      return volume.volumeSet.item[0].attachmentSet.item[0].instanceId
    end
  rescue AWS::Error => aws_error
    return nil if aws_error.message.eql? "The volume '#{volume_id}' does not exist."
  end
  return nil
end

#ec2_node(name, &block) ⇒ Object

creates a Maestro::Node::Aws::Ec2 Node



87
88
89
90
91
92
93
94
95
96
# File 'lib/maestro/cloud/aws.rb', line 87

def ec2_node(name, &block)
  if @nodes.has_key?(name)
    invalidate "Duplicate node definition: #{name}"
  else
    ec2 = Maestro::Node::Aws::Ec2.new(name, self, &block)
    @nodes[name] = ec2
    @ec2_nodes[name] = ec2
    @configurable_nodes[name] = ec2
  end
end

#ec2_node_statusesObject

Reports the current status of all Ec2 Nodes in this Cloud



232
233
234
235
236
237
238
239
240
241
242
# File 'lib/maestro/cloud/aws.rb', line 232

def ec2_node_statuses
  all_instances = @ec2.describe_instances
  @ec2_nodes.each_pair do |node_name, node|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if node_instance.nil?
      @logger.info "  #{node_name}: not running"
    else
      @logger.info "  #{node_name}: #{node_instance.instanceState.name} (instance #{node_instance.instanceId}, host: #{node_instance.dnsName})"
    end
  end
end

#elastic_ip_allocated?(elastic_ip) ⇒ Boolean

predicate indicating if the given Elastic IP address is allocated to this Cloud’s AWS account

Returns:

  • (Boolean)


571
572
573
574
575
576
577
578
579
# File 'lib/maestro/cloud/aws.rb', line 571

def elastic_ip_allocated?(elastic_ip)
  begin
    ip = @ec2.describe_addresses(:public_ip => [elastic_ip])
    return true if !ip.nil?
  rescue AWS::Error => aws_error
    return false if aws_error.message.eql? "Address '#{elastic_ip}' not found."
  end
  return false
end

#elastic_ip_association(elastic_ip) ⇒ Object

returns the instance_id which the given Elastic IP is associated with, or nil if it is not associated



582
583
584
585
586
587
588
589
590
# File 'lib/maestro/cloud/aws.rb', line 582

def elastic_ip_association(elastic_ip)
  begin
    ip = @ec2.describe_addresses(:public_ip => [elastic_ip])
    return ip.addressesSet.item[0].instanceId if !ip.nil? && !ip.addressesSet.nil?
  rescue AWS::Error => aws_error
    return nil if aws_error.message.eql? "Address '#{elastic_ip}' not found."
  end
  return nil
end

#elb_node(name, &block) ⇒ Object

creates a Maestro::Node::Aws::Elb Node



99
100
101
102
103
104
105
106
107
# File 'lib/maestro/cloud/aws.rb', line 99

def elb_node(name, &block)
  if @nodes.has_key?(name)
    invalidate "Duplicate node definition: #{name}"
  else
    elb = Maestro::Node::Aws::Elb.new(name, self, &block)
    @nodes[name] = elb
    @elb_nodes[name] = elb
  end
end

#elb_node_statusesObject

Reports the current status of all Elb Nodes in this Cloud



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/maestro/cloud/aws.rb', line 245

def elb_node_statuses
  all_balancers = @elb.describe_load_balancers
  @elb_nodes.each_pair do |node_name, node|
    node_balancer = find_elb_node_instance(node_name, all_balancers)
    if node_balancer.nil?
      @logger.info "  #{node_name}: not running"
    else
      @logger.info "  #{node_name}: running (host: #{node_balancer.DNSName})"
      @logger.info "  #{node_name} registered instances health:"
      health = @elb.describe_instance_health(:load_balancer_name => node.load_balancer_name)
      all_instances = @ec2.describe_instances
      node.ec2_nodes.each do |ec2_node_name|
        ec2_instance = find_ec2_node_instance(ec2_node_name, all_instances)
        ec2_node = @ec2_nodes[ec2_node_name]
        health_member = health.DescribeInstanceHealthResult.InstanceStates.member.select {|member| member if member.InstanceId.eql?(ec2_instance.instanceId)}
        @logger.info "  #{node_name.gsub(/./, ' ')} #{ec2_node_name}: #{health_member[0].State} (#{health_member[0].Description})"
      end
    end
  end
end

#ensure_ebs_volumesObject

ensures that all configured EBS volumes have been associated to the given nodes



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/maestro/cloud/aws.rb', line 649

def ensure_ebs_volumes
  all_instances = @ec2.describe_instances()
  @ec2_nodes.each_pair do |node_name, node|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if !node.ebs_volume_id.nil? && !node.ebs_device.nil?
      if node_instance.nil?
        @logger.error "ERROR: Node #{node_name} doesn't appear to be running to attach EBS Volume #{node.ebs_volume_id}"
      else
        if ebs_volume_allocated?(node.ebs_volume_id)
          associated_instance_id = ebs_volume_association(node.ebs_volume_id)
          if associated_instance_id.eql?(node_instance.instanceId)
            @logger.info "EBS Volume #{node.ebs_volume_id} is already attached to Node #{node_name}"
          else
            begin
              STDOUT.sync = true
              if associated_instance_id.nil?
                @logger.progress "Attaching EBS Volume #{node.ebs_volume_id} to Node #{node_name}..."
                @ec2.attach_volume(:instance_id => node_instance.instanceId, :volume_id => node.ebs_volume_id, :device => node.ebs_device)
                to_be_watched = [node.ebs_volume_id]
                while !to_be_watched.empty?
                  volumes =  @ec2.describe_volumes(:volume_id => to_be_watched[0])
                  if !volumes.volumeSet.item[0].attachmentSet.nil? && volumes.volumeSet.item[0].attachmentSet.item[0].status.eql?("attached")
                    to_be_watched.clear
                  else
                    @logger.progress "."
                  end
                  sleep 5 if !to_be_watched.empty?
                end
                @logger.info "done."
              else
                @logger.progress "EBS Volume #{node.ebs_volume_id} is attached to the wrong instance (instance #{associated_instance_id}). Detaching..."
                @ec2.detach_volume(:volume_id => node.ebs_volume_id)
                to_be_watched = [node.ebs_volume_id]
                while !to_be_watched.empty?
                  volumes =  @ec2.describe_volumes(:volume_id => to_be_watched[0])
                  if volumes.volumeSet.item[0].status.eql? "available"
                    to_be_watched.clear
                  else
                    @logger.progress "."
                  end
                  sleep 5 if !to_be_watched.empty?
                end
                @logger.info "done."
                @logger.progress "Attaching EBS Volume #{node.ebs_volume_id} to Node #{node_name}..."
                @ec2.attach_volume(:instance_id => node_instance.instanceId, :volume_id => node.ebs_volume_id, :device => node.ebs_device)
                to_be_watched = [node.ebs_volume_id]
                while !to_be_watched.empty?
                  volumes =  @ec2.describe_volumes(:volume_id => to_be_watched[0])
                  if !volumes.volumeSet.item[0].attachmentSet.nil? && volumes.volumeSet.item[0].attachmentSet.item[0].status.eql?("attached")
                    to_be_watched.clear
                  else
                    @logger.progress "."
                  end
                  sleep 5 if !to_be_watched.empty?
                end
                @logger.info "done."
              end
            rescue AWS::Error => aws_error
              @logger.error "Error attaching EBS Volume #{node.ebs_volume_id} to Node #{node_name}: #{aws_error.inspect}"
            end
          end
        else
          @logger.error "ERROR: EBS Volume #{node.ebs_volume_id} is not allocated to this AWS Account"
        end
      end
    end
  end
end

#ensure_ec2_nodesObject

ensures that the Ec2 nodes of this cloud are running



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/maestro/cloud/aws.rb', line 470

def ensure_ec2_nodes
  all_instances =  @ec2.describe_instances()
  to_be_started = Array.new
  to_be_watched = Array.new
  @ec2_nodes.keys.each do |node_name|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if node_instance.nil?
      @logger.info "Node #{node_name} not running. Starting..."
      to_be_started << node_name
    elsif node_instance.instanceState.name.eql?("shutting-down")
      @logger.info "Node #{node_name} shutting down. Re-starting..."
    elsif node_instance.instanceState.name.eql?("pending")
      @logger.info "Node #{node_name} starting up..."
      to_be_watched << node_name
    else
      @logger.info "Node #{node_name} already running (instance #{node_instance.instanceId}, host: #{node_instance.dnsName})"
    end
  end
  to_be_started.each do |node_name|
    node = @nodes[node_name]
    @ec2.run_instances(:image_id => node.ami, :min_count => 1, :max_count => 1, :key_name => keypair_name, :instance_type => node.instance_type, :availability_zone => node.availability_zone, :security_group => node.security_groups)
    to_be_watched << node_name
  end
  STDOUT.sync = true
  @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to start..." if !to_be_watched.empty?
  while !to_be_watched.empty?
    instances =  @ec2.describe_instances()
    to_be_watched.each do |node_name|
      instance = find_ec2_node_instance(node_name, instances)
      if !instance.nil? && instance.instanceState.name.eql?("running")
        @logger.progress "\n"
        @logger.info "Node #{node_name} started (instance #{instance.instanceId}, host: #{instance.dnsName})"
        to_be_watched.delete(node_name)
        @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to start..." if !to_be_watched.empty?
      else
        @logger.progress "."
      end
    end
    sleep 5 if !to_be_watched.empty?
  end
end

#ensure_ec2_nodes_terminatedObject

Ensures that the Ec2 Nodes of this Cloud are terminated



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/maestro/cloud/aws.rb', line 773

def ensure_ec2_nodes_terminated
  all_instances =  @ec2.describe_instances()
  to_be_terminated = Array.new
  to_be_watched = Array.new
  @ec2_nodes.each_pair do |node_name, node|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if node_instance.nil?
      @logger.info "Node #{node_name} already terminated"
    elsif node_instance.instanceState.name.eql?("shutting-down")
      @logger.info "Node #{node_name} terminating..."
      to_be_watched << node_name
    elsif node_instance.instanceState.name.eql?("pending") || node_instance.instanceState.name.eql?("running")
      @logger.info "Node #{node_name} running. Terminating..."
      to_be_terminated << node_instance.instanceId
      to_be_watched << node_name
    end
  end
  if !to_be_terminated.empty?
    @ec2.terminate_instances(:instance_id => to_be_terminated)
    @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to terminate..." if !to_be_watched.empty?
  end
  STDOUT.sync = true
  while !to_be_watched.empty?
    instances =  @ec2.describe_instances()
    to_be_watched.each do |node_name|
      instance = find_ec2_node_instance(node_name, instances)
      if instance.nil?
        @logger.progress "\n"
        @logger.info "Node #{node_name} terminated"
        to_be_watched.delete(node_name)
        @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to terminate..." if !to_be_watched.empty?
      else
        @logger.progress "."
      end
    end
    sleep 5 if !to_be_watched.empty?
  end
end

#ensure_ec2_security_groupsObject

ensures that the EC2 security groups of this cloud are created and configured



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/maestro/cloud/aws.rb', line 306

def ensure_ec2_security_groups
  # the default security group applied to all nodes
  ensure_ec2_security_group(@default_ec2_security_group)
  ensure_ec2_security_group_name_configuration(@default_ec2_security_group, @default_ec2_security_group, )
  ensure_ec2_security_group_cidr_configuration(@default_ec2_security_group, "22", "22", "tcp")
  # set up node groups
  @ec2_nodes.values.each do |node|
    ensure_ec2_security_group(node.node_security_group)
    @node_ec2_security_groups << node.node_security_group
  end
  # set up role groups
  role_groups = Hash.new
  @roles.keys.collect {|role_name| role_groups[role_name] = role_ec2_security_group_name(role_name)}
  role_groups.values.each {|group| ensure_ec2_security_group(group)}
  @role_ec2_security_groups = @role_ec2_security_groups + role_groups.values
  @roles.each_pair do |name, role|
    if !role.public_ports.nil? && !role.public_ports.empty?
      role.public_ports.each {|port| ensure_ec2_security_group_cidr_configuration(role_ec2_security_group_name(name), port, port, "tcp")}
    end
  end
  # collect all groups
  @ec2_security_groups = @ec2_security_groups + @node_ec2_security_groups
  @ec2_security_groups = @ec2_security_groups + @role_ec2_security_groups
end

#ensure_elastic_ipsObject

ensures that all configured Elastic IPs have been associated to the given nodes



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/maestro/cloud/aws.rb', line 593

def ensure_elastic_ips
  all_instances = @ec2.describe_instances()
  @ec2_nodes.each_pair do |node_name, node|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if !node.elastic_ip.nil?
      if node_instance.nil?
        @logger.error "ERROR: Node #{node_name} doesn't appear to be running to associate with Elastic IP #{node.elastic_ip}"
      else
        if elastic_ip_allocated?(node.elastic_ip)
          associated_instance_id = elastic_ip_association(node.elastic_ip)
          if associated_instance_id.eql?(node_instance.instanceId)
            @logger.info "Elastic IP Address #{node.elastic_ip} is already associated with Node #{node_name}"
          else
            if associated_instance_id.nil?
              @ec2.associate_address(:instance_id => node_instance.instanceId, :public_ip => node.elastic_ip)
              @logger.info "Associated Elastic IP Address #{node.elastic_ip} with Node #{node_name}"
            else
              @logger.info "Elastic IP Address #{node.elastic_ip} is associated with the wrong instance (instance #{associated_instance_id}). Disassociating."
              @ec2.disassociate_address(:public_ip => node.elastic_ip)
              @ec2.associate_address(:instance_id => node_instance.instanceId, :public_ip => node.elastic_ip)
              @logger.info "Associated Elastic IP Address #{node.elastic_ip} with Node #{node_name}"
            end
          end
        else
          @logger.error "ERROR: Elastic IP Address #{node.elastic_ip} is not allocated to this AWS Account"
        end
      end
    end
  end
end

#ensure_elb_nodesObject

ensures that the Elb nodes of this cloud are running



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/maestro/cloud/aws.rb', line 513

def ensure_elb_nodes
  all_balancers =  @elb.describe_load_balancers()
  to_be_started = Array.new
  @elb_nodes.keys.each do |node_name|
    node_instance = find_elb_node_instance(node_name, all_balancers)
    if node_instance.nil?
      @logger.info "Node #{node_name} not running. Starting..."
      to_be_started << node_name
    else
      @logger.info "Node #{node_name} already running (host: #{node_instance.DNSName})"
    end
  end
  to_be_started.each do |node_name|
    node = @nodes[node_name]
    # TODO: What to do about availability zones tied to this elb's instances, but not specified here? Validation error? Leave it to the user?
    elb = @elb.create_load_balancer(:load_balancer_name => node.load_balancer_name, :availability_zones => node.availability_zones, :listeners => node.listeners)
    node.hostname = elb.CreateLoadBalancerResult.DNSName
    @logger.info "Node #{node_name} started (host: #{node.hostname})"
    if !node.health_check.nil?
      @elb.configure_health_check({:health_check => node.health_check,
                                   :load_balancer_name => node.load_balancer_name})
    end
    if !node.ec2_nodes.nil?
      instance_ids = Array.new
      all_instances =  @ec2.describe_instances()
      node.ec2_nodes.each do |ec2_node_name|
        instance = find_ec2_node_instance(ec2_node_name, all_instances)
        if instance.nil?
          @logger.error "ERROR: Ec2 node '#{ec2_node_name}' is not running to map to Elb node '#{node.name}'"
        else
          instance_ids << instance.instanceId
        end
      end
      instance_ids.sort!
      begin
        response = @elb.register_instances_with_load_balancer(:load_balancer_name => node.load_balancer_name, :instances => instance_ids)
        if !response.RegisterInstancesWithLoadBalancerResult.nil? && !response.RegisterInstancesWithLoadBalancerResult.Instances.nil?
          registered_instances = Array.new
          response.RegisterInstancesWithLoadBalancerResult.Instances.member.each do |member|
            registered_instances << member.InstanceId
          end
          registered_instances.sort!
          if instance_ids.eql?(registered_instances)
            @logger.info "Registered Ec2 Nodes #{node.ec2_nodes.inspect} with Elb Node #{node_name}"
          else
            @logger.error "ERROR: Could not register all Ec2 Nodes #{node.ec2_nodes.inspect} with Elb Node #{node_name}. The following instances are registered: #{registered_instances}"
          end
        else
          @logger.error "ERROR: Could not register Ec2 Nodes #{node.ec2_nodes.inspect} with Elb Node #{node_name}"
        end
      rescue AWS::Error => aws_error
        @logger.error "ERROR: Could not register Ec2 Nodes #{node.ec2_nodes.inspect} with Elb Node #{node_name}: #{aws_error.message}"
      end
    end
  end
end

#ensure_elb_nodes_terminatedObject

Ensures that the Elb Nodes of this Cloud are terminated



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
# File 'lib/maestro/cloud/aws.rb', line 813

def ensure_elb_nodes_terminated
  balancers = @elb.describe_load_balancers
  to_be_deleted = Hash.new
  @elb_nodes.each_pair do |node_name, node|
    instance = find_elb_node_instance(node_name, balancers)
    if !instance.nil?
      @logger.info "Node #{node_name} terminating..."
      to_be_deleted[node_name] = node.load_balancer_name
    else
      @logger.info "Node #{node_name} already terminated"
    end
  end
  if !to_be_deleted.empty?
    to_be_deleted.each_pair do |node_name, load_balancer_name|
      @elb.delete_load_balancer(:load_balancer_name => load_balancer_name)
      @logger.info "Node #{node_name} terminated"
    end
  end
end

#ensure_nodes_runningObject

ensures that the nodes of this cloud are running



337
338
339
340
341
# File 'lib/maestro/cloud/aws.rb', line 337

def ensure_nodes_running
  ensure_rds_nodes if !@rds_nodes.empty?
  ensure_ec2_nodes if !@ec2_nodes.empty?
  ensure_elb_nodes if !@elb_nodes.empty?
end

#ensure_nodes_terminatedObject

Ensures that the Nodes of this Cloud are terminated



766
767
768
769
770
# File 'lib/maestro/cloud/aws.rb', line 766

def ensure_nodes_terminated
  ensure_elb_nodes_terminated if !@elb_nodes.empty?
  ensure_ec2_nodes_terminated if !@ec2_nodes.empty?
  ensure_rds_nodes_terminated if !@rds_nodes.empty?
end

#ensure_rds_db_parameter_groupsObject

ensures that the Rds db parameter groups of this cloud are configured



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/maestro/cloud/aws.rb', line 344

def ensure_rds_db_parameter_groups
  @rds_nodes.each_pair do |node_name, node|
    if !node.db_parameter_group_name.nil?
      begin
        group = @rds.describe_db_parameter_groups(:db_parameter_group_name => node.db_parameter_group_name)
        @logger.info "Node #{node.name}'s db parameter group already exists (#{node.db_parameter_group_name})"
      rescue AWS::Error => aws_error
        if aws_error.message.eql? "DBParameterGroup #{node.db_parameter_group_name} not found."
          @rds.create_db_parameter_group(:db_parameter_group_name => node.db_parameter_group_name, :engine => node.engine, :description => "The #{node.cloud.name} Cloud's #{node.name} Node's DB Parameter group")
          group = @rds.describe_db_parameter_groups(:db_parameter_group_name => node.db_parameter_group_name)
          @logger.info "Created db parameter group for Node #{node.name} (#{node.db_parameter_group_name})"
        else
          @logger.error "ERROR! Unexpected error retrieving db parameter groups: #{aws_error.message}"
        end
      end
      if !group.nil?
        # must modify the db param group 20 at a time.
        parameters = Array.new
        node.db_parameters.each do |p|
          parameters << {:name => p[:name], :value => p[:value], :apply_method => "pending-reboot"}
        end
        parameters.each_slice(20) do |slice|
          begin
            @rds.modify_db_parameter_group(:db_parameter_group_name => node.db_parameter_group_name, :parameters => slice)
          rescue AWS::InvalidParameterValue => invalid_param
            @logger.error "ERROR! #{invalid_param.message}"
          end
        end
        @logger.info "Updated Node #{node.name}'s db parameter group (#{node.db_parameter_group_name}). Changes will be reflected when the Node is next rebooted."
      end
    end
  end
end

#ensure_rds_db_security_groupsObject

ensures that the Rds security groups of this cloud are configured



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/maestro/cloud/aws.rb', line 379

def ensure_rds_db_security_groups
  @rds_nodes.each_pair do |node_name, node|
    begin
      group = @rds.describe_db_security_groups(:db_security_group_name => node.db_security_group_name)
      @logger.info "Node #{node.name}'s db security group already exists (#{node.db_security_group_name})"
    rescue AWS::Error => aws_error
      if aws_error.message.eql? "DBSecurityGroup #{node.db_security_group_name} not found."
        @rds.create_db_security_group(:db_security_group_name => node.db_security_group_name, :db_security_group_description => "The #{node.cloud.name} Cloud's #{node.name} Node's DB Security group")
        group = @rds.describe_db_security_groups(:db_security_group_name => node.db_security_group_name)
        @logger.info "Created db security group for Node #{node.name} (#{node.db_security_group_name})"
      else
        @logger.error "ERROR! Unexpected error retrieving db security groups: #{aws_error.message}"
      end
    end
    if !group.nil? && !@ec2_nodes.empty?
      if group.DescribeDBSecurityGroupsResult.DBSecurityGroups.DBSecurityGroup.EC2SecurityGroups.nil?
        @rds.authorize_db_security_group(:db_security_group_name => node.db_security_group_name, :ec2_security_group_name => @default_ec2_security_group, :ec2_security_group_owner_id => )
        @logger.info "Authorized network ingress from Nodes #{@ec2_nodes.keys.inspect} to Node #{node.name}"
      else
        @logger.info "Network ingress from Nodes #{@ec2_nodes.keys.inspect} to Node #{node.name} already authorized"
      end
    end
  end
end

#ensure_rds_nodesObject

ensures that the Rds nodes of this cloud are running



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/maestro/cloud/aws.rb', line 405

def ensure_rds_nodes
  all_instances =  @rds.describe_db_instances
  to_be_started = Array.new
  to_be_watched = Array.new
  @rds_nodes.each_pair do |node_name, node|
    node_instance = find_rds_node_instance(node.db_instance_identifier, all_instances)
    if node_instance.nil?
      @logger.info "Node #{node_name} not running. Starting..."
      to_be_started << node_name
    elsif node_instance.DBInstanceStatus.eql?("deleting")
      @logger.info "Node #{node_name} deleting. Re-creating..."
      to_be_started << node_name
    elsif (node_instance.DBInstanceStatus.eql?("creating"))
      @logger.info "Node #{node_name} starting up..."
      to_be_watched << node_name
    elsif (node_instance.DBInstanceStatus.eql?("rebooting"))
      @logger.info "Node #{node_name} rebooting..."
      to_be_watched << node_name
    elsif (node_instance.DBInstanceStatus.eql?("modifying"))
      @logger.info "Node #{node_name} being modified..."
      to_be_watched << node_name
    elsif (node_instance.DBInstanceStatus.eql?("resetting-mastercredentials"))
      @logger.info "Node #{node_name} resetting master credentials..."
      to_be_watched << node_name
    elsif (node_instance.DBInstanceStatus.eql?("available"))
      @logger.info "Node #{node_name} already running (host: #{node_instance.Endpoint.Address}, port: #{node_instance.Endpoint.Port})"
    elsif (node_instance.DBInstanceStatus.eql?("backing-up"))
      @logger.info "Node #{node_name} already running (host: #{node_instance.Endpoint.Address}, port: #{node_instance.Endpoint.Port})"
    elsif (node_instance.DBInstanceStatus.eql?("failed"))
      @logger.info "Node #{node_name} in a failed state (host: #{node_instance.Endpoint.Address}, port: #{node_instance.Endpoint.Port})"
    elsif (node_instance.DBInstanceStatus.eql?("storage-full"))
      @logger.info "Node #{node_name} in a failed state due to storage full (host: #{node_instance.Endpoint.Address}, port: #{node_instance.Endpoint.Port})"
    end
  end
  to_be_started.each do |node_name|
    node = @nodes[node_name]
    result = @rds.create_db_instance(:db_instance_identifier => node.db_instance_identifier, :allocated_storage => node.allocated_storage, :db_instance_class => node.db_instance_class, :engine => node.engine, :master_username => node.master_username, :master_user_password => node.master_user_password, :port => node.port, :availability_zone => node.availability_zone, :preferred_maintenance_window => node.preferred_maintenance_window, :backup_retention_period => node.backup_retention_period, :preferred_backup_window => node.preferred_backup_window)
    to_be_watched << node_name
  end
  STDOUT.sync = true
  @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to start. This may take several minutes..." if !to_be_watched.empty?
  while !to_be_watched.empty?
    instances =  @rds.describe_db_instances
    to_be_watched.each do |node_name|
      node = @nodes[node_name]
      instance = find_rds_node_instance(node.db_instance_identifier, instances)
      if !instance.nil? && instance.DBInstanceStatus.eql?("available")
        @logger.progress "\n"
        @logger.info "Node #{node_name} started (host: #{instance.Endpoint.Address}, port: #{instance.Endpoint.Port})"
        to_be_watched.delete(node_name)
        @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to start. This may take several minutes..." if !to_be_watched.empty?
      elsif !instance.nil? && instance.DBInstanceStatus.eql?("failed")
        @logger.progress "\n"
        @logger.info "Node #{node_name} failed to start!"
        to_be_watched.delete(node_name)
        @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to start. This may take several minutes..." if !to_be_watched.empty?
      else
        @logger.progress "."
      end
    end
    sleep 5 if !to_be_watched.empty?
  end
end

#ensure_rds_nodes_terminatedObject

Ensures that the Rds Nodes of this Cloud are terminated



834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
# File 'lib/maestro/cloud/aws.rb', line 834

def ensure_rds_nodes_terminated
  all_instances =  @rds.describe_db_instances
  wait_for = Hash.new
  to_be_terminated = Array.new
  to_be_watched = Array.new
  @rds_nodes.each_pair do |node_name, node|
    node_instance = find_rds_node_instance(node.db_instance_identifier, all_instances)
    if node_instance.nil?
      @logger.info "Node #{node_name} already terminated"
    elsif node_instance.DBInstanceStatus.eql?("deleting")
      @logger.info "Node #{node_name} terminating..."
      to_be_watched << node_name
    elsif (node_instance.DBInstanceStatus.eql?("creating") || 
           node_instance.DBInstanceStatus.eql?("rebooting") ||
           node_instance.DBInstanceStatus.eql?("modifying") ||
           node_instance.DBInstanceStatus.eql?("resetting-mastercredentials") ||
           node_instance.DBInstanceStatus.eql?("backing-up"))
      @logger.info "Waiting for Node #{node_name} to finish #{node_instance.DBInstanceStatus} before terminating..."
      wait_for[node_name] = node_instance.DBInstanceStatus
    elsif (node_instance.DBInstanceStatus.eql?("available") ||
           node_instance.DBInstanceStatus.eql?("failed") ||
           node_instance.DBInstanceStatus.eql?("storage-full"))
      @logger.info "Node #{node_name} running. Terminating..."
      to_be_terminated << node_name
    end
  end

  @logger.progress "Waiting for Nodes #{wait_for.keys.inspect}..." if !wait_for.empty?
  while !wait_for.empty?
    instances =  @rds.describe_db_instances
    wait_for.each_pair do |node_name, status|
      node = @nodes[node_name]
      node_instance = find_rds_node_instance(node.db_instance_identifier, instances)
      if (node_instance.DBInstanceStatus.eql?("available") ||
          node_instance.DBInstanceStatus.eql?("failed") ||
          node_instance.DBInstanceStatus.eql?("storage-full"))
        @logger.progress "\n"
        @logger.info "Node #{node_name} done #{status}. Terminating..."
        wait_for.delete(node_name)
        to_be_terminated << node_name
        @logger.progress "Waiting for Nodes #{wait_for.keys.inspect}..." if !wait_for.empty?
      else
        @logger.progress "."
      end
    end
    sleep 5 if !wait_for.empty?
  end

  to_be_terminated.each do |node_name|
    node = @nodes[node_name]
    now = DateTime.now
    final_snapshot = node.db_instance_identifier + "-" + now.to_s.gsub(/:/, '')
    @logger.info "Terminating Node #{node_name} with final snapshot id '#{final_snapshot}' ..."
    result = @rds.delete_db_instance(:db_instance_identifier => node.db_instance_identifier, :final_db_snapshot_identifier => final_snapshot)
    to_be_watched << node_name
  end
  STDOUT.sync = true
  @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to terminate. This may take several minutes..." if !to_be_watched.empty?
  while !to_be_watched.empty?
    instances =  @rds.describe_db_instances
    to_be_watched.each do |node_name|
      node = @nodes[node_name]
      instance = find_rds_node_instance(node.db_instance_identifier, instances)
      if instance.nil?
        @logger.progress "\n"
        @logger.info "Node #{node_name} terminated"
        to_be_watched.delete(node_name)
        @logger.progress "Waiting for Nodes #{to_be_watched.inspect} to terminate. This may take several minutes..." if !to_be_watched.empty?
      else
        @logger.progress "."
      end
    end
    sleep 5 if !to_be_watched.empty?
  end
end

#find_ec2_node_instance(node_name, instances) ⇒ Object

finds the non-terminated ec2 instance tagged as the given node_name, or nil if not found



280
281
282
283
284
285
286
287
288
289
290
# File 'lib/maestro/cloud/aws.rb', line 280

def find_ec2_node_instance(node_name, instances)
  node_instance = nil
  return node_instance if instances.nil? || instances.empty? || instances.reservationSet.nil? || instances.reservationSet.item.nil? || instances.reservationSet.item.empty?
  tag = @ec2_nodes[node_name].node_security_group
  instances.reservationSet.item.each do |reservation|
    if reservation.groupSet.item.any? {|group| group.groupId.eql?(tag)}
      node_instance = reservation.instancesSet.item.detect {|instance| !instance.instanceState.name.eql?("terminated")}
    end
  end
  node_instance
end

#find_elb_node_instance(node_name, balancers) ⇒ Object

finds the load balancer instance tagged as the given node_name, or nil if not found



293
294
295
296
297
298
299
300
301
302
303
# File 'lib/maestro/cloud/aws.rb', line 293

def find_elb_node_instance(node_name, balancers)
  node = @elb_nodes[node_name]
  node_instance = nil
  return node_instance if node.nil? || balancers.nil? || balancers.empty? || balancers.DescribeLoadBalancersResult.nil? || balancers.DescribeLoadBalancersResult.LoadBalancerDescriptions.nil?
  balancers.DescribeLoadBalancersResult.LoadBalancerDescriptions.member.each do |desc|
    if desc.LoadBalancerName.eql?(node.load_balancer_name)
      node_instance = desc
    end
  end
  node_instance
end

#find_rds_node_instance(node_name, db_instances) ⇒ Object

finds the db instance instance tagged as the given node_name, or nil if not found



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/maestro/cloud/aws.rb', line 267

def find_rds_node_instance(node_name, db_instances)
  node_instance = nil
  return node_instance if db_instances.nil? || db_instances.empty? || db_instances.DescribeDBInstancesResult.nil? || db_instances.DescribeDBInstancesResult.DBInstances.nil?
  db_instance = db_instances.DescribeDBInstancesResult.DBInstances.DBInstance
  if db_instance.is_a?(Array)
    db_instance.each {|db| node_instance = db if (db.DBInstanceIdentifier.eql?(node_name) && !db.DBInstanceStatus.eql?("deleted"))}
  elsif db_instance.is_a?(Hash)
    node_instance = db_instance if (db_instance.DBInstanceIdentifier.eql?(node_name) && !db_instance.DBInstanceStatus.eql?("deleted"))
  end
  node_instance
end

#get_configurable_node_hostnamesObject

Collects the current hostnames of all running Configurable Nodes



753
754
755
756
757
758
759
760
761
762
763
# File 'lib/maestro/cloud/aws.rb', line 753

def get_configurable_node_hostnames
  all_instances =  @ec2.describe_instances()
  @ec2_nodes.each_pair do |node_name, node|
    node_instance = find_ec2_node_instance(node_name, all_instances)
    if node_instance.nil?
      @logger.error "ERROR: node #{node_name} not running!"
    else
      node.hostname = node_instance.dnsName
    end
  end
end

#node_json_url(node) ⇒ Object

Returns the URL for the given node’s Chef JSON file



748
749
750
# File 'lib/maestro/cloud/aws.rb', line 748

def node_json_url(node)
  AWS::S3::S3Object.url_for(node.json_filename, chef_bucket, :expires_in => 600, :use_ssl => true)
end

#node_statusesObject

Reports the current status of all Nodes in this Cloud



212
213
214
215
216
# File 'lib/maestro/cloud/aws.rb', line 212

def node_statuses
  elb_node_statuses if !@elb_nodes.empty?
  ec2_node_statuses if !@ec2_nodes.empty?
  rds_node_statuses if !@rds_nodes.empty?
end

#rds_node(name, &block) ⇒ Object

creates a Maestro::Node::Aws::Rds Node



110
111
112
113
114
115
116
117
118
# File 'lib/maestro/cloud/aws.rb', line 110

def rds_node(name, &block)
  if @nodes.has_key?(name)
    invalidate "Duplicate node definition: #{name}"
  else
    rds = Maestro::Node::Aws::Rds.new(name, self, &block)
    @nodes[name] = rds
    @rds_nodes[name] = rds
  end
end

#rds_node_statusesObject

Reports the current status of all Rds Nodes in this Cloud



219
220
221
222
223
224
225
226
227
228
229
# File 'lib/maestro/cloud/aws.rb', line 219

def rds_node_statuses
  all_instances = @rds.describe_db_instances
  @rds_nodes.each_pair do |node_name, node|
    node_instance = find_rds_node_instance(node_name, all_instances)
    if node_instance.nil?
      @logger.info "  #{node_name}: not running"
    else
      @logger.info "  #{node_name}: #{node_instance.DBInstanceStatus} (host: #{node_instance.Endpoint.Address}, port: #{node_instance.Endpoint.Port})"
    end
  end
end

#reboot_rds_node(node_name) ⇒ Object

Reboots the given Rds Node



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/maestro/cloud/aws.rb', line 185

def reboot_rds_node(node_name)
  to_be_watched = Array.new
  node = @rds_nodes[node_name]
  @logger.info "Rebooting Node #{node_name}..."
  @rds.reboot_db_instance(:db_instance_identifier => node.db_instance_identifier)
  to_be_watched << node_name
  STDOUT.sync = true
  @logger.progress "Waiting for Node #{node_name} to reboot. This may take several minutes..."
  while !to_be_watched.empty?
    instances =  @rds.describe_db_instances
    instance = find_rds_node_instance(node.db_instance_identifier, instances)
    if !instance.nil? && instance.DBInstanceStatus.eql?("available")
      @logger.info ""
      @logger.info "Node #{node_name} rebooted"
      to_be_watched.delete(node_name)
    elsif !instance.nil? && instance.DBInstanceStatus.eql?("failed")
      @logger.info ""
      @logger.info "Node #{node_name} failed to reboot!"
      to_be_watched.delete(node_name)
    else
      @logger.progress "."
    end
    sleep 5 if !to_be_watched.empty?
  end
end

#role_ec2_security_group_name(role_name) ⇒ Object

returns an ec2 security group name to tag an instance as being in a role, using the default naming convention



332
333
334
# File 'lib/maestro/cloud/aws.rb', line 332

def role_ec2_security_group_name(role_name)
  "#{@name}.#{MAESTRO_ROLE_PREFIX}#{role_name}"
end

#shutdownObject

Shuts down this Cloud. Takes no action if the Cloud is not running



178
179
180
181
182
# File 'lib/maestro/cloud/aws.rb', line 178

def shutdown
  connect!
  super
  ensure_nodes_terminated
end

#startObject

Starts this Cloud. Takes no action if the Cloud is already running as currently configured



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/maestro/cloud/aws.rb', line 147

def start
  connect!
  super
  ensure_rds_security_groups if !@rds_nodes.empty?
  ensure_rds_db_parameter_groups if !@rds_nodes.empty?
  ensure_ec2_security_groups if !@ec2_nodes.empty?
  ensure_rds_db_security_groups if !@rds_nodes.empty?
  ensure_nodes_running
  ensure_elastic_ips if !@ec2_nodes.empty?
  ensure_ebs_volumes if !@ec2_nodes.empty?
end

#statusObject

Reports the current status of this Cloud



141
142
143
144
# File 'lib/maestro/cloud/aws.rb', line 141

def status
  connect!
  super
end

#updateObject

Updates this Cloud based on the current configuration



168
169
170
171
172
173
174
175
# File 'lib/maestro/cloud/aws.rb', line 168

def update
  connect!
  super
  # TODO:
  # Need to account for @elb.enable_availability_zones_for_load_balancer
  # in update if the availability zones of ec2 instances added/removed from
  # the lb changes the zones. ADD TESTS FOR THIS WORKFLOW!
end

#upload_chef_assetsObject

ensures the project’s Chef cookbooks and roles are deployed to the configured S3 Bucket



719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/maestro/cloud/aws.rb', line 719

def upload_chef_assets
  bucket = nil
  begin
    bucket = AWS::S3::Bucket.find(chef_bucket)
  rescue AWS::S3::ResponseError
    @logger.info "Creating S3 Bucket '#{chef_bucket}'..."
    bucket = AWS::S3::Bucket.create(chef_bucket, :access => :private)
    @logger.info "Created S3 Bucket '#{chef_bucket}'" if !bucket.nil?
  end

  @logger.info "Packaging Chef assets..."
  chef_tgz = Maestro.chef_archive
  @logger.info "Uploading Chef assets to S3 bucket '#{chef_bucket}'..."
  AWS::S3::S3Object.store(MAESTRO_CHEF_ARCHIVE, File.open(chef_tgz, "r"), chef_bucket, :access => :private)
  @logger.info "Chef assets uploaded to S3 Bucket '#{chef_bucket}' as key '#{MAESTRO_CHEF_ARCHIVE}'"

  @logger.info "Uploading Node JSON files to S3 Bucket '#{chef_bucket}'..." if !@configurable_nodes.empty?
  @configurable_nodes.each_pair do |node_name, node|
    AWS::S3::S3Object.store(node.json_filename, node.json, chef_bucket, :access => :private)
    @logger.info "Node #{node.name} JSON file uploaded to S3 Bucket '#{chef_bucket}' as key '#{node.json_filename}'"
  end
end