Hitachi

JP1 Version 12 JP1/Automatic Operation コマンド・API リファレンス 


2.13 APIの使用例

APIでサービスを実行する場合の使用例を示します。 まず,実行したいサービスのinstanceIDを特定します。その後,スケジュール種別を「即時実行」に指定して,サービスを実行する手順を説明します。

  1. サービス機能のリソース(Services)の一覧を表示して,実行したいサービスのinstanceIDを確認します。

    GET /Automation/v1/objects/Services/ HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Authorization: Basic c3lzdGVtOm1hbmFnZXI=
    User-Agent: useragent1
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:15:01 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    {
      "data" : [ {
        "instanceID" : 2269, ← instanceIDを確認する
        "name" : "リモートコマンド実行",
        "description" : "リモートの実行対象サーバ上のコマンドを実行します。",
        "tags" : "OS_Operations,Basic",
        "serviceTemplateName" : "リモートコマンド実行",
        "createTime" : "2014-08-18T16:53:50.000+0900",
        "modifyTime" : "2014-08-18T16:53:58.000+0900",
        "serviceState" : "release",
        "serviceGroupName" : "DefaultServiceGroup",
        "iconURL" : "http://10.197.112.78:22015/Automation/icon/services/com.hitachi.software.dna.cts.jp1/remoteCommandExe/01.10.00",
        "vendorName" : "Hitachi,Ltd.",
        "version" : "01.10.00",
        "latest" : true,
        "imageURL" : "http://10.197.112.78:22015/Automation/resources/images/overview/overview.png",
        "serviceTemplateID" : 2204,
        "serviceGroupID" : 2
      } ],
      "count" : 1
    }
    
  2. 確認したinstanceIDを持つリソースに対して,実行できる操作の一覧を取得します。

    GET /Automation/v1/objects/Services/2269/actions HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:24:41 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO b365e6a2cda2b4d195d55fee1461a6ed0889927_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    {
      "data" : [ {
        "name" : "submit", ← サービスを実行したいため,submitのhref情報を確認する
        "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke",
        "method" : "POST",
        "parameters" : [ ]
      } ],
      "count" : 1
    }
    
  3. 指定したサービスの実行操作に必要なリクエストボディーの情報を取得します。

    GET /Automation/v1/objects/Services/2269/actions/submit HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:26:00 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO 1b9b5891c58315e26cd0cca9aac6d43e572e3db_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    レスポンスをファイル(properties.json)に出力
    

    「properties.json」の内容

    {
      "name" : "submit",
      "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke",
      "method" : "POST",
      "parameters" : [ {
        "name" : "リモートコマンド実行_20140818202600",
        "submitter" : "System",
        "scheduleType" : "immediate",
        "description" : "",
        "scheduledStartTime" : "2014-08-18T20:26:00.536+09:00",
        "recurrenceInterval" : "daily",
        "recurrenceDayOfWeek" : "",
        "recurrenceDayOfMonth" : "",
        "recurrenceLastDayOfMonth" : false,
        "recurrenceStartDate" : "2014-08-18",
        "recurrenceTime" : "00:00:00",
        "serviceID" : 2269
      }, {
        "instanceID" : 2275,
        "type" : "string",
        "keyName" : "common.targetHost",
        "value" : "",
        "serviceID" : 2269
      }, {
        "instanceID" : 2271,
        "type" : "string",
        "keyName" : "common.remoteCommand",
        "value" : "",
        "serviceID" : 2269
      }, {
        "instanceID" : 2273,
        "type" : "string",
        "keyName" : "common.remoteCommandParameter",
        "value" : "",
        "serviceID" : 2269
      } ]
    }
    
  4. 取得したテンプレートの情報を必要に応じて編集します。スケジュール種別を「即時実行」に指定する場合を示します。

    {
      "name" : "submit",
      "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke",
      "method" : "POST",
      "parameters" : [ {
        "name" : "リモートコマンド実行_20140818202600",
        "submitter" : "System",
        "scheduleType" : "immediate", ←"immediate"を指定する
        "description" : "",
        "scheduledStartTime" : "2014-08-18T20:26:00.536+09:00",
        "recurrenceInterval" : "daily",
        "recurrenceDayOfWeek" : "",
        "recurrenceDayOfMonth" : "",
        "recurrenceLastDayOfMonth" : false,
        "recurrenceStartDate" : "2014-08-18",
        "recurrenceTime" : "00:00:00",
        "serviceID" : 2269
      }, {
        "instanceID" : 2275,
        "type" : "string",
        "keyName" : "common.targetHost",
        "value" : "",  ← 必要に応じてvalueを変更する
        "serviceID" : 2269
      }, {
        "instanceID" : 2271,
        "type" : "string",
        "keyName" : "common.remoteCommand",
        "value" : "hostname",  ← 必要に応じてvalueを変更する
        "serviceID" : 2269
      }, {
        "instanceID" : 2273,
        "type" : "string",
        "keyName" : "common.remoteCommandParameter",
        "value" : "",  ← 必要に応じてvalueを変更する
        "serviceID" : 2269
      } ]
    }
    
  5. 編集した情報を使用して,サービスを実行します。

    POST /Automation/v1/objects/Services/2269/actions/submit/invoke HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Content-Type: application/json
    Content-Length: 1087
    Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    
    properties.jsonの内容をリクエストする
    
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:39:03 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO 8ba382c1f2e81a65d7a252391b262624c6fa61_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    {
      "instanceID" : "4a9141e4-9566-4e42-af08-0f09926f2a5f",
      "created" : "2014-08-18T20:39:04.242+0900",
      "updated" : "2014-08-18T20:39:04.242+0900",
      "completed" : "2014-08-18T20:39:04.242+0900",
      "state" : "success",
      "affectedResource" : [ "http://10.197.112.78:22015/Automation/v1/objects/Schedules/2285" ←作成されたスケジュールリソースのURL, 
     "http://10.197.112.78:22015/Automation/v1/objects/Tasks/2280" ←作成されたタスクリソースのURL ],
      "result" : [ ]
    }
    

    サービスの実行によって作成されたScheduleリソースを取得し,内容を確認します。

    GET /Automation/v1/objects/Schedules/2285 HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:43:00 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO cafcefb87199122267f8ad33772555f9357c8a2_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    {
      "instanceID" : 2285,
      "name" : "リモートコマンド実行_20140818202600",
      "submitter" : "System",
      "scheduleType" : "immediate",
      "createTime" : "2014-08-18T20:39:03.000+0900",
      "modifyTime" : "2014-08-18T20:39:03.000+0900",
      "description" : "",
      "serviceState" : "release",
      "serviceID" : 2269
    }
    
  6. サービスの実行によって作成されたTaskリソースを取得し,内容を確認します。

    GET /Automation/v1/objects/Tasks/2280 HTTP/1.1
    Host:10.197.112.78:22015
    User-Agent:sample rest client/1.00.0
    Accept:application/json
    Accept-Language: ja
    Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300
    
    HTTP/1.1 200 OK
    Date: Mon, 18 Aug 2014 11:43:59 GMT
    Server: Cosminexus HTTP Server
    Access-Control-Expose-Headers: WWW-Authenticate
    WWW-Authenticate: HSSO 3713abcd1e99d1481c7b92cc9892a95d1a702d6_V0300
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache
    Transfer-Encoding: chunked
    Content-Type: application/json
    
    {
      "instanceID" : 2280,
      "name" : "リモートコマンド実行_20140818202600",
      "status" : "failed",
      "startTime" : "2014-08-18T20:39:04.000+0900",
      "completionTime" : "2014-08-18T20:39:13.000+0900",
      "submitter" : "System",
      "submitTime" : "2014-08-18T20:39:03.000+0900",
      "modifyTime" : "2014-08-18T20:39:19.000+0900",
      "serviceState" : "release",
      "scheduleType" : "immediate",
      "description" : "",
      "serviceName" : "リモートコマンド実行",
      "tags" : "",
      "serviceGroupName" : "DefaultServiceGroup",
      "serviceTemplateID" : 2204,
      "scheduleID" : 2285,
      "serviceGroupID" : 2,
      "serviceID" : 2269
    }