Class: CloudJobAws::AwsConnector
- Inherits:
-
CloudJobBase::CloudConnector
- Object
- CloudJobBase::CloudConnector
- CloudJobAws::AwsConnector
- Defined in:
- lib/cloud_job_aws.rb
Instance Attribute Summary collapse
-
#ec2client ⇒ Object
readonly
Returns the value of attribute ec2client.
-
#ec2resource ⇒ Object
readonly
Returns the value of attribute ec2resource.
-
#key_pair ⇒ Object
readonly
Returns the value of attribute key_pair.
-
#security_group ⇒ Object
readonly
Returns the value of attribute security_group.
Instance Method Summary collapse
- #check_credentials ⇒ Object
- #create_client ⇒ Object
- #create_key_pair ⇒ Object
- #create_security_group ⇒ Object
- #set_log_level(log_level) ⇒ Object
- #set_region(region) ⇒ Object
Instance Attribute Details
#ec2client ⇒ Object (readonly)
Returns the value of attribute ec2client.
10 11 12 |
# File 'lib/cloud_job_aws.rb', line 10 def ec2client @ec2client end |
#ec2resource ⇒ Object (readonly)
Returns the value of attribute ec2resource.
10 11 12 |
# File 'lib/cloud_job_aws.rb', line 10 def ec2resource @ec2resource end |
#key_pair ⇒ Object (readonly)
Returns the value of attribute key_pair.
10 11 12 |
# File 'lib/cloud_job_aws.rb', line 10 def key_pair @key_pair end |
#security_group ⇒ Object (readonly)
Returns the value of attribute security_group.
10 11 12 |
# File 'lib/cloud_job_aws.rb', line 10 def security_group @security_group end |
Instance Method Details
#check_credentials ⇒ Object
20 21 22 23 24 25 |
# File 'lib/cloud_job_aws.rb', line 20 def check_credentials raise "Key not set." if ENV['AWS_ACCESS_KEY_ID'].nil? @key = ENV['AWS_ACCESS_KEY_ID'] raise "Secret not set." if ENV['AWS_SECRET_ACCESS_KEY'].nil? @secret = ENV['AWS_SECRET_ACCESS_KEY'] end |
#create_client ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/cloud_job_aws.rb', line 27 def create_client # credentials aren't mandatory if they are set in ENV, though having it here for extendability @ec2client = Aws::EC2::Client.new(region: @region, credentials: Aws::Credentials.new(@key, @secret)) @ec2resource = Aws::EC2::Resource.new(client: @ec2client) create_security_group create_key_pair end |
#create_key_pair ⇒ Object
46 47 48 49 |
# File 'lib/cloud_job_aws.rb', line 46 def create_key_pair @key_pair = @ec2resource.create_key_pair({ key_name: "key-pair #{SecureRandom.uuid}"}) puts @key_pair.inspect end |
#create_security_group ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cloud_job_aws.rb', line 35 def create_security_group begin @security_group = @ec2resource.create_security_group({ group_name: "SSH #{SecureRandom.uuid}", description: "ssh" }) puts @security_group.inspect # allow port for ssh @security_group.({ip_permissions: [{ ip_protocol: 'tcp', from_port: 22, to_port: 22, ip_ranges: [{ cidr_ip: '0.0.0.0/0'}] }] }) rescue => ex puts ex. end end |
#set_log_level(log_level) ⇒ Object
12 13 14 |
# File 'lib/cloud_job_aws.rb', line 12 def set_log_level(log_level) Aws.config.update({log_level: log_level}) end |
#set_region(region) ⇒ Object
16 17 18 |
# File 'lib/cloud_job_aws.rb', line 16 def set_region(region) @region = region end |