GithubHelp home page GithubHelp logo

dynect_rest's Introduction

dynect-rest

Interact with the Dynect REST API.

Resource Records

Since this is 90% of what you’ll be doing, we make it easy.

require 'dynect_rest'
dyn = DynectRest.new("CUSTOMER", "USERNAME", "PASSWORD", "ZONE")
dyn.a.fqdn("sunshine.example.com").ttl(3600).address("192.168.1.1").save
dyn.cname.fqdn("something.example.com").cname("ec2-10-10-10-10.amazonaws.com").save
dyn.publish

Will add an A record and a CNAME. You can use the chained method syntax for every resource record - we map unknown methods to the resource data you make in the call. See link: (example.rb) for an executable example using environment variables.

GSLB

Create a new GSLB:

require 'dynect_rest'
dyn = DynectRest.new("CUSTOMER", "USERNAME", "PASSWORD", "ZONE")
gslb = dyn.gslb()
gslb.fqdn("sunshine.example.com").ttl(30).region_code("global")
gslb.min_healthy(1).serve_count(2)
gslb.monitor(:protocol => "HTTP", :interval => 1, :port => 8000, :path => "/healthcheck", :host => "sunshine.example.com")
gslb.add_host(:address => "1.1.1.1", :label => "friendly_name", :weight => 10, :serve_mode => "obey")
gslb.add_host(:address => "1.1.1.2", :label => "friendly_name2", :weight => 10, :serve_mode => "obey")
gslb.save

This will create a GSLB with hosts 1.1.1.1 and 1.1.1.2 in the global region. The parameters are self-explanatory.

Add a host to an existing GSLB:

require 'dynect_rest'
dyn = DynectRest.new("CUSTOMER", "USERNAME", "PASSWORD", "ZONE")
gslb = dyn.gslb.get("sunshine.example.com")
gslb.add_host(:address => "1.1.1.3", :label => "friendly_name3", :weight => 10, :serve_mode => "obey")
gslb.save(:replace)

This will fetch the GSLB object for “sunshine.example.com”, add the host 1.1.1.3, and save the updated configuration back to dynect.

Everything else

We wrap up the lower-level functionality of the API, so you can focus on just making the calls. For example, to get a list of contacts:

dyn = DynectRest.new("CUSTOMER", "USERNAME", "PASSWORD", "ZONE")
dyn.get('Contact')

To create a new contact:

dyn = DynectRest.new("CUSTOMER", "USERNAME", "PASSWORD", "ZONE")
dyn.post('Contact', { "first_name" => "Bobo", "last_name" => "Clown", "organization" => 'The Circus', "email" => "[email protected]" })

Use the API docs

For more - you should be able to find the latest at:

https://manage.dynect.net/help/docs/api2/rest/resources/

If you are a Dynect customer.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Opscode, Inc. See LICENSE for details.

dynect_rest's People

Contributors

adamhjk avatar bgentry avatar bitfehler avatar blentz avatar chrislundquist avatar cwholt avatar evan2645 avatar fairchild avatar jbarratt avatar jjasghar avatar jmervine avatar kellylsb avatar mikehale avatar ranjib avatar richadams avatar swrobel avatar technicalpickles avatar warmwaffles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dynect_rest's Issues

Updated version deployed to rubygems?

There are a number of fixes in the source code that are not available in Rubygems. Because they're not actually released, deploying them to our infrastructure would require writing our own chef deployment code, as the chef_gem seems to only work with released gems.

We're currently running into frequent errors when running this gem, errors that appear to be handled in master. Could these updates be released?

node_list method removed?

I just upgraded to the latest version of the gem (0.4.3) and node_list is no longer implemented.

I see it was removed in e03deee

Why?

Create new zone

Hi,

I can see example of adding zone records but I do not see any examples of how I can create a new zone using the API.

Is it possible to create a new zone using dynect_rest at all?

Please let me know.
Thanks

released gem version and VERSION file out of sync

