January 7, 2016

Classes
Tags fog dns

Managing DNS with fog-softlayer

Managing SoftLayer hosted domains using the fog-softlayer gem

Prerequisites

These examples all assume you have installed the fog-softlayer gem and that you have created a ~/.fog file, which contains the following:

default:
  softlayer_username: <YOUR USERNAME>
  softlayer_api_key: <YOUR API KEY>

Create a connection to SoftLayer DNS Service

	require 'fog/softlayer'
	@sl = Fog::DNS[:softlayer]

Create Operations

Create Domain

  @domain = @sl.domains.create('yourdomain.com')

Create Record

  record = {
    'value' => '127.0.0.1',
    'host' => '@',
    'type' => 'a'
  }
  @domain.create_record(record)

Read Operations

List all domains

  @domains = @sl.domains.all
  @domain = @domains.first

Get specific domain by id

  @domain = @sl.domains.get(123456)

Get specific domain by name

  @domain = @sl.domains.get_by_name('yourdomain.com')

Get Domains Records

  @domain = @sl.domains.get(123456)
  @domain.records

Get specific record by id

  @domain = @sl.domains.get(123456)
  @domain.records.get(456789012)

or using the service:

  @sl.records.get(456789012)

Update Operations

After this point we consider you have a Fog::DNS::Softlayer::Domain on @domain variable

Update Record Entry

  @domain.records
  @domain.records[3].value = "192.168.0.3"
  @domain.records[3].save

Destroy Operations

After this point we consider you have a Fog::DNS::Softlayer::Domain on @domain variable

Destroy Domain

  @domain = @sl.domains.get(123456)
  @domain.destroy
  • Destroy Record
  @domain = @sl.domains.get(123456)
  @domain.records.last.destroy