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 Method Summary collapse
- #addnode(zone, itype, role, environment, mirror = 0, security_group = nil) ⇒ Object
- #getallnodes ⇒ Object
- #getappnodes(app, environment) ⇒ Object
- #getenvnodes(environment) ⇒ Object
- #getenvroles(role, environment) ⇒ Object
- #getonenode(id) ⇒ Object
- #getrolenodes(role) ⇒ Object
-
#initialize(user, apikey, uri, default_aws_az = DEFAULT_AWS_AZ) ⇒ GaptoolServer
constructor
A new instance of GaptoolServer.
- #rehash ⇒ 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.
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 = { :body => @body, :headers => @auth} JSON::parse self.class.post("/init", ) end |
#getallnodes ⇒ Object
78 79 80 81 |
# File 'lib/gaptool-api.rb', line 78 def getallnodes() = { :headers => @auth} JSON::parse self.class.get("/hosts", ) end |
#getappnodes(app, environment) ⇒ Object
57 58 59 60 61 |
# File 'lib/gaptool-api.rb', line 57 def getappnodes(app, environment) = {:headers => @auth} role = JSON::parse(self.class.get("/apps", ))["app:#{app}"]['role'] JSON::parse self.class.get("/hosts/#{role}/#{environment}", ) end |
#getenvnodes(environment) ⇒ Object
73 74 75 76 |
# File 'lib/gaptool-api.rb', line 73 def getenvnodes(environment) = { :headers => @auth} JSON::parse self.class.get("/hosts/ALL/#{environment}", ) end |
#getenvroles(role, environment) ⇒ Object
28 29 30 31 |
# File 'lib/gaptool-api.rb', line 28 def getenvroles(role, environment) = {:headers => @auth} JSON::parse self.class.get("/hosts/#{role}/#{environment}", ) end |
#getonenode(id) ⇒ Object
23 24 25 26 |
# File 'lib/gaptool-api.rb', line 23 def getonenode(id) = {:headers => @auth} JSON::parse self.class.get("/instance/#{id}", ) end |
#getrolenodes(role) ⇒ Object
68 69 70 71 |
# File 'lib/gaptool-api.rb', line 68 def getrolenodes(role) = { :headers => @auth} JSON::parse self.class.get("/hosts/#{role}", ) end |
#rehash ⇒ Object
18 19 20 21 |
# File 'lib/gaptool-api.rb', line 18 def rehash() = {:body => '', :headers => @auth} JSON::parse self.class.post("/rehash", ) end |
#ssh(role, environment, id) ⇒ Object
63 64 65 66 |
# File 'lib/gaptool-api.rb', line 63 def ssh(role, environment, id) = { :headers => @auth} JSON::parse self.class.get("/ssh/#{role}/#{environment}/#{id}", ) 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 = {:body => @body, :headers => @auth} JSON::parse self.class.post("/terminate", ) end |