class GTAPI::GaptoolServer

Constants

DEFAULT_AWS_AZ

Attributes

version[R]

Public Class Methods

new(user, apikey, uri, default_aws_az = DEFAULT_AWS_AZ) click to toggle source
# 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_region = default_aws_az[0..-2]
  @version = File.read(File.realpath(File.join(File.dirname(__FILE__),
                                               '..', 'VERSION'))).strip
  GaptoolServer.base_uri uri
end

Public Instance Methods

addnode(zone, itype, role, environment, _mirror = nil, security_group = nil, ami = nil, chef_repo = nil, chef_branch = nil, chef_runlist = nil, no_terminate = nil) click to toggle source
# File lib/gaptool-api.rb, line 65
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
  }
  body['security_group'] = security_group unless security_group.nil?
  unless chef_runlist.nil? || chef_runlist.empty?
    body['chef_runlist'] = [*chef_runlist]
  end
  body['terminate'] = false if no_terminate
  post('/init', body: body.to_json)
end
api_version() click to toggle source
# File lib/gaptool-api.rb, line 110
def api_version
  get('/version')
end
call(verb, url, opts = {}) click to toggle source
# File lib/gaptool-api.rb, line 21
def call(verb, url, opts = {})
  options = opts || {}
  options[:headers] ||= {}
  options[:headers].merge!(@auth)
  options[:headers]['Accept'] = 'application/json'
  options[:headers]['Content-Type'] = 'application/json'
  options[:headers]['X-GAPTOOL-VERSION'] = @version
  case verb
  when :post
    options[:body] ||= ''
  end
  JSON.parse(self.class.send(verb, url, options).body)
end
get(url, opts = {}) click to toggle source
# File lib/gaptool-api.rb, line 35
def get(url, opts = {})
  call(:get, url, opts)
end
getallnodes(params = {}) click to toggle source
# File lib/gaptool-api.rb, line 106
def getallnodes(params = {})
  get('/hosts', query: params)
end
getappnodes(app, environment, params = {}) click to toggle source
# File lib/gaptool-api.rb, line 94
def getappnodes(app, environment, params = {})
  get("/app/#{app}/#{environment}/hosts", query: params)
end
getenvnodes(environment, params = {}) click to toggle source
# File lib/gaptool-api.rb, line 102
def getenvnodes(environment, params = {})
  get("/hosts/ALL/#{environment}", query: params)
end
getenvroles(role, environment, params = {}) click to toggle source
# File lib/gaptool-api.rb, line 61
def getenvroles(role, environment, params = {})
  get("/hosts/#{role}/#{environment}", query: params)
end
getnodeattrs(id, attrs = {}) click to toggle source
# File lib/gaptool-api.rb, line 55
def getnodeattrs(id, attrs = {})
  attrs ||= {}
  get("/instance/#{id}/attrs",
      body: attrs.to_json)
end
getonenode(id) click to toggle source
# File lib/gaptool-api.rb, line 51
def getonenode(id)
  get("/instance/#{id}")
end
getrolenodes(role, params = {}) click to toggle source
# File lib/gaptool-api.rb, line 98
def getrolenodes(role, params = {})
  get("/hosts/#{role}", query: params)
end
patch(url, opts = {}) click to toggle source
# File lib/gaptool-api.rb, line 43
def patch(url, opts = {})
  call(:patch, url, opts)
end
post(url, opts = {}) click to toggle source
# File lib/gaptool-api.rb, line 39
def post(url, opts = {})
  call(:post, url, opts)
end
rehash() click to toggle source
# File lib/gaptool-api.rb, line 47
def rehash
  post('/rehash')
end
setparameters(instance, params = {}) click to toggle source
# File lib/gaptool-api.rb, line 90
def setparameters(instance, params = {})
  patch("/instance/#{instance}", body: params.to_json)
end
terminatenode(id, zone) click to toggle source
# File lib/gaptool-api.rb, line 85
def terminatenode(id, zone)
  body = { 'id' => id, 'zone' => zone || @default_aws_region }
  post('/terminate', body: body.to_json)
end