Module: Cirrus
- Extended by:
- Cirrus
- Included in:
- Cirrus
- Defined in:
- lib/cirrus.rb,
lib/cirrus/scp.rb,
lib/cirrus/ssh.rb,
lib/cirrus/version.rb,
lib/cirrus/security_group.rb
Defined Under Namespace
Modules: Instance, KeyPair, SCP, SSH, SecurityGroup
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#setup(image_id, ec2_opts) ⇒ Object
Launch an instance with the default Cirrus key pair and security group, provision the instance, and wait for it to launch.
-
#teardown(instance_id, ec2_opts) ⇒ Object
Terminate an instance and its associated security groups / key pairs.
Instance Method Details
#setup(image_id, ec2_opts) ⇒ Object
Launch an instance with the default Cirrus key pair and security group, provision the instance, and wait for it to launch
image_id - String identifier, ex: “ami-ee4f77ab” ec2_opts - Hash of
access_key_id - String
secret_access_key - String
region - String, ex: "us-east-1"
Returns nothing
17 18 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 |
# File 'lib/cirrus.rb', line 17 def setup(image_id, ec2_opts) puts "Starting setup for #{ec2_opts[:region]} ..." ec2 = AWS::EC2.new(ec2_opts) key_pair, private_key_filename = Cirrus::KeyPair.find_or_create_default(ec2) security_group = Cirrus::SecurityGroup.find_or_create_default(ec2) instance_type = "m1.small" launch_opts = { :image_id => image_id, instance_type: instance_type, :key_pair => key_pair, :security_groups => security_group # :associate_public_ip_address => true # Only for VPC launch } = { 'Name' => "cirrus-sample-#{Time.now.to_i}" } instance = Cirrus::Instance.launch(ec2, launch_opts, ) host = instance.public_ip_address Cirrus::SSH.bootstrap( host: host, username: 'ubuntu', private_key_path: private_key_filename, source_path: nil ) puts "Done! Provisioned instance #{instance.id} host #{host}, key #{private_key_filename}" end |
#teardown(instance_id, ec2_opts) ⇒ Object
Terminate an instance and its associated security groups / key pairs
instance_id - String id, ex: “i-74f86cbe” ec2_opts - Hash of
access_key_id - String
secret_access_key - String
region - String, ex: "us-east-1"
Returns nothing
59 60 61 62 63 64 65 66 |
# File 'lib/cirrus.rb', line 59 def teardown(instance_id, ec2_opts) puts "Tearing down #{instance_id} ..." ec2 = AWS::EC2.new(ec2_opts) Cirrus::Instance.teardown(ec2, instance_id) puts "Teardown successful for #{instance_id}!" end |