9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go言語でConoHa VPS用のコマンドラインツールを作った

9
Last updated at Posted at 2015-02-04

CLI-tool for ConoHa VPS

ConoHa VPSは美雲このはちゃんでおなじみのVPSサービスです.

このツールは2015年5月18日以前に登録したアカウントのみ有効です

ConoHaのコントロールパネルはとっても使いやすくてそれは良いのですが、APIなどが無いのでプログラムなどから操作するのが非常に面倒です。これでは自動化ができません。ということでHTMLスクレイピングするツールを書いてみました。

以下の機能があります。

  • ログイン/ログアウト
  • VPSの一覧取得
  • VPSの詳細を取得(名前、プラン、IPアドレス、収容先など)
  • VPSの作成
  • VPSの削除
  • SSH秘密鍵のダウンロード
  • VPSへのSSH接続

Goで実装されているので、MacOSX, Linux Windowsなどだいたい動くと思います。
以下のGitHubのリンクからダウンロードできます。

hironobu-s/conoha-vps

感想

まだ速度的にあまり速くなかったり、スクレイピング故の不安はありますが、ConoHa VPSに対する操作をスクリプトで自動化できるのは夢が広がります。

スクレイピングにはgoqueryというライブラリを使いました。jQueryっぽい記述でDOMを取得できたため効率よく開発できました。これが無かったら途中であきらめてたと思います・・・。

ConoHaユーザの方は是非試してみてください。


以下はREADME.mdからの抜粋です。

インストール

MacOSX

ターミナルなどから以下のコマンドを実行します。

L=/usr/local/bin/conoha && curl -sL https://github.com/hironobu-s/conoha-vps/releases/download/v20150205.1/conoha-osx.amd64.gz | zcat > $L && chmod +x $L

アンインストールする場合は/usr/local/bin/conohaを削除してください。

Linux

ターミナルなどから以下のコマンドを実行します。/usr/local/binにインストールされるので、root権限が必要です。他のディレクトリにインストールする場合はL=/usr/local/bin/conohaの部分を適宜書き換えてください。

L=/usr/local/bin/conoha && curl -sL https://github.com/hironobu-s/conoha-vps/releases/download/v20150205.1/conoha-linux.amd64.gz | zcat > $L && chmod +x $L

アンインストールする場合は/usr/local/bin/conohaを削除してください。

Windows

ZIPファイルをダウンロードして、適当なフォルダに展開します。

実行する場合は、コマンドプロンプトから実行してください(ファイル名をダブルクリックしても何も起きません)。

アンインストールする場合はファイルをゴミ箱に入れてください。

クイックスタート

最初にログインします

$ conoha login

すると、ConoHaアカウントの入力プロンプトが出るので入力します。アカウントが正しいと「Login Successfully」となりログイン成功です。

$ conoha login
Please input ConoHa accounts.
ConoHa Account: [ACCOUNT]
Password: [PASSWORD]
INFO[0004] Login Successfully.

ログインに成功すると、全コマンドが実行できるようになります。コマンドの一覧は-hを付けると表示されます。

$ conoha -h
Usage: conoha COMMAND [OPTIONS]

DESCRIPTION
    A CLI-Tool for ConoHa VPS.

COMMANDS
    login    Authenticate an account.
    list     List VPS.
    add      Add VPS.
    remove   Remove VPS.
    ssh-key  Download and store SSH Private key.
    ssh      Login to VPS via SSH.
    logout   Remove an authenticate file(~/.conoha-vps).
    version  Print version.

まずはlistコマンドを実行してみましょう。VPSの一覧が表示されます。

$conoha list -v
VPS ID                  Label                   Plan                            Server Status   Service Status          CreatedAt
f648a6646b7e7d91        CentOS7                 8GB Memory                      Running         In operation            2015/01/27 13:15 JST
a2ae45355615d641        UbuntuDesktop           4GB Memory                      Offline         In operation            2014/12/11 16:59 JST
28ff51fd97a96106        WindowsServer2012       8GB Memory  - Windows           Running         In operation            2014/11/13 10:21 JST

次にstatコマンドを実行してみましょう。メニューが表示され、選択したVPSの詳細情報が表示されます。(サンプルのため一部を***でマスクしています)

$ conoha stat
[1] CentOS7
[2] UbuntuDesktop
[3] WindowsServer2012
Please select VPS no. [1-3]: 1
VPS ID               f648a6646b7e7d91
ServerStatus         Running
Label                CentOS7
ServiceStatus        In operation
Service ID           VPS00708435
Plan                 8GB Memory
Created At           2015-01-27T13:15:00+09:00
Delete Date          0001-01-01 00:00:00 +0000 UTC
Payment Span         1month
CPU                  Virtual6Core
Memory               8192MB
Disk1                HDD 20GB
Disk2                HDD 780GB
IPv4 Address         ***.***.***.***
IPv4 Netmask         255.255.254.0
IPv4 Gateway         ***.***.***.***
IPv4 DNS1            ***.***.***.***
IPv4 DNS2            ***.***.***.***
Host Server          cnode-f0000
Common Server ID     iu3-0000000
Serial Console(SSH)  console1001.cnode.jp
ISO Upload(SFTP)     sftp1001.cnode.jp

このように、コマンドライン操作でVPSを操作することができます。

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?