Categorygithub.com/iij/p2pubapi
modulepackage
0.1.9
Repository: https://github.com/iij/p2pubapi.git
Documentation: pkg.go.dev

# README

Golang binding for P2PUB API

Install

  • go get -u github.com/iij/p2pubapi
  • go build -o p2pub github.com/iij/p2pubapi/cli
  • install -c p2pub /usr/local/bin/p2pub

...or download binary

Use p2pub command

# vi setup.sh
IIJAPI_ACCESS_KEY=<YOUR ACCESS KEY>
IIJAPI_SECRET_KEY=<YOUR SECRET KEY>
GISSERVICECODE=<YOUR GIS SERVICE CODE>
# . ./setup.sh
# p2pub VMListGet
{... (result json)}
# p2pub VMGet --IvmServiceCode=ivm12345678
# p2pub --format yaml VMListGet
(result YAML)

Example

  • list your GIS ServiceCode
    • p2pub P2PUBContractServiceCodeListGetForSA --Item ServiceCode | jq -r '.GisList[].ServiceCode'
  • list your VM's IP Address
    • p2pub VMListGet | jq -r '.VirtualServerList[].NetworkList[].IpAddressList[].IPv4.IpAddress'

Usage for Golang users

API reference

package main

// Usage:
//   export IIJAPI_ACCESS_KEY=<YOUR ACCESSS KEY>
//   export IIJAPI_SECRET_KEY=<YOUR SECRET KEY>
//   export GISSERVICECODE=<YOUR GIS CODE>
//   $0

import (
	"log"
	"os"

	"github.com/iij/p2pubapi"
	"github.com/iij/p2pubapi/protocol"
)

func main() {
	api := p2pubapi.NewAPI(os.Getenv("IIJAPI_ACCESS_KEY"), os.Getenv("IIJAPI_SECRET_KEY"))
	// list VMs
	listarg := protocol.VMListGet{}
	listarg.GisServiceCode = os.Getenv("GISSERVICECODE")
	var listresp = protocol.VMListGetResponse{}
	if err := p2pubapi.Call(*api, listarg, &listresp); err != nil {
		log.Println("List API error", err)
	}

	// Power On Stopped VMs
	arg := protocol.VMPower{}
	arg.GisServiceCode = os.Getenv("GISSERVICECODE")
	arg.Power = "On"
	for _, v := range listresp.VirtualServerList {
		if v.ResourceStatus == "Stopped" {
			log.Println("Power On VM:", v.ServiceCode, v.OSType)
			arg.IvmServiceCode = v.ServiceCode
			var resp = protocol.VMPowerResponse{}
			if err := p2pubapi.Call(*api, arg, &resp); err != nil {
				log.Println("API error", err)
			}
			log.Printf("%+v", resp)
		}
	}
}

Example

  • vmpower-on.go
    • Power On all VMs
  • ls.go
    • Call ListGet API and show result as Text Table
  • pubkey.go
    • SSH Public Key importer
    • get public key from github API
    • set public key to System Storage with P2PUB API
  • label.go
    • set/get labels

# Packages

API呼び出しのCLI.
P2PUB APIクライアントを使った実装例.
No description provided by the author

# Functions

ArgumentList API引数のリストを求める。必須とオプションに分類.
ArgumentListType API引数のリストを求める。URI埋め込み、クエリストリング、JSONに分類.
Call API呼び出しを実行し、レスポンスを得る.
CallWithMap API呼び出しを実行する。引数と戻り値が構造体ではなくmap.
CustomEscape escape string.
GetBody API呼び出しのリクエストボディ(JSON文字列)を求める.
GetParam APIのクエリストリング部分を求める.
GetPath APIのURIのパス部分を求める.
NewAPI API構造体のコンストラクタ.
String2Sign get string to calculate signature.
Validate APIの必須引数が入っているかどうかをチェック.
ValidateMap APIの必須引数が入っているかどうかをチェック.
WaitArchiveStorage wait iar status (contract status) Contract Status(cstatus): InPreparation/InService.
WaitDataStorage wait storage status (contract status, resource status) Contract Status(cstatus): InPreparation/InService Resource Status(rstatus): Attached/NotAttached/Initializing/Configuring/Archiving.
WaitSystemStorage wait system storage status (contract status, resource status) Contract Status(cstatus): InPreparation/InService Resource Status(rstatus): Attached/NotAttached/Initializing/Configuring/Archiving.
WaitVM wait vm status (contract status, resource status) Contract Status(cstatus): InPreparation/InService Resource Status(rstatus): Stopped/Configuring/Starting/Running/Stopping/Locked.

# Constants

No description provided by the author
storage.
storage.
fw/lb.
vm, storage, fw/lb, mog.
No description provided by the author
No description provided by the author
No description provided by the author
fw/lb.
storage.
contract.
contract.
vm, fw/lb.
not defined.
storage.
No description provided by the author
vm, fw/lb, mog.
No description provided by the author
vm, fw/lb.
vm.
vm.
EndpointJSON = "http://localhost:9999/".
fw/lb.

# Structs

API の呼び出し先に関連する構造.

# Type aliases

No description provided by the author