Class: VmShepherd::AwsManager
- Inherits:
-
Object
- Object
- VmShepherd::AwsManager
- Defined in:
- lib/vm_shepherd/aws_manager.rb
Defined Under Namespace
Classes: RetryLimitExceeded
Constant Summary collapse
- AWS_REGION =
'us-east-1'- OPS_MANAGER_INSTANCE_TYPE =
'm3.medium'- RETRY_LIMIT =
60- RETRY_INTERVAL =
5- DO_NOT_TERMINATE_TAG_KEY =
'do_not_terminate'
Instance Method Summary collapse
- #deploy(ami_file_path) ⇒ Object
- #destroy ⇒ Object
-
#initialize(aws_options) ⇒ AwsManager
constructor
A new instance of AwsManager.
Constructor Details
#initialize(aws_options) ⇒ AwsManager
Returns a new instance of AwsManager.
14 15 16 17 18 19 20 21 |
# File 'lib/vm_shepherd/aws_manager.rb', line 14 def initialize() AWS.config( access_key_id: .fetch(:aws_access_key), secret_access_key: .fetch(:aws_secret_key), region: AWS_REGION ) @aws_options = end |
Instance Method Details
#deploy(ami_file_path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vm_shepherd/aws_manager.rb', line 23 def deploy(ami_file_path) image_id = File.read(ami_file_path).strip instance = retry_ignoring_error_until(AWS::EC2::Errors::InvalidIPAddress::InUse) do AWS.ec2.instances.create( image_id: image_id, key_name: .fetch(:ssh_key_name), security_group_ids: [.fetch(:security_group_id)], subnet: .fetch(:public_subnet_id), instance_type: OPS_MANAGER_INSTANCE_TYPE ) end retry_ignoring_error_until(AWS::EC2::Errors::InvalidInstanceID::NotFound) do instance.status == :running end instance.associate_elastic_ip(.fetch(:elastic_ip_id)) instance.add_tag('Name', value: .fetch(:vm_name)) end |
#destroy ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vm_shepherd/aws_manager.rb', line 45 def destroy subnets = [ AWS.ec2.subnets[.fetch(:public_subnet_id)], AWS.ec2.subnets[.fetch(:private_subnet_id)] ] subnets.each do |subnet| subnet.instances.each do |instance| instance.terminate unless instance..to_h.fetch(DO_NOT_TERMINATE_TAG_KEY, false) end end end |