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() = @compute = Fog::Compute.new( provider: 'AWS', region: ['region'], aws_access_key_id: ['access_key_id'], aws_secret_access_key: ['access_key'] ) @dns = Fog::DNS.new( provider: 'AWS', aws_access_key_id: ['access_key_id'], aws_secret_access_key: ['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(['userdata']), nil, '<>').result(b) @instance = @compute.servers.create( image_id: ['image-id'], flavor_id: ['instance-type'], security_group_ids: ['security-group-ids'], subnet_id: ['subnet-ids'][['subnet-id-index']], key_name: ['key-name'], tags: ['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 |
# File 'lib/awstool/instance.rb', line 37 def set_dns zone = @dns.zones.get(['dns-zone-id']) if ['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: ['hostname'], type: 'A' ) end |