Class: VagrantPlugins::AwsDns::Util::AwsUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-aws-dns-synchronous/util/aws_util.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accesskey, secretkey, region) ⇒ AwsUtil

Returns a new instance of AwsUtil.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 11

def initialize(accesskey, secretkey, region)
  credentials = Aws::Credentials.new(accesskey, secretkey)
  @ec2 = Aws::EC2::Client.new(
      region: region,
      credentials: credentials
  )
  @route53 = Aws::Route53::Client.new(
      region: region,
      credentials: credentials
  )
end

Instance Attribute Details

#ec2Object (readonly)

Returns the value of attribute ec2.



9
10
11
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 9

def ec2
  @ec2
end

#route53Object (readonly)

Returns the value of attribute route53.



9
10
11
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 9

def route53
  @route53
end

Instance Method Details

#add_record(hosted_zone_id, record, type, value) ⇒ Object



32
33
34
35
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 32

def add_record(hosted_zone_id, record, type, value)
  change = change_record(hosted_zone_id, record, type, value, 'UPSERT')
  wait_for_change(change)
end

#get_zone_type(hosted_zone_id) ⇒ Object



27
28
29
30
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 27

def get_zone_type(hosted_zone_id)
  zone = @route53.get_hosted_zone({id: '/hostedzone/' + hosted_zone_id})
  zone.hosted_zone.config.private_zone ? :private : :public
end

#instance_info(instance_id) ⇒ Object



23
24
25
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 23

def instance_info(instance_id)
  @ec2.describe_instances({instance_ids: [instance_id]}).reservations[0].instances[0]
end

#remove_record(hosted_zone_id, record, type, value) ⇒ Object



37
38
39
# File 'lib/vagrant-aws-dns-synchronous/util/aws_util.rb', line 37

def remove_record(hosted_zone_id, record, type, value)
    change_record(hosted_zone_id, record, type, value, 'DELETE') rescue nil
end