I was doing some work the other day to support some of the other API functions, and noticed that the released gem is 0.3.0, but, VERSION is 0.2.0.

Also, looks like you are using jeweler (sweet!). I recommend using rake release for the releasing, and that will take care of regenerating the gemspec, tagging it in git, and pushing the gem up to rubygems.org.

Occasional 307 redirects not being followed correctly

I've found somewhere around 99/100 requests to dynect end up in a 307 redirect. It looks like commit 9e331d5 added a get() call to follow that redirect, but sends the full redirect (ie, /REST/Job/1039124) to get(), which ends up prepending another /REST/ to the URI. I've tried cleaning myself so that get() gets 'Job/1039124', but this call results in an Invalid Token error. In any case, the failed redirects still succeed. This my first time working with both Ruby and REST and I'm unsure how to debug further. For now, I'm just re-trying the request in the event of 307.

Omnibus Chef `gem install` fails when trying to compile C extensions

I don't understand why gem-install here is trying to build a C extension...

ubuntu@2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43:~$ /opt/chef/embedded/bin/ruby --version
ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-linux]

ubuntu@2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43:~$ /opt/chef/bin/chef-client --version
Chef: 11.16.4

ubuntu@2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43:~$ cat /etc/product
Name: Joyent Instance
Image: Ubuntu 14.04.2 LTS 20150225.2
Documentation: https://docs.joyent.com/images/linux/ubuntu-certified

ubuntu@2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43:~$ uname -a
Linux 2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43 3.13.0-46-generic #75-Ubuntu SMP Tue Feb 10 15:24:04 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

ubuntu@2f1b3bc4-4fa3-4e98-8e15-a9cde5e9bd43:~$ sudo /opt/chef/embedded/bin/gem install dynect_rest -q --no-rdoc --no-ri -v "0.4.3"
Building native extensions.  This could take a while...
ERROR:  Error installing dynect_rest:
    ERROR: Failed to build gem native extension.

        /opt/chef/embedded/bin/ruby extconf.rb
checking for main() in -lstdc++... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/opt/chef/embedded/bin/ruby
    --with-stdc++lib
    --without-stdc++lib
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:840:in `have_library'
    from extconf.rb:2:in `<main>'


Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/unf_ext-0.0.6 for inspection.
Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/unf_ext-0.0.6/ext/unf_ext/gem_make.out

Upcoming Dyn Ruby SDK

@adamhjk @ranjib @technicalpickles @evan2645

I've invited you to the Dyn community VIP team to give
feedback on the upcoming SDK. Would you be interested
in providing feedback?

https://github.com/dyninc/dyn-rb

In any event, thank you for the work you've done with
dynect_rest! You're listed as inspiration on the THANKS
page - dynect_rest is really the basis for the new library's
API - Dyn would love to continue the work you've started in
an officially-supported way.

Thanks again!

-Sunny

May or may not want to wrap into gem

Just kind of a "gotcha" point, when dealing with GSLB which requires regions with spaces. Basically the uri needs to be normalized before being used, may want to wrap the normalization into the game itself instead of needing to be called before passing it (or just doing a quick mention of it in the docs), this is currently how I call it:

!/usr/bin/env ruby

require 'rubygems'
require 'dynect_rest'
require 'addressable/uri'
dyn = DynectRest.new("CUSTOMER_NAME", "USER_NAME", "PASSWORD", "ZONEt")
dyn.post(Addressable::URI.parse("GSLBRegionPoolEntry/ZONE/FQDN/US West/").normalize.to_str, {"address" => "2.2.32.2"})
dyn.publish

If you moved the "Addressable::URI.parse" into the gem it would simplify it for the user... I guess this is actually more a feature request since the game still works great!

rest-client sometimes returns nil payload from Dynect request resulting in JSON parsing exception

Sometimes rest-client returns a payload of nil when querying Dynect

When dynect_rest tries to parse that response here :

https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L197

it throws an exception because the json library can't parse things less than 2 characters :

http://stackoverflow.com/questions/8390256/a-json-text-must-at-least-contain-two-octets

