Class: GTAPI::GaptoolServer

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gaptool-api.rb

Constant Summary collapse

DEFAULT_AWS_AZ =
'us-west-2c'

Instance Method Summary collapse

Constructor Details

#initialize(user, apikey, uri, default_aws_az = DEFAULT_AWS_AZ) ⇒ GaptoolServer

Returns a new instance of GaptoolServer.



10
11
12
13
14
15
16
# File 'lib/gaptool-api.rb', line 10

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]
  GaptoolServer.base_uri uri
end

Instance Method Details

#addnode(zone, itype, role, environment, mirror = 0, security_group = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gaptool-api.rb', line 33

def addnode(zone, itype, role, environment, mirror=0, security_group=nil)
  @body = {
    'zone' => zone || @default_aws_az,
    'itype' => itype,
    'role' => role,
    'environment' => environment
  }
  unless mirror == 0 or mirror.nil?
    @body['mirror'] = mirror
  end
  unless security_group.nil?
    @body['security_group'] = security_group
  end
  @body = @body.to_json
  options = { :body => @body, :headers => @auth}
  JSON::parse self.class.post("/init", options)
end

#getallnodes ⇒ Object



78
79
80
81
# File 'lib/gaptool-api.rb', line 78

def getallnodes()
  options = { :headers => @auth}
  JSON::parse self.class.get("/hosts", options)
end

#getappnodes(app, environment) ⇒ Object



57
58
59
60
61
# File 'lib/gaptool-api.rb', line 57

def getappnodes(app, environment)
  options = {:headers => @auth}
  role = JSON::parse(self.class.get("/apps", options))["app:#{app}"]['role']
  JSON::parse self.class.get("/hosts/#{role}/#{environment}", options)
end

#getenvnodes(environment) ⇒ Object



73
74
75
76
# File 'lib/gaptool-api.rb', line 73

def getenvnodes(environment)
  options = { :headers => @auth}
  JSON::parse self.class.get("/hosts/ALL/#{environment}", options)
end

#getenvroles(role, environment) ⇒ Object



28
29
30
31
# File 'lib/gaptool-api.rb', line 28

def getenvroles(role, environment)
  options = {:headers => @auth}
  JSON::parse self.class.get("/hosts/#{role}/#{environment}", options)
end

#getonenode(id) ⇒ Object



23
24
25
26
# File 'lib/gaptool-api.rb', line 23

def getonenode(id)
  options = {:headers => @auth}
  JSON::parse self.class.get("/instance/#{id}", options)
end

#getrolenodes(role) ⇒ Object



68
69
70
71
# File 'lib/gaptool-api.rb', line 68

def getrolenodes(role)
  options = { :headers => @auth}
  JSON::parse self.class.get("/hosts/#{role}", options)
end

#rehash ⇒ Object



18
19
20
21
# File 'lib/gaptool-api.rb', line 18

def rehash()
  options = {:body => '', :headers => @auth}
  JSON::parse self.class.post("/rehash", options)
end

#ssh(role, environment, id) ⇒ Object



63
64
65
66
# File 'lib/gaptool-api.rb', line 63

def ssh(role, environment, id)
  options = { :headers => @auth}
  JSON::parse self.class.get("/ssh/#{role}/#{environment}/#{id}", options)
end

#terminatenode(id, zone) ⇒ Object



51
52
53
54
55
# File 'lib/gaptool-api.rb', line 51

def terminatenode(id, zone)
  @body = {'id' => id, 'zone' => zone || @default_aws_region}.to_json
  options = {:body => @body, :headers => @auth}
  JSON::parse self.class.post("/terminate", options)
end