Class: GTAPI::GaptoolServer
- Inherits:
-
Object
- Object
- GTAPI::GaptoolServer
- Includes:
- HTTParty
- Defined in:
- lib/gaptool-api.rb
Constant Summary collapse
- DEFAULT_AWS_AZ =
'us-west-2c'
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #addnode(zone, itype, role, environment, mirror = nil, security_group = nil, ami = nil, chef_repo = nil, chef_branch = nil, chef_runlist = nil, no_terminate = nil) ⇒ Object
- #api_version ⇒ Object
- #call(verb, url, opts = {}) ⇒ Object
- #get(url, opts = {}) ⇒ Object
- #getallnodes(params) ⇒ Object
- #getappnodes(app, environment, params = {}) ⇒ Object
- #getenvnodes(environment, params = {}) ⇒ Object
- #getenvroles(role, environment, params = {}) ⇒ Object
- #getonenode(id) ⇒ Object
- #getrolenodes(role, params = {}) ⇒ Object
-
#initialize(user, apikey, uri, default_aws_az = DEFAULT_AWS_AZ) ⇒ GaptoolServer
constructor
A new instance of GaptoolServer.
- #patch(url, opts = {}) ⇒ Object
- #post(url, opts = {}) ⇒ Object
- #rehash ⇒ Object
- #setparameters(instance, params = {}) ⇒ Object
- #ssh(role, environment, id) ⇒ Object
- #terminatenode(id, zone) ⇒ Object
Constructor Details
#initialize(user, apikey, uri, default_aws_az = DEFAULT_AWS_AZ) ⇒ GaptoolServer
Returns a new instance of GaptoolServer.
11 12 13 14 15 16 17 18 |
# File 'lib/gaptool-api.rb', line 11 def initialize(user, apikey, uri, default_aws_az=DEFAULT_AWS_AZ) @auth = { 'X-GAPTOOL-USER' => user, 'X-GAPTOOL-KEY' => apikey} default_aws_az = default_aws_az || DEFAULT_AWS_AZ @default_aws_az = default_aws_az @default_aws_region = default_aws_az[0..-2] @version = File.read(File.realpath(File.join(File.dirname(__FILE__), "..", 'VERSION'))).strip GaptoolServer.base_uri uri end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/gaptool-api.rb', line 9 def version @version end |
Instance Method Details
#addnode(zone, itype, role, environment, mirror = nil, security_group = nil, ami = nil, chef_repo = nil, chef_branch = nil, chef_runlist = nil, no_terminate = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gaptool-api.rb', line 57 def addnode(zone, itype, role, environment, mirror=nil, security_group=nil, ami=nil, chef_repo=nil, chef_branch=nil, chef_runlist=nil, no_terminate=nil) body = { 'zone' => zone || @default_aws_az, 'itype' => itype, 'role' => role, 'environment' => environment, 'ami' => ami, 'chef_repo' => chef_repo, 'chef_branch' => chef_branch } unless security_group.nil? body['security_group'] = security_group end unless chef_runlist.nil? || chef_runlist.empty? body['chef_runlist'] = [*chef_runlist] end if no_terminate body['terminate'] = false end post('/init', {body: body.to_json}) end |
#api_version ⇒ Object
109 110 111 |
# File 'lib/gaptool-api.rb', line 109 def api_version() get("/version") end |
#call(verb, url, opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gaptool-api.rb', line 20 def call(verb, url, opts={}) = opts || {} [:headers] ||= {} [:headers].merge!(@auth) [:headers]['Accept'] = 'application/json' [:headers]['Content-Type'] = 'application/json' case verb when :post [:body] ||= '' end JSON.parse(self.class.send(verb, url, ).body) end |
#get(url, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/gaptool-api.rb', line 33 def get(url, opts={}) call(:get, url, opts) end |
#getallnodes(params) ⇒ Object
105 106 107 |
# File 'lib/gaptool-api.rb', line 105 def getallnodes(params) get("/hosts", {query: params}) end |
#getappnodes(app, environment, params = {}) ⇒ Object
89 90 91 |
# File 'lib/gaptool-api.rb', line 89 def getappnodes(app, environment, params={}) get("/app/#{app}/#{environment}/hosts", {query: params}) end |
#getenvnodes(environment, params = {}) ⇒ Object
101 102 103 |
# File 'lib/gaptool-api.rb', line 101 def getenvnodes(environment, params={}) get("/hosts/ALL/#{environment}", {query: params}) end |
#getenvroles(role, environment, params = {}) ⇒ Object
53 54 55 |
# File 'lib/gaptool-api.rb', line 53 def getenvroles(role, environment, params={}) get("/hosts/#{role}/#{environment}", {query: params}) end |
#getonenode(id) ⇒ Object
49 50 51 |
# File 'lib/gaptool-api.rb', line 49 def getonenode(id) get("/instance/#{id}") end |
#getrolenodes(role, params = {}) ⇒ Object
97 98 99 |
# File 'lib/gaptool-api.rb', line 97 def getrolenodes(role, params={}) get("/hosts/#{role}", {query: params}) end |
#patch(url, opts = {}) ⇒ Object
41 42 43 |
# File 'lib/gaptool-api.rb', line 41 def patch(url, opts={}) call(:patch, url, opts) end |
#post(url, opts = {}) ⇒ Object
37 38 39 |
# File 'lib/gaptool-api.rb', line 37 def post(url, opts={}) call(:post, url, opts) end |
#rehash ⇒ Object
45 46 47 |
# File 'lib/gaptool-api.rb', line 45 def rehash() post("/rehash") end |
#setparameters(instance, params = {}) ⇒ Object
85 86 87 |
# File 'lib/gaptool-api.rb', line 85 def setparameters(instance, params={}) patch("/instance/#{instance}", {body: params.to_json}) end |
#ssh(role, environment, id) ⇒ Object
93 94 95 |
# File 'lib/gaptool-api.rb', line 93 def ssh(role, environment, id) get("/ssh/#{role}/#{environment}/#{id}") end |
#terminatenode(id, zone) ⇒ Object
81 82 83 |
# File 'lib/gaptool-api.rb', line 81 def terminatenode(id, zone) post('/terminate', {body: {'id' => id, 'zone' => zone || @default_aws_region}.to_json}) end |