I'm unsure what condition it is under which the rest-client returns a nil payload

The call sequence looks like this for a success

https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L143
https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L144
https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L186
https://github.com/rest-client/rest-client/blob/master/lib/restclient.rb#L67
https://github.com/rest-client/rest-client/blob/master/lib/restclient.rb#L68
https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L66
https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L68
https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L146
https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L183
http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTPResponse.html#method-i-body

And there may be something going on here that's causing the nil

https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L188

One possible solution would be to wrap the JSON parsing in a being rescue block :

https://github.com/adamhjk/dynect_rest/blob/master/lib/dynect_rest.rb#L197

Dynect calls not stable

Hi,
We're using 0.4.3 of the dynect-rest gem since Jan this year and so far its worked really well. However in the last week or so we've had several of our enable /disable calls for gslb entries that have failed intermittently. Has anyone else here faced the same ? The logs that lead to this are as follows
["/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:209:in parse_response'", "/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:197:inapi_request'", "/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:144:in get'", "/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:193:inrescue in api_request'", "/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:185:in api_request'", "/usr/local/share/gems1.9/gems/dynect_rest-0.4.3/lib/dynect_rest.rb:180:input'",
"/opt/dyn.rb:206:in `update_dynect_entry'",]

We're guessing its because of Dynect and not dynect_rest api. Does anyone else have the same issue?

JSON.parse() can't convert RestClient::Response into String

For some reason Chef's dynect cookbook returns a RestClient::Response when get()'ing resources from Dynect. This can be seen by running this recipe: https://github.com/opscode/cookbooks/blob/master/dynect/recipes/ec2.rb Which will fail with a fatal error:
[Tue, 21 Jun 2011 00:17:19 +0000] FATAL: TypeError: dynect_rr[i-8bd180e5] (dynect::ec2 line 23) had an error: can't convert RestClient::Response into String

However, the same code in ruby seems to work OK:
require 'rubygems' require 'dynect_rest' res = 'i-8bd180e5.example.com' dyn = DynectRest.new("example", "me", "xxx", "example.com") DynectRest::Resource.new(dyn, 'CNAMERecord', 'example.com').get(res)

I'm not entirely sure this is an error with the cookbook, so I'm opening an issue here for the dynect_rest library. The fix is to send the response_body to JSON.parse() with .to_s. Patch inbound.

Exception deleting A Records

I have 404 Resource Not Found: {"status": "failure", "data": null, "job_id": null, "msgs": [{"INFO": "Unknown resource ARecordRecord (Requested URI: /REST/ARecordRecord/engineyard.com/x.engineyard.com)", "SOURCE": "API-A", "ERR_CD": "INVALID_REQUEST", "LVL": "ERROR"}]} with 404
/Users/ey/.rvm/gems/ruby-1.8.7-p358/gems/dynect_rest-0.4.1/lib/dynect_rest.rb:211:in `parse_response': Request failed: ERROR INVALID_REQUEST API-A - Unknown resource ARecordRecord (Requested URI: /REST/ARecordRecord/engineyard.com/x.engineyard.com) (DynectRest::Exceptions::RequestFailed)
    from /Users/ey/.rvm/gems/ruby-1.8.7-p358/gems/dynect_rest-0.4.1/lib/dynect_rest.rb:199:in `api_request'
    from /Users/ey/.rvm/gems/ruby-1.8.7-p358/gems/dynect_rest-0.4.1/lib/dynect_rest.rb:171:in `post'
    from /Users/ey/.rvm/gems/ruby-1.8.7-p358/gems/dynect_rest-0.4.1/lib/dynect_rest/resource.rb:111:in `save'

seems like it would be fixed by the following monkey patch:

class DynectRest::Resource
  def resource_path(full=false)
    if (full == true || full == :full) 
      "/REST/#{@record_type}/#{@zone}"
    else
      "#{@record_type}/#{@zone}"
    end
  end
end

Despite a successful return code, it does not actually delete the record.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.