2
1

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.

Bluemix Infrastructure APIでPortable Subnetを作る

Last updated at Posted at 2017-03-25

Bluemix Infrastructure (旧SoftLayer)のAPI(CLI)を使って、Portable Subnetをオーダーしてみます。

SoftLayer APIをインストールする

API(含むCLI)は以下の手順で導入します。

  1. python-setuptoolsをインストールします。

    Ubuntu

    $sudo apt-get install python-setuptools

    Redhat

    $sudo yum install python-setuptools

  2. pipをインストールします。
    $sudo easy_install pip

  3. SoftLayerパッケージをインストールします。
    $sudo pip install SoftLayer==5.0.1

  4. docoptパッケージをインストールします。
    $sudo pip install docopt

  5. 認証キーを取得します。
    カスタマーポータルのメニューから「Accounts」→「Users」を選択し、自分のアカウントのAPI KEY欄のGenerateをクリックし、Viewをクリックすると表示されますので、メモしておいてください。

  6. 認証情報をセットします。
    次のコマンドを実行します。
    $slcli setup

    次の4つのパラメータを聞いてきます。

    Username []: カスタマーポータルにログインするIDと同じです。
    API Key or Password []:  5番で取得したAPI KEYを入力します。
    Endpoint (public|private|custom) []:  publicかprivateを入力します。
    Timeout [0]:  デフォルトのゼロのままで結構です。

    結果は次のような画面になります。

:..............:..................................................................:
:         name : value                                                            :
:..............:..................................................................:
:     Username : xxxxxxxx                                                      :
:      API Key : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
:
: Endpoint URL : https://api.softlayer.com/xmlrpc/v3.1/                           :
:      Timeout : not set                                                          :
:..............:..................................................................:

APIを試してみる

VLAN一覧を表示します。
$slcli vlan list

root@teacher02:~# slcli vlan list
:.........:........:......:..........:............:..........:.................:............:
:    id   : number : name : firewall : datacenter : hardware : virtual_servers : public_ips :
:.........:........:......:..........:............:..........:.................:............:
: 1542491 :  954   :  -   :   Yes    :   sea01    :    2     :        1        :     5      :
: 1555095 :  1187  :  -   :    No    :   sea01    :    1     :        0        :     5      :
: 1542493 :  979   :  -   :    No    :   sea01    :    4     :        2        :     61     :
: 1555093 :  1130  :  -   :    No    :   sea01    :    1     :        0        :     61     :
:.........:........:......:..........:............:..........:.................:............:

Subnet一覧を表示します。
$slcli subnet list

224422   10.28.153.0/28                              SECONDARY_ON_VLAN   sea01  1542493  16  0  0
251363   10.28.187.128/26                            SECONDARY_ON_VLAN   sea01  1542493  64  0  0
223358   10.29.10.224/28                             SECONDARY_ON_VLAN   sea01  1555093  16  0  0
224423   10.28.153.16/28                             ROUTED_TO_VLAN      sea01  1542493  16  0  0
252187   10.28.191.64/26                             PRIMARY             sea01  1542493  64  4  2
257373   10.28.205.128/26                            PRIMARY             sea01  1555093  64  1  0
191191   173.192.149.224/29                          PRIMARY             sea01  1542491  8   2  1
156488   174.37.186.40/29                            PRIMARY             sea01  1555095  8   1  0
998115   2607:f0d0:2002:015c:0000:0000:0000:0000/64  PRIMARY_6           sea01  1555095  7   0  0
1007449  2607:f0d0:2002:015e:0000:0000:0000:0000/64  PRIMARY_6           sea01  1555095  7   0  0

Portable Subnetを注文する

それでは早速ポータブルサブネット(追加のIPセグメント)を注文してみましょう。
書式は次の通りです。

$slcli subnet create [OPTIONS] NETWORK QUANTITY VLAN_ID

OPTIONSは次のとおりです。

--v6, --ipv6  IPv6をオーダーする
--test        テスト用で実際には注文されない
-h, --help    簡単なヘルプを表示する

NETWORKはpublicかprivateかを指定します。

public
private

QUANTITYはIPアドレス数を指定します。次の中から選択します。

public  - 4, 8, 16, 32
private - 4, 8, 16, 32, 64

VLAN_IDは$slcli vlan showで表示される一番左側のIDです。いわゆるVLAN IDではありませんのでご注意ください。

それではコマンドを試してみましょう。--testオプションを付けて実際にはオーダーしないようにします。

$slcli subnet create --test private 8 1555093
:.................................:......:
:                            Item : cost :
:.................................:......:
: 8 Portable Private IP Addresses : 0.00 :
:              Total monthly cost : 0.00 :
:.................................:......:

本番です。--testオプションを外して実行します。

$slcli subnet create private 8 1555093
This action will incur charges on your account. Continue? [y/N]: y
:....................:......:
:               Item : cost :
:....................:......:
: Total monthly cost : 0.00 :
:....................:......:

次のコマンドを実行して実際に作成されたかどうか確認します。

$slcli subnet list|grep 1555093
264526   10.28.35.224/29                             SECONDARY_ON_VLAN   sea01  1555093  8   0  0
223358   10.29.10.224/28                             SECONDARY_ON_VLAN   sea01  1555093  16  0  0
257373   10.28.205.128/26                            PRIMARY             sea01  1555093  64  1  0

先ほどの結果では1555093(VLAN 1130)に紐づくSubnetは2つでしたが、一番上に10.28.35.224/29という新しいPortable Subnetが作成されました。

ちなみに、次のように実行すると10個のPortable Subnetを作成します。

for((i=1;i<=10;i++)); do
 echo $i

 slcli -y subnet create private 8 1555093
 #slcli subnet create --test private 8 1555093

 sleep 3

done
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?