Created
May 6, 2016 12:22
-
-
Save yamamoto-febc/4f7596abe2d3e521123e1a5c20b9cb6b to your computer and use it in GitHub Desktop.
Goとlibsaloudでさくらのクラウド用CLIを素早く作ろう ref: http://qiita.com/yamamoto-febc/items/c14aceed02e494529a64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// APIクライアント作成 | |
api := API.NewClient(params.token, params.secret, params.zone) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// libsacloudを"API"という名前でインポート | |
import API "github.com/yamamoto-febc/libsacloud/api" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) 空のISOイメージオブジェクトを作成 | |
newImage := api.CDROM.New() | |
// 2) 必要な値を設定 | |
newImage.Name = params.imageName | |
newImage.SizeMB = 5120 | |
// 3) API呼び出しでリソース作成 | |
image, ftp, err := api.CDROM.Create(newImage) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) コントロールパネル上でISOファイル用領域を作成 | |
2) ファイル領域へのFTP接続情報が表示されるため控えておく | |
3) FTPS+PASV対応のFTPクライアントからアップロード |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sacloud-upload-image [オプション] [イメージ名] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-token : さくらのクラウドのAPIキー(アクセストークン) | |
-secret : さくらのクラウドのAPIキー(シークレット) | |
-zone : 作成するゾーン (is1a/is1b/tk1a) デフォルト:is1a | |
-file : アップロードするISOファイルのパス |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is1a : 石狩第1ゾーン | |
is1b : 石狩第2ゾーン | |
tk1a : 東京第1ゾーン |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sacloud-upload-image -token=[アクセストークン] -secret=[シークレット] [イメージ名] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ export SAKURACLOUD_ACCESS_TOKEN=[アクセストークン] | |
$ export SAKURACLOUD_ACCESS_TOKEN_SECRET=[シークレット] | |
$ sacloud-upload-image [イメージ名] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# curlからパイプで受け取る | |
$ curl -L http://[ISOイメージのURL] | sacloud-upload-image [オプション] [イメージ名] | |
# リダイレクトで受け取る(CoreOS.isoというファイルをアップロードする例) | |
$ sacloud-upload-image [オプション] [イメージ名] < CoreOS.iso | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# APIキーを環境変数で指定する | |
$ export SAKURACLOUD_ACCESS_TOKEN=[アクセストークン] | |
$ export SAKURACLOUD_ACCESS_TOKEN_SECRET=[シークレット] | |
# CentOS Atomic Host(http://www.projectatomic.io)の例 | |
$ curl -L http://cloud.centos.org/centos/7/atomic/images/CentOS-Atomic-Host-7-Installer.iso | \ | |
./sacloud-upload-image "CentOS Atomic Host" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# APIキーを環境変数で指定する | |
$ export SAKURACLOUD_ACCESS_TOKEN=[アクセストークン] | |
$ export SAKURACLOUD_ACCESS_TOKEN_SECRET=[シークレット] | |
# CoreOS(https://coreos.com)の例 | |
$ curl -L https://stable.release.core-os.net/amd64-usr/current/coreos_production_iso_image.iso | \ | |
./sacloud-upload-image "CoreOS stable" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment