Skip to content

Instantly share code, notes, and snippets.

@ryanseys ryanseys/dns.js
Last active Aug 29, 2015

Embed
What would you like to do?
Cloud DNS
var config = {};
var dns = gcloud.dns(config);
// - - - Zones - - - //
var query = {
maxResults: 2,
pageToken: 'blah'
};
dns.getZones(query, function(err, zones, nextQuery, apiResponse) {});
var createConfig = {
dnsName: 'example.com.',
name: 'my-unique-name',
nameServerSet: 'optional'
};
dns.createZone(config, function(err, zone, apiResponse) {});
var zone = dns.zone('my-unique-name');
zone.getMetadata(function(err, metadata, apiResponse) {});
zone.delete(function(err, apiResponse) {});
// - - - Changes - - - //
// list changes
var query = {
maxResults: 123,
pageToken: 'abc',
sort: 'asc' // asc or desc
};
zone.getChanges(query, function(err, changes, apiResponse) {});
// get change metadata
var change = zone.change('change-id');
change.getMetadata(function(err, metadata, apiResponse) {});
// create a change
var config = {
additions: [],
deletions: []
};
zone.createChange(config, function(err, change, apiResponse) {});
// - - - Resource Record Sets - - - //
var zone = dns.zone('my-zone');
var query = {
maxResults: 123,
name: 'example.com', // filter to this domain name
type: 'some-type', // filter to this type
pageToken: 'next-token'
};
zone.getRecordSets(query, function(err, recordsets, apiResponse) {});
// - - - Extending this functionality - - - //
// Import a zone file in either YAML or BIND format
// our client will attempt to guess the format based on file name
// but it can be explicitly set here in options as well.
var options = { format: 'yaml' };
zone.import('./my-zone-file.yml', options, function(err, records, apiResponse) {});
var options = { format: 'bind' };
zone.export('./file-to-save', options, function(err) {});
var record = {
name: 'example.com.',
rrdatas: [], // As defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1).
ttl: 1000, // number of seconds record is cached
type: 'A' // A, AAAA, MX, TXT
};
// Uses zone.createChange under the hood.
zone.addRecord(record, function(err, record, apiResponse) {});
// delete a record
// Uses zone.createChange under the hood.
zone.deleteRecord(record, function(err, apiResponse) {});
zone.runInTransaction(function(err, t) {
// t is the transaction and supports a subset of operations.
// nothing is committed to the API until t.commit(callback) is run.
t.addRecord(record);
t.deleteRecord(record);
t.export; // undefined - will not work in transaction
t.import() // might work in transaction?
t.commit(function(err, records, apiResponse) {});
t.abort(function() {})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.