Class: Awstool::Instance
- Inherits:
-
Object
- Object
- Awstool::Instance
- Defined in:
- lib/awstool/instance.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Instance
constructor
A new instance of Instance.
- #launch ⇒ Object
- #set_dns ⇒ Object
Constructor Details
#initialize(options) ⇒ Instance
Returns a new instance of Instance.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/awstool/instance.rb', line 5 def initialize() @options = @compute = Fog::Compute.new( provider: 'AWS', region: @options['region'], aws_access_key_id: @options['access_key_id'], aws_secret_access_key: @options['access_key'] ) @dns = Fog::DNS.new( provider: 'AWS', aws_access_key_id: @options['access_key_id'], aws_secret_access_key: @options['access_key'] ) end |
Instance Method Details
#launch ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/awstool/instance.rb', line 20 def launch b = binding userdata = ERB.new(File.read(@options['userdata']), nil, '<>').result(b) @instance = @compute.servers.create( image_id: @options['image-id'], flavor_id: @options['instance-type'], security_group_ids: @options['security-group-ids'], subnet_id: @options['subnet-ids'][@options['subnet-id-index']], key_name: @options['key-name'], tags: @options['tags'], user_data: userdata, block_device_mapping: map_block_devices ) @instance.wait_for { ready? } pp @instance.reload end |
#set_dns ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/awstool/instance.rb', line 37 def set_dns zone = @dns.zones.get(@options['dns-zone-id']) if @options['purge_dns'] record = zone.records.find { |r| r.name == "#{@options['hostname']}." } if record record.destroy end end record = zone.records.create( value: @instance.private_ip_address, name: @options['hostname'], type: 'A', ttl: '300' ) end |