2015年2月21日土曜日

groovyとshipyardでcontainerを再起動する

groovyとshipyardでcontainerを再起動するには、以下のサンプルコードのようにX-Service-Keyにサービスキーを設定して/api/containers/<container-id>/restartにアクセスします。

サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.6')
import org.apache.http.client.methods.*
import org.apache.http.impl.client.*
import org.apache.http.message.*
import org.apache.http.auth.*
import org.apache.http.entity.*
import groovy.json.*

def host = "192.168.1.212" // replace this
def port = 8080
def serviceKey = "your-service-key"
def containerId = "your-container-id"

def httpclient = new DefaultHttpClient()
httpclient.withCloseable {

  def method = new HttpGet(
    "http://${host}:${port}/api/containers/${containerId}/restart"
  )
  method.setHeader("X-Service-Key", serviceKey)
  def response = httpclient.execute(method)
  println response.getStatusLine().getStatusCode()
}

関連情報

2015年2月14日土曜日

groovyとshipyardでcontainerのログを取得する

groovyとshipyardでcontainerのログを取得するには、以下のサンプルコードのようにX-Service-Keyにサービスキーを設定して/api/containers/<container-id>/logsにアクセスします。

サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.6')
import org.apache.http.client.methods.*
import org.apache.http.impl.client.*
import org.apache.http.message.*
import org.apache.http.auth.*
import org.apache.http.entity.*
import groovy.json.*

def host = "192.168.1.212" // replace this
def port = 8080
def serviceKey = "your-service-id"
def containerId = "your-container-id"

def httpclient = new DefaultHttpClient()
httpclient.withCloseable {

  def method = new HttpGet(
    "http://${host}:${port}/api/containers/${containerId}/logs"
  )
  method.setHeader("X-Service-Key", serviceKey)
  def response = httpclient.execute(method)
  println response.getStatusLine().getStatusCode()
  println response.getEntity().getContent().text
}

関連情報

2015年2月7日土曜日

groovyとshipyardでcontainerを停止する

groovyとshipyardでcontainerを停止するには、以下のサンプルコードのようにX-Service-Keyにサービスキーを設定して/api/containers/<container-id>/stopにアクセスします。

サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.6')
import org.apache.http.client.methods.*
import org.apache.http.impl.client.*
import org.apache.http.message.*
import org.apache.http.auth.*
import org.apache.http.entity.*
import groovy.json.*

def host = "192.168.1.212" // replace this
def port = 8080
def serviceKey = "your-service-key"
def containerId = "your-container-id"

def httpclient = new DefaultHttpClient()
httpclient.withCloseable {

  def method = new HttpGet(
    "http://${host}:${port}/api/containers/${containerId}/stop"
  )
  method.setHeader("X-Service-Key", serviceKey)
  def response = httpclient.execute(method)
  println response.getStatusLine().getStatusCode()
}

関連情報