Refactor agent and server to remove duplicate code

Pulled all the duplicate resource code in agent.rb and server.rb out into a separate definition called instance.rb.  There should be no functional changes.